blob: fd4a493fadb9c6ff2bc869ba5e27c4761cf26d87 [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;
Julia Reynolds5555d262015-11-09 10:52:17 -050095import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080096import com.android.settings.print.PrintJobSettingsFragment;
97import com.android.settings.print.PrintSettingsFragment;
Jason Monk2ebc8a02015-02-13 15:23:19 -050098import com.android.settings.search.DynamicIndexableContentMonitor;
99import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700100import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800101import com.android.settings.tts.TextToSpeechSettings;
102import com.android.settings.users.UserSettings;
103import com.android.settings.vpn2.VpnSettings;
104import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700105import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800106import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700107import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800108import com.android.settings.wifi.WifiSettings;
109import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400110import com.android.settingslib.drawer.DashboardCategory;
111import com.android.settingslib.drawer.DashboardTile;
112import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500113
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800114import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800115import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700116import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800117
Jason Monk4da79e02015-09-10 10:54:36 -0400118public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800119 implements PreferenceManager.OnPreferenceTreeClickListener,
120 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100121 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700122 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100123 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800124
125 private static final String LOG_TAG = "Settings";
126
127 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700128 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700129 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
130 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700131 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700132 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700133 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800134
135 /**
136 * When starting this activity, the invoking Intent can contain this extra
137 * string to specify which fragment should be initially displayed.
138 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
139 * will call isValidFragment() to confirm that the fragment class name is valid for this
140 * activity.
141 */
142 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
143
144 /**
145 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
146 * this extra can also be specified to supply a Bundle of arguments to pass
147 * to that fragment when it is instantiated during the initial creation
148 * of the activity.
149 */
150 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
151
152 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700153 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
154 */
155 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
156
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800157 public static final String BACK_STACK_PREFS = ":settings:prefs";
158
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800159 // extras that allow any preference activity to be launched as part of a wizard
160
161 // show Back and Next buttons? takes boolean parameter
162 // Back will then return RESULT_CANCELED and Next RESULT_OK
163 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
164
165 // add a Skip button?
166 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
167
168 // specify custom text for the Back or Next buttons, or cause a button to not appear
169 // at all by setting it to null
170 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
171 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
172
173 /**
174 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700175 * 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 -0800176 * that fragment.
177 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700178 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100179 /**
180 * The package name used to resolve the title resource id.
181 */
182 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
183 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700184 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
185 ":settings:show_fragment_title_resid";
186 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
187 ":settings:show_fragment_as_shortcut";
188
189 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
190 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800191
Jason Monk30695812015-11-17 09:01:08 -0500192 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800193 "com.android.settings.FRAGMENT_CLASS";
194
195 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
196
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700197 private static final String EMPTY_QUERY = "";
198
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800199 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800200
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800201 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700202 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800203
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800204 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400205 private String[] SETTINGS_FOR_RESTRICTED = {
206 //wireless_section
207 WifiSettingsActivity.class.getName(),
208 Settings.BluetoothSettingsActivity.class.getName(),
209 Settings.DataUsageSummaryActivity.class.getName(),
210 Settings.SimSettingsActivity.class.getName(),
211 Settings.WirelessSettingsActivity.class.getName(),
212 //device_section
213 Settings.HomeSettingsActivity.class.getName(),
214 Settings.NotificationSettingsActivity.class.getName(),
215 Settings.DisplaySettingsActivity.class.getName(),
216 Settings.StorageSettingsActivity.class.getName(),
217 Settings.ManageApplicationsActivity.class.getName(),
218 Settings.PowerUsageSummaryActivity.class.getName(),
219 //personal_section
220 Settings.LocationSettingsActivity.class.getName(),
221 Settings.SecuritySettingsActivity.class.getName(),
222 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
223 Settings.UserSettingsActivity.class.getName(),
224 Settings.AccountSettingsActivity.class.getName(),
225 //system_section
226 Settings.DateTimeSettingsActivity.class.getName(),
227 Settings.DeviceInfoSettingsActivity.class.getName(),
228 Settings.AccessibilitySettingsActivity.class.getName(),
229 Settings.PrintSettingsActivity.class.getName(),
230 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800231 };
232
233 private static final String[] ENTRY_FRAGMENTS = {
234 WirelessSettings.class.getName(),
235 WifiSettings.class.getName(),
236 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700237 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800238 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700239 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800240 TetherSettings.class.getName(),
241 WifiP2pSettings.class.getName(),
242 VpnSettings.class.getName(),
243 DateTimeSettings.class.getName(),
244 LocalePicker.class.getName(),
245 InputMethodAndLanguageSettings.class.getName(),
246 SpellCheckersSettings.class.getName(),
247 UserDictionaryList.class.getName(),
248 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700249 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800250 DisplaySettings.class.getName(),
251 DeviceInfoSettings.class.getName(),
252 ManageApplications.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700253 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800254 ProcessStatsUi.class.getName(),
255 NotificationStation.class.getName(),
256 LocationSettings.class.getName(),
257 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400258 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800259 PrivacySettings.class.getName(),
260 DeviceAdminSettings.class.getName(),
261 AccessibilitySettings.class.getName(),
262 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800263 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
264 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700265 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700266 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700267 PrivateVolumeSettings.class.getName(),
268 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800269 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800270 AndroidBeam.class.getName(),
271 WifiDisplaySettings.class.getName(),
272 PowerUsageSummary.class.getName(),
273 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000274 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800275 CryptKeeperSettings.class.getName(),
276 DataUsageSummary.class.getName(),
277 DreamSettings.class.getName(),
278 UserSettings.class.getName(),
279 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400280 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800281 PrintSettingsFragment.class.getName(),
282 PrintJobSettingsFragment.class.getName(),
283 TrustedCredentialsSettings.class.getName(),
284 PaymentSettings.class.getName(),
285 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700286 ZenModeSettings.class.getName(),
287 NotificationSettings.class.getName(),
288 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
289 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400290 InstalledAppDetails.class.getName(),
291 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700292 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700293 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000294 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400295 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400296 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400297 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400298 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400299 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500300 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400301 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400302 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400303 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100304 DrawOverlayDetails.class.getName(),
305 WriteSettingsDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800306 };
307
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700308
309 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
310 "android.settings.APPLICATION_DETAILS_SETTINGS"
311 };
312
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800313 private SharedPreferences mDevelopmentPreferences;
314 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
315
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800316 private boolean mBatteryPresent = true;
317 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800318 @Override
319 public void onReceive(Context context, Intent intent) {
320 String action = intent.getAction();
321 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
322 boolean batteryPresent = Utils.isBatteryPresent(intent);
323
324 if (mBatteryPresent != batteryPresent) {
325 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400326 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800327 }
328 }
329 }
330 };
331
Svetoslav990159a2014-04-14 17:14:59 -0700332 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
333 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700334
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700335 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700336 private SwitchBar mSwitchBar;
337
338 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700339
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700340 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700341 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700342
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700343 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700344 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700345
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700346 private ViewGroup mContent;
347
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700348 private SearchView mSearchView;
349 private MenuItem mSearchMenuItem;
350 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700351 private SearchResultsSummary mSearchResultsFragment;
352 private String mSearchQuery;
353
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700354 // Categories
355 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800356
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700357 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800358
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700359 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700360 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700361
Jim Miller0698a212014-10-16 19:49:07 -0700362 private Intent mResultIntentData;
363
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700364 public SwitchBar getSwitchBar() {
365 return mSwitchBar;
366 }
367
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800368 @Override
369 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
370 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400371 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800372 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400373 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800374 }
Jason Monk39b46742015-09-10 15:52:51 -0400375 startPreferencePanel(pref.getFragment(), pref.getExtras(), 0, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800376 null, 0);
377 return true;
378 }
379
380 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400381 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800382 return false;
383 }
384
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800385 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800386 public void onConfigurationChanged(Configuration newConfig) {
387 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800388 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800389 }
390
391 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700392 protected void onStart() {
393 super.onStart();
394
395 if (mNeedToRevertToInitialFragment) {
396 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800397 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800398 }
399
400 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700401 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700402 if (!mDisplaySearch) {
403 return false;
404 }
405
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700406 MenuInflater inflater = getMenuInflater();
407 inflater.inflate(R.menu.options_menu, menu);
408
409 // Cache the search query (can be overriden by the OnQueryTextListener)
410 final String query = mSearchQuery;
411
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700412 mSearchMenuItem = menu.findItem(R.id.search);
413 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700414
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700415 if (mSearchMenuItem == null || mSearchView == null) {
416 return false;
417 }
418
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700419 if (mSearchResultsFragment != null) {
420 mSearchResultsFragment.setSearchView(mSearchView);
421 }
422
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700423 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700424 mSearchView.setOnQueryTextListener(this);
425 mSearchView.setOnCloseListener(this);
426
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700427 if (mSearchMenuItemExpanded) {
428 mSearchMenuItem.expandActionView();
429 }
430 mSearchView.setQuery(query, true /* submit */);
431
432 return true;
433 }
434
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700435 private static boolean isShortCutIntent(final Intent intent) {
436 Set<String> categories = intent.getCategories();
437 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
438 }
439
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700440 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700441 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700442 if (action == null) {
443 return false;
444 }
445 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
446 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
447 }
448 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700449 }
450
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700451 @Override
452 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700453 super.onCreate(savedState);
454
455 // Should happen before any call to getIntent()
456 getMetaData();
457
458 final Intent intent = getIntent();
459 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
460 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800461 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800462
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800463 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
464 Context.MODE_PRIVATE);
465
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700466 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700467 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700468
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700469 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700470 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
471
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700472 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700473 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700474
Jason Monk4da79e02015-09-10 10:54:36 -0400475 mIsShowingDashboard = className.equals(Settings.class.getName())
476 || className.equals(Settings.WirelessSettings.class.getName())
477 || className.equals(Settings.DeviceSettings.class.getName())
478 || className.equals(Settings.PersonalSettings.class.getName())
479 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700480
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700481 // This is a "Sub Settings" when:
482 // - this is a real SubSettings
483 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700484 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700485 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
486
487 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
488 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700489 // Check also that we are not a Theme Dialog as we don't want to override them
490 final int themeResId = getThemeResId();
491 if (themeResId != R.style.Theme_DialogWhenLarge &&
492 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
493 setTheme(R.style.Theme_SubSettings);
494 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700495 }
496
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700497 setContentView(mIsShowingDashboard ?
498 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800499
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700500 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700501
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800502 getFragmentManager().addOnBackStackChangedListener(this);
503
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700504 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800505 // Run the Index update only if we have some space
506 if (!Utils.isLowStorage(this)) {
507 Index.getInstance(getApplicationContext()).update();
508 } else {
509 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
510 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700511 }
512
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700513 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700514 // We are restarting from a previous saved state; used that to initialize, instead
515 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700516 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
517 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800518
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700519 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800520
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700521 ArrayList<DashboardCategory> categories =
522 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
523 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700524 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700525 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700526 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800527 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700528
529 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700530 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700531 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
532 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800533 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700534 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400535 mDisplaySearch = false;
536 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700537 if (mIsShortcut) {
538 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700539 } else if (isSubSettings) {
540 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700541 } else {
542 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700543 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700544 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700545
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700546 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700547 switchToFragment(initialFragmentName, initialArguments, true, false,
548 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000549 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700550 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700551 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700552 // Show Search affordance
553 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700554 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700555 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700556 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800557 }
558 }
559
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700560 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700561 if (mActionBar != null) {
562 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
563 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
564 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700565 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
566
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800567 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800568 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
569
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700570 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800571 if (buttonBar != null) {
572 buttonBar.setVisibility(View.VISIBLE);
573
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700574 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800575 backButton.setOnClickListener(new OnClickListener() {
576 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700577 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800578 finish();
579 }
580 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700581 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800582 skipButton.setOnClickListener(new OnClickListener() {
583 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700584 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800585 finish();
586 }
587 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700588 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800589 mNextButton.setOnClickListener(new OnClickListener() {
590 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700591 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800592 finish();
593 }
594 });
595
596 // set our various button parameters
597 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
598 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
599 if (TextUtils.isEmpty(buttonText)) {
600 mNextButton.setVisibility(View.GONE);
601 }
602 else {
603 mNextButton.setText(buttonText);
604 }
605 }
606 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
607 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
608 if (TextUtils.isEmpty(buttonText)) {
609 backButton.setVisibility(View.GONE);
610 }
611 else {
612 backButton.setText(buttonText);
613 }
614 }
615 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
616 skipButton.setVisibility(View.VISIBLE);
617 }
618 }
619 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700620
621 mHomeActivitiesCount = getHomeActivitiesCount();
622 }
623
624 private int getHomeActivitiesCount() {
625 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
626 getPackageManager().getHomeActivities(homeApps);
627 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800628 }
629
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700630 private void setTitleFromIntent(Intent intent) {
631 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
632 if (initialTitleResId > 0) {
633 mInitialTitle = null;
634 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100635
636 final String initialTitleResPackageName = intent.getStringExtra(
637 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
638 if (initialTitleResPackageName != null) {
639 try {
640 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
641 0 /* flags */, new UserHandle(UserHandle.myUserId()));
642 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
643 setTitle(mInitialTitle);
644 mInitialTitleResId = -1;
645 return;
646 } catch (NameNotFoundException e) {
647 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
648 }
649 } else {
650 setTitle(mInitialTitleResId);
651 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700652 } else {
653 mInitialTitleResId = -1;
654 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
655 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
656 setTitle(mInitialTitle);
657 }
658 }
659
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800660 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800661 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700662 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800663 }
664
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700665 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800666 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700667
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800668 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700669 if (mInitialTitleResId > 0) {
670 setTitle(mInitialTitleResId);
671 } else {
672 setTitle(mInitialTitle);
673 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700674 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800675 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700676
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800677 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
678 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700679
680 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800681 }
682
683 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
684 final CharSequence title;
685 final int titleRes = bse.getBreadCrumbTitleRes();
686 if (titleRes > 0) {
687 title = getText(titleRes);
688 } else {
689 title = bse.getBreadCrumbTitle();
690 }
691 if (title != null) {
692 setTitle(title);
693 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800694 }
695
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800696 @Override
697 protected void onSaveInstanceState(Bundle outState) {
698 super.onSaveInstanceState(outState);
699
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700700 if (mCategories.size() > 0) {
701 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800702 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700703
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700704 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700705 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700706
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700707 if (mDisplaySearch) {
708 // The option menus are created if the ActionBar is visible and they are also created
709 // asynchronously. If you launch Settings with an Intent action like
710 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
711 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
712 // menu item and search view are null.
713 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
714 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700715
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700716 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
717 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
718 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700719
720 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800721 }
722
723 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400724 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800725 super.onResume();
Chris Wren8a963ba2015-03-20 10:29:14 -0400726 if (mIsShowingDashboard) {
727 MetricsLogger.visible(this, MetricsLogger.MAIN_SETTINGS);
728 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800729
730 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
731 @Override
732 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400733 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800734 }
735 };
736 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
737 mDevelopmentPreferencesListener);
738
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800739 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700740
Svetoslav990159a2014-04-14 17:14:59 -0700741 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700742
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700743 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700744 onQueryTextSubmit(mSearchQuery);
745 }
Jason Monk4da79e02015-09-10 10:54:36 -0400746 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800747 }
748
749 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400750 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800751 super.onPause();
Chris Wren8a963ba2015-03-20 10:29:14 -0400752 if (mIsShowingDashboard) {
753 MetricsLogger.hidden(this, MetricsLogger.MAIN_SETTINGS);
754 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800755 unregisterReceiver(mBatteryInfoReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700756 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800757 }
758
759 @Override
760 public void onDestroy() {
761 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700762
763 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
764 mDevelopmentPreferencesListener);
765 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800766 }
767
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800768 protected boolean isValidFragment(String fragmentName) {
769 // Almost all fragments are wrapped in this,
770 // except for a few that have their own activities.
771 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
772 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
773 }
774 return false;
775 }
776
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800777 @Override
778 public Intent getIntent() {
779 Intent superIntent = super.getIntent();
780 String startingFragment = getStartingFragmentClass(superIntent);
781 // This is called from super.onCreate, isMultiPane() is not yet reliable
782 // Do not use onIsHidingHeaders either, which relies itself on this method
783 if (startingFragment != null) {
784 Intent modIntent = new Intent(superIntent);
785 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
786 Bundle args = superIntent.getExtras();
787 if (args != null) {
788 args = new Bundle(args);
789 } else {
790 args = new Bundle();
791 }
792 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100793 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800794 return modIntent;
795 }
796 return superIntent;
797 }
798
799 /**
800 * Checks if the component name in the intent is different from the Settings class and
801 * returns the class name to load as a fragment.
802 */
803 private String getStartingFragmentClass(Intent intent) {
804 if (mFragmentClass != null) return mFragmentClass;
805
806 String intentClass = intent.getComponent().getClassName();
807 if (intentClass.equals(getClass().getName())) return null;
808
809 if ("com.android.settings.ManageApplications".equals(intentClass)
810 || "com.android.settings.RunningServices".equals(intentClass)
811 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
812 // Old names of manage apps.
813 intentClass = com.android.settings.applications.ManageApplications.class.getName();
814 }
815
816 return intentClass;
817 }
818
819 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000820 * Start a new fragment containing a preference panel. If the preferences
821 * are being displayed in multi-pane mode, the given fragment class will
822 * be instantiated and placed in the appropriate pane. If running in
823 * single-pane mode, a new activity will be launched in which to show the
824 * fragment.
825 *
826 * @param fragmentClass Full name of the class implementing the fragment.
827 * @param args Any desired arguments to supply to the fragment.
828 * @param titleRes Optional resource identifier of the title of this
829 * fragment.
830 * @param titleText Optional text of the title of this fragment.
831 * @param resultTo Optional fragment that result data should be sent to.
832 * If non-null, resultTo.onActivityResult() will be called when this
833 * preference panel is done. The launched panel must use
834 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
835 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700836 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000837 */
838 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700839 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700840 String title = null;
841 if (titleRes < 0) {
842 if (titleText != null) {
843 title = titleText.toString();
844 } else {
845 // There not much we can do in that case
846 title = "";
847 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700848 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700849 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700850 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000851 }
852
853 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100854 * Start a new fragment in a new activity containing a preference panel for a given user. If the
855 * preferences are being displayed in multi-pane mode, the given fragment class will be
856 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
857 * activity will be launched in which to show the fragment.
858 *
859 * @param fragmentClass Full name of the class implementing the fragment.
860 * @param args Any desired arguments to supply to the fragment.
861 * @param titleRes Optional resource identifier of the title of this fragment.
862 * @param titleText Optional text of the title of this fragment.
863 * @param userHandle The user for which the panel has to be started.
864 */
865 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
866 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700867 // This is a workaround.
868 //
869 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
870 // starting the fragment could cause a native stack corruption. See b/17523189. However,
871 // adding that flag and start the preference panel with the same UserHandler will make it
872 // impossible to use back button to return to the previous screen. See b/20042570.
873 //
874 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
875 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
876 // when we're calling it as the same user.
877 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
878 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
879 } else {
880 String title = null;
881 if (titleRes < 0) {
882 if (titleText != null) {
883 title = titleText.toString();
884 } else {
885 // There not much we can do in that case
886 title = "";
887 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100888 }
Lifu Tangd0332852015-04-02 12:05:46 -0700889 Utils.startWithFragmentAsUser(this, fragmentClass, args,
890 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100891 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100892 }
893
894 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800895 * Called by a preference panel fragment to finish itself.
896 *
897 * @param caller The fragment that is asking to be finished.
898 * @param resultCode Optional result code to send back to the original
899 * launching fragment.
900 * @param resultData Optional result data to send back to the original
901 * launching fragment.
902 */
903 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
904 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700905 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800906 }
907
908 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000909 * Start a new fragment.
910 *
911 * @param fragment The fragment to start
912 * @param push If true, the current fragment will be pushed onto the back stack. If false,
913 * the current fragment will be replaced.
914 */
915 public void startPreferenceFragment(Fragment fragment, boolean push) {
916 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700917 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000918 if (push) {
919 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
920 transaction.addToBackStack(BACK_STACK_PREFS);
921 } else {
922 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
923 }
924 transaction.commitAllowingStateLoss();
925 }
926
927 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700928 * Switch to a specific Fragment with taking care of validation, Title and BackStack
929 */
930 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700931 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700932 if (validate && !isValidFragment(fragmentName)) {
933 throw new IllegalArgumentException("Invalid fragment for this activity: "
934 + fragmentName);
935 }
936 Fragment f = Fragment.instantiate(this, fragmentName, args);
937 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700938 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700939 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700940 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700941 }
942 if (addToBackStack) {
943 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
944 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700945 if (titleResId > 0) {
946 transaction.setBreadCrumbTitle(titleResId);
947 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700948 transaction.setBreadCrumbTitle(title);
949 }
950 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700951 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700952 return f;
953 }
954
Jason Monk4da79e02015-09-10 10:54:36 -0400955 private void updateTilesList() {
956 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700957 final UserManager um = UserManager.get(this);
958 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700959
Jason Monk4da79e02015-09-10 10:54:36 -0400960 String packageName = getPackageName();
961 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
962 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700963
Jason Monk4da79e02015-09-10 10:54:36 -0400964 setTileEnabled(new ComponentName(packageName,
965 Settings.BluetoothSettingsActivity.class.getName()),
966 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700967
Jason Monk4da79e02015-09-10 10:54:36 -0400968 setTileEnabled(new ComponentName(packageName,
969 Settings.DataUsageSummaryActivity.class.getName()),
970 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700971
Jason Monk4da79e02015-09-10 10:54:36 -0400972 setTileEnabled(new ComponentName(packageName,
973 Settings.SimSettingsActivity.class.getName()),
974 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700975
Jason Monk4da79e02015-09-10 10:54:36 -0400976 setTileEnabled(new ComponentName(packageName,
977 Settings.PowerUsageSummaryActivity.class.getName()),
978 mBatteryPresent, isAdmin, pm);
979
980 setTileEnabled(new ComponentName(packageName,
981 Settings.HomeSettingsActivity.class.getName()),
982 updateHomeSettingTiles(), isAdmin, pm);
983
984 setTileEnabled(new ComponentName(packageName,
985 Settings.UserSettingsActivity.class.getName()),
986 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
987 && !Utils.isMonkeyRunning(), isAdmin, pm);
988
989 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
990 setTileEnabled(new ComponentName(packageName,
991 Settings.PaymentSettingsActivity.class.getName()),
992 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
993 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
994 && adapter != null && adapter.isEnabled(), isAdmin, pm);
995
996 setTileEnabled(new ComponentName(packageName,
997 Settings.PrintSettingsActivity.class.getName()),
998 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
999
1000 final boolean showDev = mDevelopmentPreferences.getBoolean(
1001 DevelopmentSettings.PREF_SHOW,
1002 android.os.Build.TYPE.equals("eng"));
1003 setTileEnabled(new ComponentName(packageName,
1004 Settings.DevelopmentSettingsActivity.class.getName()),
1005 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1006 isAdmin, pm);
1007
1008 if (UserHandle.MU_ENABLED && !isAdmin) {
1009 // When on restricted users, disable all extra categories (but only the settings ones).
1010 List<DashboardCategory> categories = getDashboardCategories(true);
1011 for (DashboardCategory category : categories) {
1012 for (DashboardTile tile : category.tiles) {
1013 ComponentName component = tile.intent.getComponent();
1014 if (packageName.equals(component)&& !ArrayUtils.contains(
1015 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1016 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001017 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001018 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001019 }
1020 }
Jason Monk4da79e02015-09-10 10:54:36 -04001021
1022 updateDrawer();
Jason Monk2ebc8a02015-02-13 15:23:19 -05001023 }
1024
Jason Monk4da79e02015-09-10 10:54:36 -04001025 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1026 PackageManager pm) {
1027 if (UserHandle.MU_ENABLED && !isAdmin
1028 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1029 enabled = false;
1030 }
1031 int state = pm.getComponentEnabledSetting(component);
1032 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1033 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1034 if (isEnabled != enabled) {
1035 pm.setComponentEnabledSetting(component, enabled
1036 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1037 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1038 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001039 }
1040 }
1041
Jason Monk4da79e02015-09-10 10:54:36 -04001042 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001043 // Once we decide to show Home settings, keep showing it forever
1044 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1045 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1046 return true;
1047 }
1048
1049 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001050 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001051 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001052 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001053 }
1054 } catch (Exception e) {
1055 // Can't look up the home activity; bail on configuring the icon
1056 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1057 }
1058
1059 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1060 return true;
1061 }
1062
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001063 private void getMetaData() {
1064 try {
1065 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1066 PackageManager.GET_META_DATA);
1067 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001068 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1069 } catch (NameNotFoundException nnfe) {
1070 // No recovery
1071 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1072 }
1073 }
1074
1075 // give subclasses access to the Next button
1076 public boolean hasNextButton() {
1077 return mNextButton != null;
1078 }
1079
1080 public Button getNextButton() {
1081 return mNextButton;
1082 }
1083
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001084 @Override
1085 public boolean shouldUpRecreateTask(Intent targetIntent) {
1086 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1087 }
1088
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001089 @Override
1090 public boolean onQueryTextSubmit(String query) {
1091 switchToSearchResultsFragmentIfNeeded();
1092 mSearchQuery = query;
1093 return mSearchResultsFragment.onQueryTextSubmit(query);
1094 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001095
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001096 @Override
1097 public boolean onQueryTextChange(String newText) {
1098 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001099 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001100 return false;
1101 }
1102 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001103 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001104
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001105 @Override
1106 public boolean onClose() {
1107 return false;
1108 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001109
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001110 @Override
1111 public boolean onMenuItemActionExpand(MenuItem item) {
1112 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001113 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001114 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001115 return true;
1116 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001117
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001118 @Override
1119 public boolean onMenuItemActionCollapse(MenuItem item) {
1120 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001121 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001122 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001123 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001124 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001125 return true;
1126 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001127
Jason Monk4da79e02015-09-10 10:54:36 -04001128 @Override
1129 protected void onTileClicked(DashboardTile tile) {
1130 if (mIsShowingDashboard) {
1131 // If on dashboard, don't finish so the back comes back to here.
1132 openTile(tile);
1133 } else {
1134 super.onTileClicked(tile);
1135 }
1136 }
1137
Jason Monkaf001092015-11-04 13:16:18 -05001138 @Override
1139 public void onProfileTileOpen() {
1140 if (!mIsShowingDashboard) {
1141 finish();
1142 }
1143 }
1144
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001145 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001146 if (mSearchResultsFragment != null) {
1147 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001148 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001149 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001150 if (current != null && current instanceof SearchResultsSummary) {
1151 mSearchResultsFragment = (SearchResultsSummary) current;
1152 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001153 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001154 SearchResultsSummary.class.getName(), null, false, true,
1155 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001156 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001157 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001158 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001159 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001160
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001161 public void needToRevertToInitialFragment() {
1162 mNeedToRevertToInitialFragment = true;
1163 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001164
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001165 private void revertToInitialFragment() {
1166 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001167 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001168 mSearchMenuItemExpanded = false;
1169 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1170 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001171 if (mSearchMenuItem != null) {
1172 mSearchMenuItem.collapseActionView();
1173 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001174 }
Jim Miller0698a212014-10-16 19:49:07 -07001175
1176 public Intent getResultIntentData() {
1177 return mResultIntentData;
1178 }
1179
1180 public void setResultIntentData(Intent resultIntentData) {
1181 mResultIntentData = resultIntentData;
1182 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001183}