Sha256: aa20dbeee2cb1f096c4f56f0e07f0c25482d52c28c111880f6c81bb36c56c292

Contents?: true

Size: 1.66 KB

Versions: 23

Compression:

Stored size: 1.66 KB

Contents

package com.rhomobile.rhodes;

import java.util.HashMap;
import java.util.Map;

import android.view.Menu;
import android.view.MenuItem;

public class RhoMenu {
	
	private static final String TAG = "Menu";
	
	private static class Item
	{
		public String type;
		public String url;
		
		public Item(String t, String u) {
			type = t;
			url = u;
		}
	};
	
	private Map<MenuItem, Item> items;

	private native long allocMenu();
	private native void deallocMenu(long menu);
	
	private native int getMenuSize(long menu);
	private native String getMenuItemLabel(long menu, int index);
	private native String getMenuItemType(long menu, int index);
	private native String getMenuItemUrl(long menu, int index);
	
	public RhoMenu(Menu menu) {
		menu.clear();
		items = new HashMap<MenuItem, Item>();
		
		long m = allocMenu();
		for (int i = 0, lim = getMenuSize(m); i < lim; ++i) {
			String type = getMenuItemType(m, i);
			String url = getMenuItemUrl(m, i);
			String label = getMenuItemLabel(m, i);
			if (type.equalsIgnoreCase("unknown"))
				continue;
			
			MenuItem item = menu.add(label);
			items.put(item, new Item(type, url));
		}
		deallocMenu(m);
	}
	
	public boolean onMenuItemSelected(MenuItem item) {
		Object obj = items.get(item);
		if (obj == null || !(obj instanceof Item)) {
			Logger.E(TAG, "Unknown MenuItem");
			return false;
		}
		
		Item ri = (Item)obj;
		
		String type = ri.type;
		if (type.equalsIgnoreCase("log"))
			RhodesService.showLogView();
		else if (type.equalsIgnoreCase("logOptions"))
			RhodesService.showLogOptions();
		else {
			String url = ri.type;
			if (url.equalsIgnoreCase("url"))
				url = ri.url;
			RhodesService.loadUrl(url);
		}
		
		return true;
	}
	
}

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rhodes-3.0.2 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.2.beta.1 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.1 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.1.beta.8 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.1.beta.7 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.1.beta.6 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.1.beta.5 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.1.beta.4 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.1.beta.3 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.1.beta.2 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.0 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.0.beta.7 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.0.beta.6 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.0.beta.5 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.0.beta.4 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.0.beta.3 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.0.beta.2 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-3.0.0.beta.1 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-2.4.1 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java
rhodes-2.4.1.beta.1 platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java