Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher3; |
| 18 | |
Sunny Goyal | 4025332 | 2018-04-19 09:27:38 -0700 | [diff] [blame] | 19 | import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY; |
| 20 | import static com.android.launcher3.states.RotationHelper.getAllowRotationDefaultValue; |
Sunny Goyal | 420d545 | 2018-10-17 10:25:14 -0700 | [diff] [blame] | 21 | import static com.android.launcher3.util.SecureSettingsObserver.newNotificationSettingsObserver; |
Sunny Goyal | 4025332 | 2018-04-19 09:27:38 -0700 | [diff] [blame] | 22 | |
Sunny Goyal | ba406e2 | 2018-04-02 11:36:12 -0700 | [diff] [blame] | 23 | import android.annotation.TargetApi; |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 24 | import android.app.Activity; |
Sunny Goyal | 848cad5 | 2017-07-07 03:12:21 -0700 | [diff] [blame] | 25 | import android.app.AlertDialog; |
| 26 | import android.app.Dialog; |
| 27 | import android.app.DialogFragment; |
Sunny Goyal | 7f920b8 | 2018-06-27 15:47:49 -0700 | [diff] [blame] | 28 | import android.app.Fragment; |
Sunny Goyal | 848cad5 | 2017-07-07 03:12:21 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Sunny Goyal | f48e592 | 2016-05-12 15:36:20 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Sunny Goyal | 848cad5 | 2017-07-07 03:12:21 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.DialogInterface; |
| 33 | import android.content.Intent; |
Sunny Goyal | ba406e2 | 2018-04-02 11:36:12 -0700 | [diff] [blame] | 34 | import android.os.Build; |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 35 | import android.os.Bundle; |
Sunny Goyal | ca18746 | 2017-03-31 20:09:34 -0700 | [diff] [blame] | 36 | import android.preference.ListPreference; |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame] | 37 | import android.preference.Preference; |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 38 | import android.preference.PreferenceFragment; |
Sunny Goyal | ba406e2 | 2018-04-02 11:36:12 -0700 | [diff] [blame] | 39 | import android.preference.PreferenceScreen; |
Sunny Goyal | f48e592 | 2016-05-12 15:36:20 -0700 | [diff] [blame] | 40 | import android.provider.Settings; |
Sunny Goyal | 3fbca15 | 2017-11-02 18:55:44 -0700 | [diff] [blame] | 41 | import android.text.TextUtils; |
Sunny Goyal | 3fbca15 | 2017-11-02 18:55:44 -0700 | [diff] [blame] | 42 | import android.view.View; |
Sunny Goyal | 3fbca15 | 2017-11-02 18:55:44 -0700 | [diff] [blame] | 43 | import android.widget.Adapter; |
Sunny Goyal | ba406e2 | 2018-04-02 11:36:12 -0700 | [diff] [blame] | 44 | import android.widget.ListView; |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 45 | |
Ryan Lothian | fa530cd | 2018-10-12 14:14:16 -0400 | [diff] [blame] | 46 | import com.android.launcher3.config.FeatureFlags; |
Sunny Goyal | ca18746 | 2017-03-31 20:09:34 -0700 | [diff] [blame] | 47 | import com.android.launcher3.graphics.IconShapeOverride; |
Sunny Goyal | 848cad5 | 2017-07-07 03:12:21 -0700 | [diff] [blame] | 48 | import com.android.launcher3.notification.NotificationListener; |
Sunny Goyal | ba406e2 | 2018-04-02 11:36:12 -0700 | [diff] [blame] | 49 | import com.android.launcher3.util.ListViewHighlighter; |
Sunny Goyal | 420d545 | 2018-10-17 10:25:14 -0700 | [diff] [blame] | 50 | import com.android.launcher3.util.SecureSettingsObserver; |
Sunny Goyal | 848cad5 | 2017-07-07 03:12:21 -0700 | [diff] [blame] | 51 | import com.android.launcher3.views.ButtonPreference; |
Sunny Goyal | ba406e2 | 2018-04-02 11:36:12 -0700 | [diff] [blame] | 52 | |
| 53 | import java.util.Objects; |
Sunny Goyal | ca18746 | 2017-03-31 20:09:34 -0700 | [diff] [blame] | 54 | |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 55 | /** |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame] | 56 | * Settings activity for Launcher. Currently implements the following setting: Allow rotation |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 57 | */ |
Sunny Goyal | 7f920b8 | 2018-06-27 15:47:49 -0700 | [diff] [blame] | 58 | public class SettingsActivity extends Activity |
| 59 | implements PreferenceFragment.OnPreferenceStartFragmentCallback { |
Tony Wickham | 2ab8482 | 2017-05-12 14:59:09 -0700 | [diff] [blame] | 60 | |
Ryan Lothian | fa530cd | 2018-10-12 14:14:16 -0400 | [diff] [blame] | 61 | private static final String FLAGS_PREFERENCE_KEY = "flag_toggler"; |
| 62 | |
Tony Wickham | 2ab8482 | 2017-05-12 14:59:09 -0700 | [diff] [blame] | 63 | private static final String ICON_BADGING_PREFERENCE_KEY = "pref_icon_badging"; |
Sunny Goyal | 848cad5 | 2017-07-07 03:12:21 -0700 | [diff] [blame] | 64 | /** Hidden field Settings.Secure.ENABLED_NOTIFICATION_LISTENERS */ |
| 65 | private static final String NOTIFICATION_ENABLED_LISTENERS = "enabled_notification_listeners"; |
Tony Wickham | 2ab8482 | 2017-05-12 14:59:09 -0700 | [diff] [blame] | 66 | |
Sunny Goyal | 3fbca15 | 2017-11-02 18:55:44 -0700 | [diff] [blame] | 67 | private static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"; |
Sunny Goyal | d47f2d2 | 2018-04-18 14:11:37 -0700 | [diff] [blame] | 68 | private static final String EXTRA_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args"; |
Sunny Goyal | 3fbca15 | 2017-11-02 18:55:44 -0700 | [diff] [blame] | 69 | private static final int DELAY_HIGHLIGHT_DURATION_MILLIS = 600; |
| 70 | private static final String SAVE_HIGHLIGHTED_KEY = "android:preference_highlighted"; |
| 71 | |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 72 | @Override |
| 73 | protected void onCreate(Bundle savedInstanceState) { |
| 74 | super.onCreate(savedInstanceState); |
| 75 | |
Mario Bertschler | 2de2d67 | 2017-06-30 18:51:46 -0700 | [diff] [blame] | 76 | if (savedInstanceState == null) { |
Sunny Goyal | 7f920b8 | 2018-06-27 15:47:49 -0700 | [diff] [blame] | 77 | Fragment f = Fragment.instantiate(this, getString(R.string.settings_fragment_name)); |
Mario Bertschler | 2de2d67 | 2017-06-30 18:51:46 -0700 | [diff] [blame] | 78 | // Display the fragment as the main content. |
| 79 | getFragmentManager().beginTransaction() |
Sunny Goyal | 7f920b8 | 2018-06-27 15:47:49 -0700 | [diff] [blame] | 80 | .replace(android.R.id.content, f) |
Mario Bertschler | 2de2d67 | 2017-06-30 18:51:46 -0700 | [diff] [blame] | 81 | .commit(); |
| 82 | } |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Sunny Goyal | 3fbca15 | 2017-11-02 18:55:44 -0700 | [diff] [blame] | 85 | protected PreferenceFragment getNewFragment() { |
| 86 | return new LauncherSettingsFragment(); |
| 87 | } |
| 88 | |
Sunny Goyal | 7f920b8 | 2018-06-27 15:47:49 -0700 | [diff] [blame] | 89 | @Override |
| 90 | public boolean onPreferenceStartFragment( |
| 91 | PreferenceFragment preferenceFragment, Preference pref) { |
Sunny Goyal | 5077aef | 2018-09-17 15:22:13 -0700 | [diff] [blame] | 92 | if (getFragmentManager().isStateSaved()) { |
| 93 | // Sometimes onClick can come after onPause because of being posted on the handler. |
| 94 | // Skip starting new fragments in that case. |
| 95 | return false; |
| 96 | } |
Sunny Goyal | 7f920b8 | 2018-06-27 15:47:49 -0700 | [diff] [blame] | 97 | Fragment f = Fragment.instantiate(this, pref.getFragment(), pref.getExtras()); |
| 98 | if (f instanceof DialogFragment) { |
| 99 | ((DialogFragment) f).show(getFragmentManager(), pref.getKey()); |
| 100 | } else { |
| 101 | getFragmentManager() |
| 102 | .beginTransaction() |
| 103 | .replace(android.R.id.content, f) |
| 104 | .addToBackStack(pref.getKey()) |
| 105 | .commit(); |
| 106 | } |
| 107 | return true; |
| 108 | } |
| 109 | |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 110 | /** |
| 111 | * This fragment shows the launcher preferences. |
| 112 | */ |
Sunny Goyal | f48e592 | 2016-05-12 15:36:20 -0700 | [diff] [blame] | 113 | public static class LauncherSettingsFragment extends PreferenceFragment { |
| 114 | |
Sunny Goyal | 420d545 | 2018-10-17 10:25:14 -0700 | [diff] [blame] | 115 | private SecureSettingsObserver mIconBadgingObserver; |
Sunny Goyal | f48e592 | 2016-05-12 15:36:20 -0700 | [diff] [blame] | 116 | |
Sunny Goyal | 3fbca15 | 2017-11-02 18:55:44 -0700 | [diff] [blame] | 117 | private String mPreferenceKey; |
| 118 | private boolean mPreferenceHighlighted = false; |
| 119 | |
| 120 | @Override |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 121 | public void onCreate(Bundle savedInstanceState) { |
| 122 | super.onCreate(savedInstanceState); |
Sunny Goyal | 3fbca15 | 2017-11-02 18:55:44 -0700 | [diff] [blame] | 123 | if (savedInstanceState != null) { |
| 124 | mPreferenceHighlighted = savedInstanceState.getBoolean(SAVE_HIGHLIGHTED_KEY); |
| 125 | } |
| 126 | |
Sunny Goyal | f48e592 | 2016-05-12 15:36:20 -0700 | [diff] [blame] | 127 | getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY); |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 128 | addPreferencesFromResource(R.xml.launcher_preferences); |
Sunny Goyal | 7779d62 | 2015-06-11 16:18:39 -0700 | [diff] [blame] | 129 | |
Ryan Lothian | fa530cd | 2018-10-12 14:14:16 -0400 | [diff] [blame] | 130 | // Only show flag toggler UI if this build variant implements that. |
| 131 | Preference flagToggler = findPreference(FLAGS_PREFERENCE_KEY); |
| 132 | if (flagToggler != null && !FeatureFlags.showFlagTogglerUi()) { |
| 133 | getPreferenceScreen().removePreference(flagToggler); |
| 134 | } |
| 135 | |
Tony Wickham | 2ab8482 | 2017-05-12 14:59:09 -0700 | [diff] [blame] | 136 | ContentResolver resolver = getActivity().getContentResolver(); |
| 137 | |
Sunny Goyal | 848cad5 | 2017-07-07 03:12:21 -0700 | [diff] [blame] | 138 | ButtonPreference iconBadgingPref = |
| 139 | (ButtonPreference) findPreference(ICON_BADGING_PREFERENCE_KEY); |
Hyunyoung Song | e24cb63 | 2017-09-11 11:18:03 -0700 | [diff] [blame] | 140 | if (!Utilities.ATLEAST_OREO) { |
Sunny Goyal | 4179e9b | 2017-03-08 14:25:09 -0800 | [diff] [blame] | 141 | getPreferenceScreen().removePreference( |
| 142 | findPreference(SessionCommitReceiver.ADD_ICON_PREFERENCE_KEY)); |
Tony Wickham | 2ab8482 | 2017-05-12 14:59:09 -0700 | [diff] [blame] | 143 | getPreferenceScreen().removePreference(iconBadgingPref); |
Tony Wickham | c138515 | 2017-08-14 14:31:03 -0700 | [diff] [blame] | 144 | } else if (!getResources().getBoolean(R.bool.notification_badging_enabled)) { |
| 145 | getPreferenceScreen().removePreference(iconBadgingPref); |
Tony Wickham | 2ab8482 | 2017-05-12 14:59:09 -0700 | [diff] [blame] | 146 | } else { |
| 147 | // Listen to system notification badge settings while this UI is active. |
Sunny Goyal | 420d545 | 2018-10-17 10:25:14 -0700 | [diff] [blame] | 148 | mIconBadgingObserver = newNotificationSettingsObserver( |
| 149 | getActivity(), new IconBadgingObserver(iconBadgingPref, resolver)); |
| 150 | mIconBadgingObserver.register(); |
| 151 | // Also listen if notification permission changes |
| 152 | mIconBadgingObserver.getResolver().registerContentObserver( |
| 153 | Settings.Secure.getUriFor(NOTIFICATION_ENABLED_LISTENERS), false, |
| 154 | mIconBadgingObserver); |
| 155 | mIconBadgingObserver.dispatchOnChange(); |
Sunny Goyal | 4179e9b | 2017-03-08 14:25:09 -0800 | [diff] [blame] | 156 | } |
Sunny Goyal | ca18746 | 2017-03-31 20:09:34 -0700 | [diff] [blame] | 157 | |
| 158 | Preference iconShapeOverride = findPreference(IconShapeOverride.KEY_PREFERENCE); |
| 159 | if (iconShapeOverride != null) { |
| 160 | if (IconShapeOverride.isSupported(getActivity())) { |
| 161 | IconShapeOverride.handlePreferenceUi((ListPreference) iconShapeOverride); |
| 162 | } else { |
| 163 | getPreferenceScreen().removePreference(iconShapeOverride); |
| 164 | } |
| 165 | } |
Sunny Goyal | 4025332 | 2018-04-19 09:27:38 -0700 | [diff] [blame] | 166 | |
| 167 | // Setup allow rotation preference |
| 168 | Preference rotationPref = findPreference(ALLOW_ROTATION_PREFERENCE_KEY); |
| 169 | if (getResources().getBoolean(R.bool.allow_rotation)) { |
| 170 | // Launcher supports rotation by default. No need to show this setting. |
| 171 | getPreferenceScreen().removePreference(rotationPref); |
| 172 | } else { |
Sunny Goyal | 4025332 | 2018-04-19 09:27:38 -0700 | [diff] [blame] | 173 | // Initialize the UI once |
| 174 | rotationPref.setDefaultValue(getAllowRotationDefaultValue()); |
| 175 | } |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 176 | } |
Rahul Chaturvedi | 799aa04 | 2015-06-01 21:26:41 -0400 | [diff] [blame] | 177 | |
| 178 | @Override |
Sunny Goyal | 3fbca15 | 2017-11-02 18:55:44 -0700 | [diff] [blame] | 179 | public void onSaveInstanceState(Bundle outState) { |
| 180 | super.onSaveInstanceState(outState); |
| 181 | outState.putBoolean(SAVE_HIGHLIGHTED_KEY, mPreferenceHighlighted); |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public void onResume() { |
| 186 | super.onResume(); |
| 187 | |
| 188 | Intent intent = getActivity().getIntent(); |
| 189 | mPreferenceKey = intent.getStringExtra(EXTRA_FRAGMENT_ARG_KEY); |
| 190 | if (isAdded() && !mPreferenceHighlighted && !TextUtils.isEmpty(mPreferenceKey)) { |
| 191 | getView().postDelayed(this::highlightPreference, DELAY_HIGHLIGHT_DURATION_MILLIS); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | private void highlightPreference() { |
Sunny Goyal | 3fbca15 | 2017-11-02 18:55:44 -0700 | [diff] [blame] | 196 | Preference pref = findPreference(mPreferenceKey); |
Sunny Goyal | ba406e2 | 2018-04-02 11:36:12 -0700 | [diff] [blame] | 197 | if (pref == null || getPreferenceScreen() == null) { |
Sunny Goyal | 3fbca15 | 2017-11-02 18:55:44 -0700 | [diff] [blame] | 198 | return; |
| 199 | } |
Sunny Goyal | ba406e2 | 2018-04-02 11:36:12 -0700 | [diff] [blame] | 200 | PreferenceScreen screen = getPreferenceScreen(); |
| 201 | if (Utilities.ATLEAST_OREO) { |
| 202 | screen = selectPreferenceRecursive(pref, screen); |
| 203 | } |
| 204 | if (screen == null) { |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | View root = screen.getDialog() != null |
| 209 | ? screen.getDialog().getWindow().getDecorView() : getView(); |
| 210 | ListView list = root.findViewById(android.R.id.list); |
| 211 | if (list == null || list.getAdapter() == null) { |
| 212 | return; |
| 213 | } |
| 214 | Adapter adapter = list.getAdapter(); |
Sunny Goyal | 3fbca15 | 2017-11-02 18:55:44 -0700 | [diff] [blame] | 215 | |
| 216 | // Find the position |
| 217 | int position = -1; |
| 218 | for (int i = adapter.getCount() - 1; i >= 0; i--) { |
| 219 | if (pref == adapter.getItem(i)) { |
| 220 | position = i; |
| 221 | break; |
| 222 | } |
| 223 | } |
Sunny Goyal | ba406e2 | 2018-04-02 11:36:12 -0700 | [diff] [blame] | 224 | new ListViewHighlighter(list, position); |
Sunny Goyal | 3fbca15 | 2017-11-02 18:55:44 -0700 | [diff] [blame] | 225 | mPreferenceHighlighted = true; |
| 226 | } |
| 227 | |
| 228 | @Override |
Sunny Goyal | f48e592 | 2016-05-12 15:36:20 -0700 | [diff] [blame] | 229 | public void onDestroy() { |
Tony Wickham | 2ab8482 | 2017-05-12 14:59:09 -0700 | [diff] [blame] | 230 | if (mIconBadgingObserver != null) { |
Tony | d48710c | 2017-07-27 23:23:58 -0700 | [diff] [blame] | 231 | mIconBadgingObserver.unregister(); |
Tony Wickham | 2ab8482 | 2017-05-12 14:59:09 -0700 | [diff] [blame] | 232 | mIconBadgingObserver = null; |
| 233 | } |
Sunny Goyal | f48e592 | 2016-05-12 15:36:20 -0700 | [diff] [blame] | 234 | super.onDestroy(); |
| 235 | } |
Sunny Goyal | ba406e2 | 2018-04-02 11:36:12 -0700 | [diff] [blame] | 236 | |
| 237 | @TargetApi(Build.VERSION_CODES.O) |
| 238 | private PreferenceScreen selectPreferenceRecursive( |
| 239 | Preference pref, PreferenceScreen topParent) { |
| 240 | if (!(pref.getParent() instanceof PreferenceScreen)) { |
| 241 | return null; |
| 242 | } |
| 243 | |
| 244 | PreferenceScreen parent = (PreferenceScreen) pref.getParent(); |
| 245 | if (Objects.equals(parent.getKey(), topParent.getKey())) { |
| 246 | return parent; |
| 247 | } else if (selectPreferenceRecursive(parent, topParent) != null) { |
| 248 | ((PreferenceScreen) parent.getParent()) |
| 249 | .onItemClick(null, null, parent.getOrder(), 0); |
| 250 | return parent; |
| 251 | } else { |
| 252 | return null; |
| 253 | } |
| 254 | } |
Sunny Goyal | f48e592 | 2016-05-12 15:36:20 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | /** |
Tony Wickham | 2ab8482 | 2017-05-12 14:59:09 -0700 | [diff] [blame] | 258 | * Content observer which listens for system badging setting changes, |
| 259 | * and updates the launcher badging setting subtext accordingly. |
| 260 | */ |
Sunny Goyal | 420d545 | 2018-10-17 10:25:14 -0700 | [diff] [blame] | 261 | private static class IconBadgingObserver implements SecureSettingsObserver.OnChangeListener { |
Tony Wickham | 2ab8482 | 2017-05-12 14:59:09 -0700 | [diff] [blame] | 262 | |
Sunny Goyal | 848cad5 | 2017-07-07 03:12:21 -0700 | [diff] [blame] | 263 | private final ButtonPreference mBadgingPref; |
Tony Wickham | 2ab8482 | 2017-05-12 14:59:09 -0700 | [diff] [blame] | 264 | private final ContentResolver mResolver; |
| 265 | |
Sunny Goyal | 420d545 | 2018-10-17 10:25:14 -0700 | [diff] [blame] | 266 | public IconBadgingObserver(ButtonPreference badgingPref, ContentResolver resolver) { |
Tony Wickham | 2ab8482 | 2017-05-12 14:59:09 -0700 | [diff] [blame] | 267 | mBadgingPref = badgingPref; |
| 268 | mResolver = resolver; |
| 269 | } |
| 270 | |
| 271 | @Override |
Sunny Goyal | 420d545 | 2018-10-17 10:25:14 -0700 | [diff] [blame] | 272 | public void onSettingsChanged(boolean enabled) { |
Sunny Goyal | 848cad5 | 2017-07-07 03:12:21 -0700 | [diff] [blame] | 273 | int summary = enabled ? R.string.icon_badging_desc_on : R.string.icon_badging_desc_off; |
| 274 | |
| 275 | boolean serviceEnabled = true; |
| 276 | if (enabled) { |
| 277 | // Check if the listener is enabled or not. |
| 278 | String enabledListeners = |
| 279 | Settings.Secure.getString(mResolver, NOTIFICATION_ENABLED_LISTENERS); |
| 280 | ComponentName myListener = |
| 281 | new ComponentName(mBadgingPref.getContext(), NotificationListener.class); |
| 282 | serviceEnabled = enabledListeners != null && |
| 283 | (enabledListeners.contains(myListener.flattenToString()) || |
| 284 | enabledListeners.contains(myListener.flattenToShortString())); |
| 285 | if (!serviceEnabled) { |
| 286 | summary = R.string.title_missing_notification_access; |
| 287 | } |
| 288 | } |
Sunny Goyal | b65e13c | 2017-08-01 11:04:15 -0700 | [diff] [blame] | 289 | mBadgingPref.setWidgetFrameVisible(!serviceEnabled); |
Sunny Goyal | 5077aef | 2018-09-17 15:22:13 -0700 | [diff] [blame] | 290 | mBadgingPref.setFragment( |
| 291 | serviceEnabled ? null : NotificationAccessConfirmation.class.getName()); |
Sunny Goyal | 848cad5 | 2017-07-07 03:12:21 -0700 | [diff] [blame] | 292 | mBadgingPref.setSummary(summary); |
| 293 | |
| 294 | } |
Tony Wickham | 2ab8482 | 2017-05-12 14:59:09 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Sunny Goyal | 848cad5 | 2017-07-07 03:12:21 -0700 | [diff] [blame] | 297 | public static class NotificationAccessConfirmation |
| 298 | extends DialogFragment implements DialogInterface.OnClickListener { |
| 299 | |
| 300 | @Override |
| 301 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 302 | final Context context = getActivity(); |
| 303 | String msg = context.getString(R.string.msg_missing_notification_access, |
| 304 | context.getString(R.string.derived_app_name)); |
| 305 | return new AlertDialog.Builder(context) |
| 306 | .setTitle(R.string.title_missing_notification_access) |
| 307 | .setMessage(msg) |
| 308 | .setNegativeButton(android.R.string.cancel, null) |
| 309 | .setPositiveButton(R.string.title_change_settings, this) |
| 310 | .create(); |
| 311 | } |
| 312 | |
| 313 | @Override |
| 314 | public void onClick(DialogInterface dialogInterface, int i) { |
| 315 | ComponentName cn = new ComponentName(getActivity(), NotificationListener.class); |
Sunny Goyal | d47f2d2 | 2018-04-18 14:11:37 -0700 | [diff] [blame] | 316 | Bundle showFragmentArgs = new Bundle(); |
| 317 | showFragmentArgs.putString(EXTRA_FRAGMENT_ARG_KEY, cn.flattenToString()); |
| 318 | |
Sunny Goyal | 848cad5 | 2017-07-07 03:12:21 -0700 | [diff] [blame] | 319 | Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS) |
| 320 | .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
Sunny Goyal | d47f2d2 | 2018-04-18 14:11:37 -0700 | [diff] [blame] | 321 | .putExtra(EXTRA_FRAGMENT_ARG_KEY, cn.flattenToString()) |
| 322 | .putExtra(EXTRA_SHOW_FRAGMENT_ARGS, showFragmentArgs); |
Sunny Goyal | 848cad5 | 2017-07-07 03:12:21 -0700 | [diff] [blame] | 323 | getActivity().startActivity(intent); |
| 324 | } |
| 325 | } |
Rahul Chaturvedi | 7fc77ca | 2015-05-19 18:02:16 -0700 | [diff] [blame] | 326 | } |