blob: 4eaabe93ba7b904bc25fc6b4d1086d16780f4dae [file] [log] [blame]
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001/*
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
17package com.android.settings;
18
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080019import android.app.ActionBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080020import android.app.Fragment;
21import android.app.FragmentManager;
22import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080023import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070024import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080025import android.content.Context;
26import android.content.Intent;
27import android.content.IntentFilter;
28import android.content.SharedPreferences;
29import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.PackageManager.NameNotFoundException;
32import android.content.pm.ResolveInfo;
33import android.content.res.Configuration;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080034import android.nfc.NfcAdapter;
35import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080036import android.os.UserHandle;
37import android.os.UserManager;
Jason Monk39b46742015-09-10 15:52:51 -040038import android.support.v14.preference.PreferenceFragment;
39import android.support.v7.preference.Preference;
40import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080041import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070042import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080043import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070044import android.view.Menu;
45import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080046import android.view.MenuItem;
47import android.view.View;
48import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070049import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080050import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070051import android.widget.SearchView;
Chris Wren8a963ba2015-03-20 10:29:14 -040052import com.android.internal.logging.MetricsLogger;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080053import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040054import com.android.settings.Settings.WifiSettingsActivity;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080055import com.android.settings.accessibility.AccessibilitySettings;
56import com.android.settings.accessibility.CaptionPropertiesFragment;
Alexandra Gherghina6d839872014-07-22 12:04:58 +000057import com.android.settings.accounts.AccountSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080058import com.android.settings.accounts.AccountSyncSettings;
Billy Laufee78562015-07-27 12:57:07 +010059import com.android.settings.applications.DrawOverlayDetails;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070060import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080061import com.android.settings.applications.ManageApplications;
Xiyuan Xia86a55402015-06-02 14:55:32 -070062import com.android.settings.applications.ManageAssist;
Jason Monk2cdafc62015-06-12 12:32:50 -040063import com.android.settings.applications.ProcessStatsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080064import com.android.settings.applications.ProcessStatsUi;
Jason Monkd8da51c2015-04-17 14:34:12 -040065import com.android.settings.applications.UsageAccessDetails;
Billy Laufee78562015-07-27 12:57:07 +010066import com.android.settings.applications.WriteSettingsDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080067import com.android.settings.bluetooth.BluetoothSettings;
68import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070069import com.android.settings.dashboard.SearchResultsSummary;
Jeff Sharkeya16257d2015-04-28 13:41:01 -070070import com.android.settings.deviceinfo.PrivateVolumeForget;
Jeff Sharkeye77f0682015-04-29 11:24:57 -070071import com.android.settings.deviceinfo.PrivateVolumeSettings;
Jeff Sharkey42833b22015-04-11 21:27:33 -070072import com.android.settings.deviceinfo.PublicVolumeSettings;
73import com.android.settings.deviceinfo.StorageSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040074import com.android.settings.fuelgauge.BatterySaverSettings;
Jason Monk1eb54eb2015-04-29 12:46:42 -040075import com.android.settings.fuelgauge.PowerUsageDetail;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080076import com.android.settings.fuelgauge.PowerUsageSummary;
77import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
78import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
79import com.android.settings.inputmethod.SpellCheckersSettings;
80import com.android.settings.inputmethod.UserDictionaryList;
81import com.android.settings.location.LocationSettings;
82import com.android.settings.nfc.AndroidBeam;
83import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -040084import com.android.settings.notification.AppNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -040085import com.android.settings.notification.NotificationAccessSettings;
86import com.android.settings.notification.NotificationSettings;
87import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -050088import com.android.settings.notification.OtherSoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -040089import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -040090import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -040091import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -040092import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -040093import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -040094import com.android.settings.notification.ZenModeSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080095import com.android.settings.print.PrintJobSettingsFragment;
96import com.android.settings.print.PrintSettingsFragment;
Jason Monk2ebc8a02015-02-13 15:23:19 -050097import com.android.settings.search.DynamicIndexableContentMonitor;
98import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -070099import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800100import com.android.settings.tts.TextToSpeechSettings;
101import com.android.settings.users.UserSettings;
102import com.android.settings.vpn2.VpnSettings;
103import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700104import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800105import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700106import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800107import com.android.settings.wifi.WifiSettings;
108import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400109import com.android.settingslib.drawer.DashboardCategory;
110import com.android.settingslib.drawer.DashboardTile;
111import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500112
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800113import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800114import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700115import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800116
Jason Monk4da79e02015-09-10 10:54:36 -0400117public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800118 implements PreferenceManager.OnPreferenceTreeClickListener,
119 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100120 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700121 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100122 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800123
124 private static final String LOG_TAG = "Settings";
125
126 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700127 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700128 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
129 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700130 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700131 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700132 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800133
134 /**
135 * When starting this activity, the invoking Intent can contain this extra
136 * string to specify which fragment should be initially displayed.
137 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
138 * will call isValidFragment() to confirm that the fragment class name is valid for this
139 * activity.
140 */
141 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
142
143 /**
144 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
145 * this extra can also be specified to supply a Bundle of arguments to pass
146 * to that fragment when it is instantiated during the initial creation
147 * of the activity.
148 */
149 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
150
151 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700152 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
153 */
154 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
155
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800156 public static final String BACK_STACK_PREFS = ":settings:prefs";
157
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800158 // extras that allow any preference activity to be launched as part of a wizard
159
160 // show Back and Next buttons? takes boolean parameter
161 // Back will then return RESULT_CANCELED and Next RESULT_OK
162 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
163
164 // add a Skip button?
165 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
166
167 // specify custom text for the Back or Next buttons, or cause a button to not appear
168 // at all by setting it to null
169 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
170 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
171
172 /**
173 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700174 * those extra can also be specify to supply the title or title res id to be shown for
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800175 * that fragment.
176 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700177 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100178 /**
179 * The package name used to resolve the title resource id.
180 */
181 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
182 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700183 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
184 ":settings:show_fragment_title_resid";
185 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
186 ":settings:show_fragment_as_shortcut";
187
188 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
189 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800190
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800191 private static final String META_DATA_KEY_FRAGMENT_CLASS =
192 "com.android.settings.FRAGMENT_CLASS";
193
194 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
195
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700196 private static final String EMPTY_QUERY = "";
197
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800198 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800199
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800200 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700201 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800202
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800203 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400204 private String[] SETTINGS_FOR_RESTRICTED = {
205 //wireless_section
206 WifiSettingsActivity.class.getName(),
207 Settings.BluetoothSettingsActivity.class.getName(),
208 Settings.DataUsageSummaryActivity.class.getName(),
209 Settings.SimSettingsActivity.class.getName(),
210 Settings.WirelessSettingsActivity.class.getName(),
211 //device_section
212 Settings.HomeSettingsActivity.class.getName(),
213 Settings.NotificationSettingsActivity.class.getName(),
214 Settings.DisplaySettingsActivity.class.getName(),
215 Settings.StorageSettingsActivity.class.getName(),
216 Settings.ManageApplicationsActivity.class.getName(),
217 Settings.PowerUsageSummaryActivity.class.getName(),
218 //personal_section
219 Settings.LocationSettingsActivity.class.getName(),
220 Settings.SecuritySettingsActivity.class.getName(),
221 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
222 Settings.UserSettingsActivity.class.getName(),
223 Settings.AccountSettingsActivity.class.getName(),
224 //system_section
225 Settings.DateTimeSettingsActivity.class.getName(),
226 Settings.DeviceInfoSettingsActivity.class.getName(),
227 Settings.AccessibilitySettingsActivity.class.getName(),
228 Settings.PrintSettingsActivity.class.getName(),
229 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800230 };
231
232 private static final String[] ENTRY_FRAGMENTS = {
233 WirelessSettings.class.getName(),
234 WifiSettings.class.getName(),
235 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700236 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800237 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700238 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800239 TetherSettings.class.getName(),
240 WifiP2pSettings.class.getName(),
241 VpnSettings.class.getName(),
242 DateTimeSettings.class.getName(),
243 LocalePicker.class.getName(),
244 InputMethodAndLanguageSettings.class.getName(),
245 SpellCheckersSettings.class.getName(),
246 UserDictionaryList.class.getName(),
247 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700248 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800249 DisplaySettings.class.getName(),
250 DeviceInfoSettings.class.getName(),
251 ManageApplications.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700252 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800253 ProcessStatsUi.class.getName(),
254 NotificationStation.class.getName(),
255 LocationSettings.class.getName(),
256 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400257 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800258 PrivacySettings.class.getName(),
259 DeviceAdminSettings.class.getName(),
260 AccessibilitySettings.class.getName(),
261 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800262 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
263 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700264 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700265 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700266 PrivateVolumeSettings.class.getName(),
267 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800268 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800269 AndroidBeam.class.getName(),
270 WifiDisplaySettings.class.getName(),
271 PowerUsageSummary.class.getName(),
272 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000273 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800274 CryptKeeperSettings.class.getName(),
275 DataUsageSummary.class.getName(),
276 DreamSettings.class.getName(),
277 UserSettings.class.getName(),
278 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400279 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800280 PrintSettingsFragment.class.getName(),
281 PrintJobSettingsFragment.class.getName(),
282 TrustedCredentialsSettings.class.getName(),
283 PaymentSettings.class.getName(),
284 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700285 ZenModeSettings.class.getName(),
286 NotificationSettings.class.getName(),
287 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
288 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400289 InstalledAppDetails.class.getName(),
290 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700291 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700292 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000293 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400294 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400295 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400296 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400297 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400298 ZenModeEventRuleSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400299 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400300 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400301 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100302 DrawOverlayDetails.class.getName(),
303 WriteSettingsDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800304 };
305
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700306
307 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
308 "android.settings.APPLICATION_DETAILS_SETTINGS"
309 };
310
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800311 private SharedPreferences mDevelopmentPreferences;
312 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
313
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800314 private boolean mBatteryPresent = true;
315 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800316 @Override
317 public void onReceive(Context context, Intent intent) {
318 String action = intent.getAction();
319 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
320 boolean batteryPresent = Utils.isBatteryPresent(intent);
321
322 if (mBatteryPresent != batteryPresent) {
323 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400324 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800325 }
326 }
327 }
328 };
329
Svetoslav990159a2014-04-14 17:14:59 -0700330 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
331 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700332
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700333 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700334 private SwitchBar mSwitchBar;
335
336 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700337
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700338 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700339 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700340
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700341 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700342 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700343
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700344 private ViewGroup mContent;
345
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700346 private SearchView mSearchView;
347 private MenuItem mSearchMenuItem;
348 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700349 private SearchResultsSummary mSearchResultsFragment;
350 private String mSearchQuery;
351
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700352 // Categories
353 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800354
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700355 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800356
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700357 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700358 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700359
Jim Miller0698a212014-10-16 19:49:07 -0700360 private Intent mResultIntentData;
361
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700362 public SwitchBar getSwitchBar() {
363 return mSwitchBar;
364 }
365
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800366 @Override
367 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
368 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400369 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800370 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400371 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800372 }
Jason Monk39b46742015-09-10 15:52:51 -0400373 startPreferencePanel(pref.getFragment(), pref.getExtras(), 0, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800374 null, 0);
375 return true;
376 }
377
378 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400379 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800380 return false;
381 }
382
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800383 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800384 public void onConfigurationChanged(Configuration newConfig) {
385 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800386 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800387 }
388
389 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700390 protected void onStart() {
391 super.onStart();
392
393 if (mNeedToRevertToInitialFragment) {
394 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800395 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800396 }
397
398 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700399 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700400 if (!mDisplaySearch) {
401 return false;
402 }
403
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700404 MenuInflater inflater = getMenuInflater();
405 inflater.inflate(R.menu.options_menu, menu);
406
407 // Cache the search query (can be overriden by the OnQueryTextListener)
408 final String query = mSearchQuery;
409
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700410 mSearchMenuItem = menu.findItem(R.id.search);
411 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700412
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700413 if (mSearchMenuItem == null || mSearchView == null) {
414 return false;
415 }
416
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700417 if (mSearchResultsFragment != null) {
418 mSearchResultsFragment.setSearchView(mSearchView);
419 }
420
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700421 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700422 mSearchView.setOnQueryTextListener(this);
423 mSearchView.setOnCloseListener(this);
424
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700425 if (mSearchMenuItemExpanded) {
426 mSearchMenuItem.expandActionView();
427 }
428 mSearchView.setQuery(query, true /* submit */);
429
430 return true;
431 }
432
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700433 private static boolean isShortCutIntent(final Intent intent) {
434 Set<String> categories = intent.getCategories();
435 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
436 }
437
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700438 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700439 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700440 if (action == null) {
441 return false;
442 }
443 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
444 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
445 }
446 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700447 }
448
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700449 @Override
450 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700451 super.onCreate(savedState);
452
453 // Should happen before any call to getIntent()
454 getMetaData();
455
456 final Intent intent = getIntent();
457 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
458 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800459 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800460
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800461 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
462 Context.MODE_PRIVATE);
463
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700464 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700465 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700466
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700467 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700468 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
469
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700470 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700471 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700472
Jason Monk4da79e02015-09-10 10:54:36 -0400473 mIsShowingDashboard = className.equals(Settings.class.getName())
474 || className.equals(Settings.WirelessSettings.class.getName())
475 || className.equals(Settings.DeviceSettings.class.getName())
476 || className.equals(Settings.PersonalSettings.class.getName())
477 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700478
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700479 // This is a "Sub Settings" when:
480 // - this is a real SubSettings
481 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700482 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700483 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
484
485 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
486 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700487 // Check also that we are not a Theme Dialog as we don't want to override them
488 final int themeResId = getThemeResId();
489 if (themeResId != R.style.Theme_DialogWhenLarge &&
490 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
491 setTheme(R.style.Theme_SubSettings);
492 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700493 }
494
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700495 setContentView(mIsShowingDashboard ?
496 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800497
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700498 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700499
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800500 getFragmentManager().addOnBackStackChangedListener(this);
501
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700502 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800503 // Run the Index update only if we have some space
504 if (!Utils.isLowStorage(this)) {
505 Index.getInstance(getApplicationContext()).update();
506 } else {
507 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
508 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700509 }
510
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700511 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700512 // We are restarting from a previous saved state; used that to initialize, instead
513 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700514 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
515 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800516
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700517 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800518
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700519 ArrayList<DashboardCategory> categories =
520 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
521 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700522 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700523 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700524 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800525 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700526
527 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700528 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700529 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
530 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800531 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700532 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400533 mDisplaySearch = false;
534 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700535 if (mIsShortcut) {
536 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700537 } else if (isSubSettings) {
538 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700539 } else {
540 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700541 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700542 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700543
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700544 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700545 switchToFragment(initialFragmentName, initialArguments, true, false,
546 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000547 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700548 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700549 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700550 // Show Search affordance
551 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700552 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700553 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700554 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800555 }
556 }
557
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700558 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700559 if (mActionBar != null) {
560 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
561 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
562 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700563 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
564
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800565 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800566 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
567
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700568 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800569 if (buttonBar != null) {
570 buttonBar.setVisibility(View.VISIBLE);
571
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700572 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800573 backButton.setOnClickListener(new OnClickListener() {
574 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700575 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800576 finish();
577 }
578 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700579 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800580 skipButton.setOnClickListener(new OnClickListener() {
581 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700582 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800583 finish();
584 }
585 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700586 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800587 mNextButton.setOnClickListener(new OnClickListener() {
588 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700589 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800590 finish();
591 }
592 });
593
594 // set our various button parameters
595 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
596 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
597 if (TextUtils.isEmpty(buttonText)) {
598 mNextButton.setVisibility(View.GONE);
599 }
600 else {
601 mNextButton.setText(buttonText);
602 }
603 }
604 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
605 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
606 if (TextUtils.isEmpty(buttonText)) {
607 backButton.setVisibility(View.GONE);
608 }
609 else {
610 backButton.setText(buttonText);
611 }
612 }
613 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
614 skipButton.setVisibility(View.VISIBLE);
615 }
616 }
617 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700618
619 mHomeActivitiesCount = getHomeActivitiesCount();
620 }
621
622 private int getHomeActivitiesCount() {
623 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
624 getPackageManager().getHomeActivities(homeApps);
625 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800626 }
627
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700628 private void setTitleFromIntent(Intent intent) {
629 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
630 if (initialTitleResId > 0) {
631 mInitialTitle = null;
632 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100633
634 final String initialTitleResPackageName = intent.getStringExtra(
635 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
636 if (initialTitleResPackageName != null) {
637 try {
638 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
639 0 /* flags */, new UserHandle(UserHandle.myUserId()));
640 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
641 setTitle(mInitialTitle);
642 mInitialTitleResId = -1;
643 return;
644 } catch (NameNotFoundException e) {
645 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
646 }
647 } else {
648 setTitle(mInitialTitleResId);
649 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700650 } else {
651 mInitialTitleResId = -1;
652 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
653 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
654 setTitle(mInitialTitle);
655 }
656 }
657
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800658 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800659 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700660 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800661 }
662
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700663 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800664 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700665
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800666 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700667 if (mInitialTitleResId > 0) {
668 setTitle(mInitialTitleResId);
669 } else {
670 setTitle(mInitialTitle);
671 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700672 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800673 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700674
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800675 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
676 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700677
678 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800679 }
680
681 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
682 final CharSequence title;
683 final int titleRes = bse.getBreadCrumbTitleRes();
684 if (titleRes > 0) {
685 title = getText(titleRes);
686 } else {
687 title = bse.getBreadCrumbTitle();
688 }
689 if (title != null) {
690 setTitle(title);
691 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800692 }
693
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800694 @Override
695 protected void onSaveInstanceState(Bundle outState) {
696 super.onSaveInstanceState(outState);
697
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700698 if (mCategories.size() > 0) {
699 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800700 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700701
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700702 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700703 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700704
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700705 if (mDisplaySearch) {
706 // The option menus are created if the ActionBar is visible and they are also created
707 // asynchronously. If you launch Settings with an Intent action like
708 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
709 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
710 // menu item and search view are null.
711 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
712 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700713
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700714 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
715 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
716 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700717
718 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800719 }
720
721 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400722 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800723 super.onResume();
Chris Wren8a963ba2015-03-20 10:29:14 -0400724 if (mIsShowingDashboard) {
725 MetricsLogger.visible(this, MetricsLogger.MAIN_SETTINGS);
726 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800727
728 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
729 @Override
730 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400731 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800732 }
733 };
734 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
735 mDevelopmentPreferencesListener);
736
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800737 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700738
Svetoslav990159a2014-04-14 17:14:59 -0700739 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700740
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700741 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700742 onQueryTextSubmit(mSearchQuery);
743 }
Jason Monk4da79e02015-09-10 10:54:36 -0400744 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800745 }
746
747 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400748 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800749 super.onPause();
Chris Wren8a963ba2015-03-20 10:29:14 -0400750 if (mIsShowingDashboard) {
751 MetricsLogger.hidden(this, MetricsLogger.MAIN_SETTINGS);
752 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800753 unregisterReceiver(mBatteryInfoReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700754 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800755 }
756
757 @Override
758 public void onDestroy() {
759 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700760
761 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
762 mDevelopmentPreferencesListener);
763 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800764 }
765
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800766 protected boolean isValidFragment(String fragmentName) {
767 // Almost all fragments are wrapped in this,
768 // except for a few that have their own activities.
769 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
770 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
771 }
772 return false;
773 }
774
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800775 @Override
776 public Intent getIntent() {
777 Intent superIntent = super.getIntent();
778 String startingFragment = getStartingFragmentClass(superIntent);
779 // This is called from super.onCreate, isMultiPane() is not yet reliable
780 // Do not use onIsHidingHeaders either, which relies itself on this method
781 if (startingFragment != null) {
782 Intent modIntent = new Intent(superIntent);
783 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
784 Bundle args = superIntent.getExtras();
785 if (args != null) {
786 args = new Bundle(args);
787 } else {
788 args = new Bundle();
789 }
790 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100791 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800792 return modIntent;
793 }
794 return superIntent;
795 }
796
797 /**
798 * Checks if the component name in the intent is different from the Settings class and
799 * returns the class name to load as a fragment.
800 */
801 private String getStartingFragmentClass(Intent intent) {
802 if (mFragmentClass != null) return mFragmentClass;
803
804 String intentClass = intent.getComponent().getClassName();
805 if (intentClass.equals(getClass().getName())) return null;
806
807 if ("com.android.settings.ManageApplications".equals(intentClass)
808 || "com.android.settings.RunningServices".equals(intentClass)
809 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
810 // Old names of manage apps.
811 intentClass = com.android.settings.applications.ManageApplications.class.getName();
812 }
813
814 return intentClass;
815 }
816
817 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000818 * Start a new fragment containing a preference panel. If the preferences
819 * are being displayed in multi-pane mode, the given fragment class will
820 * be instantiated and placed in the appropriate pane. If running in
821 * single-pane mode, a new activity will be launched in which to show the
822 * fragment.
823 *
824 * @param fragmentClass Full name of the class implementing the fragment.
825 * @param args Any desired arguments to supply to the fragment.
826 * @param titleRes Optional resource identifier of the title of this
827 * fragment.
828 * @param titleText Optional text of the title of this fragment.
829 * @param resultTo Optional fragment that result data should be sent to.
830 * If non-null, resultTo.onActivityResult() will be called when this
831 * preference panel is done. The launched panel must use
832 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
833 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700834 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000835 */
836 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700837 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700838 String title = null;
839 if (titleRes < 0) {
840 if (titleText != null) {
841 title = titleText.toString();
842 } else {
843 // There not much we can do in that case
844 title = "";
845 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700846 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700847 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700848 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000849 }
850
851 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100852 * Start a new fragment in a new activity containing a preference panel for a given user. If the
853 * preferences are being displayed in multi-pane mode, the given fragment class will be
854 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
855 * activity will be launched in which to show the fragment.
856 *
857 * @param fragmentClass Full name of the class implementing the fragment.
858 * @param args Any desired arguments to supply to the fragment.
859 * @param titleRes Optional resource identifier of the title of this fragment.
860 * @param titleText Optional text of the title of this fragment.
861 * @param userHandle The user for which the panel has to be started.
862 */
863 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
864 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700865 // This is a workaround.
866 //
867 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
868 // starting the fragment could cause a native stack corruption. See b/17523189. However,
869 // adding that flag and start the preference panel with the same UserHandler will make it
870 // impossible to use back button to return to the previous screen. See b/20042570.
871 //
872 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
873 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
874 // when we're calling it as the same user.
875 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
876 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
877 } else {
878 String title = null;
879 if (titleRes < 0) {
880 if (titleText != null) {
881 title = titleText.toString();
882 } else {
883 // There not much we can do in that case
884 title = "";
885 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100886 }
Lifu Tangd0332852015-04-02 12:05:46 -0700887 Utils.startWithFragmentAsUser(this, fragmentClass, args,
888 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100889 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100890 }
891
892 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800893 * Called by a preference panel fragment to finish itself.
894 *
895 * @param caller The fragment that is asking to be finished.
896 * @param resultCode Optional result code to send back to the original
897 * launching fragment.
898 * @param resultData Optional result data to send back to the original
899 * launching fragment.
900 */
901 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
902 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700903 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800904 }
905
906 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000907 * Start a new fragment.
908 *
909 * @param fragment The fragment to start
910 * @param push If true, the current fragment will be pushed onto the back stack. If false,
911 * the current fragment will be replaced.
912 */
913 public void startPreferenceFragment(Fragment fragment, boolean push) {
914 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700915 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000916 if (push) {
917 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
918 transaction.addToBackStack(BACK_STACK_PREFS);
919 } else {
920 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
921 }
922 transaction.commitAllowingStateLoss();
923 }
924
925 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700926 * Switch to a specific Fragment with taking care of validation, Title and BackStack
927 */
928 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700929 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700930 if (validate && !isValidFragment(fragmentName)) {
931 throw new IllegalArgumentException("Invalid fragment for this activity: "
932 + fragmentName);
933 }
934 Fragment f = Fragment.instantiate(this, fragmentName, args);
935 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700936 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700937 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700938 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700939 }
940 if (addToBackStack) {
941 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
942 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700943 if (titleResId > 0) {
944 transaction.setBreadCrumbTitle(titleResId);
945 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700946 transaction.setBreadCrumbTitle(title);
947 }
948 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700949 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700950 return f;
951 }
952
Jason Monk4da79e02015-09-10 10:54:36 -0400953 private void updateTilesList() {
954 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700955 final UserManager um = UserManager.get(this);
956 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700957
Jason Monk4da79e02015-09-10 10:54:36 -0400958 String packageName = getPackageName();
959 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
960 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700961
Jason Monk4da79e02015-09-10 10:54:36 -0400962 setTileEnabled(new ComponentName(packageName,
963 Settings.BluetoothSettingsActivity.class.getName()),
964 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700965
Jason Monk4da79e02015-09-10 10:54:36 -0400966 setTileEnabled(new ComponentName(packageName,
967 Settings.DataUsageSummaryActivity.class.getName()),
968 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700969
Jason Monk4da79e02015-09-10 10:54:36 -0400970 setTileEnabled(new ComponentName(packageName,
971 Settings.SimSettingsActivity.class.getName()),
972 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700973
Jason Monk4da79e02015-09-10 10:54:36 -0400974 setTileEnabled(new ComponentName(packageName,
975 Settings.PowerUsageSummaryActivity.class.getName()),
976 mBatteryPresent, isAdmin, pm);
977
978 setTileEnabled(new ComponentName(packageName,
979 Settings.HomeSettingsActivity.class.getName()),
980 updateHomeSettingTiles(), isAdmin, pm);
981
982 setTileEnabled(new ComponentName(packageName,
983 Settings.UserSettingsActivity.class.getName()),
984 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
985 && !Utils.isMonkeyRunning(), isAdmin, pm);
986
987 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
988 setTileEnabled(new ComponentName(packageName,
989 Settings.PaymentSettingsActivity.class.getName()),
990 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
991 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
992 && adapter != null && adapter.isEnabled(), isAdmin, pm);
993
994 setTileEnabled(new ComponentName(packageName,
995 Settings.PrintSettingsActivity.class.getName()),
996 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
997
998 final boolean showDev = mDevelopmentPreferences.getBoolean(
999 DevelopmentSettings.PREF_SHOW,
1000 android.os.Build.TYPE.equals("eng"));
1001 setTileEnabled(new ComponentName(packageName,
1002 Settings.DevelopmentSettingsActivity.class.getName()),
1003 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1004 isAdmin, pm);
1005
1006 if (UserHandle.MU_ENABLED && !isAdmin) {
1007 // When on restricted users, disable all extra categories (but only the settings ones).
1008 List<DashboardCategory> categories = getDashboardCategories(true);
1009 for (DashboardCategory category : categories) {
1010 for (DashboardTile tile : category.tiles) {
1011 ComponentName component = tile.intent.getComponent();
1012 if (packageName.equals(component)&& !ArrayUtils.contains(
1013 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1014 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001015 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001016 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001017 }
1018 }
Jason Monk4da79e02015-09-10 10:54:36 -04001019
1020 updateDrawer();
Jason Monk2ebc8a02015-02-13 15:23:19 -05001021 }
1022
Jason Monk4da79e02015-09-10 10:54:36 -04001023 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1024 PackageManager pm) {
1025 if (UserHandle.MU_ENABLED && !isAdmin
1026 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1027 enabled = false;
1028 }
1029 int state = pm.getComponentEnabledSetting(component);
1030 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1031 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1032 if (isEnabled != enabled) {
1033 pm.setComponentEnabledSetting(component, enabled
1034 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1035 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1036 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001037 }
1038 }
1039
Jason Monk4da79e02015-09-10 10:54:36 -04001040 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001041 // Once we decide to show Home settings, keep showing it forever
1042 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1043 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1044 return true;
1045 }
1046
1047 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001048 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001049 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001050 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001051 }
1052 } catch (Exception e) {
1053 // Can't look up the home activity; bail on configuring the icon
1054 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1055 }
1056
1057 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1058 return true;
1059 }
1060
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001061 private void getMetaData() {
1062 try {
1063 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1064 PackageManager.GET_META_DATA);
1065 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001066 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1067 } catch (NameNotFoundException nnfe) {
1068 // No recovery
1069 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1070 }
1071 }
1072
1073 // give subclasses access to the Next button
1074 public boolean hasNextButton() {
1075 return mNextButton != null;
1076 }
1077
1078 public Button getNextButton() {
1079 return mNextButton;
1080 }
1081
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001082 @Override
1083 public boolean shouldUpRecreateTask(Intent targetIntent) {
1084 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1085 }
1086
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001087 @Override
1088 public boolean onQueryTextSubmit(String query) {
1089 switchToSearchResultsFragmentIfNeeded();
1090 mSearchQuery = query;
1091 return mSearchResultsFragment.onQueryTextSubmit(query);
1092 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001093
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001094 @Override
1095 public boolean onQueryTextChange(String newText) {
1096 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001097 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001098 return false;
1099 }
1100 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001101 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001102
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001103 @Override
1104 public boolean onClose() {
1105 return false;
1106 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001107
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001108 @Override
1109 public boolean onMenuItemActionExpand(MenuItem item) {
1110 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001111 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001112 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001113 return true;
1114 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001115
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001116 @Override
1117 public boolean onMenuItemActionCollapse(MenuItem item) {
1118 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001119 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001120 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001121 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001122 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001123 return true;
1124 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001125
Jason Monk4da79e02015-09-10 10:54:36 -04001126 @Override
1127 protected void onTileClicked(DashboardTile tile) {
1128 if (mIsShowingDashboard) {
1129 // If on dashboard, don't finish so the back comes back to here.
1130 openTile(tile);
1131 } else {
1132 super.onTileClicked(tile);
1133 }
1134 }
1135
Jason Monkaf001092015-11-04 13:16:18 -05001136 @Override
1137 public void onProfileTileOpen() {
1138 if (!mIsShowingDashboard) {
1139 finish();
1140 }
1141 }
1142
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001143 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001144 if (mSearchResultsFragment != null) {
1145 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001146 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001147 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001148 if (current != null && current instanceof SearchResultsSummary) {
1149 mSearchResultsFragment = (SearchResultsSummary) current;
1150 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001151 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001152 SearchResultsSummary.class.getName(), null, false, true,
1153 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001154 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001155 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001156 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001157 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001158
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001159 public void needToRevertToInitialFragment() {
1160 mNeedToRevertToInitialFragment = true;
1161 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001162
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001163 private void revertToInitialFragment() {
1164 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001165 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001166 mSearchMenuItemExpanded = false;
1167 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1168 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001169 if (mSearchMenuItem != null) {
1170 mSearchMenuItem.collapseActionView();
1171 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001172 }
Jim Miller0698a212014-10-16 19:49:07 -07001173
1174 public Intent getResultIntentData() {
1175 return mResultIntentData;
1176 }
1177
1178 public void setResultIntentData(Intent resultIntentData) {
1179 mResultIntentData = resultIntentData;
1180 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001181}