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

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

Issue 1660353002: Update account and sync management UX (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add TODO in comments for an additional task for the bug Created 4 years, 10 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/SyncedAccountPreference.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncedAccountPreference.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncedAccountPreference.java
new file mode 100644
index 0000000000000000000000000000000000000000..9a7f8ff9fe92613900b8c53c4bca72bec681b0fb
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/SyncedAccountPreference.java
@@ -0,0 +1,69 @@
+// 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;
+
+import android.accounts.Account;
+import android.content.Context;
+import android.preference.ListPreference;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+
+import org.chromium.chrome.R;
+import org.chromium.sync.AndroidSyncSettings;
+import org.chromium.sync.signin.AccountManagerHelper;
+import org.chromium.sync.signin.ChromeSigninController;
+
+/**
+ * A preference that displays the account currently being synced and allows the user to choose a new
+ * account to use for syncing
+ */
+public class SyncedAccountPreference extends ListPreference {
+
+ /**
+ * Constructor for inflating from XML
+ */
+ public SyncedAccountPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ setTitle(context.getResources().getString(R.string.sync_to_account_header));
+ updateAccountsList();
+ }
+
+ private void updateAccountsList() {
+ boolean syncEnabled = AndroidSyncSettings.isSyncEnabled(getContext());
+ if (!syncEnabled) {
+ setEnabled(false);
+ return;
+ }
+
+ Account[] accounts = AccountManagerHelper.get(getContext()).getGoogleAccounts();
+ String[] accountNames = new String[accounts.length];
+ String[] accountValues = new String[accounts.length];
+
+ String signedInAccountName =
+ ChromeSigninController.get(getContext()).getSignedInAccountName();
+ String signedInSettingsKey = "";
+
+ for (int i = 0; i < accounts.length; ++i) {
+ Account account = accounts[i];
+ accountNames[i] = account.name;
+ accountValues[i] = account.name;
+ boolean isPrimaryAccount = TextUtils.equals(account.name, signedInAccountName);
+ if (isPrimaryAccount) {
+ signedInSettingsKey = accountValues[i];
+ }
+ }
+
+ setEntries(accountNames);
+ setEntryValues(accountValues);
+ setDefaultValue(signedInSettingsKey);
+ setSummary(signedInAccountName);
+ }
+
+ @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