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