[TIMOB-12307] Android: Refactor MenuItemProxy
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-01-18T17:34:25.000+0000 |
Affected Version/s | Release 3.0.0 |
Fix Version/s | Release 3.0.2, Release 3.1.0, 2013 Sprint 02 API, 2013 Sprint 02 |
Components | Android |
Labels | api, module_android, qe-testadded |
Reporter | Hieu Pham |
Assignee | Hieu Pham |
Created | 2013-01-16T15:33:53.000+0000 |
Updated | 2013-01-24T05:49:23.000+0000 |
Description
Starting from API 11, menuItem methods must be run from the main thread, otherwise a Java exception will occur. MenuItemProxy needs to be refactor to address this issue.
Testing code:
var win1 = Ti.UI.createWindow({
backgroundColor: 'blue',
fullscreen: false
});
var tab1 = Ti.UI.createTab({
window: win1,
title: 'Tab 1'
});
var win2 = Ti.UI.createWindow({
backgroundColor: 'yellow'
});
var tab2 = Ti.UI.createTab({
window: win2,
title: 'Tab 2'
});
var tabGroup = Ti.UI.createTabGroup({
activity: {
onCreateOptionsMenu: function(e) {
var menu = e.menu;
var menuItem = menu.add({
title : "Item 1",
itemId: 1
});
var menuItem2 = menu.add({
title : "Item 2",
itemId: 2
});
menuItem.addEventListener("click", function(e) {
Ti.API.info("I was clicked");
});
},
onPrepareOptionsMenu: function(e) {
var menu = e.menu;
if (tab1.active) {
menu.findItem(1).setVisible(false);
var menuItem2 = menu.findItem(2);
menuItem2.setVisible(true);
Ti.API.info("item2 is checked: " + menuItem2.isChecked());
Ti.API.info("item2 is enabled: " + menuItem2.isEnabled());
}
if (tab2.active) {
var menuItem = menu.findItem(1);
menuItem.setVisible(true);
Ti.API.info("item1 is checked: " + menuItem.isChecked());
Ti.API.info("item1 is enabled: " + menuItem.isEnabled());
menu.findItem(2).setVisible(false);
}
}
}
});
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
tabGroup.open();
1. Run app.js
2. Click on menu/optionMenu button: you should see Item 2 in tab1 and Item 1 in tab2. You should also see "is checked" and "is enabled" in logcat.
PR: https://github.com/appcelerator/titanium_mobile/pull/3619 3_0_X PR: https://github.com/appcelerator/titanium_mobile/pull/3740
Tested with: SDK:3.1.0.v20130123144204,3.0.2.v20130123192623 Studio:3.0.1.201212181159 Device: Android Nexus7(v 4.1)