Skip to content

Commit

Permalink
Merge pull request #335 from skypanther/ALOY-784
Browse files Browse the repository at this point in the history
[ALOY-784] Implement Titanium.Android.ActionBar properties in <Menu>
  • Loading branch information
skypanther committed Apr 21, 2014
2 parents afb9cad + cf87892 commit 6d196d7
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Alloy/commands/compile/compilerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ exports.getParserArgs = function(node, state, opts) {
var attrName = attr.nodeName;
if (_.contains(attrs, attrName)) { return; }
var matches = attrName.match(RESERVED_EVENT_REGEX);
if (matches !== null && exports.isNodeForCurrentPlatform(node)) {
if (matches !== null && exports.isNodeForCurrentPlatform(node) && attrName !== 'onHomeIconItemSelected') {
events.push({
name: U.lcfirst(matches[1]),
value: node.getAttribute(attrName)
Expand Down
24 changes: 24 additions & 0 deletions Alloy/commands/compile/parsers/Ti.Android.Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ function parse(node, state, args) {
});
});

// ALOY-784, support Activity properties as attributes of <Menu>
var menuTssStyles = _.filter(state.styles, function(elem) {
// generate a list of style defined in the TSS file
return elem.key == node.getAttribute('id');
}),
xmlStyles = {
title: node.getAttribute('title') ? node.getAttribute('title') : undefined,
backgroundImage: node.getAttribute('backgroundImage') ? node.getAttribute('backgroundImage') : undefined,
displayHomeAsUp: node.getAttribute('displayHomeAsUp') ? node.getAttribute('displayHomeAsUp') : undefined,
icon: node.getAttribute('icon') ? node.getAttribute('icon') : undefined,
logo: node.getAttribute('logo') ? node.getAttribute('logo') : undefined,
navigationMode: node.getAttribute('navigationMode') ? node.getAttribute('navigationMode') : undefined,
onHomeIconItemSelected: node.getAttribute('onHomeIconItemSelected') ? node.getAttribute('onHomeIconItemSelected') : undefined
};
if(menuTssStyles[0].style) {
_.defaults(xmlStyles, menuTssStyles[0].style);
}
if(xmlStyles.title) { code += state.parent.symbol + '.activity.actionBar.title = "' + xmlStyles.title + '";'; }
if(xmlStyles.backgroundImage) { code += state.parent.symbol + '.activity.actionBar.backgroundImage = "' + xmlStyles.backgroundImage + '";'; }
if(xmlStyles.displayHomeAsUp) { code += state.parent.symbol + '.activity.actionBar.displayHomeAsUp = ' + xmlStyles.displayHomeAsUp + ';'; }
if(xmlStyles.icon) { code += state.parent.symbol + '.activity.actionBar.icon = "' + xmlStyles.icon + '";'; }
if(xmlStyles.logo) { code += state.parent.symbol + '.activity.actionBar.logo = "' + xmlStyles.logo + '";'; }
if(xmlStyles.navigationMode) { code += state.parent.symbol + '.activity.actionBar.navigationMode = ' + xmlStyles.navigationMode + ';'; }
if(xmlStyles.onHomeIconItemSelected) { code += state.parent.symbol + '.activity.actionBar.onHomeIconItemSelected = ' + xmlStyles.onHomeIconItemSelected + ';'; }
// Update the parsing state
return {
parent: {},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions test/apps/testing/ALOY-784/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function doClick() {
alert('label clicked');
}
function doMenuClick() {
alert('menu clicked');
}

$.index.open();
24 changes: 24 additions & 0 deletions test/apps/testing/ALOY-784/styles/index.tss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
".container": {
},
"MenuItem": {
showAsAction: Ti.Android.SHOW_AS_ACTION_ALWAYS
},
"#item1": {
title: "One"
},
"#item2": {
title: "Two",
icon: Ti.Android.R.drawable.ic_menu_share
},

"Label": {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#fff"
}
"menu": {
title: "My Menu",
icon: "/actionicon.png",
displayHomeAsUp: true,
backgroundImage: "/actionbackground.png"
}
9 changes: 9 additions & 0 deletions test/apps/testing/ALOY-784/views/index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Alloy>
<Window class="container" title="My Test App">
<Menu id="menu" platform="android" title="My XML Menu" onHomeIconItemSelected="doMenuClick">
<MenuItem id="item1" title="One" onClick="doMenuClick" />
<MenuItem id="item2" title="Two" onClick="doMenuClick" />
</Menu>
<Label id="label" onClick="doClick">Hello, World</Label>
</Window>
</Alloy>

0 comments on commit 6d196d7

Please sign in to comment.