Bug 752905 - Move the Prompt:Show handler out of handleGeckoMessage. r=margaret

This commit is contained in:
Kartikaya Gupta 2012-06-13 17:12:15 -04:00
Родитель 86e7241aae
Коммит 35fcc0a8cc
3 изменённых файлов: 30 добавлений и 27 удалений

Просмотреть файл

@ -102,6 +102,7 @@ abstract public class GeckoApp
private GeckoConnectivityReceiver mConnectivityReceiver;
private GeckoBatteryManager mBatteryReceiver;
private PromptService mPromptService;
public static DoorHangerPopup mDoorHangerPopup;
public static FormAssistPopup mFormAssistPopup;
@ -1855,6 +1856,8 @@ abstract public class GeckoApp
mConnectivityReceiver = new GeckoConnectivityReceiver();
mConnectivityReceiver.registerFor(mAppContext);
mPromptService = new PromptService();
GeckoNetworkManager.getInstance().init();
GeckoNetworkManager.getInstance().start();
@ -2455,7 +2458,7 @@ abstract public class GeckoApp
}
public void run() {
GeckoAppShell.getPromptService().Show(mTitle, "", null, mItems, false);
mPromptService.Show(mTitle, "", null, mItems, false);
}
private String mTitle;

Просмотреть файл

@ -64,7 +64,6 @@ public class GeckoAppShell
new LinkedList<GeckoEvent>();
static private boolean gRestartScheduled = false;
static private PromptService gPromptService = null;
static private GeckoInputConnection mInputConnection = null;
@ -1833,22 +1832,6 @@ public class GeckoAppShell
final JSONObject geckoObject = json.getJSONObject("gecko");
String type = geckoObject.getString("type");
if (type.equals("Prompt:Show")) {
getHandler().post(new Runnable() {
public void run() {
getPromptService().processMessage(geckoObject);
}
});
String promptServiceResult = "";
try {
promptServiceResult = PromptService.waitForReturn();
} catch (InterruptedException e) {
Log.i(LOGTAG, "showing prompt ", e);
}
return promptServiceResult;
}
CopyOnWriteArrayList<GeckoEventListener> listeners;
synchronized (mEventListeners) {
listeners = mEventListeners.get(type);
@ -1884,13 +1867,6 @@ public class GeckoAppShell
GeckoBatteryManager.disableNotifications();
}
public static PromptService getPromptService() {
if (gPromptService == null) {
gPromptService = new PromptService();
}
return gPromptService;
}
public static double[] getCurrentBatteryInformation() {
return GeckoBatteryManager.getCurrentInformation();
}

Просмотреть файл

@ -41,7 +41,7 @@ import org.json.JSONArray;
import org.json.JSONObject;
import android.text.InputType;
public class PromptService implements OnClickListener, OnCancelListener, OnItemClickListener {
public class PromptService implements OnClickListener, OnCancelListener, OnItemClickListener, GeckoEventResponder {
private static final String LOGTAG = "GeckoPromptService";
private PromptInput[] mInputs;
@ -81,6 +81,8 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC
mIconSize = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
ICON_SIZE,
res.getDisplayMetrics());
GeckoAppShell.registerGeckoEventListener("Prompt:Show", this);
}
private class PromptButton {
@ -172,6 +174,28 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC
}
}
// GeckoEventListener implementation
public void handleMessage(String event, final JSONObject message) {
GeckoAppShell.getHandler().post(new Runnable() {
public void run() {
processMessage(message);
}
});
}
// GeckoEventResponder implementation
public String getResponse() {
// we only handle one kind of message in handleMessage, and this is the
// response we provide for that message
String promptServiceResult = "";
try {
promptServiceResult = waitForReturn();
} catch (InterruptedException e) {
Log.i(LOGTAG, "showing prompt ", e);
}
return promptServiceResult;
}
public void Show(String aTitle, String aText, PromptButton[] aButtons, PromptListItem[] aMenuList, boolean aMultipleSelection) {
AlertDialog.Builder builder = new AlertDialog.Builder(GeckoApp.mAppContext);
if (!aTitle.equals("")) {
@ -318,7 +342,7 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC
} catch(Exception ex) { }
}
public void processMessage(JSONObject geckoObject) {
private void processMessage(JSONObject geckoObject) {
String title = "";
try {
title = geckoObject.getString("title");