Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(539)

Unified Diff: blimp/client/core/android/java/src/org/chromium/blimp/core/settings/AboutBlimpPreferences.java

Issue 2173563003: Blimp settings UI integration for Chrome, everything still lives in Blimp. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add v7 support jar in Blimp build.gn, to make trybot happy. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: blimp/client/core/android/java/src/org/chromium/blimp/core/settings/AboutBlimpPreferences.java
diff --git a/blimp/client/core/android/java/src/org/chromium/blimp/core/settings/AboutBlimpPreferences.java b/blimp/client/core/android/java/src/org/chromium/blimp/core/settings/AboutBlimpPreferences.java
new file mode 100644
index 0000000000000000000000000000000000000000..d0d8c7d0e92fadf3168b4bb6c9ed59ee5b9e93c8
--- /dev/null
+++ b/blimp/client/core/android/java/src/org/chromium/blimp/core/settings/AboutBlimpPreferences.java
@@ -0,0 +1,136 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.blimp.core.settings;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceFragment;
+import android.preference.PreferenceScreen;
+import android.support.v7.app.AlertDialog;
+
+import org.chromium.blimp.R;
+import org.chromium.blimp_public.BlimpSettingsCallbacks;
+
+// import org.chromium.chrome.browser.ApplicationLifetime;
David Trainor- moved to gerrit 2016/07/22 16:51:42 ?
xingliu 2016/07/23 23:50:36 Done.
+
+/**
+ * Blimp preferences page in Chrome.
+ */
+public class AboutBlimpPreferences extends PreferenceFragment {
+
+ public static final String PREF_BLIMP_SWITCH = "blimp_switch";
+ private static final String PREF_ASSIGNER_URL = "blimp_assigner_url";
David Trainor- moved to gerrit 2016/07/22 16:51:42 Public as well. And javadocs for both :). Or hel
xingliu 2016/07/23 23:50:36 Done.
+
+ private static BlimpSettingsCallbacks sSettingsCallback;
+
+ /**
+ * Attach the blimp setting preferences to a {@link PreferenceFragment}.
+ * @param fragment The fragment that blimp setting attach to.
+ */
+ public static void addBlimpPreferences(PreferenceFragment fragment) {
+ PreferenceScreen screen = fragment.getPreferenceScreen();
+
+ Preference blimpSetting = new Preference(fragment.getActivity());
+ blimpSetting.setTitle(R.string.blimp_about_blimp_preferences);
+ blimpSetting.setFragment(AboutBlimpPreferences.class.getName());
+ blimpSetting.setKey(AboutBlimpPreferences.PREF_BLIMP_SWITCH);
+
+ screen.addPreference(blimpSetting);
+ fragment.setPreferenceScreen(screen);
+ }
+
+ /**
+ * Register Chrome callback related to Blimp settings.
+ * @param callback
+ */
+ public static void registerCallback(BlimpSettingsCallbacks callback) {
+ sSettingsCallback = callback;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getActivity().setTitle(R.string.blimp_about_blimp_preferences);
+ addPreferencesFromResource(R.xml.blimp_preferences);
+
+ setupBlimpSwitch();
+ setupAssignerPreferences();
+ }
+
+ /**
+ * Setup the switch preference for blimp.
+ */
+ private void setupBlimpSwitch() {
+ // An alternative is to use {@link ChromeSwitchPreference}.
David Trainor- moved to gerrit 2016/07/22 16:51:42 Can you add a TODO and a bug for when this is move
xingliu 2016/07/23 23:50:36 Done.
+ final Preference pref = findPreference(PREF_BLIMP_SWITCH);
+
+ pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ // For blimp client 0.6, if blimp switch changed, show restart
+ // dialog.
+ // TODO(xingliu): Figure out if we need to close all tabs before restart.
+ showRestartDialog(getActivity(), R.string.blimp_switch_changed_please_restart);
+ return true;
+ }
+ });
+ }
+
+ /**
+ * When the user taps on the current assigner, a list of available assigners pops up.
+ * User is allowed to change the assigner which is saved to shared preferences.
+ * A dialog is displayed which prompts the user to restart the application.
+ */
+ private void setupAssignerPreferences() {
+ final Activity activity = getActivity();
+
+ final ListPreference lp = (ListPreference) findPreference(PREF_ASSIGNER_URL);
+ lp.setSummary(lp.getValue());
+
+ lp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ String newAssignmentUrl = (String) newValue;
+ lp.setSummary(newAssignmentUrl);
+ showRestartDialog(activity, R.string.blimp_assigner_changed_please_restart);
+ return true;
+ }
+ });
+ }
+
+ /**
+ * Show restart browser dialog.
+ * @param context The context where we display the restart browser dialog.
+ * @param message The message shown to the user.
+ */
+ private static void showRestartDialog(final Context context, int message) {
+ new AlertDialog.Builder(context)
+ .setTitle(R.string.blimp_restart_blimp)
+ .setMessage(message)
+ .setPositiveButton(R.string.blimp_restart_now,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ restartBrowser(context);
+ }
+ })
+ .create()
+ .show();
+ }
+
+ /**
+ * Restart the browser.
+ * @param context The context of restart application dialog.
+ */
+ private static void restartBrowser(Context context) {
David Trainor- moved to gerrit 2016/07/22 16:51:42 Do we need the context?
xingliu 2016/07/23 23:50:36 Done.
+ if (sSettingsCallback != null) {
+ sSettingsCallback.onRestartBrowserRequested();
David Trainor- moved to gerrit 2016/07/22 16:51:42 Just to confirm, there's no way to avoid restartin
xingliu 2016/07/23 23:50:36 Not sure why we need undo the preferences, is it s
David Trainor- moved to gerrit 2016/07/27 17:31:34 I just meant the restart dialog (and subsequent re
xingliu 2016/07/27 23:52:04 Oh, restart will be triggered only if user clicks
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698