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