diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index b038cf5aa76..5c46706e774 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -41,6 +41,7 @@ import org.mozilla.gecko.home.SearchEngine; import org.mozilla.gecko.menu.GeckoMenu; import org.mozilla.gecko.preferences.GeckoPreferences; import org.mozilla.gecko.prompts.Prompt; +import org.mozilla.gecko.prompts.PromptListItem; import org.mozilla.gecko.sync.setup.SyncAccounts; import org.mozilla.gecko.toolbar.AutocompleteHandler; import org.mozilla.gecko.toolbar.BrowserToolbar; diff --git a/mobile/android/base/moz.build b/mobile/android/base/moz.build index 0c89eb729aa..f5ad395ca24 100644 --- a/mobile/android/base/moz.build +++ b/mobile/android/base/moz.build @@ -298,6 +298,7 @@ gbjar.sources += [ 'prompts/IconGridInput.java', 'prompts/Prompt.java', 'prompts/PromptInput.java', + 'prompts/PromptListItem.java', 'prompts/PromptService.java', 'ReaderModeUtils.java', 'ReferrerReceiver.java', diff --git a/mobile/android/base/prompts/Prompt.java b/mobile/android/base/prompts/Prompt.java index ff83fe96f6b..23f2cfdd802 100644 --- a/mobile/android/base/prompts/Prompt.java +++ b/mobile/android/base/prompts/Prompt.java @@ -433,7 +433,7 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis } catch(Exception ex) { } } - PromptListItem[] menuitems = getListItemArray(geckoObject, "listitems"); + PromptListItem[] menuitems = PromptListItem.getArray(geckoObject.optJSONArray("listitems")); mSelected = getBooleanArray(geckoObject, "selected"); boolean multiple = geckoObject.optBoolean("multiple"); show(title, text, menuitems, multiple); @@ -474,48 +474,6 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis return list; } - private PromptListItem[] getListItemArray(JSONObject aObject, String aName) { - JSONArray items = getSafeArray(aObject, aName); - int length = items.length(); - PromptListItem[] list = new PromptListItem[length]; - for (int i = 0; i < length; i++) { - try { - list[i] = new PromptListItem(items.getJSONObject(i)); - } catch(Exception ex) { } - } - return list; - } - - public static class PromptListItem { - public final String label; - public final boolean isGroup; - public final boolean inGroup; - public final boolean disabled; - public final int id; - public final boolean isParent; - - // This member can't be accessible from JS, see bug 733749. - public Drawable icon; - - PromptListItem(JSONObject aObject) { - label = aObject.optString("label"); - isGroup = aObject.optBoolean("isGroup"); - inGroup = aObject.optBoolean("inGroup"); - disabled = aObject.optBoolean("disabled"); - id = aObject.optInt("id"); - isParent = aObject.optBoolean("isParent"); - } - - public PromptListItem(String aLabel) { - label = aLabel; - isGroup = false; - inGroup = false; - disabled = false; - id = 0; - isParent = false; - } - } - public interface PromptCallback { public void onPromptFinished(String jsonResult); } diff --git a/mobile/android/base/prompts/PromptListItem.java b/mobile/android/base/prompts/PromptListItem.java new file mode 100644 index 00000000000..6430de96ce8 --- /dev/null +++ b/mobile/android/base/prompts/PromptListItem.java @@ -0,0 +1,59 @@ +package org.mozilla.gecko.prompts; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONException; + +import android.graphics.drawable.Drawable; +import java.util.List; +import java.util.ArrayList; + +// This class should die and be replaced with normal menu items +public class PromptListItem { + private static final String LOGTAG = "GeckoPromptListItem"; + public final String label; + public final boolean isGroup; + public final boolean inGroup; + public final boolean disabled; + public final int id; + public boolean isParent; + + public Drawable icon; + + PromptListItem(JSONObject aObject) { + label = aObject.optString("label"); + isGroup = aObject.optBoolean("isGroup"); + inGroup = aObject.optBoolean("inGroup"); + disabled = aObject.optBoolean("disabled"); + id = aObject.optInt("id"); + isParent = aObject.optBoolean("isParent"); + } + + public PromptListItem(String aLabel) { + label = aLabel; + isGroup = false; + inGroup = false; + disabled = false; + id = 0; + isParent = false; + } + + static PromptListItem[] getArray(JSONArray items) { + if (items == null) { + return new PromptListItem[0]; + } + + int length = items.length(); + List list = new ArrayList(length); + for (int i = 0; i < length; i++) { + try { + PromptListItem item = new PromptListItem(items.getJSONObject(i)); + list.add(item); + } catch(Exception ex) { } + } + + PromptListItem[] arrays = new PromptListItem[length]; + list.toArray(arrays); + return arrays; + } +} diff --git a/mobile/android/base/prompts/PromptService.java b/mobile/android/base/prompts/PromptService.java index d4dbc29a2ea..eb3f90a4445 100644 --- a/mobile/android/base/prompts/PromptService.java +++ b/mobile/android/base/prompts/PromptService.java @@ -31,7 +31,7 @@ public class PromptService implements GeckoEventListener { GeckoAppShell.getEventDispatcher().unregisterEventListener("Prompt:ShowTop", this); } - public void show(final String aTitle, final String aText, final Prompt.PromptListItem[] aMenuList, + public void show(final String aTitle, final String aText, final PromptListItem[] aMenuList, final boolean aMultipleSelection, final Prompt.PromptCallback callback) { // The dialog must be created on the UI thread. ThreadUtils.postToUiThread(new Runnable() {