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