PageRenderTime 14ms CodeModel.GetById 8ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/titanium/mobile/android/Menu.hx

http://github.com/visup/haxe-titanium-api
Haxe | 147 lines | 19 code | 5 blank | 123 comment | 0 complexity | a0efc52913d5f22ddfa81a616483baed MD5 | raw file
  1package titanium.mobile.android;
  2
  3
  4/**
  5Menu class
  6
  7Documentation available at:
  8http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android.Menu-object
  9
 10- namespace
 11
 12Titanium.Android.Menu
 13
 14- type
 15
 16proxy
 17
 18- description
 19
 20The Titanium binding of an [Android Menu](http://developer.android.com/reference/android/view/Menu.html)
 21
 22- since
 23
 241.5
 25
 26- platforms
 27
 28android
 29
 30- methods
 31add: creates a [[Titanium.Android.MenuItem]] from the passed creation options.
 32clear: clear all items from the menu. You should release all references you have retained to [[Titanium.Android.MenuItem]] previously created.
 33close: close the menu if visible
 34findItem: locate a [[Titanium.Android.MenuItem]]
 35getItem: return the [[Titanium.Android.MenuItem]] at a specific index
 36hasVisibleItems: query for any visible menu items
 37removeGroup: remove all [[Titanium.Android.MenuItem]] with the specified groupId
 38removeItem: remove a specific [[Titanium.Android.MenuItem]] by the specified itemId
 39setGroupEnabled: enable or disable a group of [[Titanium.Android.MenuItem]] by groupId
 40setGroupVisible: show or hide a group of [[Titanium.Android.MenuItem]] by groupId
 41size: number of [[Titanium.Android.MenuItem]] in this menu
 42
 43- method : add, `Titanium.Android.MenuItem`
 44options[object]: creation options. Supported options are itemId, groupId, title, and order.
 45
 46- method : clear
 47
 48- method : close
 49
 50- method : findItem, `Titanium.Android.MenuItem`
 51
 52item[object] : integer itemId or `Titanium.Android.MenuItem`
 53
 54- method : getItem, `Titanium.Android.MenuItem`
 55
 56index[int] :  item at index where index < size()
 57
 58- method : hasVisibleItems, boolean
 59
 60- method : removeGroup
 61
 62groupId[int]: groupId of items to remove.
 63
 64- method : removeItem
 65
 66itemId[int]: itemId of item to remove.
 67
 68- method : setGroupEnabled
 69
 70groupId[int]: groupId to enable or disable
 71enabled[boolean]: true to enable, false to disable.
 72
 73- method : setGroupVisible
 74
 75groupId[int]: groupId to enable or disable
 76visible[boolean]: true to show, false to hide
 77
 78- method : size, int
 79
 80- properties
 81
 82items[array]: array of `Titanium.Android.MenuItem`
 83
 84- example : Simple menu create
 85~~~
 86activity.onCreateOptionsMenu = function(e) {
 87    var menu = e.menu;
 88    var menuItem = menu.add({ title: "Item 1" });
 89    menuItem.setIcon("item1.png");
 90    menuItem.addEventListener("click", function(e) {
 91        Ti.API.debug("I was clicked");
 92    });
 93};
 94~~~
 95
 96- example : Dynamic menu create
 97~~~
 98var win = Ti.UI.createWindow({ fullscreen: true });
 99
100var LOGIN = 1, LOGOUT = 2;
101var loggedIn = false;
102activity.onCreateOptionsMenu = function(e) {
103    var menu = e.menu;
104    var login = menu.add({ title: "Login", itemId: LOGIN });
105    login.setIcon("login.png");
106    login.addEventListener("click", function(e) {
107        loggedIn = true;
108    });
109    var logout = menu.add({ title: "Logout", itemId: LOGOUT });
110    logout.setIcon("logout.png");
111    logout.addEventListener("click", function(e) {
112        loggedIn = false;
113    });
114};
115
116activity.onPrepareOptionsMenu = function(e) {
117    var menu = e.menu;
118    menu.findItem(LOGIN).setVisible(!loggedIn);
119    menu.findItem(LOGOUT).setVisible(loggedIn);
120};
121win.open();
122~~~
123
124**/
125
126#if androidos
127@:native("Titanium.Android.Menu")
128extern class Menu
129{
130	// static methods	
131	public static function add(options:Dynamic):MenuItem;
132	public static function clear():Void;
133	public static function close():Void;
134	public static function findItem(item:Dynamic):MenuItem;
135	public static function getItem(index:Int):MenuItem;
136	public static function hasVisibleItems():Bool;
137	public static function removeGroup(groupId:Int):Void;
138	public static function removeItem(itemId:Int):Void;
139	public static function setGroupEnabled(groupId:Int, enabled:Bool):Void;
140	public static function setGroupVisible(groupId:Int, visible:Bool):Void;
141	public static function size():Int;
142
143	// static properties
144	public static var items:Array<MenuItem>;
145
146}
147#end