Bug 896117 - Add enter and exit dialogs for guest mode. r=margaret

This commit is contained in:
Wes Johnston 2013-07-26 09:14:04 -07:00
parent 2e45a9aaf4
commit c8bee97f32
4 changed files with 71 additions and 7 deletions

View File

@ -113,6 +113,12 @@ abstract public class BrowserApp extends GeckoApp
public int parent; public int parent;
} }
// The types of guest mdoe dialogs we show
private static enum GuestModeDialog {
ENTERING,
LEAVING
}
private Vector<MenuItemInfo> mAddonMenuItemsCache; private Vector<MenuItemInfo> mAddonMenuItemsCache;
private PropertyAnimator mMainLayoutAnimator; private PropertyAnimator mMainLayoutAnimator;
@ -1755,18 +1761,55 @@ abstract public class BrowserApp extends GeckoApp
addPrivateTab(); addPrivateTab();
return true; return true;
case R.id.enter_guest_mode: case R.id.enter_guest_mode:
doRestart("--guest-mode"); showGuestModeDialog(GuestModeDialog.ENTERING);
System.exit(0);
return true; return true;
case R.id.exit_guest_mode: case R.id.exit_guest_mode:
doRestart(); showGuestModeDialog(GuestModeDialog.LEAVING);
System.exit(0);
return true; return true;
default: default:
return super.onOptionsItemSelected(item); 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. * This will detect if the key pressed is back. If so, will show the history.
*/ */

View File

@ -75,7 +75,6 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
private static int mInputPaddingSize; private static int mInputPaddingSize;
private static int mMinRowSize; private static int mMinRowSize;
public Prompt(Context context, ConcurrentLinkedQueue<String> queue) { public Prompt(Context context, ConcurrentLinkedQueue<String> queue) {
this(context); this(context);
mCallback = null; mCallback = null;
@ -212,6 +211,14 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
mDialog.show(); mDialog.show();
} }
public void setButtons(String[] buttons) {
mButtons = buttons;
}
public void setInputs(PromptInput[] inputs) {
mInputs = inputs;
}
@Override @Override
public void onClick(DialogInterface aDialog, int aWhich) { public void onClick(DialogInterface aDialog, int aWhich) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();

View File

@ -352,5 +352,12 @@ just addresses the organization to follow, e.g. "This site is run by " -->
<!ENTITY updater_apply_select2 "Touch to update"> <!ENTITY updater_apply_select2 "Touch to update">
<!-- Guest mode --> <!-- Guest mode -->
<!ENTITY enter_guest_mode "Enter Guest Mode"> <!ENTITY enter_guest_mode "Enter guest mode">
<!ENTITY exit_guest_mode "Exit Guest Mode"> <!ENTITY exit_guest_mode "Leave guest mode">
<!ENTITY guest_mode_dialog_continue "Continue">
<!ENTITY guest_mode_dialog_cancel "Cancel">
<!ENTITY guest_mode_enter_title "Guest mode">
<!ENTITY guest_mode_enter_text "While in guest mode, the person using &brandShortName; will not be able to see any of your personal browsing data (like your saved passwords, history or bookmarks).\n\nWhen your guest is done, their browsing data will be deleted.">
<!ENTITY guest_mode_leave_title "Leaving guest mode">
<!ENTITY guest_mode_leave_text "&brandShortName; will delete browsing data from this session.">

View File

@ -323,4 +323,11 @@
<!-- Guest mode --> <!-- Guest mode -->
<string name="enter_guest_mode">&enter_guest_mode;</string> <string name="enter_guest_mode">&enter_guest_mode;</string>
<string name="exit_guest_mode">&exit_guest_mode;</string> <string name="exit_guest_mode">&exit_guest_mode;</string>
<string name="guest_mode_dialog_continue">&guest_mode_dialog_continue;</string>
<string name="guest_mode_dialog_cancel">&guest_mode_dialog_cancel;</string>
<string name="guest_mode_enter_title">&guest_mode_enter_title;</string>
<string name="guest_mode_enter_text">&guest_mode_enter_text;</string>
<string name="guest_mode_leave_title">&guest_mode_leave_title;</string>
<string name="guest_mode_leave_text">&guest_mode_leave_text;</string>
</resources> </resources>