Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3179] Android: Tab icons should support resource ids

GitHub Issuen/a
TypeNew Feature
PriorityTrivial
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T02:01:07.000+0000
Affected Version/sn/a
Fix Version/sSprint-2011-08
ComponentsAndroid
Labelsandroid, feature, release-1.7.0, reported-1.5.1, rplist
ReporterBill Dawson
AssigneeDon Thorp
Created2011-04-15T03:38:53.000+0000
Updated2011-04-17T02:01:07.000+0000

Description

Now that we expose Ti.Android.R we should allow resource ids instead of paths to the icon property of tabs.

Excerpt from http://developer.appcelerator.com/helpdesk/view/73511">HD:

I've put a {root}/platform/android/res/drawable directory in place.

In there I've put in a state-list-drawable XML file for each of my tabs following the naming convention "ic_tab_tabName1.xml"

I've then put in corresponding {root}/platform/android/res/drawable-{ldpi/mdpi/hdpi} directories with appropriately sized icons for both the selected and unselected states.

Then when I create the tab, my call looks something like this:

var tab1 = Titanium.UI.createTab({
    icon:Titanium.Android.R.drawable.ic_tab_tabName1,
    title:'Tab 1',
    window:win1
});
 
tabGroup.add(tab1);

So, this doesn't work... At runtime I get an exception like this:

[TRACE] E/TiUncaughtHandler( 429): java.lang.ClassCastException: org.appcelerator.titanium.proxy.RProxy
[TRACE] E/TiUncaughtHandler( 429): at ti.modules.titanium.ui.TabGroupProxy.addTabToGroup(TabGroupProxy.java:163)

Comments

  1. Jean-Etienne LaVallee 2011-04-15

    Thanks for reporting this, Bill. I'm also wondering if there should be an over-all assessment of the entire API to address all the various properties where @drawable resources could/should be allowed as values (and correspondingly, properly resolved in the native layer)?

    Also, I've noticed in an app I'm currently working on that if I do use Ti.Android.R.xxx I receive an "no such method for [undefined]" javascript error in iOS EVEN IF I go through the trouble of using a Ti.Platform.osname-based resolver (e.g. like the tt.os utility method in the Tweetanium app). This totally makes sense since the whole Ti.Android.xxx namespace is unresolved in the iOS build configuration.

    BUT, this makes coding much more complicated because I have to revert back to encapsulating such references in their own include files and then doing conditional-wrapped Ti.Platform.osname switching. Is there any way we can make this more graceful w/r/t supporting multi-target app development?

    Thanks,
    Etienne

  2. Bill Dawson 2011-04-15

    Yes, we're looking at it for the whole api.

    Re your other problem: be sure to put it in Helpdesk so our Support guys can try to help you.

  3. Bill Dawson 2011-04-15

    Test Case for QE:

    • Use this app.js:
       Titanium.UI.setBackgroundColor('#000');
       var tabGroup = Titanium.UI.createTabGroup();
       var win1 = Titanium.UI.createWindow({  
           title:"Tab 1 with icon",
           backgroundColor:'#fff'
       });
       var tab1 = Titanium.UI.createTab({  
           icon:Ti.App.Android.R.drawable.ic_tab1,
           title:"Tab 1 with icon",
           window:win1
       });
       win1.add(Ti.UI.createLabel({text: 'Win1'}));
       
       var win2 = Titanium.UI.createWindow({  
           title:'Tab 2 no icon',
           backgroundColor:'#fff'
       });
       var tab2 = Titanium.UI.createTab({  
           title:'Tab 2 no icon',
           window:win2
       });
       win2.add(Ti.UI.createLabel({text: 'Win2'}));
       
       tabGroup.addTab(tab1);  
       tabGroup.addTab(tab2);  
       tabGroup.open();
       
    • From the project's root folder, create the folder platform/android/res/drawable.

    • Plop the two .pngs here -- selected.png & unselected.png -- into the platform/android/res/drawable folder.

    • Save the following xml as platform/android/res/drawable/ic_tab1.xml:

       <?xml version="1.0" encoding="utf-8"?>
       <selector xmlns:android="http://schemas.android.com/apk/res/android">
           <item android:drawable="@drawable/selected" android:state_pressed="false" android:state_selected="true"/>
           <item android:drawable="@drawable/unselected"/>
       </selector>
       
    • Run the app.

    In the "old" version (pre-commit), the app will crash immediately. If you look at logcat you will see a ClassCastException similar to:

       E/AndroidRuntime( 1434): java.lang.ClassCastException: java.lang.Integer
       E/AndroidRuntime( 1434):    at ti.modules.titanium.ui.TabGroupProxy.addTabToGroup(TabGroupProxy.java:163)
       

    With the post-commit version, you should see that the first tab has a bird icon when selected, and a star icon when not selected (i.e., when the other tab is selected).

  4. Don Thorp 2011-04-15

    removed tbs-1.7.0 added release-1.7.0

  5. Bill Dawson 2011-04-15

    don't know why this didn't get updated with my commits. Here they are:

    https://github.com/appcelerator/titanium_mobile/commit/dddf612e49194b97f1522fc53e3c3ea22a842dd5"> https://github.com/appcelerator/titanium_mobile/commit/dddf612e4919...

    https://github.com/appcelerator/titanium_mobile/commit/979a1c50a695a03a442be2446c411835ac39148d"> https://github.com/appcelerator/titanium_mobile/commit/979a1c50a695...

  6. Natalie Huynh 2011-04-15

    Tested with Titanium SDK version: 1.7.0 (03/01/11 16:09 e613126)
    GalaxyTab 2.2
    Emulator 2.1

JSON Source