forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EoC] Contextual suggestions opt out
Add an item in settings to turn on/off contextual suggestions. Bug: 822953 Change-Id: I9533b6afcc21c23ee580e8d7008b6dc3ca1e74d3 Reviewed-on: https://chromium-review.googlesource.com/1006232 Commit-Queue: Becky Zhou <huayinz@chromium.org> Reviewed-by: Theresa <twellington@chromium.org> Reviewed-by: Matthew Jones <mdjones@chromium.org> Reviewed-by: Bernhard Bauer <bauerb@chromium.org> Cr-Commit-Position: refs/heads/master@{#550465}
- Loading branch information
Becky Zhou
authored and
Commit Bot
committed
Apr 13, 2018
1 parent
16ad333
commit 5ea1b5b
Showing
17 changed files
with
297 additions
and
29 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
chrome/android/java/res/xml/contextual_suggestions_preferences.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2018 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. --> | ||
|
||
<PreferenceScreen | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:chrome="http://schemas.android.com/apk/res-auto"> | ||
|
||
<org.chromium.chrome.browser.preferences.ChromeSwitchPreference | ||
android:key="contextual_suggestions_switch" | ||
android:summaryOn="@string/text_on" | ||
android:summaryOff="@string/text_off" | ||
chrome:drawDivider="true" /> | ||
|
||
<org.chromium.chrome.browser.preferences.TextMessagePreference | ||
android:title="@string/contextual_suggestions_description" /> | ||
|
||
<org.chromium.chrome.browser.preferences.TextMessagePreference | ||
android:key="contextual_suggestions_message" /> | ||
|
||
</PreferenceScreen> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...oid/java/src/org/chromium/chrome/browser/preferences/ContextualSuggestionsPreference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright 2018 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; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.preference.Preference; | ||
import android.preference.PreferenceFragment; | ||
import android.support.annotation.Nullable; | ||
import android.text.SpannableString; | ||
import android.view.View; | ||
|
||
import org.chromium.chrome.R; | ||
import org.chromium.chrome.browser.contextual_suggestions.ContextualSuggestionsBridge; | ||
import org.chromium.chrome.browser.contextual_suggestions.EnabledStateMonitor; | ||
import org.chromium.chrome.browser.signin.AccountSigninActivity; | ||
import org.chromium.chrome.browser.signin.SigninAccessPoint; | ||
import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment; | ||
import org.chromium.chrome.browser.util.IntentUtils; | ||
import org.chromium.components.signin.ChromeSigninController; | ||
import org.chromium.ui.text.NoUnderlineClickableSpan; | ||
import org.chromium.ui.text.SpanApplier; | ||
|
||
/** | ||
* Fragment to manage the Contextual Suggestions preference and to explain to the user what it does. | ||
*/ | ||
public class ContextualSuggestionsPreference | ||
extends PreferenceFragment implements EnabledStateMonitor.Observer { | ||
private static final String PREF_CONTEXTUAL_SUGGESTIONS_SWITCH = | ||
"contextual_suggestions_switch"; | ||
private static final String PREF_CONTEXTUAL_SUGGESTIONS_MESSAGE = | ||
"contextual_suggestions_message"; | ||
|
||
private ChromeSwitchPreference mSwitch; | ||
private EnabledStateMonitor mEnabledStateMonitor; | ||
|
||
@Override | ||
public void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
PreferenceUtils.addPreferencesFromResource(this, R.xml.contextual_suggestions_preferences); | ||
getActivity().setTitle(R.string.prefs_contextual_suggestions); | ||
|
||
mSwitch = (ChromeSwitchPreference) findPreference(PREF_CONTEXTUAL_SUGGESTIONS_SWITCH); | ||
mEnabledStateMonitor = new EnabledStateMonitor(this); | ||
initialize(); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
updateSwitch(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
mEnabledStateMonitor.destroy(); | ||
} | ||
|
||
@Override | ||
public void onEnabledStateChanged(boolean enabled) {} | ||
|
||
@Override | ||
public void onSettingsStateChanged(boolean enabled) { | ||
if (mEnabledStateMonitor != null) updateSwitch(); | ||
} | ||
|
||
/** Helper method to initialize the switch preference and the message preference. */ | ||
private void initialize() { | ||
final TextMessagePreference message = | ||
(TextMessagePreference) findPreference(PREF_CONTEXTUAL_SUGGESTIONS_MESSAGE); | ||
final SpannableString spannable = SpanApplier.applySpans( | ||
getResources().getString(R.string.contextual_suggestions_message), | ||
new SpanApplier.SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() { | ||
@Override | ||
public void onClick(View widget) { | ||
Context context = getActivity(); | ||
if (ChromeSigninController.get().isSignedIn()) { | ||
Intent intent = PreferencesLauncher.createIntentForSettingsPage( | ||
context, SyncCustomizationFragment.class.getName()); | ||
IntentUtils.safeStartActivity(context, intent); | ||
} else { | ||
startActivity(AccountSigninActivity.createIntentForDefaultSigninFlow( | ||
context, SigninAccessPoint.SETTINGS, false)); | ||
} | ||
} | ||
})); | ||
message.setTitle(spannable); | ||
|
||
updateSwitch(); | ||
mSwitch.setOnPreferenceChangeListener((preference, newValue) -> { | ||
PrefServiceBridge.getInstance().setBoolean( | ||
Pref.CONTEXTUAL_SUGGESTIONS_ENABLED, (boolean) newValue); | ||
return true; | ||
}); | ||
mSwitch.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() { | ||
@Override | ||
public boolean isPreferenceControlledByPolicy(Preference preference) { | ||
return ContextualSuggestionsBridge.isEnterprisePolicyManaged(); | ||
} | ||
}); | ||
} | ||
|
||
/** Helper method to update the enabled state of the switch. */ | ||
private void updateSwitch() { | ||
mSwitch.setEnabled(EnabledStateMonitor.getSettingsEnabled()); | ||
mSwitch.setChecked(EnabledStateMonitor.getEnabledState()); | ||
} | ||
} |
Oops, something went wrong.