OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.signin; |
| 6 |
| 7 import android.accounts.Account; |
| 8 import android.app.Activity; |
| 9 import android.app.Dialog; |
| 10 import android.content.Intent; |
| 11 import android.os.Bundle; |
| 12 import android.text.TextUtils; |
| 13 import android.view.LayoutInflater; |
| 14 import android.view.View; |
| 15 import android.widget.LinearLayout; |
| 16 |
| 17 import com.google.android.apps.chrome.R; |
| 18 |
| 19 import org.chromium.base.ApplicationStatus; |
| 20 import org.chromium.chrome.browser.ChromiumApplication; |
| 21 import org.chromium.chrome.browser.firstrun.AccountFirstRunView; |
| 22 import org.chromium.chrome.browser.firstrun.ProfileDataCache; |
| 23 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
| 24 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
| 25 import org.chromium.chrome.browser.preferences.Preferences; |
| 26 import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
| 27 import org.chromium.chrome.browser.profiles.Profile; |
| 28 import org.chromium.chrome.browser.signin.SigninManager.SignInFlowObserver; |
| 29 import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment; |
| 30 import org.chromium.sync.signin.AccountManagerHelper; |
| 31 import org.chromium.sync.signin.ChromeSigninController; |
| 32 |
| 33 /** |
| 34 * This class implements the dialog UI for the signin promo. |
| 35 */ |
| 36 public class SigninPromoScreen extends Dialog implements AccountFirstRunView.Lis
tener { |
| 37 |
| 38 private AccountFirstRunView mAccountFirstRunView; |
| 39 |
| 40 /** |
| 41 * Launches the signin promo if it needs to be displayed. |
| 42 * @param activity The parent activity. |
| 43 * @return Whether the signin promo is shown. |
| 44 */ |
| 45 public static boolean launchSigninPromoIfNeeded(final Activity activity) { |
| 46 // The promo is displayed if Chrome is launched directly (i.e., not with
the intent to |
| 47 // navigate to and view a URL on startup), the instance is part of the f
ield trial, |
| 48 // and the promo has been marked to display. |
| 49 ChromePreferenceManager preferenceManager = ChromePreferenceManager.getI
nstance(activity); |
| 50 ChromiumApplication application = |
| 51 (ChromiumApplication) ApplicationStatus.getApplicationContext(); |
| 52 if (application.isMultiWindow(activity)) return false; |
| 53 if (!preferenceManager.getShowSigninPromo()) return false; |
| 54 preferenceManager.setShowSigninPromo(false); |
| 55 |
| 56 String lastSyncName = PrefServiceBridge.getInstance().getSyncLastAccount
Name(); |
| 57 if (SigninManager.getAndroidSigninPromoExperimentGroup() < 0 |
| 58 || ChromeSigninController.get(activity).isSignedIn() |
| 59 || !TextUtils.isEmpty(lastSyncName)) { |
| 60 return false; |
| 61 } |
| 62 |
| 63 SigninPromoScreen promoScreen = new SigninPromoScreen(activity); |
| 64 promoScreen.show(); |
| 65 preferenceManager.setSigninPromoShown(); |
| 66 return true; |
| 67 } |
| 68 |
| 69 /** |
| 70 * SigninPromoScreen constructor. |
| 71 * |
| 72 * @param activity An Android activity. |
| 73 */ |
| 74 private SigninPromoScreen(Activity activity) { |
| 75 super(activity, R.style.SigninPromoDialog); |
| 76 setOwnerActivity(activity); |
| 77 |
| 78 LayoutInflater inflater = LayoutInflater.from(activity); |
| 79 View view = inflater.inflate(R.layout.fre_choose_account, null); |
| 80 ProfileDataCache profileData = new ProfileDataCache(activity, Profile.ge
tLastUsedProfile()); |
| 81 mAccountFirstRunView = (AccountFirstRunView) view.findViewById(R.id.fre_
account_layout); |
| 82 mAccountFirstRunView.init(profileData); |
| 83 mAccountFirstRunView.configureForAddAccountPromo(); |
| 84 mAccountFirstRunView.setListener(this); |
| 85 |
| 86 setContentView(view, new LinearLayout.LayoutParams( |
| 87 LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParam
s.MATCH_PARENT)); |
| 88 } |
| 89 |
| 90 @Override |
| 91 protected void onCreate(Bundle savedInstanceState) { |
| 92 super.onCreate(savedInstanceState); |
| 93 SigninPromoUma.recordAction(SigninPromoUma.SIGNIN_PROMO_SHOWN); |
| 94 } |
| 95 |
| 96 @Override |
| 97 public void onAccountSelectionConfirmed(String accountName) { |
| 98 final Account account = |
| 99 AccountManagerHelper.get(getContext()).getAccountFromName(accoun
tName); |
| 100 SignInFlowObserver signInCallback = new SignInFlowObserver() { |
| 101 @Override |
| 102 public void onSigninComplete() { |
| 103 mAccountFirstRunView.switchToSignedMode(); |
| 104 SigninManager.get(getOwnerActivity()).logInSignedInUser(); |
| 105 SigninPromoUma.recordAction(SigninPromoUma.SIGNIN_PROMO_ACCEPTED
); |
| 106 } |
| 107 |
| 108 @Override |
| 109 public void onSigninCancelled() { |
| 110 SigninPromoUma.recordAction(SigninPromoUma.SIGNIN_PROMO_DECLINED
); |
| 111 dismiss(); |
| 112 } |
| 113 }; |
| 114 SigninManager.get(getOwnerActivity().getApplicationContext()).signInToSe
lectedAccount( |
| 115 getOwnerActivity(), account, SigninManager.SIGNIN_TYPE_INTERACTI
VE, |
| 116 SigninManager.SIGNIN_SYNC_IMMEDIATELY, false, signInCallback); |
| 117 } |
| 118 |
| 119 @Override |
| 120 public void onAccountSelectionCanceled() { |
| 121 SigninPromoUma.recordAction(SigninPromoUma.SIGNIN_PROMO_DECLINED); |
| 122 dismiss(); |
| 123 } |
| 124 |
| 125 @Override |
| 126 public void onNewAccount() { |
| 127 AccountAdder.getInstance().addAccount(getOwnerActivity(), AccountAdder.A
DD_ACCOUNT_RESULT); |
| 128 } |
| 129 |
| 130 @Override |
| 131 public void onSigningInCompleted(String accountName) { |
| 132 dismiss(); |
| 133 } |
| 134 |
| 135 @Override |
| 136 public void onSettingsButtonClicked(String accountName) { |
| 137 Intent intent = PreferencesLauncher.createIntentForSettingsPage(getConte
xt(), |
| 138 SyncCustomizationFragment.class.getName()); |
| 139 Bundle args = new Bundle(); |
| 140 args.putString(SyncCustomizationFragment.ARGUMENT_ACCOUNT, accountName); |
| 141 intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); |
| 142 getContext().startActivity(intent); |
| 143 |
| 144 SigninPromoUma.recordAction(SigninPromoUma.SIGNIN_PROMO_ACCEPTED_WITH_AD
VANCED); |
| 145 dismiss(); |
| 146 } |
| 147 |
| 148 @Override |
| 149 public void onFailedToSetForcedAccount(String forcedAccountName) { |
| 150 assert false : "No forced accounts in SigninPromoScreen"; |
| 151 } |
| 152 } |
OLD | NEW |