зеркало из https://github.com/mozilla/gecko-dev.git
Bug 973013 - Pull PromptListItem into its own class. r=bnicholson
This commit is contained in:
Родитель
61b8d7a32c
Коммит
ed20ea43d5
|
@ -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;
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<PromptListItem> list = new ArrayList<PromptListItem>(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;
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче