packages/apps/Launcher3
Revisión | 2ab8482809109c7c202e12bcef083cc3783e852e (tree) |
---|---|
Tiempo | 2017-05-17 06:08:42 |
Autor | Tony Wickham <twickham@goog...> |
Commiter | Tony |
Add setting to turn off icon badging
Redirects to system Notifications setting page.
Bug: 36815147
Change-Id: I5ee542f94ed51a73a57df3a726384944ff3ee71d
@@ -172,6 +172,12 @@ | ||
172 | 172 | <string name="allow_rotation_desc">When phone is rotated</string> |
173 | 173 | <!-- Text explaining that rotation is disabled in Display settings. 'Display' refers to the Display section in system settings [CHAR LIMIT=100] --> |
174 | 174 | <string name="allow_rotation_blocked_desc">Current Display setting doesn\'t permit rotation</string> |
175 | + <!-- 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] --> | |
176 | + <string name="icon_badging_title">Icon badging</string> | |
177 | + <!-- Text to indicate that the system icon badging setting is on [CHAR LIMIT=100] --> | |
178 | + <string name="icon_badging_desc_on">On for all apps</string> | |
179 | + <!-- Text to indicate that the system icon badging setting is off [CHAR LIMIT=100] --> | |
180 | + <string name="icon_badging_desc_off">Off for all apps</string> | |
175 | 181 | |
176 | 182 | <!-- Label for the setting that allows the automatic placement of launcher shortcuts for applications and games installed on the device [CHAR LIMIT=40] --> |
177 | 183 | <string name="auto_add_shortcuts_label">Add icon to Home screen</string> |
@@ -17,13 +17,6 @@ | ||
17 | 17 | <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> |
18 | 18 | |
19 | 19 | <SwitchPreference |
20 | - android:key="pref_allowRotation" | |
21 | - android:title="@string/allow_rotation_title" | |
22 | - android:defaultValue="@bool/allow_rotation" | |
23 | - android:persistent="true" | |
24 | - /> | |
25 | - | |
26 | - <SwitchPreference | |
27 | 20 | android:key="pref_add_icon_to_home" |
28 | 21 | android:title="@string/auto_add_shortcuts_label" |
29 | 22 | android:summary="@string/auto_add_shortcuts_description" |
@@ -40,4 +33,23 @@ | ||
40 | 33 | android:defaultValue="" |
41 | 34 | android:persistent="false" /> |
42 | 35 | |
36 | + <Preference | |
37 | + android:key="pref_icon_badging" | |
38 | + android:title="@string/icon_badging_title" | |
39 | + android:persistent="false"> | |
40 | + <intent android:action="android.settings.NOTIFICATION_SETTINGS"> | |
41 | + <!-- This extra highlights the "Allow icon badges" field in Notification settings --> | |
42 | + <extra | |
43 | + android:name=":settings:fragment_args_key" | |
44 | + android:value="notification_badging" /> | |
45 | + </intent> | |
46 | + </Preference>/> | |
47 | + | |
48 | + <SwitchPreference | |
49 | + android:key="pref_allowRotation" | |
50 | + android:title="@string/allow_rotation_title" | |
51 | + android:defaultValue="@bool/allow_rotation" | |
52 | + android:persistent="true" | |
53 | + /> | |
54 | + | |
43 | 55 | </PreferenceScreen> |
@@ -34,6 +34,11 @@ import com.android.launcher3.graphics.IconShapeOverride; | ||
34 | 34 | * Settings activity for Launcher. Currently implements the following setting: Allow rotation |
35 | 35 | */ |
36 | 36 | public class SettingsActivity extends Activity { |
37 | + | |
38 | + private static final String ICON_BADGING_PREFERENCE_KEY = "pref_icon_badging"; | |
39 | + // TODO: use Settings.Secure.NOTIFICATION_BADGING | |
40 | + private static final String NOTIFICATION_BADGING = "notification_badging"; | |
41 | + | |
37 | 42 | @Override |
38 | 43 | protected void onCreate(Bundle savedInstanceState) { |
39 | 44 | super.onCreate(savedInstanceState); |
@@ -50,6 +55,7 @@ public class SettingsActivity extends Activity { | ||
50 | 55 | public static class LauncherSettingsFragment extends PreferenceFragment { |
51 | 56 | |
52 | 57 | private SystemDisplayRotationLockObserver mRotationLockObserver; |
58 | + private IconBadgingObserver mIconBadgingObserver; | |
53 | 59 | |
54 | 60 | @Override |
55 | 61 | public void onCreate(Bundle savedInstanceState) { |
@@ -57,13 +63,14 @@ public class SettingsActivity extends Activity { | ||
57 | 63 | getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY); |
58 | 64 | addPreferencesFromResource(R.xml.launcher_preferences); |
59 | 65 | |
66 | + ContentResolver resolver = getActivity().getContentResolver(); | |
67 | + | |
60 | 68 | // Setup allow rotation preference |
61 | 69 | Preference rotationPref = findPreference(Utilities.ALLOW_ROTATION_PREFERENCE_KEY); |
62 | 70 | if (getResources().getBoolean(R.bool.allow_rotation)) { |
63 | 71 | // Launcher supports rotation by default. No need to show this setting. |
64 | 72 | getPreferenceScreen().removePreference(rotationPref); |
65 | 73 | } else { |
66 | - ContentResolver resolver = getActivity().getContentResolver(); | |
67 | 74 | mRotationLockObserver = new SystemDisplayRotationLockObserver(rotationPref, resolver); |
68 | 75 | |
69 | 76 | // Register a content observer to listen for system setting changes while |
@@ -77,9 +84,18 @@ public class SettingsActivity extends Activity { | ||
77 | 84 | rotationPref.setDefaultValue(Utilities.getAllowRotationDefaultValue(getActivity())); |
78 | 85 | } |
79 | 86 | |
87 | + Preference iconBadgingPref = findPreference(ICON_BADGING_PREFERENCE_KEY); | |
80 | 88 | if (!BuildCompat.isAtLeastO()) { |
81 | 89 | getPreferenceScreen().removePreference( |
82 | 90 | findPreference(SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY)); |
91 | + getPreferenceScreen().removePreference(iconBadgingPref); | |
92 | + } else { | |
93 | + // Listen to system notification badge settings while this UI is active. | |
94 | + mIconBadgingObserver = new IconBadgingObserver(iconBadgingPref, resolver); | |
95 | + resolver.registerContentObserver( | |
96 | + Settings.Secure.getUriFor(NOTIFICATION_BADGING), | |
97 | + false, mIconBadgingObserver); | |
98 | + mIconBadgingObserver.onChange(true); | |
83 | 99 | } |
84 | 100 | |
85 | 101 | Preference iconShapeOverride = findPreference(IconShapeOverride.KEY_PREFERENCE); |
@@ -98,6 +114,10 @@ public class SettingsActivity extends Activity { | ||
98 | 114 | getActivity().getContentResolver().unregisterContentObserver(mRotationLockObserver); |
99 | 115 | mRotationLockObserver = null; |
100 | 116 | } |
117 | + if (mIconBadgingObserver != null) { | |
118 | + getActivity().getContentResolver().unregisterContentObserver(mIconBadgingObserver); | |
119 | + mIconBadgingObserver = null; | |
120 | + } | |
101 | 121 | super.onDestroy(); |
102 | 122 | } |
103 | 123 | } |
@@ -127,4 +147,29 @@ public class SettingsActivity extends Activity { | ||
127 | 147 | ? R.string.allow_rotation_desc : R.string.allow_rotation_blocked_desc); |
128 | 148 | } |
129 | 149 | } |
150 | + | |
151 | + /** | |
152 | + * Content observer which listens for system badging setting changes, | |
153 | + * and updates the launcher badging setting subtext accordingly. | |
154 | + */ | |
155 | + private static class IconBadgingObserver extends ContentObserver { | |
156 | + | |
157 | + private final Preference mBadgingPref; | |
158 | + private final ContentResolver mResolver; | |
159 | + | |
160 | + public IconBadgingObserver(Preference badgingPref, ContentResolver resolver) { | |
161 | + super(new Handler()); | |
162 | + mBadgingPref = badgingPref; | |
163 | + mResolver = resolver; | |
164 | + } | |
165 | + | |
166 | + @Override | |
167 | + public void onChange(boolean selfChange) { | |
168 | + boolean enabled = Settings.Secure.getInt(mResolver, NOTIFICATION_BADGING, 1) == 1; | |
169 | + mBadgingPref.setSummary(enabled | |
170 | + ? R.string.icon_badging_desc_on | |
171 | + : R.string.icon_badging_desc_off); | |
172 | + } | |
173 | + } | |
174 | + | |
130 | 175 | } |