mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 973013 - Pull PromptListItem into its own class. r=bnicholson
This commit is contained in:
parent
0ef8752074
commit
ed8c72de46
@ -41,6 +41,7 @@ import org.mozilla.gecko.home.SearchEngine;
|
|||||||
import org.mozilla.gecko.menu.GeckoMenu;
|
import org.mozilla.gecko.menu.GeckoMenu;
|
||||||
import org.mozilla.gecko.preferences.GeckoPreferences;
|
import org.mozilla.gecko.preferences.GeckoPreferences;
|
||||||
import org.mozilla.gecko.prompts.Prompt;
|
import org.mozilla.gecko.prompts.Prompt;
|
||||||
|
import org.mozilla.gecko.prompts.PromptListItem;
|
||||||
import org.mozilla.gecko.sync.setup.SyncAccounts;
|
import org.mozilla.gecko.sync.setup.SyncAccounts;
|
||||||
import org.mozilla.gecko.toolbar.AutocompleteHandler;
|
import org.mozilla.gecko.toolbar.AutocompleteHandler;
|
||||||
import org.mozilla.gecko.toolbar.BrowserToolbar;
|
import org.mozilla.gecko.toolbar.BrowserToolbar;
|
||||||
|
@ -298,6 +298,7 @@ gbjar.sources += [
|
|||||||
'prompts/IconGridInput.java',
|
'prompts/IconGridInput.java',
|
||||||
'prompts/Prompt.java',
|
'prompts/Prompt.java',
|
||||||
'prompts/PromptInput.java',
|
'prompts/PromptInput.java',
|
||||||
|
'prompts/PromptListItem.java',
|
||||||
'prompts/PromptService.java',
|
'prompts/PromptService.java',
|
||||||
'ReaderModeUtils.java',
|
'ReaderModeUtils.java',
|
||||||
'ReferrerReceiver.java',
|
'ReferrerReceiver.java',
|
||||||
|
@ -433,7 +433,7 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
|
|||||||
} catch(Exception ex) { }
|
} catch(Exception ex) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
PromptListItem[] menuitems = getListItemArray(geckoObject, "listitems");
|
PromptListItem[] menuitems = PromptListItem.getArray(geckoObject.optJSONArray("listitems"));
|
||||||
mSelected = getBooleanArray(geckoObject, "selected");
|
mSelected = getBooleanArray(geckoObject, "selected");
|
||||||
boolean multiple = geckoObject.optBoolean("multiple");
|
boolean multiple = geckoObject.optBoolean("multiple");
|
||||||
show(title, text, menuitems, multiple);
|
show(title, text, menuitems, multiple);
|
||||||
@ -474,48 +474,6 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
|
|||||||
return list;
|
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 interface PromptCallback {
|
||||||
public void onPromptFinished(String jsonResult);
|
public void onPromptFinished(String jsonResult);
|
||||||
}
|
}
|
||||||
|
59
mobile/android/base/prompts/PromptListItem.java
Normal file
59
mobile/android/base/prompts/PromptListItem.java
Normal file
@ -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);
|
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) {
|
final boolean aMultipleSelection, final Prompt.PromptCallback callback) {
|
||||||
// The dialog must be created on the UI thread.
|
// The dialog must be created on the UI thread.
|
||||||
ThreadUtils.postToUiThread(new Runnable() {
|
ThreadUtils.postToUiThread(new Runnable() {
|
||||||
|
Loading…
Reference in New Issue
Block a user