Skip to content

Instantly share code, notes, and snippets.

@benbahrenburg
Created January 6, 2012 13:56
Show Gist options
  • Save benbahrenburg/1570731 to your computer and use it in GitHub Desktop.
Save benbahrenburg/1570731 to your computer and use it in GitHub Desktop.
1.8.0.1 & CI Build Android Menu Issue
// This is a test case showing how the Android menu
// no longer works as excepted when using a function return
// similar to how you would return a window from a commonJS module
//
// To cover all test cases please update the
// useApproach variable with a number between 1 and 4
// This will return each of the examples as outlined
// in another Jira ticket located here http://jira.appcelerator.org/browse/TIMOB-6648
//
// Please note at the time of this writing there is no Jira
// ticket for the issue outlined below.
var my={};
my.makeWindow=function(a){
a = a || {};
var win = Ti.UI.createWindow(a);
win.orientationModes = [
Ti.UI.PORTRAIT,
Ti.UI.UPSIDE_PORTRAIT
];
win.fullscreen=false;
return win;
};
//Window builder helper, simulates commonJS return
my.myWindowBuilder=function(winConfig){
var win = my.makeWindow(winConfig);
return win;
};
var winConfig ={
tabBarHidden:true,
navBarHidden:true,
backgroundColor:'#fff'
};
my.win = my.myWindowBuilder(winConfig);
my.win.add(Ti.UI.createLabel({
text: 'Press your Android device\'s menu button!',
color: '#000'
}));
var useApproach = 1;
switch (useApproach) {
case 1:
/*
WORKS in 1.7.5. BROKEN in 1.8.0.1 and 1.9.x CI builds
*/
my.win.open();
Ti.Android.currentActivity.onCreateOptionsMenu = function (e) {
e.menu.add({ title: 'Approach 1', itemId: 1 });
};
break;
case 2:
/*
WORKS in 1.7.5. BROKEN in 1.8.0.1 and 1.9.x CI builds
*/
my.win.open();
my.win.activity.onCreateOptionsMenu = function (e) {
e.menu.add({ title: 'Approach 2', itemId: 2 });
};
break;
case 3:
/*
WORKS in 1.7.5. BROKEN in 1.8.0.1 and 1.9.x CI builds
*/
my.win.activity.onCreateOptionsMenu = function (e) {
e.menu.add({ title: 'Approach 3', itemId: 2 });
};
my.win.open();
break;
case 4:
/*
WORKS in 1.7.5. BROKEN in 1.8.0.1 and 1.9.x CI builds
*/
my.win.addEventListener('open', function (evt) {
my.win.activity.onCreateOptionsMenu = function (e) {
e.menu.add({ title: 'Approach 4', itemId: 3 });
};
});
my.win.open();
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment