Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.settings; |
| 18 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 19 | import android.app.ActionBar; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 20 | import android.app.Fragment; |
| 21 | import android.app.FragmentManager; |
| 22 | import android.app.FragmentTransaction; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 24 | import android.content.ComponentName; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
| 27 | import android.content.IntentFilter; |
| 28 | import android.content.SharedPreferences; |
| 29 | import android.content.pm.ActivityInfo; |
| 30 | import android.content.pm.PackageManager; |
| 31 | import android.content.pm.PackageManager.NameNotFoundException; |
| 32 | import android.content.pm.ResolveInfo; |
| 33 | import android.content.res.Configuration; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 34 | import android.nfc.NfcAdapter; |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 35 | import android.os.AsyncTask; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 36 | import android.os.Bundle; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 37 | import android.os.UserHandle; |
| 38 | import android.os.UserManager; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 39 | import android.support.v14.preference.PreferenceFragment; |
| 40 | import android.support.v7.preference.Preference; |
| 41 | import android.support.v7.preference.PreferenceManager; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 42 | import android.text.TextUtils; |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 43 | import android.transition.TransitionManager; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 44 | import android.util.Log; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 45 | import android.view.Menu; |
| 46 | import android.view.MenuInflater; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 47 | import android.view.MenuItem; |
| 48 | import android.view.View; |
| 49 | import android.view.View.OnClickListener; |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 50 | import android.view.ViewGroup; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 51 | import android.widget.Button; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 52 | import android.widget.SearchView; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 53 | import com.android.internal.logging.MetricsLogger; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 54 | import com.android.internal.util.ArrayUtils; |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 55 | import com.android.settings.Settings.WifiSettingsActivity; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 56 | import com.android.settings.accessibility.AccessibilitySettings; |
| 57 | import com.android.settings.accessibility.CaptionPropertiesFragment; |
Alexandra Gherghina | 6d83987 | 2014-07-22 12:04:58 +0000 | [diff] [blame] | 58 | import com.android.settings.accounts.AccountSettings; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 59 | import com.android.settings.accounts.AccountSyncSettings; |
Billy Lau | fee7856 | 2015-07-27 12:57:07 +0100 | [diff] [blame] | 60 | import com.android.settings.applications.DrawOverlayDetails; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 61 | import com.android.settings.applications.InstalledAppDetails; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 62 | import com.android.settings.applications.ManageApplications; |
Xiyuan Xia | 86a5540 | 2015-06-02 14:55:32 -0700 | [diff] [blame] | 63 | import com.android.settings.applications.ManageAssist; |
Julia Reynolds | 2e1e0b7 | 2015-12-14 08:32:46 -0500 | [diff] [blame^] | 64 | import com.android.settings.applications.ManageDefaultApps; |
Jason Monk | 2cdafc6 | 2015-06-12 12:32:50 -0400 | [diff] [blame] | 65 | import com.android.settings.applications.ProcessStatsSummary; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 66 | import com.android.settings.applications.ProcessStatsUi; |
Jason Monk | d8da51c | 2015-04-17 14:34:12 -0400 | [diff] [blame] | 67 | import com.android.settings.applications.UsageAccessDetails; |
Billy Lau | fee7856 | 2015-07-27 12:57:07 +0100 | [diff] [blame] | 68 | import com.android.settings.applications.WriteSettingsDetails; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 69 | import com.android.settings.bluetooth.BluetoothSettings; |
| 70 | import com.android.settings.dashboard.DashboardSummary; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 71 | import com.android.settings.dashboard.SearchResultsSummary; |
Jeff Sharkey | a16257d | 2015-04-28 13:41:01 -0700 | [diff] [blame] | 72 | import com.android.settings.deviceinfo.PrivateVolumeForget; |
Jeff Sharkey | e77f068 | 2015-04-29 11:24:57 -0700 | [diff] [blame] | 73 | import com.android.settings.deviceinfo.PrivateVolumeSettings; |
Jeff Sharkey | 42833b2 | 2015-04-11 21:27:33 -0700 | [diff] [blame] | 74 | import com.android.settings.deviceinfo.PublicVolumeSettings; |
| 75 | import com.android.settings.deviceinfo.StorageSettings; |
John Spurlock | c7f8e8c | 2014-06-04 19:11:22 -0400 | [diff] [blame] | 76 | import com.android.settings.fuelgauge.BatterySaverSettings; |
Jason Monk | 1eb54eb | 2015-04-29 12:46:42 -0400 | [diff] [blame] | 77 | import com.android.settings.fuelgauge.PowerUsageDetail; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 78 | import com.android.settings.fuelgauge.PowerUsageSummary; |
| 79 | import com.android.settings.inputmethod.InputMethodAndLanguageSettings; |
| 80 | import com.android.settings.inputmethod.KeyboardLayoutPickerFragment; |
| 81 | import com.android.settings.inputmethod.SpellCheckersSettings; |
| 82 | import com.android.settings.inputmethod.UserDictionaryList; |
| 83 | import com.android.settings.location.LocationSettings; |
| 84 | import com.android.settings.nfc.AndroidBeam; |
| 85 | import com.android.settings.nfc.PaymentSettings; |
John Spurlock | 802ddf9 | 2014-07-18 11:51:13 -0400 | [diff] [blame] | 86 | import com.android.settings.notification.AppNotificationSettings; |
Julia Reynolds | 8c0a423 | 2015-11-24 10:08:14 -0500 | [diff] [blame] | 87 | import com.android.settings.notification.ConfigureNotificationSettings; |
John Spurlock | 4a35051 | 2014-04-08 14:08:21 -0400 | [diff] [blame] | 88 | import com.android.settings.notification.NotificationAccessSettings; |
Julia Reynolds | 8c0a423 | 2015-11-24 10:08:14 -0500 | [diff] [blame] | 89 | import com.android.settings.notification.SoundSettings; |
John Spurlock | 4a35051 | 2014-04-08 14:08:21 -0400 | [diff] [blame] | 90 | import com.android.settings.notification.NotificationStation; |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 91 | import com.android.settings.notification.OtherSoundSettings; |
John Spurlock | 08531a8 | 2015-05-07 17:45:43 -0400 | [diff] [blame] | 92 | import com.android.settings.notification.ZenAccessSettings; |
John Spurlock | 533a566 | 2015-06-19 10:47:36 -0400 | [diff] [blame] | 93 | import com.android.settings.notification.ZenModeAutomationSettings; |
John Spurlock | f57bad7 | 2015-04-30 09:26:15 -0400 | [diff] [blame] | 94 | import com.android.settings.notification.ZenModeEventRuleSettings; |
John Spurlock | c1df2aa | 2015-04-13 20:57:06 -0400 | [diff] [blame] | 95 | import com.android.settings.notification.ZenModePrioritySettings; |
John Spurlock | 45fa140 | 2015-04-09 12:50:04 -0400 | [diff] [blame] | 96 | import com.android.settings.notification.ZenModeScheduleRuleSettings; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 97 | import com.android.settings.notification.ZenModeSettings; |
Julia Reynolds | 5555d26 | 2015-11-09 10:52:17 -0500 | [diff] [blame] | 98 | import com.android.settings.notification.ZenModeVisualInterruptionSettings; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 99 | import com.android.settings.print.PrintJobSettingsFragment; |
| 100 | import com.android.settings.print.PrintSettingsFragment; |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 101 | import com.android.settings.search.DynamicIndexableContentMonitor; |
| 102 | import com.android.settings.search.Index; |
PauloftheWest | 3815561 | 2014-06-30 10:02:36 -0700 | [diff] [blame] | 103 | import com.android.settings.sim.SimSettings; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 104 | import com.android.settings.tts.TextToSpeechSettings; |
| 105 | import com.android.settings.users.UserSettings; |
| 106 | import com.android.settings.vpn2.VpnSettings; |
| 107 | import com.android.settings.wfd.WifiDisplaySettings; |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 108 | import com.android.settings.widget.SwitchBar; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 109 | import com.android.settings.wifi.AdvancedWifiSettings; |
PauloftheWest | 7837b99 | 2014-06-24 07:42:27 -0700 | [diff] [blame] | 110 | import com.android.settings.wifi.SavedAccessPointsWifiSettings; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 111 | import com.android.settings.wifi.WifiSettings; |
| 112 | import com.android.settings.wifi.p2p.WifiP2pSettings; |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 113 | import com.android.settingslib.drawer.DashboardCategory; |
| 114 | import com.android.settingslib.drawer.DashboardTile; |
| 115 | import com.android.settingslib.drawer.SettingsDrawerActivity; |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 116 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 117 | import java.util.ArrayList; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 118 | import java.util.List; |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 119 | import java.util.Set; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 120 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 121 | public class SettingsActivity extends SettingsDrawerActivity |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 122 | implements PreferenceManager.OnPreferenceTreeClickListener, |
| 123 | PreferenceFragment.OnPreferenceStartFragmentCallback, |
Alexandra Gherghina | cfc7f9d | 2014-07-04 12:25:38 +0100 | [diff] [blame] | 124 | ButtonBarHandler, FragmentManager.OnBackStackChangedListener, |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 125 | SearchView.OnQueryTextListener, SearchView.OnCloseListener, |
Alexandra Gherghina | cfc7f9d | 2014-07-04 12:25:38 +0100 | [diff] [blame] | 126 | MenuItem.OnActionExpandListener { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 127 | |
| 128 | private static final String LOG_TAG = "Settings"; |
| 129 | |
| 130 | // Constants for state save/restore |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 131 | private static final String SAVE_KEY_CATEGORIES = ":settings:categories"; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 132 | private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded"; |
| 133 | private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query"; |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 134 | private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up"; |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 135 | private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search"; |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 136 | private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count"; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * When starting this activity, the invoking Intent can contain this extra |
| 140 | * string to specify which fragment should be initially displayed. |
| 141 | * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity |
| 142 | * will call isValidFragment() to confirm that the fragment class name is valid for this |
| 143 | * activity. |
| 144 | */ |
| 145 | public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment"; |
| 146 | |
| 147 | /** |
| 148 | * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, |
| 149 | * this extra can also be specified to supply a Bundle of arguments to pass |
| 150 | * to that fragment when it is instantiated during the initial creation |
| 151 | * of the activity. |
| 152 | */ |
| 153 | public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args"; |
| 154 | |
| 155 | /** |
Fabrice Di Meglio | c145732 | 2014-04-04 19:07:50 -0700 | [diff] [blame] | 156 | * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS} |
| 157 | */ |
| 158 | public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"; |
| 159 | |
Fabrice Di Meglio | 6f0739a | 2014-02-03 18:12:25 -0800 | [diff] [blame] | 160 | public static final String BACK_STACK_PREFS = ":settings:prefs"; |
| 161 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 162 | // extras that allow any preference activity to be launched as part of a wizard |
| 163 | |
| 164 | // show Back and Next buttons? takes boolean parameter |
| 165 | // Back will then return RESULT_CANCELED and Next RESULT_OK |
| 166 | protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; |
| 167 | |
| 168 | // add a Skip button? |
| 169 | private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip"; |
| 170 | |
| 171 | // specify custom text for the Back or Next buttons, or cause a button to not appear |
| 172 | // at all by setting it to null |
| 173 | protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text"; |
| 174 | protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text"; |
| 175 | |
| 176 | /** |
| 177 | * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 178 | * those extra can also be specify to supply the title or title res id to be shown for |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 179 | * that fragment. |
| 180 | */ |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 181 | public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title"; |
Alexandra Gherghina | 62464b8 | 2014-08-11 12:40:13 +0100 | [diff] [blame] | 182 | /** |
| 183 | * The package name used to resolve the title resource id. |
| 184 | */ |
| 185 | public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME = |
| 186 | ":settings:show_fragment_title_res_package_name"; |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 187 | public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = |
| 188 | ":settings:show_fragment_title_resid"; |
| 189 | public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT = |
| 190 | ":settings:show_fragment_as_shortcut"; |
| 191 | |
| 192 | public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING = |
| 193 | ":settings:show_fragment_as_subsetting"; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 194 | |
Jason Monk | 3069581 | 2015-11-17 09:01:08 -0500 | [diff] [blame] | 195 | public static final String META_DATA_KEY_FRAGMENT_CLASS = |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 196 | "com.android.settings.FRAGMENT_CLASS"; |
| 197 | |
| 198 | private static final String EXTRA_UI_OPTIONS = "settings:ui_options"; |
| 199 | |
Fabrice Di Meglio | d6985df | 2014-04-03 16:43:26 -0700 | [diff] [blame] | 200 | private static final String EMPTY_QUERY = ""; |
| 201 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 202 | private String mFragmentClass; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 203 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 204 | private CharSequence mInitialTitle; |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 205 | private int mInitialTitleResId; |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 206 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 207 | // Show only these settings for restricted users |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 208 | private String[] SETTINGS_FOR_RESTRICTED = { |
| 209 | //wireless_section |
| 210 | WifiSettingsActivity.class.getName(), |
| 211 | Settings.BluetoothSettingsActivity.class.getName(), |
| 212 | Settings.DataUsageSummaryActivity.class.getName(), |
| 213 | Settings.SimSettingsActivity.class.getName(), |
| 214 | Settings.WirelessSettingsActivity.class.getName(), |
| 215 | //device_section |
| 216 | Settings.HomeSettingsActivity.class.getName(), |
Julia Reynolds | 8c0a423 | 2015-11-24 10:08:14 -0500 | [diff] [blame] | 217 | Settings.SoundSettingsActivity.class.getName(), |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 218 | Settings.DisplaySettingsActivity.class.getName(), |
| 219 | Settings.StorageSettingsActivity.class.getName(), |
| 220 | Settings.ManageApplicationsActivity.class.getName(), |
| 221 | Settings.PowerUsageSummaryActivity.class.getName(), |
| 222 | //personal_section |
| 223 | Settings.LocationSettingsActivity.class.getName(), |
| 224 | Settings.SecuritySettingsActivity.class.getName(), |
| 225 | Settings.InputMethodAndLanguageSettingsActivity.class.getName(), |
| 226 | Settings.UserSettingsActivity.class.getName(), |
| 227 | Settings.AccountSettingsActivity.class.getName(), |
| 228 | //system_section |
| 229 | Settings.DateTimeSettingsActivity.class.getName(), |
| 230 | Settings.DeviceInfoSettingsActivity.class.getName(), |
| 231 | Settings.AccessibilitySettingsActivity.class.getName(), |
| 232 | Settings.PrintSettingsActivity.class.getName(), |
| 233 | Settings.PaymentSettingsActivity.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | private static final String[] ENTRY_FRAGMENTS = { |
| 237 | WirelessSettings.class.getName(), |
| 238 | WifiSettings.class.getName(), |
| 239 | AdvancedWifiSettings.class.getName(), |
PauloftheWest | 7837b99 | 2014-06-24 07:42:27 -0700 | [diff] [blame] | 240 | SavedAccessPointsWifiSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 241 | BluetoothSettings.class.getName(), |
PauloftheWest | 3815561 | 2014-06-30 10:02:36 -0700 | [diff] [blame] | 242 | SimSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 243 | TetherSettings.class.getName(), |
| 244 | WifiP2pSettings.class.getName(), |
| 245 | VpnSettings.class.getName(), |
| 246 | DateTimeSettings.class.getName(), |
| 247 | LocalePicker.class.getName(), |
| 248 | InputMethodAndLanguageSettings.class.getName(), |
| 249 | SpellCheckersSettings.class.getName(), |
| 250 | UserDictionaryList.class.getName(), |
| 251 | UserDictionarySettings.class.getName(), |
Amith Yamasani | 3033ce0 | 2014-07-14 18:03:15 -0700 | [diff] [blame] | 252 | HomeSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 253 | DisplaySettings.class.getName(), |
| 254 | DeviceInfoSettings.class.getName(), |
| 255 | ManageApplications.class.getName(), |
Xiyuan Xia | 86a5540 | 2015-06-02 14:55:32 -0700 | [diff] [blame] | 256 | ManageAssist.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 257 | ProcessStatsUi.class.getName(), |
| 258 | NotificationStation.class.getName(), |
| 259 | LocationSettings.class.getName(), |
| 260 | SecuritySettings.class.getName(), |
Jason Monk | d8da51c | 2015-04-17 14:34:12 -0400 | [diff] [blame] | 261 | UsageAccessDetails.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 262 | PrivacySettings.class.getName(), |
| 263 | DeviceAdminSettings.class.getName(), |
| 264 | AccessibilitySettings.class.getName(), |
| 265 | CaptionPropertiesFragment.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 266 | com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(), |
| 267 | TextToSpeechSettings.class.getName(), |
Jeff Sharkey | 42833b2 | 2015-04-11 21:27:33 -0700 | [diff] [blame] | 268 | StorageSettings.class.getName(), |
Jeff Sharkey | a16257d | 2015-04-28 13:41:01 -0700 | [diff] [blame] | 269 | PrivateVolumeForget.class.getName(), |
Jeff Sharkey | e77f068 | 2015-04-29 11:24:57 -0700 | [diff] [blame] | 270 | PrivateVolumeSettings.class.getName(), |
| 271 | PublicVolumeSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 272 | DevelopmentSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 273 | AndroidBeam.class.getName(), |
| 274 | WifiDisplaySettings.class.getName(), |
| 275 | PowerUsageSummary.class.getName(), |
| 276 | AccountSyncSettings.class.getName(), |
Alexandra Gherghina | 6d83987 | 2014-07-22 12:04:58 +0000 | [diff] [blame] | 277 | AccountSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 278 | CryptKeeperSettings.class.getName(), |
| 279 | DataUsageSummary.class.getName(), |
| 280 | DreamSettings.class.getName(), |
| 281 | UserSettings.class.getName(), |
| 282 | NotificationAccessSettings.class.getName(), |
John Spurlock | 08531a8 | 2015-05-07 17:45:43 -0400 | [diff] [blame] | 283 | ZenAccessSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 284 | PrintSettingsFragment.class.getName(), |
| 285 | PrintJobSettingsFragment.class.getName(), |
| 286 | TrustedCredentialsSettings.class.getName(), |
| 287 | PaymentSettings.class.getName(), |
| 288 | KeyboardLayoutPickerFragment.class.getName(), |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 289 | ZenModeSettings.class.getName(), |
Julia Reynolds | 8c0a423 | 2015-11-24 10:08:14 -0500 | [diff] [blame] | 290 | SoundSettings.class.getName(), |
| 291 | ConfigureNotificationSettings.class.getName(), |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 292 | ChooseLockPassword.ChooseLockPasswordFragment.class.getName(), |
| 293 | ChooseLockPattern.ChooseLockPatternFragment.class.getName(), |
John Spurlock | c7f8e8c | 2014-06-04 19:11:22 -0400 | [diff] [blame] | 294 | InstalledAppDetails.class.getName(), |
| 295 | BatterySaverSettings.class.getName(), |
Fabrice Di Meglio | dcf59dd | 2014-07-21 11:22:20 -0700 | [diff] [blame] | 296 | AppNotificationSettings.class.getName(), |
Fabrice Di Meglio | e3ff4d8 | 2014-07-23 20:03:20 -0700 | [diff] [blame] | 297 | OtherSoundSettings.class.getName(), |
Narayan Kamath | 33acb15 | 2015-03-16 12:48:05 +0000 | [diff] [blame] | 298 | ApnSettings.class.getName(), |
John Spurlock | 45fa140 | 2015-04-09 12:50:04 -0400 | [diff] [blame] | 299 | WifiCallingSettings.class.getName(), |
John Spurlock | c1df2aa | 2015-04-13 20:57:06 -0400 | [diff] [blame] | 300 | ZenModePrioritySettings.class.getName(), |
John Spurlock | 533a566 | 2015-06-19 10:47:36 -0400 | [diff] [blame] | 301 | ZenModeAutomationSettings.class.getName(), |
John Spurlock | 45fa140 | 2015-04-09 12:50:04 -0400 | [diff] [blame] | 302 | ZenModeScheduleRuleSettings.class.getName(), |
John Spurlock | f57bad7 | 2015-04-30 09:26:15 -0400 | [diff] [blame] | 303 | ZenModeEventRuleSettings.class.getName(), |
Julia Reynolds | 5555d26 | 2015-11-09 10:52:17 -0500 | [diff] [blame] | 304 | ZenModeVisualInterruptionSettings.class.getName(), |
Jason Monk | 2583fc1 | 2015-03-25 09:46:30 -0400 | [diff] [blame] | 305 | ProcessStatsUi.class.getName(), |
Jason Monk | 1eb54eb | 2015-04-29 12:46:42 -0400 | [diff] [blame] | 306 | PowerUsageDetail.class.getName(), |
Jason Monk | 2cdafc6 | 2015-06-12 12:32:50 -0400 | [diff] [blame] | 307 | ProcessStatsSummary.class.getName(), |
Billy Lau | fee7856 | 2015-07-27 12:57:07 +0100 | [diff] [blame] | 308 | DrawOverlayDetails.class.getName(), |
| 309 | WriteSettingsDetails.class.getName(), |
Julia Reynolds | 2e1e0b7 | 2015-12-14 08:32:46 -0500 | [diff] [blame^] | 310 | ManageDefaultApps.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 311 | }; |
| 312 | |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 313 | |
| 314 | private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = { |
| 315 | "android.settings.APPLICATION_DETAILS_SETTINGS" |
| 316 | }; |
| 317 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 318 | private SharedPreferences mDevelopmentPreferences; |
| 319 | private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener; |
| 320 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 321 | private boolean mBatteryPresent = true; |
| 322 | private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 323 | @Override |
| 324 | public void onReceive(Context context, Intent intent) { |
| 325 | String action = intent.getAction(); |
| 326 | if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { |
| 327 | boolean batteryPresent = Utils.isBatteryPresent(intent); |
| 328 | |
| 329 | if (mBatteryPresent != batteryPresent) { |
| 330 | mBatteryPresent = batteryPresent; |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 331 | updateTilesList(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | } |
| 335 | }; |
| 336 | |
Svetoslav | 990159a | 2014-04-14 17:14:59 -0700 | [diff] [blame] | 337 | private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor = |
| 338 | new DynamicIndexableContentMonitor(); |
Svetoslav | 853e471 | 2014-04-14 10:10:25 -0700 | [diff] [blame] | 339 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 340 | private ActionBar mActionBar; |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 341 | private SwitchBar mSwitchBar; |
| 342 | |
| 343 | private Button mNextButton; |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 344 | |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 345 | private boolean mDisplayHomeAsUpEnabled; |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 346 | private boolean mDisplaySearch; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 347 | |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 348 | private boolean mIsShowingDashboard; |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 349 | private boolean mIsShortcut; |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 350 | |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 351 | private ViewGroup mContent; |
| 352 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 353 | private SearchView mSearchView; |
| 354 | private MenuItem mSearchMenuItem; |
| 355 | private boolean mSearchMenuItemExpanded = false; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 356 | private SearchResultsSummary mSearchResultsFragment; |
| 357 | private String mSearchQuery; |
| 358 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 359 | // Categories |
| 360 | private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 361 | |
Fabrice Di Meglio | b0a464f | 2014-07-23 18:15:42 -0700 | [diff] [blame] | 362 | private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh"; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 363 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 364 | private boolean mNeedToRevertToInitialFragment = false; |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 365 | private int mHomeActivitiesCount = 1; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 366 | |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 367 | private Intent mResultIntentData; |
| 368 | |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 369 | public SwitchBar getSwitchBar() { |
| 370 | return mSwitchBar; |
| 371 | } |
| 372 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 373 | @Override |
| 374 | public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { |
| 375 | // Override the fragment title for Wallpaper settings |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 376 | CharSequence title = pref.getTitle(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 377 | if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) { |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 378 | title = getString(R.string.wallpaper_settings_fragment_title); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 379 | } |
Jason Monk | b1dd5c9 | 2015-12-16 16:13:54 -0500 | [diff] [blame] | 380 | startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title, |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 381 | null, 0); |
| 382 | return true; |
| 383 | } |
| 384 | |
| 385 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 386 | public boolean onPreferenceTreeClick(Preference preference) { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 387 | return false; |
| 388 | } |
| 389 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 390 | @Override |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 391 | public void onConfigurationChanged(Configuration newConfig) { |
| 392 | super.onConfigurationChanged(newConfig); |
Fabrice Di Meglio | 6f0739a | 2014-02-03 18:12:25 -0800 | [diff] [blame] | 393 | Index.getInstance(this).update(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | @Override |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 397 | protected void onStart() { |
| 398 | super.onStart(); |
| 399 | |
| 400 | if (mNeedToRevertToInitialFragment) { |
| 401 | revertToInitialFragment(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 402 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | @Override |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 406 | public boolean onCreateOptionsMenu(Menu menu) { |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 407 | if (!mDisplaySearch) { |
| 408 | return false; |
| 409 | } |
| 410 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 411 | MenuInflater inflater = getMenuInflater(); |
| 412 | inflater.inflate(R.menu.options_menu, menu); |
| 413 | |
| 414 | // Cache the search query (can be overriden by the OnQueryTextListener) |
| 415 | final String query = mSearchQuery; |
| 416 | |
Fabrice Di Meglio | 9593782 | 2014-03-31 19:46:42 -0700 | [diff] [blame] | 417 | mSearchMenuItem = menu.findItem(R.id.search); |
| 418 | mSearchView = (SearchView) mSearchMenuItem.getActionView(); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 419 | |
Fabrice Di Meglio | 23ae00c | 2014-04-21 12:43:20 -0700 | [diff] [blame] | 420 | if (mSearchMenuItem == null || mSearchView == null) { |
| 421 | return false; |
| 422 | } |
| 423 | |
Fabrice Di Meglio | 8c3b0ce | 2014-05-12 18:54:32 -0700 | [diff] [blame] | 424 | if (mSearchResultsFragment != null) { |
| 425 | mSearchResultsFragment.setSearchView(mSearchView); |
| 426 | } |
| 427 | |
Fabrice Di Meglio | 9593782 | 2014-03-31 19:46:42 -0700 | [diff] [blame] | 428 | mSearchMenuItem.setOnActionExpandListener(this); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 429 | mSearchView.setOnQueryTextListener(this); |
| 430 | mSearchView.setOnCloseListener(this); |
| 431 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 432 | if (mSearchMenuItemExpanded) { |
| 433 | mSearchMenuItem.expandActionView(); |
| 434 | } |
| 435 | mSearchView.setQuery(query, true /* submit */); |
| 436 | |
| 437 | return true; |
| 438 | } |
| 439 | |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 440 | private static boolean isShortCutIntent(final Intent intent) { |
| 441 | Set<String> categories = intent.getCategories(); |
| 442 | return (categories != null) && categories.contains("com.android.settings.SHORTCUT"); |
| 443 | } |
| 444 | |
Fabrice Di Meglio | 5b3c3c0 | 2014-06-30 15:18:08 -0700 | [diff] [blame] | 445 | private static boolean isLikeShortCutIntent(final Intent intent) { |
Fabrice Di Meglio | 5b7a100 | 2014-06-23 17:54:40 -0700 | [diff] [blame] | 446 | String action = intent.getAction(); |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 447 | if (action == null) { |
| 448 | return false; |
| 449 | } |
| 450 | for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) { |
| 451 | if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true; |
| 452 | } |
| 453 | return false; |
Fabrice Di Meglio | 5b7a100 | 2014-06-23 17:54:40 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 456 | @Override |
| 457 | protected void onCreate(Bundle savedState) { |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 458 | super.onCreate(savedState); |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 459 | long startTime = System.currentTimeMillis(); |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 460 | |
| 461 | // Should happen before any call to getIntent() |
| 462 | getMetaData(); |
| 463 | |
| 464 | final Intent intent = getIntent(); |
| 465 | if (intent.hasExtra(EXTRA_UI_OPTIONS)) { |
| 466 | getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0)); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 467 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 468 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 469 | mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, |
| 470 | Context.MODE_PRIVATE); |
| 471 | |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 472 | // Getting Intent properties can only be done after the super.onCreate(...) |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 473 | final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 474 | |
Fabrice Di Meglio | 5b3c3c0 | 2014-06-30 15:18:08 -0700 | [diff] [blame] | 475 | mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 476 | intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false); |
| 477 | |
Fabrice Di Meglio | e817a66 | 2014-07-16 19:51:06 -0700 | [diff] [blame] | 478 | final ComponentName cn = intent.getComponent(); |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 479 | final String className = cn.getClassName(); |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 480 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 481 | mIsShowingDashboard = className.equals(Settings.class.getName()) |
| 482 | || className.equals(Settings.WirelessSettings.class.getName()) |
| 483 | || className.equals(Settings.DeviceSettings.class.getName()) |
| 484 | || className.equals(Settings.PersonalSettings.class.getName()) |
| 485 | || className.equals(Settings.WirelessSettings.class.getName()); |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 486 | |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 487 | // This is a "Sub Settings" when: |
| 488 | // - this is a real SubSettings |
| 489 | // - or :settings:show_fragment_as_subsetting is passed to the Intent |
Jorim Jaggi | 4dfcb82 | 2015-04-29 17:21:32 -0700 | [diff] [blame] | 490 | final boolean isSubSettings = this instanceof SubSettings || |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 491 | intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false); |
| 492 | |
| 493 | // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets |
| 494 | if (isSubSettings) { |
Fabrice Di Meglio | 712df6c | 2014-07-18 17:44:37 -0700 | [diff] [blame] | 495 | // Check also that we are not a Theme Dialog as we don't want to override them |
| 496 | final int themeResId = getThemeResId(); |
| 497 | if (themeResId != R.style.Theme_DialogWhenLarge && |
| 498 | themeResId != R.style.Theme_SubSettingsDialogWhenLarge) { |
| 499 | setTheme(R.style.Theme_SubSettings); |
| 500 | } |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Fabrice Di Meglio | d40dd45 | 2014-07-18 15:20:34 -0700 | [diff] [blame] | 503 | setContentView(mIsShowingDashboard ? |
| 504 | R.layout.settings_main_dashboard : R.layout.settings_main_prefs); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 505 | |
Fabrice Di Meglio | d40dd45 | 2014-07-18 15:20:34 -0700 | [diff] [blame] | 506 | mContent = (ViewGroup) findViewById(R.id.main_content); |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 507 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 508 | getFragmentManager().addOnBackStackChangedListener(this); |
| 509 | |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 510 | if (mIsShowingDashboard) { |
Fabrice Di Meglio | dff3faa | 2015-02-27 11:14:11 -0800 | [diff] [blame] | 511 | // Run the Index update only if we have some space |
| 512 | if (!Utils.isLowStorage(this)) { |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 513 | long indexStartTime = System.currentTimeMillis(); |
| 514 | AsyncTask.execute(new Runnable() { |
| 515 | @Override |
| 516 | public void run() { |
| 517 | Index.getInstance(getApplicationContext()).update(); |
| 518 | } |
| 519 | }); |
| 520 | if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took " |
| 521 | + (System.currentTimeMillis() - indexStartTime) + " ms"); |
Fabrice Di Meglio | dff3faa | 2015-02-27 11:14:11 -0800 | [diff] [blame] | 522 | } else { |
| 523 | Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!"); |
| 524 | } |
Fabrice Di Meglio | 5cda21b | 2014-04-21 10:14:28 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 527 | if (savedState != null) { |
Fabrice Di Meglio | 1800a9f | 2014-04-03 19:31:07 -0700 | [diff] [blame] | 528 | // We are restarting from a previous saved state; used that to initialize, instead |
| 529 | // of starting fresh. |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 530 | mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED); |
| 531 | mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 532 | |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 533 | setTitleFromIntent(intent); |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 534 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 535 | ArrayList<DashboardCategory> categories = |
| 536 | savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); |
| 537 | if (categories != null) { |
Fabrice Di Meglio | 5f99572 | 2014-05-19 19:51:31 -0700 | [diff] [blame] | 538 | mCategories.clear(); |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 539 | mCategories.addAll(categories); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 540 | setTitleFromBackStack(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 541 | } |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 542 | |
| 543 | mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 544 | mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH); |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 545 | mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, |
| 546 | 1 /* one home activity by default */); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 547 | } else { |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 548 | if (!mIsShowingDashboard) { |
Jason Monk | ea8b1a7 | 2015-06-02 16:46:34 -0400 | [diff] [blame] | 549 | mDisplaySearch = false; |
| 550 | // UP will be shown only if it is a sub settings |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 551 | if (mIsShortcut) { |
| 552 | mDisplayHomeAsUpEnabled = isSubSettings; |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 553 | } else if (isSubSettings) { |
| 554 | mDisplayHomeAsUpEnabled = true; |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 555 | } else { |
| 556 | mDisplayHomeAsUpEnabled = false; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 557 | } |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 558 | setTitleFromIntent(intent); |
Fabrice Di Meglio | c145732 | 2014-04-04 19:07:50 -0700 | [diff] [blame] | 559 | |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 560 | Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 561 | switchToFragment(initialFragmentName, initialArguments, true, false, |
| 562 | mInitialTitleResId, mInitialTitle, false); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 563 | } else { |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 564 | // No UP affordance if we are displaying the main Dashboard |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 565 | mDisplayHomeAsUpEnabled = false; |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 566 | // Show Search affordance |
| 567 | mDisplaySearch = true; |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 568 | mInitialTitleResId = R.string.dashboard_title; |
Fabrice Di Meglio | 42c4b0a | 2014-05-22 10:30:03 -0700 | [diff] [blame] | 569 | switchToFragment(DashboardSummary.class.getName(), null, false, false, |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 570 | mInitialTitleResId, mInitialTitle, false); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 574 | mActionBar = getActionBar(); |
Fabrice Di Meglio | d8aec08 | 2014-05-20 10:49:50 -0700 | [diff] [blame] | 575 | if (mActionBar != null) { |
| 576 | mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); |
| 577 | mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); |
| 578 | } |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 579 | mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar); |
| 580 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 581 | // see if we should show Back/Next buttons |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 582 | if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) { |
| 583 | |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 584 | View buttonBar = findViewById(R.id.button_bar); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 585 | if (buttonBar != null) { |
| 586 | buttonBar.setVisibility(View.VISIBLE); |
| 587 | |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 588 | Button backButton = (Button)findViewById(R.id.back_button); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 589 | backButton.setOnClickListener(new OnClickListener() { |
| 590 | public void onClick(View v) { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 591 | setResult(RESULT_CANCELED, getResultIntentData()); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 592 | finish(); |
| 593 | } |
| 594 | }); |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 595 | Button skipButton = (Button)findViewById(R.id.skip_button); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 596 | skipButton.setOnClickListener(new OnClickListener() { |
| 597 | public void onClick(View v) { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 598 | setResult(RESULT_OK, getResultIntentData()); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 599 | finish(); |
| 600 | } |
| 601 | }); |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 602 | mNextButton = (Button)findViewById(R.id.next_button); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 603 | mNextButton.setOnClickListener(new OnClickListener() { |
| 604 | public void onClick(View v) { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 605 | setResult(RESULT_OK, getResultIntentData()); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 606 | finish(); |
| 607 | } |
| 608 | }); |
| 609 | |
| 610 | // set our various button parameters |
| 611 | if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) { |
| 612 | String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT); |
| 613 | if (TextUtils.isEmpty(buttonText)) { |
| 614 | mNextButton.setVisibility(View.GONE); |
| 615 | } |
| 616 | else { |
| 617 | mNextButton.setText(buttonText); |
| 618 | } |
| 619 | } |
| 620 | if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) { |
| 621 | String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT); |
| 622 | if (TextUtils.isEmpty(buttonText)) { |
| 623 | backButton.setVisibility(View.GONE); |
| 624 | } |
| 625 | else { |
| 626 | backButton.setText(buttonText); |
| 627 | } |
| 628 | } |
| 629 | if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) { |
| 630 | skipButton.setVisibility(View.VISIBLE); |
| 631 | } |
| 632 | } |
| 633 | } |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 634 | |
| 635 | mHomeActivitiesCount = getHomeActivitiesCount(); |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 636 | if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) |
| 637 | + " ms"); |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | private int getHomeActivitiesCount() { |
| 641 | final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>(); |
| 642 | getPackageManager().getHomeActivities(homeApps); |
| 643 | return homeApps.size(); |
Fabrice Di Meglio | c95be4f | 2014-03-07 12:57:38 -0800 | [diff] [blame] | 644 | } |
| 645 | |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 646 | private void setTitleFromIntent(Intent intent) { |
| 647 | final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1); |
| 648 | if (initialTitleResId > 0) { |
| 649 | mInitialTitle = null; |
| 650 | mInitialTitleResId = initialTitleResId; |
Alexandra Gherghina | 62464b8 | 2014-08-11 12:40:13 +0100 | [diff] [blame] | 651 | |
| 652 | final String initialTitleResPackageName = intent.getStringExtra( |
| 653 | EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME); |
| 654 | if (initialTitleResPackageName != null) { |
| 655 | try { |
| 656 | Context authContext = createPackageContextAsUser(initialTitleResPackageName, |
| 657 | 0 /* flags */, new UserHandle(UserHandle.myUserId())); |
| 658 | mInitialTitle = authContext.getResources().getText(mInitialTitleResId); |
| 659 | setTitle(mInitialTitle); |
| 660 | mInitialTitleResId = -1; |
| 661 | return; |
| 662 | } catch (NameNotFoundException e) { |
| 663 | Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName); |
| 664 | } |
| 665 | } else { |
| 666 | setTitle(mInitialTitleResId); |
| 667 | } |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 668 | } else { |
| 669 | mInitialTitleResId = -1; |
| 670 | final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); |
| 671 | mInitialTitle = (initialTitle != null) ? initialTitle : getTitle(); |
| 672 | setTitle(mInitialTitle); |
| 673 | } |
| 674 | } |
| 675 | |
Fabrice Di Meglio | c95be4f | 2014-03-07 12:57:38 -0800 | [diff] [blame] | 676 | @Override |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 677 | public void onBackStackChanged() { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 678 | setTitleFromBackStack(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 679 | } |
| 680 | |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 681 | private int setTitleFromBackStack() { |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 682 | final int count = getFragmentManager().getBackStackEntryCount(); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 683 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 684 | if (count == 0) { |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 685 | if (mInitialTitleResId > 0) { |
| 686 | setTitle(mInitialTitleResId); |
| 687 | } else { |
| 688 | setTitle(mInitialTitle); |
| 689 | } |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 690 | return 0; |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 691 | } |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 692 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 693 | FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1); |
| 694 | setTitleFromBackStackEntry(bse); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 695 | |
| 696 | return count; |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) { |
| 700 | final CharSequence title; |
| 701 | final int titleRes = bse.getBreadCrumbTitleRes(); |
| 702 | if (titleRes > 0) { |
| 703 | title = getText(titleRes); |
| 704 | } else { |
| 705 | title = bse.getBreadCrumbTitle(); |
| 706 | } |
| 707 | if (title != null) { |
| 708 | setTitle(title); |
| 709 | } |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 710 | } |
| 711 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 712 | @Override |
| 713 | protected void onSaveInstanceState(Bundle outState) { |
| 714 | super.onSaveInstanceState(outState); |
| 715 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 716 | if (mCategories.size() > 0) { |
| 717 | outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 718 | } |
Fabrice Di Meglio | d6985df | 2014-04-03 16:43:26 -0700 | [diff] [blame] | 719 | |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 720 | outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled); |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 721 | outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch); |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 722 | |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 723 | if (mDisplaySearch) { |
| 724 | // The option menus are created if the ActionBar is visible and they are also created |
| 725 | // asynchronously. If you launch Settings with an Intent action like |
| 726 | // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked |
| 727 | // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search |
| 728 | // menu item and search view are null. |
| 729 | boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded(); |
| 730 | outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded); |
Fabrice Di Meglio | d6985df | 2014-04-03 16:43:26 -0700 | [diff] [blame] | 731 | |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 732 | String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY; |
| 733 | outState.putString(SAVE_KEY_SEARCH_QUERY, query); |
| 734 | } |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 735 | |
| 736 | outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 740 | protected void onResume() { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 741 | super.onResume(); |
| 742 | |
| 743 | mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { |
| 744 | @Override |
| 745 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 746 | updateTilesList(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 747 | } |
| 748 | }; |
| 749 | mDevelopmentPreferences.registerOnSharedPreferenceChangeListener( |
| 750 | mDevelopmentPreferencesListener); |
| 751 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 752 | registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); |
Svetoslav | 853e471 | 2014-04-14 10:10:25 -0700 | [diff] [blame] | 753 | |
Svetoslav | 990159a | 2014-04-14 17:14:59 -0700 | [diff] [blame] | 754 | mDynamicIndexableContentMonitor.register(this); |
Fabrice Di Meglio | a327076 | 2014-04-16 16:54:56 -0700 | [diff] [blame] | 755 | |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 756 | if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) { |
Fabrice Di Meglio | a327076 | 2014-04-16 16:54:56 -0700 | [diff] [blame] | 757 | onQueryTextSubmit(mSearchQuery); |
| 758 | } |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 759 | updateTilesList(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 763 | protected void onPause() { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 764 | super.onPause(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 765 | unregisterReceiver(mBatteryInfoReceiver); |
Svetoslav | 990159a | 2014-04-14 17:14:59 -0700 | [diff] [blame] | 766 | mDynamicIndexableContentMonitor.unregister(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | @Override |
| 770 | public void onDestroy() { |
| 771 | super.onDestroy(); |
Fabrice Di Meglio | 680b064 | 2014-05-20 15:19:29 -0700 | [diff] [blame] | 772 | |
| 773 | mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener( |
| 774 | mDevelopmentPreferencesListener); |
| 775 | mDevelopmentPreferencesListener = null; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 776 | } |
| 777 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 778 | protected boolean isValidFragment(String fragmentName) { |
| 779 | // Almost all fragments are wrapped in this, |
| 780 | // except for a few that have their own activities. |
| 781 | for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) { |
| 782 | if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true; |
| 783 | } |
| 784 | return false; |
| 785 | } |
| 786 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 787 | @Override |
| 788 | public Intent getIntent() { |
| 789 | Intent superIntent = super.getIntent(); |
| 790 | String startingFragment = getStartingFragmentClass(superIntent); |
| 791 | // This is called from super.onCreate, isMultiPane() is not yet reliable |
| 792 | // Do not use onIsHidingHeaders either, which relies itself on this method |
| 793 | if (startingFragment != null) { |
| 794 | Intent modIntent = new Intent(superIntent); |
| 795 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); |
| 796 | Bundle args = superIntent.getExtras(); |
| 797 | if (args != null) { |
| 798 | args = new Bundle(args); |
| 799 | } else { |
| 800 | args = new Bundle(); |
| 801 | } |
| 802 | args.putParcelable("intent", superIntent); |
Kenny Guy | ac1e20e | 2014-06-24 14:34:14 +0100 | [diff] [blame] | 803 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 804 | return modIntent; |
| 805 | } |
| 806 | return superIntent; |
| 807 | } |
| 808 | |
| 809 | /** |
| 810 | * Checks if the component name in the intent is different from the Settings class and |
| 811 | * returns the class name to load as a fragment. |
| 812 | */ |
| 813 | private String getStartingFragmentClass(Intent intent) { |
| 814 | if (mFragmentClass != null) return mFragmentClass; |
| 815 | |
| 816 | String intentClass = intent.getComponent().getClassName(); |
| 817 | if (intentClass.equals(getClass().getName())) return null; |
| 818 | |
| 819 | if ("com.android.settings.ManageApplications".equals(intentClass) |
| 820 | || "com.android.settings.RunningServices".equals(intentClass) |
| 821 | || "com.android.settings.applications.StorageUse".equals(intentClass)) { |
| 822 | // Old names of manage apps. |
| 823 | intentClass = com.android.settings.applications.ManageApplications.class.getName(); |
| 824 | } |
| 825 | |
| 826 | return intentClass; |
| 827 | } |
| 828 | |
| 829 | /** |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 830 | * Start a new fragment containing a preference panel. If the preferences |
| 831 | * are being displayed in multi-pane mode, the given fragment class will |
| 832 | * be instantiated and placed in the appropriate pane. If running in |
| 833 | * single-pane mode, a new activity will be launched in which to show the |
| 834 | * fragment. |
| 835 | * |
| 836 | * @param fragmentClass Full name of the class implementing the fragment. |
| 837 | * @param args Any desired arguments to supply to the fragment. |
| 838 | * @param titleRes Optional resource identifier of the title of this |
| 839 | * fragment. |
| 840 | * @param titleText Optional text of the title of this fragment. |
| 841 | * @param resultTo Optional fragment that result data should be sent to. |
| 842 | * If non-null, resultTo.onActivityResult() will be called when this |
| 843 | * preference panel is done. The launched panel must use |
| 844 | * {@link #finishPreferencePanel(Fragment, int, Intent)} when done. |
| 845 | * @param resultRequestCode If resultTo is non-null, this is the caller's |
Fabrice Di Meglio | 58146c2 | 2014-06-26 16:20:26 -0700 | [diff] [blame] | 846 | * request code to be received with the result. |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 847 | */ |
| 848 | public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes, |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 849 | CharSequence titleText, Fragment resultTo, int resultRequestCode) { |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 850 | String title = null; |
| 851 | if (titleRes < 0) { |
| 852 | if (titleText != null) { |
| 853 | title = titleText.toString(); |
| 854 | } else { |
| 855 | // There not much we can do in that case |
| 856 | title = ""; |
| 857 | } |
Fabrice Di Meglio | 911fb2a | 2014-04-04 17:55:57 -0700 | [diff] [blame] | 858 | } |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 859 | Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode, |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 860 | titleRes, title, mIsShortcut); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | /** |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 864 | * Start a new fragment in a new activity containing a preference panel for a given user. If the |
| 865 | * preferences are being displayed in multi-pane mode, the given fragment class will be |
| 866 | * instantiated and placed in the appropriate pane. If running in single-pane mode, a new |
| 867 | * activity will be launched in which to show the fragment. |
| 868 | * |
| 869 | * @param fragmentClass Full name of the class implementing the fragment. |
| 870 | * @param args Any desired arguments to supply to the fragment. |
| 871 | * @param titleRes Optional resource identifier of the title of this fragment. |
| 872 | * @param titleText Optional text of the title of this fragment. |
| 873 | * @param userHandle The user for which the panel has to be started. |
| 874 | */ |
| 875 | public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes, |
| 876 | CharSequence titleText, UserHandle userHandle) { |
Lifu Tang | d033285 | 2015-04-02 12:05:46 -0700 | [diff] [blame] | 877 | // This is a workaround. |
| 878 | // |
| 879 | // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent |
| 880 | // starting the fragment could cause a native stack corruption. See b/17523189. However, |
| 881 | // adding that flag and start the preference panel with the same UserHandler will make it |
| 882 | // impossible to use back button to return to the previous screen. See b/20042570. |
| 883 | // |
| 884 | // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing |
| 885 | // another check here to call startPreferencePanel() instead of startWithFragmentAsUser() |
| 886 | // when we're calling it as the same user. |
| 887 | if (userHandle.getIdentifier() == UserHandle.myUserId()) { |
| 888 | startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0); |
| 889 | } else { |
| 890 | String title = null; |
| 891 | if (titleRes < 0) { |
| 892 | if (titleText != null) { |
| 893 | title = titleText.toString(); |
| 894 | } else { |
| 895 | // There not much we can do in that case |
| 896 | title = ""; |
| 897 | } |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 898 | } |
Lifu Tang | d033285 | 2015-04-02 12:05:46 -0700 | [diff] [blame] | 899 | Utils.startWithFragmentAsUser(this, fragmentClass, args, |
| 900 | titleRes, title, mIsShortcut, userHandle); |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 901 | } |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | /** |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 905 | * Called by a preference panel fragment to finish itself. |
| 906 | * |
| 907 | * @param caller The fragment that is asking to be finished. |
| 908 | * @param resultCode Optional result code to send back to the original |
| 909 | * launching fragment. |
| 910 | * @param resultData Optional result data to send back to the original |
| 911 | * launching fragment. |
| 912 | */ |
| 913 | public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) { |
| 914 | setResult(resultCode, resultData); |
Fabrice Di Meglio | 58146c2 | 2014-06-26 16:20:26 -0700 | [diff] [blame] | 915 | finish(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | /** |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 919 | * Start a new fragment. |
| 920 | * |
| 921 | * @param fragment The fragment to start |
| 922 | * @param push If true, the current fragment will be pushed onto the back stack. If false, |
| 923 | * the current fragment will be replaced. |
| 924 | */ |
| 925 | public void startPreferenceFragment(Fragment fragment, boolean push) { |
| 926 | FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Fabrice Di Meglio | d40dd45 | 2014-07-18 15:20:34 -0700 | [diff] [blame] | 927 | transaction.replace(R.id.main_content, fragment); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 928 | if (push) { |
| 929 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); |
| 930 | transaction.addToBackStack(BACK_STACK_PREFS); |
| 931 | } else { |
| 932 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); |
| 933 | } |
| 934 | transaction.commitAllowingStateLoss(); |
| 935 | } |
| 936 | |
| 937 | /** |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 938 | * Switch to a specific Fragment with taking care of validation, Title and BackStack |
| 939 | */ |
| 940 | private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate, |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 941 | boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 942 | if (validate && !isValidFragment(fragmentName)) { |
| 943 | throw new IllegalArgumentException("Invalid fragment for this activity: " |
| 944 | + fragmentName); |
| 945 | } |
| 946 | Fragment f = Fragment.instantiate(this, fragmentName, args); |
| 947 | FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Fabrice Di Meglio | d40dd45 | 2014-07-18 15:20:34 -0700 | [diff] [blame] | 948 | transaction.replace(R.id.main_content, f); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 949 | if (withTransition) { |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 950 | TransitionManager.beginDelayedTransition(mContent); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 951 | } |
| 952 | if (addToBackStack) { |
| 953 | transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS); |
| 954 | } |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 955 | if (titleResId > 0) { |
| 956 | transaction.setBreadCrumbTitle(titleResId); |
| 957 | } else if (title != null) { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 958 | transaction.setBreadCrumbTitle(title); |
| 959 | } |
| 960 | transaction.commitAllowingStateLoss(); |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 961 | getFragmentManager().executePendingTransactions(); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 962 | return f; |
| 963 | } |
| 964 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 965 | private void updateTilesList() { |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 966 | // Generally the items that are will be changing from these updates will |
| 967 | // not be in the top list of tiles, so run it in the background and the |
| 968 | // SettingsDrawerActivity will pick up on the updates automatically. |
| 969 | AsyncTask.execute(new Runnable() { |
| 970 | @Override |
| 971 | public void run() { |
| 972 | doUpdateTilesList(); |
| 973 | } |
| 974 | }); |
| 975 | } |
| 976 | |
| 977 | private void doUpdateTilesList() { |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 978 | PackageManager pm = getPackageManager(); |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 979 | final UserManager um = UserManager.get(this); |
| 980 | final boolean isAdmin = um.isAdminUser(); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 981 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 982 | String packageName = getPackageName(); |
| 983 | setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()), |
| 984 | pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 985 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 986 | setTileEnabled(new ComponentName(packageName, |
| 987 | Settings.BluetoothSettingsActivity.class.getName()), |
| 988 | pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 989 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 990 | setTileEnabled(new ComponentName(packageName, |
| 991 | Settings.DataUsageSummaryActivity.class.getName()), |
| 992 | Utils.isBandwidthControlEnabled(), isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 993 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 994 | setTileEnabled(new ComponentName(packageName, |
| 995 | Settings.SimSettingsActivity.class.getName()), |
| 996 | Utils.showSimCardTile(this), isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 997 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 998 | setTileEnabled(new ComponentName(packageName, |
| 999 | Settings.PowerUsageSummaryActivity.class.getName()), |
| 1000 | mBatteryPresent, isAdmin, pm); |
| 1001 | |
| 1002 | setTileEnabled(new ComponentName(packageName, |
| 1003 | Settings.HomeSettingsActivity.class.getName()), |
| 1004 | updateHomeSettingTiles(), isAdmin, pm); |
| 1005 | |
| 1006 | setTileEnabled(new ComponentName(packageName, |
| 1007 | Settings.UserSettingsActivity.class.getName()), |
| 1008 | UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers() |
| 1009 | && !Utils.isMonkeyRunning(), isAdmin, pm); |
| 1010 | |
| 1011 | NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); |
| 1012 | setTileEnabled(new ComponentName(packageName, |
| 1013 | Settings.PaymentSettingsActivity.class.getName()), |
| 1014 | pm.hasSystemFeature(PackageManager.FEATURE_NFC) |
| 1015 | && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION) |
| 1016 | && adapter != null && adapter.isEnabled(), isAdmin, pm); |
| 1017 | |
| 1018 | setTileEnabled(new ComponentName(packageName, |
| 1019 | Settings.PrintSettingsActivity.class.getName()), |
| 1020 | pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm); |
| 1021 | |
| 1022 | final boolean showDev = mDevelopmentPreferences.getBoolean( |
| 1023 | DevelopmentSettings.PREF_SHOW, |
| 1024 | android.os.Build.TYPE.equals("eng")); |
| 1025 | setTileEnabled(new ComponentName(packageName, |
| 1026 | Settings.DevelopmentSettingsActivity.class.getName()), |
| 1027 | showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES), |
| 1028 | isAdmin, pm); |
| 1029 | |
| 1030 | if (UserHandle.MU_ENABLED && !isAdmin) { |
| 1031 | // When on restricted users, disable all extra categories (but only the settings ones). |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 1032 | List<DashboardCategory> categories = getDashboardCategories(); |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1033 | for (DashboardCategory category : categories) { |
| 1034 | for (DashboardTile tile : category.tiles) { |
| 1035 | ComponentName component = tile.intent.getComponent(); |
| 1036 | if (packageName.equals(component)&& !ArrayUtils.contains( |
| 1037 | SETTINGS_FOR_RESTRICTED, component.getClassName())) { |
| 1038 | setTileEnabled(component, false, isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1039 | } |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1040 | } |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1041 | } |
| 1042 | } |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 1043 | } |
| 1044 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1045 | private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin, |
| 1046 | PackageManager pm) { |
| 1047 | if (UserHandle.MU_ENABLED && !isAdmin |
| 1048 | && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) { |
| 1049 | enabled = false; |
| 1050 | } |
| 1051 | int state = pm.getComponentEnabledSetting(component); |
| 1052 | boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT |
| 1053 | || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
| 1054 | if (isEnabled != enabled) { |
| 1055 | pm.setComponentEnabledSetting(component, enabled |
| 1056 | ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED |
| 1057 | : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, |
| 1058 | PackageManager.DONT_KILL_APP); |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 1059 | } |
| 1060 | } |
| 1061 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1062 | private boolean updateHomeSettingTiles() { |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1063 | // Once we decide to show Home settings, keep showing it forever |
| 1064 | SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE); |
| 1065 | if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) { |
| 1066 | return true; |
| 1067 | } |
| 1068 | |
| 1069 | try { |
Fabrice Di Meglio | b0a464f | 2014-07-23 18:15:42 -0700 | [diff] [blame] | 1070 | mHomeActivitiesCount = getHomeActivitiesCount(); |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 1071 | if (mHomeActivitiesCount < 2) { |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1072 | return false; |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1073 | } |
| 1074 | } catch (Exception e) { |
| 1075 | // Can't look up the home activity; bail on configuring the icon |
| 1076 | Log.w(LOG_TAG, "Problem looking up home activity!", e); |
| 1077 | } |
| 1078 | |
| 1079 | sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply(); |
| 1080 | return true; |
| 1081 | } |
| 1082 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1083 | private void getMetaData() { |
| 1084 | try { |
| 1085 | ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), |
| 1086 | PackageManager.GET_META_DATA); |
| 1087 | if (ai == null || ai.metaData == null) return; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1088 | mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); |
| 1089 | } catch (NameNotFoundException nnfe) { |
| 1090 | // No recovery |
| 1091 | Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString()); |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | // give subclasses access to the Next button |
| 1096 | public boolean hasNextButton() { |
| 1097 | return mNextButton != null; |
| 1098 | } |
| 1099 | |
| 1100 | public Button getNextButton() { |
| 1101 | return mNextButton; |
| 1102 | } |
| 1103 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1104 | @Override |
| 1105 | public boolean shouldUpRecreateTask(Intent targetIntent) { |
| 1106 | return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class)); |
| 1107 | } |
| 1108 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1109 | @Override |
| 1110 | public boolean onQueryTextSubmit(String query) { |
| 1111 | switchToSearchResultsFragmentIfNeeded(); |
| 1112 | mSearchQuery = query; |
| 1113 | return mSearchResultsFragment.onQueryTextSubmit(query); |
| 1114 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1115 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1116 | @Override |
| 1117 | public boolean onQueryTextChange(String newText) { |
| 1118 | mSearchQuery = newText; |
Fabrice Di Meglio | 7e4855e | 2014-05-23 16:03:43 -0700 | [diff] [blame] | 1119 | if (mSearchResultsFragment == null) { |
Fabrice Di Meglio | a327076 | 2014-04-16 16:54:56 -0700 | [diff] [blame] | 1120 | return false; |
| 1121 | } |
| 1122 | return mSearchResultsFragment.onQueryTextChange(newText); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1123 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1124 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1125 | @Override |
| 1126 | public boolean onClose() { |
| 1127 | return false; |
| 1128 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1129 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1130 | @Override |
| 1131 | public boolean onMenuItemActionExpand(MenuItem item) { |
| 1132 | if (item.getItemId() == mSearchMenuItem.getItemId()) { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1133 | switchToSearchResultsFragmentIfNeeded(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1134 | } |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1135 | return true; |
| 1136 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1137 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1138 | @Override |
| 1139 | public boolean onMenuItemActionCollapse(MenuItem item) { |
| 1140 | if (item.getItemId() == mSearchMenuItem.getItemId()) { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1141 | if (mSearchMenuItemExpanded) { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1142 | revertToInitialFragment(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1143 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1144 | } |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1145 | return true; |
| 1146 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1147 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1148 | @Override |
| 1149 | protected void onTileClicked(DashboardTile tile) { |
| 1150 | if (mIsShowingDashboard) { |
| 1151 | // If on dashboard, don't finish so the back comes back to here. |
| 1152 | openTile(tile); |
| 1153 | } else { |
| 1154 | super.onTileClicked(tile); |
| 1155 | } |
| 1156 | } |
| 1157 | |
Jason Monk | af00109 | 2015-11-04 13:16:18 -0500 | [diff] [blame] | 1158 | @Override |
| 1159 | public void onProfileTileOpen() { |
| 1160 | if (!mIsShowingDashboard) { |
| 1161 | finish(); |
| 1162 | } |
| 1163 | } |
| 1164 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1165 | private void switchToSearchResultsFragmentIfNeeded() { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1166 | if (mSearchResultsFragment != null) { |
| 1167 | return; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1168 | } |
Fabrice Di Meglio | d40dd45 | 2014-07-18 15:20:34 -0700 | [diff] [blame] | 1169 | Fragment current = getFragmentManager().findFragmentById(R.id.main_content); |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1170 | if (current != null && current instanceof SearchResultsSummary) { |
| 1171 | mSearchResultsFragment = (SearchResultsSummary) current; |
| 1172 | } else { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1173 | mSearchResultsFragment = (SearchResultsSummary) switchToFragment( |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 1174 | SearchResultsSummary.class.getName(), null, false, true, |
| 1175 | R.string.search_results_title, null, true); |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1176 | } |
Fabrice Di Meglio | d297a58 | 2014-04-22 17:23:23 -0700 | [diff] [blame] | 1177 | mSearchResultsFragment.setSearchView(mSearchView); |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1178 | mSearchMenuItemExpanded = true; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1179 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1180 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1181 | public void needToRevertToInitialFragment() { |
| 1182 | mNeedToRevertToInitialFragment = true; |
| 1183 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1184 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1185 | private void revertToInitialFragment() { |
| 1186 | mNeedToRevertToInitialFragment = false; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1187 | mSearchResultsFragment = null; |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1188 | mSearchMenuItemExpanded = false; |
| 1189 | getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS, |
| 1190 | FragmentManager.POP_BACK_STACK_INCLUSIVE); |
Fabrice Di Meglio | 23ae00c | 2014-04-21 12:43:20 -0700 | [diff] [blame] | 1191 | if (mSearchMenuItem != null) { |
| 1192 | mSearchMenuItem.collapseActionView(); |
| 1193 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1194 | } |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 1195 | |
| 1196 | public Intent getResultIntentData() { |
| 1197 | return mResultIntentData; |
| 1198 | } |
| 1199 | |
| 1200 | public void setResultIntentData(Intent resultIntentData) { |
| 1201 | mResultIntentData = resultIntentData; |
| 1202 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1203 | } |