Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #470 from skypanther/ALOY-994
[ALOY-994] Add ActionBar tag to set actionBar properties
- Loading branch information
Showing
20 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
var _ = require('../../../lib/alloy/underscore')._, | ||
U = require('../../../utils'), | ||
CU = require('../compilerUtils'), | ||
CONST = require('../../../common/constants'), | ||
logger = require('../../../logger'); | ||
|
||
exports.parse = function(node, state) { | ||
return require('./base').parse(node, state, parse); | ||
}; | ||
|
||
function parse(node, state, args) { | ||
var eventObject = 'e', | ||
code = '', | ||
xmlStyles = {}, | ||
actionBarProperties = ['title', 'subtitle', 'backgroundImage', 'displayHomeAsUp', 'homeButtonEnabled', 'icon', 'logo', 'navigationMode', 'onHomeIconItemSelected']; | ||
|
||
// if this isn't android, generate no code, but show a warning | ||
var config = CU.getCompilerConfig(), | ||
platform = config && config.alloyConfig ? config.alloyConfig.platform : undefined; | ||
if (platform !== 'android') { | ||
if (node.getAttribute('platform') !== 'android') { | ||
logger.warn([ | ||
'<Activity> is only available in Android', | ||
'To get rid of this warning, add platform="android" to your <Activity> element' | ||
]); | ||
} | ||
return { | ||
parent: {}, | ||
styles: state.styles, | ||
code: '' | ||
}; | ||
} | ||
|
||
var activityTssStyles = _.filter(state.styles, function(elem) { | ||
// generates a sorted array of styles filtered to include only elements | ||
// associated with the activity (by ID, class, or API name) | ||
return elem.key === node.getAttribute('id') || elem.key === node.getAttribute('class') || elem.key === node.nodeName; | ||
}); | ||
// create an object holding all the actionBar-related properties set in the XML | ||
_.each(actionBarProperties, function(prop) { | ||
if(node.hasAttribute(prop)) { | ||
xmlStyles[prop] = node.getAttribute(prop); | ||
} | ||
}) | ||
// to respect proper style hierarchy, take the last element in the array (which will be the highest priority) | ||
var activityTssKey = _.isArray(activityTssStyles) ? activityTssStyles.length-1 : 0; | ||
if(activityTssStyles[activityTssKey] && activityTssStyles[activityTssKey].style) { | ||
_.defaults(xmlStyles, activityTssStyles[activityTssKey].style); | ||
} | ||
// generate the template code | ||
if((_.filter(_.values(xmlStyles), function(val) { return val !== undefined; })).length > 0) { | ||
if(xmlStyles.title) { code += state.parent.symbol + '.activity.actionBar.title = "' + xmlStyles.title + '";'; } | ||
if(xmlStyles.subtitle) { code += state.parent.symbol + '.activity.actionBar.subtitle = "' + xmlStyles.subtitle + '";'; } | ||
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.homeButtonEnabled) { code += state.parent.symbol + '.activity.actionBar.homeButtonEnabled = ' + xmlStyles.homeButtonEnabled + ';'; } | ||
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, and process the template | ||
return { | ||
parent: {}, | ||
styles: state.styles, | ||
code: U.evaluateTemplate('Ti.Android.ActionBar.js', { | ||
parent: state.parent.symbol || CONST.PARENT_SYMBOL_VAR, | ||
code: code, | ||
eventObject: eventObject, | ||
openFunc: CU.generateUniqueId() | ||
}) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function <%= openFunc %>() { | ||
<%= parent %>.removeEventListener('open', <%= openFunc %>); | ||
if (<%= parent %>.activity) { | ||
<%= code %> | ||
} else { | ||
Ti.API.warn('You attempted to access an Activity on a lightweight Window or other'); | ||
Ti.API.warn('UI component which does not have an Android activity. Android Activities'); | ||
Ti.API.warn('are valid with only windows in TabGroups or heavyweight Windows.'); | ||
} | ||
} | ||
<%= parent %>.addEventListener('open', <%= openFunc %>); |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"sourcemap": false, | ||
"adapters": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function doClick(e) { | ||
alert(e.source.title); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
$.win2.addEventListener('open', function() { | ||
if($.win2.activity) { | ||
$.win2.activity.actionBar.title = "Child window"; | ||
} | ||
}); | ||
|
||
function doHomeIcon(e) { | ||
$.win2.close(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function doClick(e) { | ||
alert(e.source.title); | ||
} | ||
|
||
function openWin2(e) { | ||
Alloy.createController('win2').getView().open(); | ||
} | ||
|
||
$.index.open(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"Window": { | ||
backgroundColor: '#000' | ||
} | ||
|
||
"Label": { | ||
color: '#fff', | ||
font: { | ||
fontSize: '18dp', | ||
fontWeight: 'bold' | ||
}, | ||
height: Ti.UI.SIZE, | ||
width: Ti.UI.SIZE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"#index": { | ||
modal: false, | ||
exitOnClose: true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'#win2': { | ||
modal: false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Alloy> | ||
<Window> | ||
<ActionBar | ||
title="My App Title" | ||
subtitle="App subtitle" | ||
icon="/actionicon.png" | ||
backgroundImage="/actionbackground.png" /> | ||
<!-- This will add an Android menu --> | ||
<Menu title="Title from menu"> | ||
<MenuItem title="option 1" icon="/ic_menu_help.png" onClick="doClick"/> | ||
<MenuItem title="option 2" icon="/ic_menu_home.png" onClick="openWin2"/> | ||
</Menu> | ||
|
||
<!-- Build the rest of your UI as usual --> | ||
<Label>Window 1</Label> | ||
<Label bottom="20dp">Press the menu button</Label> | ||
</Window> | ||
</Alloy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<Alloy> | ||
<Menu> | ||
<MenuItem title="require 1" icon="/ic_menu_goto.png" onClick="doClick"/> | ||
<MenuItem title="require 2" icon="/ic_menu_manage.png" onClick="doClick"/> | ||
</Menu> | ||
</Alloy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Alloy> | ||
<Window id="win2"> | ||
<!-- actionbar title set in the win2.js file --> | ||
<ActionBar | ||
icon="/actionicon.png" | ||
displayHomeAsUp="true" | ||
onHomeIconItemSelected="doHomeIcon" | ||
backgroundImage="/actionbackground.png" /> | ||
<Require src="menu"/> | ||
|
||
<!-- Build the rest of your UI as usual --> | ||
<Label>Window 2</Label> | ||
<Label bottom="20dp">Press the menu button</Label> | ||
</Window> | ||
</Alloy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<Alloy> | ||
<Window> | ||
<!-- ActionBar/Menu code is in views/android/index.xml --> | ||
<Label>ActionBar/Menu only supported on Android</Label> | ||
</Window> | ||
</Alloy> |