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