Add setting to turn off icon badging
Redirects to system Notifications setting page. Bug: 36815147 Change-Id: I5ee542f94ed51a73a57df3a726384944ff3ee71d
This commit is contained in:
parent
441c628a75
commit
2ab8482809
|
@ -172,6 +172,12 @@
|
||||||
<string name="allow_rotation_desc">When phone is rotated</string>
|
<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] -->
|
<!-- 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>
|
<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] -->
|
<!-- 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>
|
<string name="auto_add_shortcuts_label">Add icon to Home screen</string>
|
||||||
|
|
|
@ -16,13 +16,6 @@
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<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
|
<SwitchPreference
|
||||||
android:key="pref_add_icon_to_home"
|
android:key="pref_add_icon_to_home"
|
||||||
android:title="@string/auto_add_shortcuts_label"
|
android:title="@string/auto_add_shortcuts_label"
|
||||||
|
@ -40,4 +33,23 @@
|
||||||
android:defaultValue=""
|
android:defaultValue=""
|
||||||
android:persistent="false" />
|
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>
|
</PreferenceScreen>
|
||||||
|
|
|
@ -34,6 +34,11 @@ import com.android.launcher3.graphics.IconShapeOverride;
|
||||||
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
|
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
|
||||||
*/
|
*/
|
||||||
public class SettingsActivity extends Activity {
|
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
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -50,6 +55,7 @@ public class SettingsActivity extends Activity {
|
||||||
public static class LauncherSettingsFragment extends PreferenceFragment {
|
public static class LauncherSettingsFragment extends PreferenceFragment {
|
||||||
|
|
||||||
private SystemDisplayRotationLockObserver mRotationLockObserver;
|
private SystemDisplayRotationLockObserver mRotationLockObserver;
|
||||||
|
private IconBadgingObserver mIconBadgingObserver;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -57,13 +63,14 @@ public class SettingsActivity extends Activity {
|
||||||
getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
|
getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);
|
||||||
addPreferencesFromResource(R.xml.launcher_preferences);
|
addPreferencesFromResource(R.xml.launcher_preferences);
|
||||||
|
|
||||||
|
ContentResolver resolver = getActivity().getContentResolver();
|
||||||
|
|
||||||
// Setup allow rotation preference
|
// Setup allow rotation preference
|
||||||
Preference rotationPref = findPreference(Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
|
Preference rotationPref = findPreference(Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
|
||||||
if (getResources().getBoolean(R.bool.allow_rotation)) {
|
if (getResources().getBoolean(R.bool.allow_rotation)) {
|
||||||
// Launcher supports rotation by default. No need to show this setting.
|
// Launcher supports rotation by default. No need to show this setting.
|
||||||
getPreferenceScreen().removePreference(rotationPref);
|
getPreferenceScreen().removePreference(rotationPref);
|
||||||
} else {
|
} else {
|
||||||
ContentResolver resolver = getActivity().getContentResolver();
|
|
||||||
mRotationLockObserver = new SystemDisplayRotationLockObserver(rotationPref, resolver);
|
mRotationLockObserver = new SystemDisplayRotationLockObserver(rotationPref, resolver);
|
||||||
|
|
||||||
// Register a content observer to listen for system setting changes while
|
// 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()));
|
rotationPref.setDefaultValue(Utilities.getAllowRotationDefaultValue(getActivity()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Preference iconBadgingPref = findPreference(ICON_BADGING_PREFERENCE_KEY);
|
||||||
if (!BuildCompat.isAtLeastO()) {
|
if (!BuildCompat.isAtLeastO()) {
|
||||||
getPreferenceScreen().removePreference(
|
getPreferenceScreen().removePreference(
|
||||||
findPreference(SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY));
|
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);
|
Preference iconShapeOverride = findPreference(IconShapeOverride.KEY_PREFERENCE);
|
||||||
|
@ -98,6 +114,10 @@ public class SettingsActivity extends Activity {
|
||||||
getActivity().getContentResolver().unregisterContentObserver(mRotationLockObserver);
|
getActivity().getContentResolver().unregisterContentObserver(mRotationLockObserver);
|
||||||
mRotationLockObserver = null;
|
mRotationLockObserver = null;
|
||||||
}
|
}
|
||||||
|
if (mIconBadgingObserver != null) {
|
||||||
|
getActivity().getContentResolver().unregisterContentObserver(mIconBadgingObserver);
|
||||||
|
mIconBadgingObserver = null;
|
||||||
|
}
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,4 +147,29 @@ public class SettingsActivity extends Activity {
|
||||||
? R.string.allow_rotation_desc : R.string.allow_rotation_blocked_desc);
|
? 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue