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