diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index 46e316c4716..ae2bedd933f 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -113,6 +113,12 @@ abstract public class BrowserApp extends GeckoApp public int parent; } + // The types of guest mdoe dialogs we show + private static enum GuestModeDialog { + ENTERING, + LEAVING + } + private Vector mAddonMenuItemsCache; private PropertyAnimator mMainLayoutAnimator; @@ -1755,18 +1761,55 @@ abstract public class BrowserApp extends GeckoApp addPrivateTab(); return true; case R.id.enter_guest_mode: - doRestart("--guest-mode"); - System.exit(0); + showGuestModeDialog(GuestModeDialog.ENTERING); return true; case R.id.exit_guest_mode: - doRestart(); - System.exit(0); + showGuestModeDialog(GuestModeDialog.LEAVING); return true; default: return super.onOptionsItemSelected(item); } } + private void showGuestModeDialog(final GuestModeDialog type) { + final Prompt ps = new Prompt(this, new Prompt.PromptCallback() { + @Override + public void onPromptFinished(String result) { + try { + int itemId = new JSONObject(result).getInt("button"); + if (itemId == 0) { + String args = ""; + if (type == GuestModeDialog.ENTERING) { + args = "--guest-mode"; + } + doRestart(args); + System.exit(0); + } + } catch(JSONException ex) { + Log.e(LOGTAG, "Exception reading guest mode prompt result", ex); + } + } + }); + + Resources res = getResources(); + ps.setButtons(new String[] { + res.getString(R.string.guest_mode_dialog_continue), + res.getString(R.string.guest_mode_dialog_cancel) + }); + + int titleString = 0; + int msgString = 0; + if (type == GuestModeDialog.ENTERING) { + titleString = R.string.guest_mode_enter_title; + msgString = R.string.guest_mode_enter_text; + } else { + titleString = R.string.guest_mode_leave_title; + msgString = R.string.guest_mode_leave_text; + } + + ps.show(res.getString(titleString), res.getString(msgString), null, false); + } + /** * This will detect if the key pressed is back. If so, will show the history. */ diff --git a/mobile/android/base/Prompt.java b/mobile/android/base/Prompt.java index 79137026381..5a29ec553f6 100644 --- a/mobile/android/base/Prompt.java +++ b/mobile/android/base/Prompt.java @@ -75,7 +75,6 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis private static int mInputPaddingSize; private static int mMinRowSize; - public Prompt(Context context, ConcurrentLinkedQueue queue) { this(context); mCallback = null; @@ -212,6 +211,14 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis mDialog.show(); } + public void setButtons(String[] buttons) { + mButtons = buttons; + } + + public void setInputs(PromptInput[] inputs) { + mInputs = inputs; + } + @Override public void onClick(DialogInterface aDialog, int aWhich) { ThreadUtils.assertOnUiThread(); diff --git a/mobile/android/base/locales/en-US/android_strings.dtd b/mobile/android/base/locales/en-US/android_strings.dtd index 5ec329072d2..ecc8965a5eb 100644 --- a/mobile/android/base/locales/en-US/android_strings.dtd +++ b/mobile/android/base/locales/en-US/android_strings.dtd @@ -352,5 +352,12 @@ just addresses the organization to follow, e.g. "This site is run by " --> - - + + + + + + + + + diff --git a/mobile/android/base/strings.xml.in b/mobile/android/base/strings.xml.in index 184066a4103..c39ea22154c 100644 --- a/mobile/android/base/strings.xml.in +++ b/mobile/android/base/strings.xml.in @@ -323,4 +323,11 @@ &enter_guest_mode; &exit_guest_mode; + &guest_mode_dialog_continue; + &guest_mode_dialog_cancel; + &guest_mode_enter_title; + &guest_mode_enter_text; + + &guest_mode_leave_title; + &guest_mode_leave_text;