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

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

Issue 1660353002: Update account and sync management UX (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor formatting changes Created 4 years, 11 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/src/org/chromium/chrome/browser/preferences/SyncAccountListPreference.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncAccountListPreference.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncAccountListPreference.java
new file mode 100644
index 0000000000000000000000000000000000000000..4e9d8af642c5e35be13106c68d767781cafcdc00
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncAccountListPreference.java
@@ -0,0 +1,65 @@
+// 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.chrome.browser.preferences;
newt (away) 2016/02/12 22:03:50 newline before package
+
+import android.accounts.Account;
+import android.content.Context;
+import android.preference.ListPreference;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+
+import org.chromium.sync.AndroidSyncSettings;
+import org.chromium.sync.signin.AccountManagerHelper;
+import org.chromium.sync.signin.ChromeSigninController;
+
+/**
+ * A custom preference that opens a dialog picker to choose an account to use for syncing.
newt (away) 2016/02/12 22:03:50 maybe: "A preference that displays the account tha
May 2016/02/16 17:32:07 Done.
+ */
+public class SyncAccountListPreference extends ListPreference {
newt (away) 2016/02/12 22:03:50 How about calling this "SyncedAccountPreference"?
May 2016/02/16 17:32:07 Done.
+ public SyncAccountListPreference(Context context, AttributeSet attrs) {
newt (away) 2016/02/12 22:03:50 javadoc for all public methods
May 2016/02/16 17:32:07 Done.
+ super(context, attrs);
+ updateAccountsList();
+ }
+
+ private void updateAccountsList() {
+ boolean syncEnabled = AndroidSyncSettings.isSyncEnabled(getContext());
+ if (!syncEnabled) {
+ setEnabled(false);
+ return;
+ }
+
+ Account[] accounts = AccountManagerHelper.get(getContext()).getGoogleAccounts();
+ String[] accountDisplayEntries = new String[accounts.length];
newt (away) 2016/02/12 22:03:50 How about calling this "accountNames", and the var
May 2016/02/16 17:32:07 Done.
+ String[] accountSyncSettingsKeys = new String[accounts.length];
+
+ String signedInAccountName =
+ ChromeSigninController.get(getContext()).getSignedInAccountName();
+ String signedInSettingsKey = "";
+
+ for (int i = 0; i < accounts.length; ++i) {
+ Account account = accounts[i];
+ accountDisplayEntries[i] = account.name;
+ accountSyncSettingsKeys[i] = "sync_setting_" + account.name;
newt (away) 2016/02/12 22:03:50 Do you really need to prefix with "sync_setting"?
May 2016/02/16 17:32:07 No, I suppose not at the moment.
+ boolean isPrimaryAccount = TextUtils.equals(account.name, signedInAccountName);
+ if (isPrimaryAccount) {
+ signedInSettingsKey = accountSyncSettingsKeys[i];
+ }
+ }
+
+ setEntries(accountDisplayEntries);
+ setEntryValues(accountSyncSettingsKeys);
+ setDefaultValue(signedInSettingsKey);
+ setSummary(signedInAccountName);
newt (away) 2016/02/12 22:03:50 Do you need this? I thought the summary was alread
May 2016/02/16 17:32:07 Removed the android:summary entry in the xml
+ }
+
+ public void updateState(boolean enabled) {
newt (away) 2016/02/12 22:03:50 Since this doesn't actually update which account i
May 2016/02/16 17:32:07 When sync is disabled, this becomes disabled as we
+ setEnabled(enabled);
+ }
+
+ @Override
+ protected void onDialogClosed(boolean positiveResult) {
+ super.onDialogClosed(positiveResult);
+ // TODO(crbug/557786): Add switching sync accounts
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698