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