diff options
author | Tony Wickham <twickham@google.com> | 2017-05-12 14:59:09 -0700 |
---|---|---|
committer | Tony <twickham@google.com> | 2017-05-16 14:08:42 -0700 |
commit | 2ab8482809109c7c202e12bcef083cc3783e852e (patch) | |
tree | 2103d4d8fac65fa8cd992a2ffa50a4facbfba746 | |
parent | 441c628a751be4960b6955dfdf4e9557f0fc5220 (diff) | |
download | android_packages_apps_Trebuchet-2ab8482809109c7c202e12bcef083cc3783e852e.tar.gz android_packages_apps_Trebuchet-2ab8482809109c7c202e12bcef083cc3783e852e.tar.bz2 android_packages_apps_Trebuchet-2ab8482809109c7c202e12bcef083cc3783e852e.zip |
Add setting to turn off icon badging
Redirects to system Notifications setting page.
Bug: 36815147
Change-Id: I5ee542f94ed51a73a57df3a726384944ff3ee71d
-rw-r--r-- | res/values/strings.xml | 6 | ||||
-rw-r--r-- | res/xml/launcher_preferences.xml | 26 | ||||
-rw-r--r-- | src/com/android/launcher3/SettingsActivity.java | 47 |
3 files changed, 71 insertions, 8 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index e840328a5..f7c482567 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -172,6 +172,12 @@ <string name="allow_rotation_desc">When phone is rotated</string> <!-- Text explaining that rotation is disabled in Display settings. 'Display' refers to the Display section in system settings [CHAR LIMIT=100] --> <string name="allow_rotation_blocked_desc">Current Display setting doesn\'t permit rotation</string> + <!-- Title for Icon Badging setting. Tapping this will link to the system Notifications Settings screen where the user can turn off badging globally. [CHAR LIMIT=50] --> + <string name="icon_badging_title">Icon badging</string> + <!-- Text to indicate that the system icon badging setting is on [CHAR LIMIT=100] --> + <string name="icon_badging_desc_on">On for all apps</string> + <!-- Text to indicate that the system icon badging setting is off [CHAR LIMIT=100] --> + <string name="icon_badging_desc_off">Off for all apps</string> <!-- Label for the setting that allows the automatic placement of launcher shortcuts for applications and games installed on the device [CHAR LIMIT=40] --> <string name="auto_add_shortcuts_label">Add icon to Home screen</string> diff --git a/res/xml/launcher_preferences.xml b/res/xml/launcher_preferences.xml index 301bef104..876388363 100644 --- a/res/xml/launcher_preferences.xml +++ b/res/xml/launcher_preferences.xml @@ -17,13 +17,6 @@ <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <SwitchPreference - android:key="pref_allowRotation" - android:title="@string/allow_rotation_title" - android:defaultValue="@bool/allow_rotation" - android:persistent="true" - /> - - <SwitchPreference android:key="pref_add_icon_to_home" android:title="@string/auto_add_shortcuts_label" android:summary="@string/auto_add_shortcuts_description" @@ -40,4 +33,23 @@ android:defaultValue="" android:persistent="false" /> + <Preference + android:key="pref_icon_badging" + android:title="@string/icon_badging_title" + android:persistent="false"> + <intent android:action="android.settings.NOTIFICATION_SETTINGS"> + <!-- This extra highlights the "Allow icon badges" field in Notification settings --> + <extra + android:name=":settings:fragment_args_key" + android:value="notification_badging" /> + </intent> + </Preference>/> + + <SwitchPreference + android:key="pref_allowRotation" + android:title="@string/allow_rotation_title" + android:defaultValue="@bool/allow_rotation" + android:persistent="true" + /> + </PreferenceScreen> diff --git a/src/com/android/launcher3/SettingsActivity.java b/src/com/android/launcher3/SettingsActivity.java index 7ae6b261d..0902b2029 100644 --- a/src/com/android/launcher3/SettingsActivity.java +++ b/src/com/android/launcher3/SettingsActivity.java @@ -34,6 +34,11 @@ import com.android.launcher3.graphics.IconShapeOverride; * Settings activity for Launcher. Currently implements the following setting: Allow rotation */ public class SettingsActivity extends Activity { + + private static final String ICON_BADGING_PREFERENCE_KEY = "pref_icon_badging"; + // TODO: use Settings.Secure.NOTIFICATION_BADGING + private static final String NOTIFICATION_BADGING = "notification_badging"; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -50,6 +55,7 @@ public class SettingsActivity extends Activity { public static class LauncherSettingsFragment extends PreferenceFragment { private SystemDisplayRotationLockObserver mRotationLockObserver; + private IconBadgingObserver mIconBadgingObserver; @Override public void onCreate(Bundle savedInstanceState) { @@ -57,13 +63,14 @@ public class SettingsActivity extends Activity { getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY); addPreferencesFromResource(R.xml.launcher_preferences); + ContentResolver resolver = getActivity().getContentResolver(); + // Setup allow rotation preference Preference rotationPref = findPreference(Utilities.ALLOW_ROTATION_PREFERENCE_KEY); if (getResources().getBoolean(R.bool.allow_rotation)) { // Launcher supports rotation by default. No need to show this setting. getPreferenceScreen().removePreference(rotationPref); } else { - ContentResolver resolver = getActivity().getContentResolver(); mRotationLockObserver = new SystemDisplayRotationLockObserver(rotationPref, resolver); // Register a content observer to listen for system setting changes while @@ -77,9 +84,18 @@ public class SettingsActivity extends Activity { rotationPref.setDefaultValue(Utilities.getAllowRotationDefaultValue(getActivity())); } + Preference iconBadgingPref = findPreference(ICON_BADGING_PREFERENCE_KEY); if (!BuildCompat.isAtLeastO()) { getPreferenceScreen().removePreference( findPreference(SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY)); + getPreferenceScreen().removePreference(iconBadgingPref); + } else { + // Listen to system notification badge settings while this UI is active. + mIconBadgingObserver = new IconBadgingObserver(iconBadgingPref, resolver); + resolver.registerContentObserver( + Settings.Secure.getUriFor(NOTIFICATION_BADGING), + false, mIconBadgingObserver); + mIconBadgingObserver.onChange(true); } Preference iconShapeOverride = findPreference(IconShapeOverride.KEY_PREFERENCE); @@ -98,6 +114,10 @@ public class SettingsActivity extends Activity { getActivity().getContentResolver().unregisterContentObserver(mRotationLockObserver); mRotationLockObserver = null; } + if (mIconBadgingObserver != null) { + getActivity().getContentResolver().unregisterContentObserver(mIconBadgingObserver); + mIconBadgingObserver = null; + } super.onDestroy(); } } @@ -127,4 +147,29 @@ public class SettingsActivity extends Activity { ? R.string.allow_rotation_desc : R.string.allow_rotation_blocked_desc); } } + + /** + * Content observer which listens for system badging setting changes, + * and updates the launcher badging setting subtext accordingly. + */ + private static class IconBadgingObserver extends ContentObserver { + + private final Preference mBadgingPref; + private final ContentResolver mResolver; + + public IconBadgingObserver(Preference badgingPref, ContentResolver resolver) { + super(new Handler()); + mBadgingPref = badgingPref; + mResolver = resolver; + } + + @Override + public void onChange(boolean selfChange) { + boolean enabled = Settings.Secure.getInt(mResolver, NOTIFICATION_BADGING, 1) == 1; + mBadgingPref.setSummary(enabled + ? R.string.icon_badging_desc_on + : R.string.icon_badging_desc_off); + } + } + } |