| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SubresourceFilterListPreference.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SubresourceFilterListPreference.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SubresourceFilterListPreference.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..766c26a21f711eea57eae0b635375dd18efb890c
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/SubresourceFilterListPreference.java
|
| @@ -0,0 +1,87 @@
|
| +// Copyright 2017 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.website;
|
| +
|
| +import android.app.AlertDialog;
|
| +import android.content.Context;
|
| +import android.content.res.TypedArray;
|
| +import android.util.AttributeSet;
|
| +
|
| +import org.chromium.chrome.browser.preferences.ChromeBaseListPreference;
|
| +import org.chromium.ui.R;
|
| +
|
| +/**
|
| + * Subresource filter specific list preference, which maintains slightly different behavior from the
|
| + * standard Chrome one.
|
| + * - The Block and Allow strings are custom.
|
| + * - The Block and Allow strings can change when displayed in the radio dialog.
|
| + * - The Block and Allow strings can change depending on whether the site is on the Safe Browsing
|
| + * blacklist (aka activated).
|
| + */
|
| +public class SubresourceFilterListPreference extends ChromeBaseListPreference {
|
| + // The Allow/Block strings to show for the setting if the subresource filter is activated.
|
| + private String mActiveAllowString;
|
| + private String mActiveBlockString;
|
| +
|
| + // The Allow/Block strings to show for the setting if the subresource filter is not activated
|
| + // but we are still displaying the setting. These strings should also always be used in the
|
| + // radio dialog.
|
| + private String mPassiveAllowString;
|
| + private String mPassiveBlockString;
|
| +
|
| + private boolean mShouldUseActiveStrings;
|
| +
|
| + /**
|
| + * Constructor for inflating from XML.
|
| + */
|
| + public SubresourceFilterListPreference(Context context, AttributeSet attrs) {
|
| + super(context, attrs);
|
| +
|
| + // Use the active string by default.
|
| + mShouldUseActiveStrings = true;
|
| +
|
| + TypedArray a = context.obtainStyledAttributes(
|
| + attrs, R.styleable.SubresourceFilterListPreference, 0, 0);
|
| + assert a.hasValue(R.styleable.SubresourceFilterListPreference_activeAllowText);
|
| + assert a.hasValue(R.styleable.SubresourceFilterListPreference_passiveAllowText);
|
| + assert a.hasValue(R.styleable.SubresourceFilterListPreference_activeBlockText);
|
| + assert a.hasValue(R.styleable.SubresourceFilterListPreference_passiveBlockText);
|
| + mActiveAllowString =
|
| + a.getString(R.styleable.SubresourceFilterListPreference_activeAllowText);
|
| + mPassiveAllowString =
|
| + a.getString(R.styleable.SubresourceFilterListPreference_passiveAllowText);
|
| + mActiveBlockString =
|
| + a.getString(R.styleable.SubresourceFilterListPreference_activeBlockText);
|
| + mPassiveBlockString =
|
| + a.getString(R.styleable.SubresourceFilterListPreference_passiveBlockText);
|
| + a.recycle();
|
| + }
|
| +
|
| + public void setShouldUseActiveStrings(boolean shouldUseActiveStrings) {
|
| + mShouldUseActiveStrings = shouldUseActiveStrings;
|
| + resetEntries(mShouldUseActiveStrings);
|
| + }
|
| +
|
| + @Override
|
| + protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
| + // The dialog always uses passive strings.
|
| + resetEntries(false /* active */);
|
| + super.onPrepareDialogBuilder(builder);
|
| + }
|
| +
|
| + @Override
|
| + protected void onDialogClosed(boolean positiveResult) {
|
| + // Reset the string to what was originally there.
|
| + resetEntries(mShouldUseActiveStrings);
|
| + super.onDialogClosed(positiveResult);
|
| + }
|
| +
|
| + private void resetEntries(boolean active) {
|
| + CharSequence[] entries = getEntries();
|
| + String allowString = active ? mActiveAllowString : mPassiveAllowString;
|
| + String blockString = active ? mActiveBlockString : mPassiveBlockString;
|
| + setEntries(new String[] {allowString, blockString});
|
| + }
|
| +}
|
|
|