diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index 285c2407c33a..4da419fcd681 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -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; diff --git a/mobile/android/base/GeckoAppShell.java b/mobile/android/base/GeckoAppShell.java index 08cf09891baa..430421eb5999 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -64,7 +64,6 @@ public class GeckoAppShell new LinkedList(); 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 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(); } diff --git a/mobile/android/base/PromptService.java b/mobile/android/base/PromptService.java index b1115cbdcd30..125664426f0e 100644 --- a/mobile/android/base/PromptService.java +++ b/mobile/android/base/PromptService.java @@ -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");