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