diff --git a/res/values/strings.xml b/res/values/strings.xml index e840328a52..f7c482567e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -172,6 +172,12 @@ When phone is rotated Current Display setting doesn\'t permit rotation + + Icon badging + + On for all apps + + Off for all apps Add icon to Home screen diff --git a/res/xml/launcher_preferences.xml b/res/xml/launcher_preferences.xml index 301bef104d..876388363f 100644 --- a/res/xml/launcher_preferences.xml +++ b/res/xml/launcher_preferences.xml @@ -16,13 +16,6 @@ - - + + + + + + /> + + + diff --git a/src/com/android/launcher3/SettingsActivity.java b/src/com/android/launcher3/SettingsActivity.java index 7ae6b261d6..0902b2029d 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); + } + } + }