Titanium JIRA Archive
Alloy (ALOY)

[ALOY-994] Add <ActionBar> tag to set activity.actionBar properties

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2014-11-26T02:21:26.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.5.0
ComponentsXML
Labelsqe-manualtest
ReporterTim Poulsen
AssigneeTim Poulsen
Created2014-04-25T17:22:16.000+0000
Updated2014-11-26T02:21:26.000+0000

Description

Implement a parser for an tag to provide functionality like that implemented in ALOY-784. Don't remove features enabled by ALOY-784. Will also require a docs update and a sample app. Possible implementation:
<Alloy>
  <Window>
    <ActionBar id="actionbar" title="My App Title" subtitle="App subtitle" .../>
  </Window>
</Alloy>
* - This tag would be valid as a child of Window or TabGroup and should throw a compiler error if placed elsewhere. * - It would be an empty tag with no valid children (actionBar properties would be set via tag attributes). * - If both and are present, the last-defined property would win. * - Because this tag is valid for only Android, there should be no requirement to include the platform="" attribute. This would match the behavior of the tag. * - If an ID is supplied, the developer should be able to modify activity.actionBar properties at runtime, such as changing the title, with a reference to $.actionbarID.propertyname * - Must support all the properties currently supported by http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Android.ActionBar

Comments

  1. Tim Poulsen 2014-04-25

    Should also support new properties added in TIMOB-16212
  2. Tim Poulsen 2014-06-30

    Possible implementation options:

    ActionBar and Menu as separate tags

    Order shouldn't matter. Both tags are children of Window. *Pros:* - clear that these are separate controls (which they are at SDK level) - thus clear that you can use one or the other or both - simplest to implement within Alloy and easy to document - likewise relatively simple for developers to implement in their apps *Cons:* - Seems like extra code - Visually, the menu is part of the ActionBar, thus is probably conceptually related for many developers
       <Alloy>
         <Window>
           <ActionBar 
             title="My App Title" 
             subtitle="App subtitle"
             displayHomeAsUp=true
             icon="/images/icon.png" />
           <Menu id="menu" platform="android">
             <MenuItem id="saveitem" title="Save" icon="item1.png" onClick="doSave" />
             <MenuItem id="closeitem" title="Close" icon="item1.png" onClick="doClose" />
           </Menu>
         </Window>
       </Alloy>
       

    ActionBar properties become properties of the Window, but Menu is a separate tag

    *Pros:* - Titles and such are properties of Window on iOS, so putting them as properties for Android makes sense - Clear that the menu is a separately-added component *Cons:* - To later change these properties, you need a handle to the Activity. We'll need to define a way for developers to hook into this activity in their controllers -- perhaps $.index.activity would be logical? - Adds platform-specific properties to a cross-platform tag, which could cause developer confusion - This would be a bit more difficult to document given that our docs are organized by API and we're adding properties at the Alloy level that aren't there at the SDK level - Need to account for cases when ti.android.useLegacyWindow is set to true in the tiapp.xml (until the option for lightweight windows is fully removed). Adds an SDK version dependency.
       <Alloy>
         <Window
           title="My App Title" 
           subtitle="App subtitle"
           displayHomeAsUp=true
           icon="/images/icon.png">
           <Menu id="menu" platform="android">
             <MenuItem id="saveitem" title="Save" icon="item1.png" onClick="doSave" />
             <MenuItem id="closeitem" title="Close" icon="item1.png" onClick="doClose" />
           </Menu>
         </Window>
       </Alloy>
       

    Menu as child of ActionBar

    *Pros:* - Probably conceptually clear to developers given that visually, the menu is part of the ActionBar *Cons:* - Again, we'd need to expose a hook to the activity and menu in the controller so the developer can reset menu items (when a TabGroup is involved and the developer needs different menus on different tabs). - Maintains the current platform differences for Window titles (e.g. on iOS, title is a property of the Window) - Would we maintain the tag for situations where a developer doesn't want to set ActionBar properties but does want a menu?
       <Alloy>
         <Window>
           <ActionBar 
             title="My App Title" 
             subtitle="App subtitle"
             displayHomeAsUp=true
             icon="/images/icon.png">
               <MenuItem id="saveitem" title="Save" icon="item1.png" onClick="doSave" />
               <MenuItem id="closeitem" title="Close" icon="item1.png" onClick="doClose" />
           </ActionBar>
         </Window>
       </Alloy>
       
  3. Tony Lukasavage 2014-06-30

    Seems to me that option #1 would be best, if only because it would give us the ability to add #3 in the future and maintain backwards compatiblity. I don't like #2. Adding APIs to comopnents should be an absolute last resort.
  4. Rick Blalock 2014-06-30

    Def. no on #2. #1 and #3 both make sense to me. I'm assuming you'll generate the onCreate when the activity open event fires and all that...what happens when I want to put stuff in the activity onCreate and such in addition to what you'll auto put in there for me?
  5. Tim Poulsen 2014-06-30

    Another possibility, taking future features into account:

    Activity tag with Menu and BottomBar as children

       <Alloy>
         <Window>
         	<Activity
             title="My App Title" 
             subtitle="App subtitle"
             displayHomeAsUp=true
             icon="/images/icon.png" />
             <ActionView .../> <!-- future support for this -->
             <Menu id="menu" platform="android">
               <MenuItem id="saveitem" title="Save" icon="item1.png" onClick="doSave" />
               <MenuItem id="closeitem" title="Close" icon="item4.png" onClick="doClose" />
             </Menu>
             <BottomBar> <!-- future support for split actionbars -->
               <MenuItem id="foo" title="Foo" icon="item3.png" onClick="doFoo" />
               <MenuItem id="bar" title="Bar" icon="item4.png" onClick="doBar" />
             </BottomBar>
           </Activity>
         </Window>
       </Alloy>
       
  6. Stephen Feather 2014-06-30

    Hell no to #2 Liking #1 Would tolerate #3 but will bitz about it to you everyday.
  7. Feon Sua Xin Miao 2014-07-02

    (y) #1
  8. Tim Poulsen 2014-07-03

    PR https://github.com/appcelerator/alloy/pull/470 Test app: https://github.com/skypanther/alloy/blob/ALOY-994/test/apps/testing/ALOY-994 Functional test: run the associated sample app in the Android emulator, Genymotion, or on a device. The app should feature a customized ActionBar with title and subtitle, background image, and icon. Open the menu, choose 'option 2' to open the child window. It also has a customized actionBar. Tap the home icon to close the child window. [~fmiao] would you please test before I merge?
  9. Feon Sua Xin Miao 2014-07-04

    Tested on Nexus 4 with provided test app, it works fine! (y)
  10. Tim Poulsen 2014-07-04

    PR merged
  11. Federico Casali 2014-08-13

    Verified working as expected on Nexus Galaxy 4.3 and Sony Xperia 2.3.4 - Genymotion 2.3.7 and 4.3. TiSDK 3.4.0.v20140808101714 Appcelerator Studio 3.3.1.201408080925 Alloy 1.5.0-dev Note: With the sample code provided, MenuItems are not visible on Android 2.3.X devices. On 2.3.X devices, MenuItem has to be set in this way:
        "MenuItem":{
        	showAsAction: Ti.Android.SHOW_AS_ACTION_IF_ROOM
        }
        
    This is also valid for Classic Titanium projects when using Menu in the ActionBar.
  12. Tim Poulsen 2014-08-19

    Two pull requests: https://github.com/appcelerator/alloy/pull/513 against the 1_5_X branch https://github.com/appcelerator/alloy/pull/512 against master Both implement the same fix. Functional test 1. Run the included ALOY\-994b test app for Android. This app contains a tab group with a customized actionbar and menu. One of the menu options opens a child window, which also has a customized actionbar. The app should run without errors. 2. Run the ALOY\-994 test app, which sets a customized actionbar with just a window (no tab group)
  13. Feon Sua Xin Miao 2014-08-20

    **APPROVED**
  14. Feon Sua Xin Miao 2014-08-20

    PR merged
  15. Federico Casali 2014-08-20

    Description regarding how to access to the activity property should be changed. This bullet should be removed as accessing to the activity is actually done in a different way. See for example ALOY-994b sample code, in win2.js:
        $.win2.addEventListener('open', function() {
        	if($.win2.activity) {
        		$.win2.activity.actionBar.title = "Child window";
        	}
        });
        
  16. Federico Casali 2014-11-26

    Verified working as expected with the provided samples. TiSDK 3.5.0.v20141124092514 CLI 3.4.1-GA Alloy 1.5.1-GA Appceleator Studio 3.4.1.201410281743 Android Nexus 5 (Android 5)

JSON Source