Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11602] Android: Expose activity.invalidateOptionsMenu to allow changing action items in Android 3.0 and above

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-08-15T21:13:54.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 3.0.0, Release 3.1.0, 2012 Sprint 23 Core, 2012 Sprint 23
ComponentsAndroid
Labels3.0.0beta2, module_android, qe-automation, qe-port, triage
ReporterArthur Evans
AssigneeAllen Yeung
Created2012-10-29T21:24:17.000+0000
Updated2014-08-15T21:13:54.000+0000

Description

As described in http://developer.android.com/guide/topics/ui/menus.html#ChangingTheMenu, to change menu items (action items) in 3.0 and above, we'd need to expose the invalidateOptionsMenu method.

Comments

  1. Allen Yeung 2012-11-01

    Test Steps: 1. Add the following entry into your Tiapp.xml:
           <android xmlns:android="http://schemas.android.com/apk/res/android">
               <manifest>
                   <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14"/>
               </manifest>
           </android>
       
    2. Run the code snippet:
       var win = Ti.UI.createWindow({
       	fullscreen : true
       });
       var LOGIN = 1, LOGOUT = 2;
       var loggedIn = false;
       
       var activity = win.activity;
       
       activity.onCreateOptionsMenu = function(e) {
       	var menu = e.menu;
       	var login = menu.add({
       		title : "Login",
       		itemId : LOGIN
       	});
       	login.setIcon("login.png");
       	login.addEventListener("click", function(e) {
       		loggedIn = true;
       		win.activity.invalidateOptionsMenu();
       	});
       	login.showAsAction = Ti.Android.SHOW_AS_ACTION_ALWAYS;
       	var logout = menu.add({
       		title : "Logout",
       		itemId : LOGOUT
       	});
       	logout.setIcon("logout.png");
       
       	logout.addEventListener("click", function(e) {
       		loggedIn = false;
       		win.activity.invalidateOptionsMenu();
       	}); 
       
       	logout.showAsAction = Ti.Android.SHOW_AS_ACTION_ALWAYS;
       };
       
       activity.onPrepareOptionsMenu = function(e) {
       	var menu = e.menu;
       	menu.findItem(LOGIN).setVisible(!loggedIn);
       	menu.findItem(LOGOUT).setVisible(loggedIn);
       };
       
       win.addEventListener('click', function(){
       	win.activity.openOptionsMenu();
       });
       
       win.open(); 
       
    3. Click the login button in the action bar and it should change to logout This should be run on a 2.3 and a 3.0+ devices. When testing on a 2.3 device also click on the window and make sure that the menu bar opens.
  2. Ping Wang 2012-11-12

    PR: https://github.com/appcelerator/titanium_mobile/pull/3369
  3. Allen Yeung 2012-11-13

    3.X PR: https://github.com/appcelerator/titanium_mobile/pull/3414
  4. Tamila Smolich 2012-11-13

    Closing as fixed. Expected behavior is shown. Tested and verified on: Titanium Studio, build: 3.0.0.201211121907 Titanium SDK, builds: 3.0.0.v20121113111657; 3.1.0.v20121112192600 Device: Samsung Galaxy SIII (4.0.4)
  5. Arthur Evans 2012-11-16

    Reopening to add label.

JSON Source