Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/OtherFormsOfHistoryDialogFragment.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/OtherFormsOfHistoryDialogFragment.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/OtherFormsOfHistoryDialogFragment.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9a9503c470a32a4a12ae9ef85c94c83a269e9a28 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/privacy/OtherFormsOfHistoryDialogFragment.java |
| @@ -0,0 +1,128 @@ |
| +// 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.privacy; |
| + |
| +import android.app.Activity; |
| +import android.app.Dialog; |
| +import android.app.DialogFragment; |
| +import android.content.Context; |
| +import android.content.DialogInterface; |
| +import android.content.SharedPreferences; |
| +import android.os.Bundle; |
| +import android.preference.PreferenceManager; |
| +import android.support.v7.app.AlertDialog; |
| +import android.text.SpannableString; |
| +import android.text.method.LinkMovementMethod; |
| +import android.view.LayoutInflater; |
| +import android.view.View; |
| +import android.widget.TextView; |
| + |
| +import org.chromium.base.VisibleForTesting; |
| +import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| +import org.chromium.chrome.browser.tabmodel.document.TabDelegate; |
| +import org.chromium.ui.text.NoUnderlineClickableSpan; |
| +import org.chromium.ui.text.SpanApplier; |
| + |
| +/** |
| + * Informs the user about the existence of other forms of browsing history. |
| + */ |
| +public class OtherFormsOfHistoryDialogFragment extends DialogFragment implements |
| + DialogInterface.OnClickListener { |
| + |
| + public static final String PREF_OTHER_FORMS_OF_HISTORY_DIALOG_SHOWN = |
| + "clear_browsing_data_history_dialog_shown"; |
|
gone
2016/04/07 21:05:26
Prefix this with the package name, and make the st
msramek
2016/04/08 11:20:42
Done.
|
| + |
| + /** The my activity URL. */ |
| + private static final String URL_MY_ACTIVITY = |
|
gone
2016/04/07 21:05:27
Can you think of a different way to name this? In
msramek
2016/04/08 11:20:42
Done. Renamed here and in ClearBrowsingDataPrefere
|
| + "https://history.google.com/history/?utm_source=chrome_n"; |
| + |
| + private static final String TAG = "OtherFormsOfHistoryDialogFragment"; |
| + |
| + @Override |
| + public Dialog onCreateDialog(Bundle savedInstanceState) { |
| + super.onCreateDialog(savedInstanceState); |
| + LayoutInflater inflater = getActivity().getLayoutInflater(); |
| + View view = inflater.inflate(R.layout.other_forms_of_history_dialog, null); |
| + |
| + // Linkify the <link></link> span in the second paragraph. |
| + TextView secondParagraph = (TextView) view.findViewById(R.id.paragraph_2); |
| + final SpannableString textWithLink = SpanApplier.applySpans( |
| + secondParagraph.getText().toString(), |
| + new SpanApplier.SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() { |
| + @Override |
| + public void onClick(View widget) { |
| + new TabDelegate(false /* incognito */).launchUrl( |
| + URL_MY_ACTIVITY, TabLaunchType.FROM_CHROME_UI); |
| + } |
| + })); |
| + |
| + secondParagraph.setText(textWithLink); |
| + secondParagraph.setMovementMethod(LinkMovementMethod.getInstance()); |
| + |
| + // Construct the dialog. |
| + AlertDialog dialog = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme) |
| + .setView(view) |
| + .setTitle(R.string.clear_browsing_data_history_dialog_title) |
| + .setPositiveButton( |
| + R.string.clear_browsing_data_history_dialog_positive_button, this) |
| + .create(); |
| + |
| + dialog.setCanceledOnTouchOutside(false); |
| + return dialog; |
| + } |
| + |
| + @Override |
| + public void onClick(DialogInterface dialog, int which) { |
| + assert which == AlertDialog.BUTTON_POSITIVE; |
| + |
| + // Remember that the dialog about other forms of browsing history has been shown |
| + // to the user. |
| + setShown(getActivity(), true); |
| + |
| + // Finishes the ClearBrowsingDataPreferences activity that created this dialog. |
| + getActivity().finish(); |
| + } |
| + |
| + /** |
| + * Sets the preference indicating whether this dialog was already shown. |
| + * @param activity The Activity storing the preference. |
| + * @param shown Whether the dialog was shown. |
| + */ |
| + private static void setShown(Activity activity, boolean shown) { |
|
gone
2016/04/07 21:05:27
recordDialogWasShown()? setShown sounds like a mu
msramek
2016/04/08 11:20:42
Done.
|
| + SharedPreferences preferences = |
| + PreferenceManager.getDefaultSharedPreferences(activity); |
| + SharedPreferences.Editor editor = preferences.edit(); |
| + editor.putBoolean(PREF_OTHER_FORMS_OF_HISTORY_DIALOG_SHOWN, shown); |
| + editor.apply(); |
| + } |
| + |
| + /** |
| + * @return Whether the dialog has already been shown to the user before. |
| + */ |
| + public static boolean wasDialogShown(Context context) { |
|
gone
2016/04/07 21:05:27
package protected?
msramek
2016/04/08 11:20:42
Done.
|
| + return PreferenceManager.getDefaultSharedPreferences(context).getBoolean( |
| + PREF_OTHER_FORMS_OF_HISTORY_DIALOG_SHOWN, false); |
| + } |
| + |
| + /** |
| + * A convenience method to create and show the dialog. |
| + */ |
| + public static OtherFormsOfHistoryDialogFragment show(Activity activity) { |
|
gone
2016/04/07 21:05:27
nit: Put this at the top of the class to make it m
msramek
2016/04/08 11:20:42
Makes sense. Done.
|
| + OtherFormsOfHistoryDialogFragment dialog = new OtherFormsOfHistoryDialogFragment(); |
| + dialog.show(activity.getFragmentManager(), TAG); |
| + return dialog; |
| + } |
| + |
| + /** |
| + * For testing purposes, resets the preference indicating that this dialog has been shown |
| + * to false. |
| + * @param activity The Activity storing the preference. |
| + */ |
| + @VisibleForTesting |
| + public static void clearShownPreferenceForTesting(Activity activity) { |
|
gone
2016/04/07 21:05:26
Possible to package protect?
msramek
2016/04/08 11:20:42
Done. Yes, the test is in this package.
|
| + setShown(activity, false); |
| + } |
| +} |