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

Unified Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/preferences/MainPreferences.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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: chrome/android/java_staging/src/org/chromium/chrome/browser/preferences/MainPreferences.java
diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/preferences/MainPreferences.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/preferences/MainPreferences.java
new file mode 100644
index 0000000000000000000000000000000000000000..50e4d829d4b6ca1e3f06f69419f51b6f6c047a63
--- /dev/null
+++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/preferences/MainPreferences.java
@@ -0,0 +1,253 @@
+// Copyright 2015 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.chrome.browser.preferences;
+
+import android.content.Context;
+import android.os.Handler;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.PreferenceFragment;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+
+import com.google.android.apps.chrome.R;
+
+import org.chromium.chrome.browser.PasswordUIView;
+import org.chromium.chrome.browser.autofill.PersonalDataManager;
+import org.chromium.chrome.browser.bookmarkimport.AndroidBrowserImporter;
+import org.chromium.chrome.browser.bookmarkimport.ImportBookmarksAlertDialog;
+import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
+import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
+import org.chromium.chrome.browser.preferences.bandwidth.BandwidthReductionPreferences;
+import org.chromium.chrome.browser.signin.AccountAdder;
+import org.chromium.chrome.browser.signin.AddGoogleAccountDialogFragment;
+import org.chromium.chrome.browser.signin.AddGoogleAccountDialogFragment.AddGoogleAccountListener;
+import org.chromium.chrome.browser.signin.SigninManager;
+import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver;
+import org.chromium.chrome.browser.sync.ui.ChooseAccountFragment;
+import org.chromium.chrome.browser.util.FeatureUtilities;
+import org.chromium.sync.signin.AccountManagerHelper;
+import org.chromium.sync.signin.ChromeSigninController;
+
+/**
+ * The main settings screen, shown when the user first opens Settings.
+ */
+public class MainPreferences extends PreferenceFragment implements SignInStateObserver {
+
+ public static final String PREF_SIGN_IN = "sign_in";
+ public static final String PREF_DOCUMENT_MODE = "document_mode";
+ public static final String PREF_AUTOFILL_SETTINGS = "autofill_settings";
+ public static final String PREF_SAVED_PASSWORDS = "saved_passwords";
+ public static final String PREF_HOMEPAGE = "homepage";
+ public static final String PREF_REDUCE_DATA_USAGE = "reduce_data_usage";
+
+ public static final String ACCOUNT_PICKER_DIALOG_TAG = "account_picker_dialog_tag";
+
+ private SignInPreference mSignInPreference;
+ private ManagedPreferenceDelegate mManagedPreferenceDelegate;
+
+ public MainPreferences() {
+ setHasOptionsMenu(true);
+ mManagedPreferenceDelegate = createManagedPreferenceDelegate();
+ }
+
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ if (getActivity() == null) return;
+
+ AndroidBrowserImporter androidBrowserImporter = new AndroidBrowserImporter(getActivity());
+ if (androidBrowserImporter.areBookmarksAccessible()) {
+ menu.add(Menu.NONE, R.id.menu_id_import_bookmarks, Menu.NONE,
+ R.string.import_bookmarks);
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == R.id.menu_id_import_bookmarks) {
+ ImportBookmarksAlertDialog importBookmarksFragment =
+ new ImportBookmarksAlertDialog();
+ importBookmarksFragment.show(getFragmentManager(), null);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ SigninManager.get(getActivity()).addSignInStateObserver(this);
+ updatePreferences();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ SigninManager.get(getActivity()).removeSignInStateObserver(this);
+ unregisterSignInPref();
+ }
+
+ private void updatePreferences() {
+ if (getPreferenceScreen() != null) getPreferenceScreen().removeAll();
+ addPreferencesFromResource(R.xml.main_preferences);
+
+ registerSignInPref();
+ mSignInPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ if (!ChromeSigninController.get(getActivity()).isSignedIn()) {
+ displayAccountPicker();
+ return true;
+ }
+ return false;
+ }
+ });
+
+ Preference documentMode = findPreference(PREF_DOCUMENT_MODE);
+ if (FeatureUtilities.isDocumentModeEligible(getActivity())) {
+ setOnOffSummary(documentMode,
+ !DocumentModeManager.getInstance(getActivity()).isOptedOutOfDocumentMode());
+ } else {
+ getPreferenceScreen().removePreference(documentMode);
+ }
+
+ ChromeBasePreference autofillPref =
+ (ChromeBasePreference) findPreference(PREF_AUTOFILL_SETTINGS);
+ setOnOffSummary(autofillPref, PersonalDataManager.isAutofillEnabled());
+ autofillPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
+
+ ChromeBasePreference passwordsPref =
+ (ChromeBasePreference) findPreference(PREF_SAVED_PASSWORDS);
+ if (PasswordUIView.shouldUseSmartLockBranding()) {
+ passwordsPref.setTitle(getResources().getString(
+ R.string.prefs_smart_lock_for_passwords));
+ }
+ setOnOffSummary(passwordsPref,
+ PrefServiceBridge.getInstance().isRememberPasswordsEnabled());
+ passwordsPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
+
+ Preference homepagePref = findPreference(PREF_HOMEPAGE);
+ if (HomepageManager.shouldShowHomepageSetting()) {
+ setOnOffSummary(homepagePref,
+ HomepageManager.getInstance(getActivity()).getPrefHomepageEnabled());
+ } else {
+ getPreferenceScreen().removePreference(homepagePref);
+ }
+
+ ChromeBasePreference bandwidthReduction =
+ (ChromeBasePreference) findPreference(PREF_REDUCE_DATA_USAGE);
+ if (DataReductionProxySettings.getInstance().isDataReductionProxyAllowed()) {
+ bandwidthReduction.setSummary(
+ BandwidthReductionPreferences.generateSummary(getResources()));
+ bandwidthReduction.setManagedPreferenceDelegate(mManagedPreferenceDelegate);
+ } else {
+ getPreferenceScreen().removePreference(bandwidthReduction);
+ }
+ }
+
+ private void setOnOffSummary(Preference pref, boolean isOn) {
+ pref.setSummary(getResources().getString(isOn ? R.string.text_on : R.string.text_off));
+ }
+
+ private void registerSignInPref() {
+ unregisterSignInPref();
+ mSignInPreference = (SignInPreference) findPreference(PREF_SIGN_IN);
+ mSignInPreference.registerForUpdates();
+ }
+
+ private void unregisterSignInPref() {
+ if (mSignInPreference != null) {
+ mSignInPreference.unregisterForUpdates();
+ mSignInPreference = null;
+ }
+ }
+
+ /**
+ * Displays the account picker or the add account dialog and signs the user in.
+ */
+ private void displayAccountPicker() {
+ Context context = getActivity();
+ if (context == null) return;
+
+ if (!SigninManager.get(context).isSignInAllowed()) {
+ if (SigninManager.get(context).isSigninDisabledByPolicy()) {
+ ManagedPreferencesUtils.showManagedByAdministratorToast(context);
+ }
+ return;
+ }
+
+ if (AccountManagerHelper.get(context).hasGoogleAccounts()) {
+ ChooseAccountFragment chooserFragment = new ChooseAccountFragment();
+ chooserFragment.show(getFragmentManager(), ACCOUNT_PICKER_DIALOG_TAG);
+ } else {
+ AddGoogleAccountDialogFragment dialog = new AddGoogleAccountDialogFragment();
+ dialog.setListener(new AddGoogleAccountListener() {
+ @Override
+ public void onAddAccountClicked() {
+ AccountAdder.getInstance().addAccount(MainPreferences.this,
+ AccountAdder.ADD_ACCOUNT_RESULT);
+ }
+ });
+ dialog.show(getFragmentManager(), null);
+ }
+ }
+
+ // SignInStateObserver
+
+ @Override
+ public void onSignedIn() {
+ // After signing in or out of a managed account, preferences may change or become enabled
+ // or disabled.
+ new Handler().post(new Runnable() {
+ @Override
+ public void run() {
+ updatePreferences();
+ }
+ });
+ }
+
+ @Override
+ public void onSignedOut() {
+ updatePreferences();
+ }
+
+ private ManagedPreferenceDelegate createManagedPreferenceDelegate() {
+ return new ManagedPreferenceDelegate() {
+ @Override
+ public boolean isPreferenceControlledByPolicy(Preference preference) {
+ if (PREF_AUTOFILL_SETTINGS.equals(preference.getKey())) {
+ return PersonalDataManager.isAutofillManaged();
+ }
+ if (PREF_SAVED_PASSWORDS.equals(preference.getKey())) {
+ return PrefServiceBridge.getInstance().isRememberPasswordsManaged();
+ }
+ if (PREF_REDUCE_DATA_USAGE.equals(preference.getKey())) {
+ return DataReductionProxySettings.getInstance().isDataReductionProxyManaged();
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isPreferenceClickDisabledByPolicy(Preference preference) {
+ if (PREF_AUTOFILL_SETTINGS.equals(preference.getKey())) {
+ return PersonalDataManager.isAutofillManaged()
+ && !PersonalDataManager.isAutofillEnabled();
+ }
+ if (PREF_SAVED_PASSWORDS.equals(preference.getKey())) {
+ PrefServiceBridge prefs = PrefServiceBridge.getInstance();
+ return prefs.isRememberPasswordsManaged()
+ && !prefs.isRememberPasswordsEnabled();
+ }
+ if (PREF_REDUCE_DATA_USAGE.equals(preference.getKey())) {
+ DataReductionProxySettings settings = DataReductionProxySettings.getInstance();
+ return settings.isDataReductionProxyManaged()
+ && !settings.isDataReductionProxyEnabled();
+ }
+ return super.isPreferenceClickDisabledByPolicy(preference);
+ }
+ };
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698