Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11642] Android: Enable click event listeners for app icon/app logo in action bar

GitHub Issuen/a
TypeSub-task
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-11-13T22:05:31.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsactionbar, qe-testadded
ReporterAllen Yeung
AssigneeAllen Yeung
Created2012-11-02T00:31:41.000+0000
Updated2014-06-19T12:42:51.000+0000

Description

We need to be able to add click event listeners to the app icon button inside the action bar. According the action docs, we would need to handle it in the onOptionsItemSelected() method. http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems

Comments

  1. Allen Yeung 2012-11-05

    Test case: 1. Set your target sdk version to 14 by adding the entry if 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 following code:
       var win = Ti.UI.createWindow({
       	fullscreen : true
       });
       
       win.addEventListener('open', function(){
       	var actionBar = win.activity.actionBar;
       	actionBar.onHomeIconItemSelected = function() {
       		Ti.API.info('-------------------Home Icon Selected');
       	}
       });
       
       win.open();
       
    3. Click on the app logo on the top left, and you should see the log message pop up in the logs This needs to be tested in v8 and rhino.
  2. Igor Santos 2012-11-15

    Is it possible to add the event this way too?
       win.activity.actionBar.addEventListener('homeIconItemSelected', function() { })
       
    I couldn't find in the 3.0 docs yet about the ActionBar object, sorry if I'm being too fast.
  3. Allen Yeung 2012-11-15

    No, we currently don't support anything like that. You need to add a handler onHomeIconItemSelected as shown above.
  4. Igor Santos 2012-11-15

    Ok, thanks!
  5. Igor Santos 2012-11-15

    I tried to add it to my code now. The log command worked just fine, and also worked opening a new window. Although, I tried to run an alert() and fire another event in the same window when the App Icon was clicked, and the application crashed.
  6. Arthur Evans 2012-11-19

    Allen, This property is missing from ActionBar.yml.
  7. Paras Mishra 2013-03-08

    Added the testcase for it.
  8. Paras Mishra 2013-03-21

    Clicking on App icon on actionBar. '-------------------Home Icon Selected' is logged on the console. Verifed on: Device : Google Nexus 7, Android Version: 4.1 SDK version: 3.1.0.v20130320190115 CLI version : 3.0.24 OS : MAC OSX 10.7.5

JSON Source