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.app.Activity; |
| 8 import android.app.Dialog; |
| 9 import android.app.DialogFragment; |
| 10 import android.content.DialogInterface; |
| 11 import android.content.Intent; |
| 12 import android.os.Bundle; |
| 13 import android.support.v7.app.AlertDialog; |
| 14 import android.text.SpannableString; |
| 15 import android.text.method.LinkMovementMethod; |
| 16 import android.text.style.ClickableSpan; |
| 17 import android.view.LayoutInflater; |
| 18 import android.view.View; |
| 19 import android.widget.TextView; |
| 20 |
| 21 import org.chromium.base.metrics.RecordUserAction; |
| 22 import org.chromium.chrome.R; |
| 23 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
| 24 import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
| 25 import org.chromium.chrome.browser.sync.ui.ClearSyncDataPreferences; |
| 26 import org.chromium.ui.text.SpanApplier; |
| 27 import org.chromium.ui.text.SpanApplier.SpanInfo; |
| 28 |
| 29 /** |
| 30 * The fragment shown when the user was previously signed in, then disconnected
their account, |
| 31 * and is now attempting to sign in to a new account. This dialog warns the user
that they should |
| 32 * clear their browser data, or else their bookmarks etc from their old account
will be merged with |
| 33 * the new account when they sign in. This dialog assumes it is being created in
the middle of the |
| 34 * signin flow, and as such is purposefully package private. |
| 35 */ |
| 36 class ConfirmAccountChangeFragment |
| 37 extends DialogFragment implements DialogInterface.OnClickListener { |
| 38 private static final String KEY_OLD_ACCOUNT_NAME = "lastAccountName"; |
| 39 private static final String KEY_NEW_ACCOUNT_NAME = "newAccountName"; |
| 40 |
| 41 // Tracks whether to abort signin in onDismiss. |
| 42 private boolean mAbortSignin = true; |
| 43 |
| 44 public static ConfirmAccountChangeFragment newInstance(String accountName) { |
| 45 ConfirmAccountChangeFragment dialogFragment = new ConfirmAccountChangeFr
agment(); |
| 46 Bundle args = new Bundle(); |
| 47 args.putString( |
| 48 KEY_OLD_ACCOUNT_NAME, PrefServiceBridge.getInstance().getSyncLas
tAccountName()); |
| 49 args.putString(KEY_NEW_ACCOUNT_NAME, accountName); |
| 50 dialogFragment.setArguments(args); |
| 51 return dialogFragment; |
| 52 } |
| 53 |
| 54 @Override |
| 55 public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 56 final Activity activity = getActivity(); |
| 57 String lastSyncAccountName = getArguments().getString(KEY_OLD_ACCOUNT_NA
ME); |
| 58 String currentAccountName = getArguments().getString(KEY_NEW_ACCOUNT_NAM
E); |
| 59 |
| 60 LayoutInflater inflater = activity.getLayoutInflater(); |
| 61 View v = inflater.inflate(R.layout.confirm_sync_account_change_account,
null); |
| 62 final TextView textView = (TextView) v.findViewById(R.id.confirmMessage)
; |
| 63 String message = activity.getString(R.string.confirm_account_change_dial
og_message, |
| 64 lastSyncAccountName, currentAccountName); |
| 65 |
| 66 // Show clear sync data dialog when the user clicks the "settings" link. |
| 67 SpannableString messageWithLink = SpanApplier.applySpans( |
| 68 message, new SpanInfo("<link>", "</link>", new ClickableSpan() { |
| 69 @Override |
| 70 public void onClick(View widget) { |
| 71 showClearSyncDataPreferences(); |
| 72 } |
| 73 })); |
| 74 |
| 75 RecordUserAction.record("Signin_Show_ImportDataPrompt"); |
| 76 textView.setText(messageWithLink); |
| 77 textView.setMovementMethod(LinkMovementMethod.getInstance()); |
| 78 return new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme) |
| 79 .setTitle(R.string.confirm_account_change_dialog_title) |
| 80 .setPositiveButton(R.string.confirm_account_change_dialog_signin
, this) |
| 81 .setNegativeButton(R.string.cancel, this) |
| 82 .setView(v) |
| 83 .create(); |
| 84 } |
| 85 |
| 86 @Override |
| 87 public void onClick(DialogInterface dialog, int which) { |
| 88 if (which == AlertDialog.BUTTON_POSITIVE) { |
| 89 RecordUserAction.record("Signin_ImportDataPrompt_ImportData"); |
| 90 SigninManager.get(getActivity()).progressInteractiveSignInFlowAccoun
tConfirmed(); |
| 91 mAbortSignin = false; |
| 92 } else if (which == AlertDialog.BUTTON_NEGATIVE) { |
| 93 RecordUserAction.record("Signin_ImportDataPrompt_Cancel"); |
| 94 } |
| 95 } |
| 96 |
| 97 @Override |
| 98 public void onDismiss(DialogInterface dialogInterface) { |
| 99 super.onDismiss(dialogInterface); |
| 100 if (mAbortSignin) { |
| 101 // Something other than BUTTON_POSITIVE is dismissing this fragment;
abort signin. |
| 102 SigninManager.get(getActivity()).abortSignIn(); |
| 103 } |
| 104 } |
| 105 |
| 106 private void showClearSyncDataPreferences() { |
| 107 Intent intent = PreferencesLauncher.createIntentForSettingsPage(getActiv
ity(), |
| 108 ClearSyncDataPreferences.class.getName()); |
| 109 startActivity(intent); |
| 110 |
| 111 RecordUserAction.record("Signin_ImportDataPrompt_DontImport"); |
| 112 dismiss(); |
| 113 } |
| 114 } |
OLD | NEW |