[TIMOB-11602] Android: Expose activity.invalidateOptionsMenu to allow changing action items in Android 3.0 and above
| GitHub Issue | n/a |
|---|---|
| Type | New Feature |
| Priority | High |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2014-08-15T21:13:54.000+0000 |
| Affected Version/s | Release 3.0.0 |
| Fix Version/s | Release 3.0.0, Release 3.1.0, 2012 Sprint 23 Core, 2012 Sprint 23 |
| Components | Android |
| Labels | 3.0.0beta2, module_android, qe-automation, qe-port, triage |
| Reporter | Arthur Evans |
| Assignee | Allen Yeung |
| Created | 2012-10-29T21:24:17.000+0000 |
| Updated | 2014-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.
Test Steps: 1. Add the following entry into your Tiapp.xml:
2. Run the code snippet:<android xmlns:android="http://schemas.android.com/apk/res/android"> <manifest> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14"/> </manifest> </android>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.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();PR: https://github.com/appcelerator/titanium_mobile/pull/3369
3.X PR: https://github.com/appcelerator/titanium_mobile/pull/3414
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)
Reopening to add label.