blob: 809a740c30f33186dc0f823f313da2b9b22ed3af [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;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050085import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -040086import com.android.settings.notification.NotificationAccessSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050087import com.android.settings.notification.SoundSettings;
John Spurlock4a350512014-04-08 14:08:21 -040088import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -050089import com.android.settings.notification.OtherSoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -040090import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -040091import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -040092import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -040093import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -040094import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -040095import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -050096import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080097import com.android.settings.print.PrintJobSettingsFragment;
98import com.android.settings.print.PrintSettingsFragment;
Jason Monk2ebc8a02015-02-13 15:23:19 -050099import com.android.settings.search.DynamicIndexableContentMonitor;
100import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700101import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800102import com.android.settings.tts.TextToSpeechSettings;
103import com.android.settings.users.UserSettings;
104import com.android.settings.vpn2.VpnSettings;
105import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700106import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800107import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700108import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800109import com.android.settings.wifi.WifiSettings;
110import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400111import com.android.settingslib.drawer.DashboardCategory;
112import com.android.settingslib.drawer.DashboardTile;
113import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500114
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800115import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800116import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700117import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800118
Jason Monk4da79e02015-09-10 10:54:36 -0400119public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800120 implements PreferenceManager.OnPreferenceTreeClickListener,
121 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100122 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700123 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100124 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800125
126 private static final String LOG_TAG = "Settings";
127
128 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700129 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700130 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
131 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700132 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700133 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700134 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800135
136 /**
137 * When starting this activity, the invoking Intent can contain this extra
138 * string to specify which fragment should be initially displayed.
139 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
140 * will call isValidFragment() to confirm that the fragment class name is valid for this
141 * activity.
142 */
143 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
144
145 /**
146 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
147 * this extra can also be specified to supply a Bundle of arguments to pass
148 * to that fragment when it is instantiated during the initial creation
149 * of the activity.
150 */
151 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
152
153 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700154 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
155 */
156 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
157
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800158 public static final String BACK_STACK_PREFS = ":settings:prefs";
159
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800160 // extras that allow any preference activity to be launched as part of a wizard
161
162 // show Back and Next buttons? takes boolean parameter
163 // Back will then return RESULT_CANCELED and Next RESULT_OK
164 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
165
166 // add a Skip button?
167 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
168
169 // specify custom text for the Back or Next buttons, or cause a button to not appear
170 // at all by setting it to null
171 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
172 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
173
174 /**
175 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700176 * 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 -0800177 * that fragment.
178 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700179 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100180 /**
181 * The package name used to resolve the title resource id.
182 */
183 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
184 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700185 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
186 ":settings:show_fragment_title_resid";
187 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
188 ":settings:show_fragment_as_shortcut";
189
190 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
191 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800192
Jason Monk30695812015-11-17 09:01:08 -0500193 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800194 "com.android.settings.FRAGMENT_CLASS";
195
196 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
197
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700198 private static final String EMPTY_QUERY = "";
199
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800200 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800201
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800202 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700203 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800204
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800205 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400206 private String[] SETTINGS_FOR_RESTRICTED = {
207 //wireless_section
208 WifiSettingsActivity.class.getName(),
209 Settings.BluetoothSettingsActivity.class.getName(),
210 Settings.DataUsageSummaryActivity.class.getName(),
211 Settings.SimSettingsActivity.class.getName(),
212 Settings.WirelessSettingsActivity.class.getName(),
213 //device_section
214 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500215 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400216 Settings.DisplaySettingsActivity.class.getName(),
217 Settings.StorageSettingsActivity.class.getName(),
218 Settings.ManageApplicationsActivity.class.getName(),
219 Settings.PowerUsageSummaryActivity.class.getName(),
220 //personal_section
221 Settings.LocationSettingsActivity.class.getName(),
222 Settings.SecuritySettingsActivity.class.getName(),
223 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
224 Settings.UserSettingsActivity.class.getName(),
225 Settings.AccountSettingsActivity.class.getName(),
226 //system_section
227 Settings.DateTimeSettingsActivity.class.getName(),
228 Settings.DeviceInfoSettingsActivity.class.getName(),
229 Settings.AccessibilitySettingsActivity.class.getName(),
230 Settings.PrintSettingsActivity.class.getName(),
231 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800232 };
233
234 private static final String[] ENTRY_FRAGMENTS = {
235 WirelessSettings.class.getName(),
236 WifiSettings.class.getName(),
237 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700238 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800239 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700240 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800241 TetherSettings.class.getName(),
242 WifiP2pSettings.class.getName(),
243 VpnSettings.class.getName(),
244 DateTimeSettings.class.getName(),
245 LocalePicker.class.getName(),
246 InputMethodAndLanguageSettings.class.getName(),
247 SpellCheckersSettings.class.getName(),
248 UserDictionaryList.class.getName(),
249 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700250 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800251 DisplaySettings.class.getName(),
252 DeviceInfoSettings.class.getName(),
253 ManageApplications.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700254 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800255 ProcessStatsUi.class.getName(),
256 NotificationStation.class.getName(),
257 LocationSettings.class.getName(),
258 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400259 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800260 PrivacySettings.class.getName(),
261 DeviceAdminSettings.class.getName(),
262 AccessibilitySettings.class.getName(),
263 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800264 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
265 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700266 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700267 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700268 PrivateVolumeSettings.class.getName(),
269 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800270 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800271 AndroidBeam.class.getName(),
272 WifiDisplaySettings.class.getName(),
273 PowerUsageSummary.class.getName(),
274 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000275 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800276 CryptKeeperSettings.class.getName(),
277 DataUsageSummary.class.getName(),
278 DreamSettings.class.getName(),
279 UserSettings.class.getName(),
280 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400281 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800282 PrintSettingsFragment.class.getName(),
283 PrintJobSettingsFragment.class.getName(),
284 TrustedCredentialsSettings.class.getName(),
285 PaymentSettings.class.getName(),
286 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700287 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500288 SoundSettings.class.getName(),
289 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700290 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
291 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400292 InstalledAppDetails.class.getName(),
293 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700294 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700295 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000296 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400297 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400298 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400299 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400300 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400301 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500302 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400303 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400304 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400305 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100306 DrawOverlayDetails.class.getName(),
307 WriteSettingsDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800308 };
309
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700310
311 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
312 "android.settings.APPLICATION_DETAILS_SETTINGS"
313 };
314
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800315 private SharedPreferences mDevelopmentPreferences;
316 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
317
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800318 private boolean mBatteryPresent = true;
319 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800320 @Override
321 public void onReceive(Context context, Intent intent) {
322 String action = intent.getAction();
323 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
324 boolean batteryPresent = Utils.isBatteryPresent(intent);
325
326 if (mBatteryPresent != batteryPresent) {
327 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400328 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800329 }
330 }
331 }
332 };
333
Svetoslav990159a2014-04-14 17:14:59 -0700334 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
335 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700336
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700337 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700338 private SwitchBar mSwitchBar;
339
340 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700341
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700342 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700343 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700344
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700345 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700346 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700347
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700348 private ViewGroup mContent;
349
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700350 private SearchView mSearchView;
351 private MenuItem mSearchMenuItem;
352 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700353 private SearchResultsSummary mSearchResultsFragment;
354 private String mSearchQuery;
355
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700356 // Categories
357 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800358
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700359 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800360
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700361 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700362 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700363
Jim Miller0698a212014-10-16 19:49:07 -0700364 private Intent mResultIntentData;
365
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700366 public SwitchBar getSwitchBar() {
367 return mSwitchBar;
368 }
369
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800370 @Override
371 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
372 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400373 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800374 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400375 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800376 }
Jason Monk39b46742015-09-10 15:52:51 -0400377 startPreferencePanel(pref.getFragment(), pref.getExtras(), 0, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800378 null, 0);
379 return true;
380 }
381
382 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400383 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800384 return false;
385 }
386
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800387 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800388 public void onConfigurationChanged(Configuration newConfig) {
389 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800390 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800391 }
392
393 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700394 protected void onStart() {
395 super.onStart();
396
397 if (mNeedToRevertToInitialFragment) {
398 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800399 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800400 }
401
402 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700403 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700404 if (!mDisplaySearch) {
405 return false;
406 }
407
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700408 MenuInflater inflater = getMenuInflater();
409 inflater.inflate(R.menu.options_menu, menu);
410
411 // Cache the search query (can be overriden by the OnQueryTextListener)
412 final String query = mSearchQuery;
413
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700414 mSearchMenuItem = menu.findItem(R.id.search);
415 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700416
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700417 if (mSearchMenuItem == null || mSearchView == null) {
418 return false;
419 }
420
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700421 if (mSearchResultsFragment != null) {
422 mSearchResultsFragment.setSearchView(mSearchView);
423 }
424
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700425 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700426 mSearchView.setOnQueryTextListener(this);
427 mSearchView.setOnCloseListener(this);
428
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700429 if (mSearchMenuItemExpanded) {
430 mSearchMenuItem.expandActionView();
431 }
432 mSearchView.setQuery(query, true /* submit */);
433
434 return true;
435 }
436
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700437 private static boolean isShortCutIntent(final Intent intent) {
438 Set<String> categories = intent.getCategories();
439 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
440 }
441
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700442 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700443 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700444 if (action == null) {
445 return false;
446 }
447 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
448 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
449 }
450 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700451 }
452
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700453 @Override
454 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700455 super.onCreate(savedState);
456
457 // Should happen before any call to getIntent()
458 getMetaData();
459
460 final Intent intent = getIntent();
461 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
462 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800463 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800464
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800465 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
466 Context.MODE_PRIVATE);
467
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700468 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700469 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700470
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700471 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700472 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
473
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700474 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700475 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700476
Jason Monk4da79e02015-09-10 10:54:36 -0400477 mIsShowingDashboard = className.equals(Settings.class.getName())
478 || className.equals(Settings.WirelessSettings.class.getName())
479 || className.equals(Settings.DeviceSettings.class.getName())
480 || className.equals(Settings.PersonalSettings.class.getName())
481 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700482
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700483 // This is a "Sub Settings" when:
484 // - this is a real SubSettings
485 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700486 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700487 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
488
489 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
490 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700491 // Check also that we are not a Theme Dialog as we don't want to override them
492 final int themeResId = getThemeResId();
493 if (themeResId != R.style.Theme_DialogWhenLarge &&
494 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
495 setTheme(R.style.Theme_SubSettings);
496 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700497 }
498
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700499 setContentView(mIsShowingDashboard ?
500 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800501
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700502 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700503
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800504 getFragmentManager().addOnBackStackChangedListener(this);
505
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700506 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800507 // Run the Index update only if we have some space
508 if (!Utils.isLowStorage(this)) {
509 Index.getInstance(getApplicationContext()).update();
510 } else {
511 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
512 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700513 }
514
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700515 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700516 // We are restarting from a previous saved state; used that to initialize, instead
517 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700518 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
519 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800520
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700521 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800522
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700523 ArrayList<DashboardCategory> categories =
524 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
525 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700526 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700527 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700528 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800529 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700530
531 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700532 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700533 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
534 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800535 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700536 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400537 mDisplaySearch = false;
538 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700539 if (mIsShortcut) {
540 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700541 } else if (isSubSettings) {
542 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700543 } else {
544 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700545 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700546 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700547
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700548 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700549 switchToFragment(initialFragmentName, initialArguments, true, false,
550 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000551 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700552 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700553 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700554 // Show Search affordance
555 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700556 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700557 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700558 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800559 }
560 }
561
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700562 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700563 if (mActionBar != null) {
564 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
565 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
566 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700567 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
568
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800569 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800570 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
571
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700572 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800573 if (buttonBar != null) {
574 buttonBar.setVisibility(View.VISIBLE);
575
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700576 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800577 backButton.setOnClickListener(new OnClickListener() {
578 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700579 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800580 finish();
581 }
582 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700583 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800584 skipButton.setOnClickListener(new OnClickListener() {
585 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700586 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800587 finish();
588 }
589 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700590 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800591 mNextButton.setOnClickListener(new OnClickListener() {
592 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700593 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800594 finish();
595 }
596 });
597
598 // set our various button parameters
599 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
600 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
601 if (TextUtils.isEmpty(buttonText)) {
602 mNextButton.setVisibility(View.GONE);
603 }
604 else {
605 mNextButton.setText(buttonText);
606 }
607 }
608 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
609 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
610 if (TextUtils.isEmpty(buttonText)) {
611 backButton.setVisibility(View.GONE);
612 }
613 else {
614 backButton.setText(buttonText);
615 }
616 }
617 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
618 skipButton.setVisibility(View.VISIBLE);
619 }
620 }
621 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700622
623 mHomeActivitiesCount = getHomeActivitiesCount();
624 }
625
626 private int getHomeActivitiesCount() {
627 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
628 getPackageManager().getHomeActivities(homeApps);
629 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800630 }
631
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700632 private void setTitleFromIntent(Intent intent) {
633 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
634 if (initialTitleResId > 0) {
635 mInitialTitle = null;
636 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100637
638 final String initialTitleResPackageName = intent.getStringExtra(
639 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
640 if (initialTitleResPackageName != null) {
641 try {
642 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
643 0 /* flags */, new UserHandle(UserHandle.myUserId()));
644 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
645 setTitle(mInitialTitle);
646 mInitialTitleResId = -1;
647 return;
648 } catch (NameNotFoundException e) {
649 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
650 }
651 } else {
652 setTitle(mInitialTitleResId);
653 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700654 } else {
655 mInitialTitleResId = -1;
656 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
657 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
658 setTitle(mInitialTitle);
659 }
660 }
661
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800662 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800663 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700664 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800665 }
666
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700667 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800668 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700669
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800670 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700671 if (mInitialTitleResId > 0) {
672 setTitle(mInitialTitleResId);
673 } else {
674 setTitle(mInitialTitle);
675 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700676 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800677 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700678
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800679 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
680 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700681
682 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800683 }
684
685 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
686 final CharSequence title;
687 final int titleRes = bse.getBreadCrumbTitleRes();
688 if (titleRes > 0) {
689 title = getText(titleRes);
690 } else {
691 title = bse.getBreadCrumbTitle();
692 }
693 if (title != null) {
694 setTitle(title);
695 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800696 }
697
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800698 @Override
699 protected void onSaveInstanceState(Bundle outState) {
700 super.onSaveInstanceState(outState);
701
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700702 if (mCategories.size() > 0) {
703 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800704 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700705
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700706 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700707 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700708
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700709 if (mDisplaySearch) {
710 // The option menus are created if the ActionBar is visible and they are also created
711 // asynchronously. If you launch Settings with an Intent action like
712 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
713 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
714 // menu item and search view are null.
715 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
716 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700717
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700718 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
719 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
720 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700721
722 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800723 }
724
725 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400726 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800727 super.onResume();
Chris Wren8a963ba2015-03-20 10:29:14 -0400728 if (mIsShowingDashboard) {
729 MetricsLogger.visible(this, MetricsLogger.MAIN_SETTINGS);
730 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800731
732 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
733 @Override
734 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400735 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800736 }
737 };
738 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
739 mDevelopmentPreferencesListener);
740
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800741 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700742
Svetoslav990159a2014-04-14 17:14:59 -0700743 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700744
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700745 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700746 onQueryTextSubmit(mSearchQuery);
747 }
Jason Monk4da79e02015-09-10 10:54:36 -0400748 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800749 }
750
751 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400752 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800753 super.onPause();
Chris Wren8a963ba2015-03-20 10:29:14 -0400754 if (mIsShowingDashboard) {
755 MetricsLogger.hidden(this, MetricsLogger.MAIN_SETTINGS);
756 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800757 unregisterReceiver(mBatteryInfoReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700758 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800759 }
760
761 @Override
762 public void onDestroy() {
763 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700764
765 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
766 mDevelopmentPreferencesListener);
767 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800768 }
769
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800770 protected boolean isValidFragment(String fragmentName) {
771 // Almost all fragments are wrapped in this,
772 // except for a few that have their own activities.
773 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
774 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
775 }
776 return false;
777 }
778
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800779 @Override
780 public Intent getIntent() {
781 Intent superIntent = super.getIntent();
782 String startingFragment = getStartingFragmentClass(superIntent);
783 // This is called from super.onCreate, isMultiPane() is not yet reliable
784 // Do not use onIsHidingHeaders either, which relies itself on this method
785 if (startingFragment != null) {
786 Intent modIntent = new Intent(superIntent);
787 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
788 Bundle args = superIntent.getExtras();
789 if (args != null) {
790 args = new Bundle(args);
791 } else {
792 args = new Bundle();
793 }
794 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100795 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800796 return modIntent;
797 }
798 return superIntent;
799 }
800
801 /**
802 * Checks if the component name in the intent is different from the Settings class and
803 * returns the class name to load as a fragment.
804 */
805 private String getStartingFragmentClass(Intent intent) {
806 if (mFragmentClass != null) return mFragmentClass;
807
808 String intentClass = intent.getComponent().getClassName();
809 if (intentClass.equals(getClass().getName())) return null;
810
811 if ("com.android.settings.ManageApplications".equals(intentClass)
812 || "com.android.settings.RunningServices".equals(intentClass)
813 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
814 // Old names of manage apps.
815 intentClass = com.android.settings.applications.ManageApplications.class.getName();
816 }
817
818 return intentClass;
819 }
820
821 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000822 * Start a new fragment containing a preference panel. If the preferences
823 * are being displayed in multi-pane mode, the given fragment class will
824 * be instantiated and placed in the appropriate pane. If running in
825 * single-pane mode, a new activity will be launched in which to show the
826 * fragment.
827 *
828 * @param fragmentClass Full name of the class implementing the fragment.
829 * @param args Any desired arguments to supply to the fragment.
830 * @param titleRes Optional resource identifier of the title of this
831 * fragment.
832 * @param titleText Optional text of the title of this fragment.
833 * @param resultTo Optional fragment that result data should be sent to.
834 * If non-null, resultTo.onActivityResult() will be called when this
835 * preference panel is done. The launched panel must use
836 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
837 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700838 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000839 */
840 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700841 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700842 String title = null;
843 if (titleRes < 0) {
844 if (titleText != null) {
845 title = titleText.toString();
846 } else {
847 // There not much we can do in that case
848 title = "";
849 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700850 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700851 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700852 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000853 }
854
855 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100856 * Start a new fragment in a new activity containing a preference panel for a given user. If the
857 * preferences are being displayed in multi-pane mode, the given fragment class will be
858 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
859 * activity will be launched in which to show the fragment.
860 *
861 * @param fragmentClass Full name of the class implementing the fragment.
862 * @param args Any desired arguments to supply to the fragment.
863 * @param titleRes Optional resource identifier of the title of this fragment.
864 * @param titleText Optional text of the title of this fragment.
865 * @param userHandle The user for which the panel has to be started.
866 */
867 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
868 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700869 // This is a workaround.
870 //
871 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
872 // starting the fragment could cause a native stack corruption. See b/17523189. However,
873 // adding that flag and start the preference panel with the same UserHandler will make it
874 // impossible to use back button to return to the previous screen. See b/20042570.
875 //
876 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
877 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
878 // when we're calling it as the same user.
879 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
880 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
881 } else {
882 String title = null;
883 if (titleRes < 0) {
884 if (titleText != null) {
885 title = titleText.toString();
886 } else {
887 // There not much we can do in that case
888 title = "";
889 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100890 }
Lifu Tangd0332852015-04-02 12:05:46 -0700891 Utils.startWithFragmentAsUser(this, fragmentClass, args,
892 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100893 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100894 }
895
896 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800897 * Called by a preference panel fragment to finish itself.
898 *
899 * @param caller The fragment that is asking to be finished.
900 * @param resultCode Optional result code to send back to the original
901 * launching fragment.
902 * @param resultData Optional result data to send back to the original
903 * launching fragment.
904 */
905 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
906 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700907 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800908 }
909
910 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000911 * Start a new fragment.
912 *
913 * @param fragment The fragment to start
914 * @param push If true, the current fragment will be pushed onto the back stack. If false,
915 * the current fragment will be replaced.
916 */
917 public void startPreferenceFragment(Fragment fragment, boolean push) {
918 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700919 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000920 if (push) {
921 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
922 transaction.addToBackStack(BACK_STACK_PREFS);
923 } else {
924 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
925 }
926 transaction.commitAllowingStateLoss();
927 }
928
929 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700930 * Switch to a specific Fragment with taking care of validation, Title and BackStack
931 */
932 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700933 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700934 if (validate && !isValidFragment(fragmentName)) {
935 throw new IllegalArgumentException("Invalid fragment for this activity: "
936 + fragmentName);
937 }
938 Fragment f = Fragment.instantiate(this, fragmentName, args);
939 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700940 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700941 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700942 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700943 }
944 if (addToBackStack) {
945 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
946 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700947 if (titleResId > 0) {
948 transaction.setBreadCrumbTitle(titleResId);
949 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700950 transaction.setBreadCrumbTitle(title);
951 }
952 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700953 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700954 return f;
955 }
956
Jason Monk4da79e02015-09-10 10:54:36 -0400957 private void updateTilesList() {
958 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700959 final UserManager um = UserManager.get(this);
960 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700961
Jason Monk4da79e02015-09-10 10:54:36 -0400962 String packageName = getPackageName();
963 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
964 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), 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.BluetoothSettingsActivity.class.getName()),
968 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), 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.DataUsageSummaryActivity.class.getName()),
972 Utils.isBandwidthControlEnabled(), 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.SimSettingsActivity.class.getName()),
976 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700977
Jason Monk4da79e02015-09-10 10:54:36 -0400978 setTileEnabled(new ComponentName(packageName,
979 Settings.PowerUsageSummaryActivity.class.getName()),
980 mBatteryPresent, isAdmin, pm);
981
982 setTileEnabled(new ComponentName(packageName,
983 Settings.HomeSettingsActivity.class.getName()),
984 updateHomeSettingTiles(), isAdmin, pm);
985
986 setTileEnabled(new ComponentName(packageName,
987 Settings.UserSettingsActivity.class.getName()),
988 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
989 && !Utils.isMonkeyRunning(), isAdmin, pm);
990
991 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
992 setTileEnabled(new ComponentName(packageName,
993 Settings.PaymentSettingsActivity.class.getName()),
994 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
995 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
996 && adapter != null && adapter.isEnabled(), isAdmin, pm);
997
998 setTileEnabled(new ComponentName(packageName,
999 Settings.PrintSettingsActivity.class.getName()),
1000 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1001
1002 final boolean showDev = mDevelopmentPreferences.getBoolean(
1003 DevelopmentSettings.PREF_SHOW,
1004 android.os.Build.TYPE.equals("eng"));
1005 setTileEnabled(new ComponentName(packageName,
1006 Settings.DevelopmentSettingsActivity.class.getName()),
1007 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1008 isAdmin, pm);
1009
1010 if (UserHandle.MU_ENABLED && !isAdmin) {
1011 // When on restricted users, disable all extra categories (but only the settings ones).
1012 List<DashboardCategory> categories = getDashboardCategories(true);
1013 for (DashboardCategory category : categories) {
1014 for (DashboardTile tile : category.tiles) {
1015 ComponentName component = tile.intent.getComponent();
1016 if (packageName.equals(component)&& !ArrayUtils.contains(
1017 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1018 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001019 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001020 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001021 }
1022 }
Jason Monk4da79e02015-09-10 10:54:36 -04001023
1024 updateDrawer();
Jason Monk2ebc8a02015-02-13 15:23:19 -05001025 }
1026
Jason Monk4da79e02015-09-10 10:54:36 -04001027 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1028 PackageManager pm) {
1029 if (UserHandle.MU_ENABLED && !isAdmin
1030 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1031 enabled = false;
1032 }
1033 int state = pm.getComponentEnabledSetting(component);
1034 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1035 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1036 if (isEnabled != enabled) {
1037 pm.setComponentEnabledSetting(component, enabled
1038 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1039 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1040 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001041 }
1042 }
1043
Jason Monk4da79e02015-09-10 10:54:36 -04001044 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001045 // Once we decide to show Home settings, keep showing it forever
1046 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1047 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1048 return true;
1049 }
1050
1051 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001052 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001053 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001054 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001055 }
1056 } catch (Exception e) {
1057 // Can't look up the home activity; bail on configuring the icon
1058 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1059 }
1060
1061 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1062 return true;
1063 }
1064
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001065 private void getMetaData() {
1066 try {
1067 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1068 PackageManager.GET_META_DATA);
1069 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001070 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1071 } catch (NameNotFoundException nnfe) {
1072 // No recovery
1073 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1074 }
1075 }
1076
1077 // give subclasses access to the Next button
1078 public boolean hasNextButton() {
1079 return mNextButton != null;
1080 }
1081
1082 public Button getNextButton() {
1083 return mNextButton;
1084 }
1085
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001086 @Override
1087 public boolean shouldUpRecreateTask(Intent targetIntent) {
1088 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1089 }
1090
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001091 @Override
1092 public boolean onQueryTextSubmit(String query) {
1093 switchToSearchResultsFragmentIfNeeded();
1094 mSearchQuery = query;
1095 return mSearchResultsFragment.onQueryTextSubmit(query);
1096 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001097
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001098 @Override
1099 public boolean onQueryTextChange(String newText) {
1100 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001101 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001102 return false;
1103 }
1104 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001105 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001106
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001107 @Override
1108 public boolean onClose() {
1109 return false;
1110 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001111
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001112 @Override
1113 public boolean onMenuItemActionExpand(MenuItem item) {
1114 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001115 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001116 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001117 return true;
1118 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001119
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001120 @Override
1121 public boolean onMenuItemActionCollapse(MenuItem item) {
1122 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001123 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001124 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001125 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001126 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001127 return true;
1128 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001129
Jason Monk4da79e02015-09-10 10:54:36 -04001130 @Override
1131 protected void onTileClicked(DashboardTile tile) {
1132 if (mIsShowingDashboard) {
1133 // If on dashboard, don't finish so the back comes back to here.
1134 openTile(tile);
1135 } else {
1136 super.onTileClicked(tile);
1137 }
1138 }
1139
Jason Monkaf001092015-11-04 13:16:18 -05001140 @Override
1141 public void onProfileTileOpen() {
1142 if (!mIsShowingDashboard) {
1143 finish();
1144 }
1145 }
1146
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001147 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001148 if (mSearchResultsFragment != null) {
1149 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001150 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001151 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001152 if (current != null && current instanceof SearchResultsSummary) {
1153 mSearchResultsFragment = (SearchResultsSummary) current;
1154 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001155 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001156 SearchResultsSummary.class.getName(), null, false, true,
1157 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001158 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001159 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001160 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001161 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001162
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001163 public void needToRevertToInitialFragment() {
1164 mNeedToRevertToInitialFragment = true;
1165 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001166
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001167 private void revertToInitialFragment() {
1168 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001169 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001170 mSearchMenuItemExpanded = false;
1171 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1172 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001173 if (mSearchMenuItem != null) {
1174 mSearchMenuItem.collapseActionView();
1175 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001176 }
Jim Miller0698a212014-10-16 19:49:07 -07001177
1178 public Intent getResultIntentData() {
1179 return mResultIntentData;
1180 }
1181
1182 public void setResultIntentData(Intent resultIntentData) {
1183 mResultIntentData = resultIntentData;
1184 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001185}