| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.preferences; | 5 package org.chromium.chrome.browser.preferences; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.res.Resources; | 8 import android.content.res.Resources; |
| 9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
| 10 import android.graphics.drawable.BitmapDrawable; | 10 import android.graphics.drawable.BitmapDrawable; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * A preference that displays "Sign in to Chrome" when the user is not sign in,
and displays | 33 * A preference that displays "Sign in to Chrome" when the user is not sign in,
and displays |
| 34 * the user's name, email, profile image and sync error icon if necessary when t
he user is signed | 34 * the user's name, email, profile image and sync error icon if necessary when t
he user is signed |
| 35 * in. | 35 * in. |
| 36 */ | 36 */ |
| 37 public class SignInPreference extends Preference | 37 public class SignInPreference extends Preference |
| 38 implements SignInAllowedObserver, ProfileDownloader.Observer, | 38 implements SignInAllowedObserver, ProfileDownloader.Observer, |
| 39 AndroidSyncSettings.AndroidSyncSettingsObserver, SyncStateCha
ngedListener { | 39 AndroidSyncSettings.AndroidSyncSettingsObserver, SyncStateCha
ngedListener { |
| 40 private boolean mViewEnabled; | 40 private boolean mViewEnabled; |
| 41 private boolean mShowingPromo; |
| 41 | 42 |
| 42 /** | 43 /** |
| 43 * Constructor for inflating from XML. | 44 * Constructor for inflating from XML. |
| 44 */ | 45 */ |
| 45 public SignInPreference(Context context, AttributeSet attrs) { | 46 public SignInPreference(Context context, AttributeSet attrs) { |
| 46 super(context, attrs); | 47 super(context, attrs); |
| 47 update(); | 48 update(); |
| 48 } | 49 } |
| 49 | 50 |
| 50 /** | 51 /** |
| (...skipping 26 matching lines...) Expand all Loading... |
| 77 } | 78 } |
| 78 } | 79 } |
| 79 | 80 |
| 80 /** | 81 /** |
| 81 * Updates the title, summary, and image based on the current sign-in state. | 82 * Updates the title, summary, and image based on the current sign-in state. |
| 82 */ | 83 */ |
| 83 private void update() { | 84 private void update() { |
| 84 String accountName = ChromeSigninController.get().getSignedInAccountName
(); | 85 String accountName = ChromeSigninController.get().getSignedInAccountName
(); |
| 85 if (SigninManager.get(getContext()).isSigninDisabledByPolicy()) { | 86 if (SigninManager.get(getContext()).isSigninDisabledByPolicy()) { |
| 86 setupSigninDisabled(); | 87 setupSigninDisabled(); |
| 88 mShowingPromo = false; |
| 87 } else if (accountName == null) { | 89 } else if (accountName == null) { |
| 88 setupNotSignedIn(); | 90 setupNotSignedIn(); |
| 91 |
| 92 if (!mShowingPromo) { |
| 93 // This user action should be recorded when message with sign-in
prompt is shown |
| 94 RecordUserAction.record("Signin_Impression_FromSettings"); |
| 95 } |
| 96 mShowingPromo = true; |
| 89 } else { | 97 } else { |
| 90 setupSignedIn(accountName); | 98 setupSignedIn(accountName); |
| 99 mShowingPromo = false; |
| 91 } | 100 } |
| 92 | 101 |
| 93 setOnPreferenceClickListener(new OnPreferenceClickListener() { | 102 setOnPreferenceClickListener(new OnPreferenceClickListener() { |
| 94 @Override | 103 @Override |
| 95 public boolean onPreferenceClick(Preference preference) { | 104 public boolean onPreferenceClick(Preference preference) { |
| 96 return AccountSigninActivity.startIfAllowed( | 105 return AccountSigninActivity.startIfAllowed( |
| 97 getContext(), SigninAccessPoint.SETTINGS); | 106 getContext(), SigninAccessPoint.SETTINGS); |
| 98 } | 107 } |
| 99 }); | 108 }); |
| 100 | |
| 101 if (accountName == null && SigninManager.get(getContext()).isSignInAllow
ed()) { | |
| 102 RecordUserAction.record("Signin_Impression_FromSettings"); | |
| 103 } | |
| 104 } | 109 } |
| 105 | 110 |
| 106 private void setupSigninDisabled() { | 111 private void setupSigninDisabled() { |
| 107 setTitle(R.string.sign_in_to_chrome); | 112 setTitle(R.string.sign_in_to_chrome); |
| 108 setSummary(R.string.sign_in_to_chrome_summary); | 113 setSummary(R.string.sign_in_to_chrome_summary); |
| 109 setFragment(null); | 114 setFragment(null); |
| 110 setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId()); | 115 setIcon(ManagedPreferencesUtils.getManagedByEnterpriseIconId()); |
| 111 setWidgetLayoutResource(0); | 116 setWidgetLayoutResource(0); |
| 112 setViewEnabled(false); | 117 setViewEnabled(false); |
| 113 } | 118 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 AccountManagementFragment.updateUserNamePictureCache(accountId, fullName
, bitmap); | 190 AccountManagementFragment.updateUserNamePictureCache(accountId, fullName
, bitmap); |
| 186 update(); | 191 update(); |
| 187 } | 192 } |
| 188 | 193 |
| 189 // AndroidSyncSettings.AndroidSyncSettingsObserver | 194 // AndroidSyncSettings.AndroidSyncSettingsObserver |
| 190 @Override | 195 @Override |
| 191 public void androidSyncSettingsChanged() { | 196 public void androidSyncSettingsChanged() { |
| 192 update(); | 197 update(); |
| 193 } | 198 } |
| 194 } | 199 } |
| OLD | NEW |