blob: 94379b35992ee8bab04dece949967129c2a246c8 [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;
Jason Monkfd2c7222015-12-02 15:38:38 -050035import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080036import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080037import android.os.UserHandle;
38import android.os.UserManager;
Jason Monk39b46742015-09-10 15:52:51 -040039import android.support.v14.preference.PreferenceFragment;
40import android.support.v7.preference.Preference;
41import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080042import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070043import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080044import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070045import android.view.Menu;
46import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080047import android.view.MenuItem;
48import android.view.View;
49import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070050import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080051import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070052import android.widget.SearchView;
Chris Wren8a963ba2015-03-20 10:29:14 -040053import com.android.internal.logging.MetricsLogger;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080054import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040055import com.android.settings.Settings.WifiSettingsActivity;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080056import com.android.settings.accessibility.AccessibilitySettings;
57import com.android.settings.accessibility.CaptionPropertiesFragment;
Alexandra Gherghina6d839872014-07-22 12:04:58 +000058import com.android.settings.accounts.AccountSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080059import com.android.settings.accounts.AccountSyncSettings;
Billy Laufee78562015-07-27 12:57:07 +010060import com.android.settings.applications.DrawOverlayDetails;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070061import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080062import com.android.settings.applications.ManageApplications;
Xiyuan Xia86a55402015-06-02 14:55:32 -070063import com.android.settings.applications.ManageAssist;
Jason Monk2cdafc62015-06-12 12:32:50 -040064import com.android.settings.applications.ProcessStatsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080065import com.android.settings.applications.ProcessStatsUi;
Jason Monkd8da51c2015-04-17 14:34:12 -040066import com.android.settings.applications.UsageAccessDetails;
Billy Laufee78562015-07-27 12:57:07 +010067import com.android.settings.applications.WriteSettingsDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080068import com.android.settings.bluetooth.BluetoothSettings;
69import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070070import com.android.settings.dashboard.SearchResultsSummary;
Jeff Sharkeya16257d2015-04-28 13:41:01 -070071import com.android.settings.deviceinfo.PrivateVolumeForget;
Jeff Sharkeye77f0682015-04-29 11:24:57 -070072import com.android.settings.deviceinfo.PrivateVolumeSettings;
Jeff Sharkey42833b22015-04-11 21:27:33 -070073import com.android.settings.deviceinfo.PublicVolumeSettings;
74import com.android.settings.deviceinfo.StorageSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040075import com.android.settings.fuelgauge.BatterySaverSettings;
Jason Monk1eb54eb2015-04-29 12:46:42 -040076import com.android.settings.fuelgauge.PowerUsageDetail;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080077import com.android.settings.fuelgauge.PowerUsageSummary;
78import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
79import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
80import com.android.settings.inputmethod.SpellCheckersSettings;
81import com.android.settings.inputmethod.UserDictionaryList;
82import com.android.settings.location.LocationSettings;
83import com.android.settings.nfc.AndroidBeam;
84import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -040085import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050086import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -040087import com.android.settings.notification.NotificationAccessSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050088import com.android.settings.notification.SoundSettings;
John Spurlock4a350512014-04-08 14:08:21 -040089import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -050090import com.android.settings.notification.OtherSoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -040091import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -040092import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -040093import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -040094import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -040095import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -040096import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -050097import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080098import com.android.settings.print.PrintJobSettingsFragment;
99import com.android.settings.print.PrintSettingsFragment;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500100import com.android.settings.search.DynamicIndexableContentMonitor;
101import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700102import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800103import com.android.settings.tts.TextToSpeechSettings;
104import com.android.settings.users.UserSettings;
105import com.android.settings.vpn2.VpnSettings;
106import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700107import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800108import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700109import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800110import com.android.settings.wifi.WifiSettings;
111import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400112import com.android.settingslib.drawer.DashboardCategory;
113import com.android.settingslib.drawer.DashboardTile;
114import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500115
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800116import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800117import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700118import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800119
Jason Monk4da79e02015-09-10 10:54:36 -0400120public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800121 implements PreferenceManager.OnPreferenceTreeClickListener,
122 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100123 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700124 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100125 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800126
127 private static final String LOG_TAG = "Settings";
128
129 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700130 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700131 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
132 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700133 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700134 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700135 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800136
137 /**
138 * When starting this activity, the invoking Intent can contain this extra
139 * string to specify which fragment should be initially displayed.
140 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
141 * will call isValidFragment() to confirm that the fragment class name is valid for this
142 * activity.
143 */
144 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
145
146 /**
147 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
148 * this extra can also be specified to supply a Bundle of arguments to pass
149 * to that fragment when it is instantiated during the initial creation
150 * of the activity.
151 */
152 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
153
154 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700155 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
156 */
157 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
158
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800159 public static final String BACK_STACK_PREFS = ":settings:prefs";
160
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800161 // extras that allow any preference activity to be launched as part of a wizard
162
163 // show Back and Next buttons? takes boolean parameter
164 // Back will then return RESULT_CANCELED and Next RESULT_OK
165 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
166
167 // add a Skip button?
168 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
169
170 // specify custom text for the Back or Next buttons, or cause a button to not appear
171 // at all by setting it to null
172 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
173 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
174
175 /**
176 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700177 * 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 -0800178 * that fragment.
179 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700180 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100181 /**
182 * The package name used to resolve the title resource id.
183 */
184 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
185 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700186 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
187 ":settings:show_fragment_title_resid";
188 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
189 ":settings:show_fragment_as_shortcut";
190
191 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
192 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800193
Jason Monk30695812015-11-17 09:01:08 -0500194 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800195 "com.android.settings.FRAGMENT_CLASS";
196
197 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
198
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700199 private static final String EMPTY_QUERY = "";
200
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800201 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800202
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800203 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700204 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800205
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800206 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400207 private String[] SETTINGS_FOR_RESTRICTED = {
208 //wireless_section
209 WifiSettingsActivity.class.getName(),
210 Settings.BluetoothSettingsActivity.class.getName(),
211 Settings.DataUsageSummaryActivity.class.getName(),
212 Settings.SimSettingsActivity.class.getName(),
213 Settings.WirelessSettingsActivity.class.getName(),
214 //device_section
215 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500216 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400217 Settings.DisplaySettingsActivity.class.getName(),
218 Settings.StorageSettingsActivity.class.getName(),
219 Settings.ManageApplicationsActivity.class.getName(),
220 Settings.PowerUsageSummaryActivity.class.getName(),
221 //personal_section
222 Settings.LocationSettingsActivity.class.getName(),
223 Settings.SecuritySettingsActivity.class.getName(),
224 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
225 Settings.UserSettingsActivity.class.getName(),
226 Settings.AccountSettingsActivity.class.getName(),
227 //system_section
228 Settings.DateTimeSettingsActivity.class.getName(),
229 Settings.DeviceInfoSettingsActivity.class.getName(),
230 Settings.AccessibilitySettingsActivity.class.getName(),
231 Settings.PrintSettingsActivity.class.getName(),
232 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800233 };
234
235 private static final String[] ENTRY_FRAGMENTS = {
236 WirelessSettings.class.getName(),
237 WifiSettings.class.getName(),
238 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700239 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800240 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700241 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800242 TetherSettings.class.getName(),
243 WifiP2pSettings.class.getName(),
244 VpnSettings.class.getName(),
245 DateTimeSettings.class.getName(),
246 LocalePicker.class.getName(),
247 InputMethodAndLanguageSettings.class.getName(),
248 SpellCheckersSettings.class.getName(),
249 UserDictionaryList.class.getName(),
250 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700251 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800252 DisplaySettings.class.getName(),
253 DeviceInfoSettings.class.getName(),
254 ManageApplications.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700255 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800256 ProcessStatsUi.class.getName(),
257 NotificationStation.class.getName(),
258 LocationSettings.class.getName(),
259 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400260 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800261 PrivacySettings.class.getName(),
262 DeviceAdminSettings.class.getName(),
263 AccessibilitySettings.class.getName(),
264 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800265 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
266 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700267 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700268 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700269 PrivateVolumeSettings.class.getName(),
270 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800271 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800272 AndroidBeam.class.getName(),
273 WifiDisplaySettings.class.getName(),
274 PowerUsageSummary.class.getName(),
275 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000276 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800277 CryptKeeperSettings.class.getName(),
278 DataUsageSummary.class.getName(),
279 DreamSettings.class.getName(),
280 UserSettings.class.getName(),
281 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400282 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800283 PrintSettingsFragment.class.getName(),
284 PrintJobSettingsFragment.class.getName(),
285 TrustedCredentialsSettings.class.getName(),
286 PaymentSettings.class.getName(),
287 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700288 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500289 SoundSettings.class.getName(),
290 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700291 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
292 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400293 InstalledAppDetails.class.getName(),
294 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700295 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700296 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000297 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400298 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400299 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400300 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400301 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400302 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500303 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400304 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400305 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400306 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100307 DrawOverlayDetails.class.getName(),
308 WriteSettingsDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800309 };
310
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700311
312 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
313 "android.settings.APPLICATION_DETAILS_SETTINGS"
314 };
315
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800316 private SharedPreferences mDevelopmentPreferences;
317 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
318
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800319 private boolean mBatteryPresent = true;
320 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800321 @Override
322 public void onReceive(Context context, Intent intent) {
323 String action = intent.getAction();
324 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
325 boolean batteryPresent = Utils.isBatteryPresent(intent);
326
327 if (mBatteryPresent != batteryPresent) {
328 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400329 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800330 }
331 }
332 }
333 };
334
Svetoslav990159a2014-04-14 17:14:59 -0700335 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
336 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700337
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700338 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700339 private SwitchBar mSwitchBar;
340
341 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700342
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700343 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700344 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700345
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700346 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700347 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700348
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700349 private ViewGroup mContent;
350
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700351 private SearchView mSearchView;
352 private MenuItem mSearchMenuItem;
353 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700354 private SearchResultsSummary mSearchResultsFragment;
355 private String mSearchQuery;
356
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700357 // Categories
358 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800359
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700360 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800361
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700362 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700363 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700364
Jim Miller0698a212014-10-16 19:49:07 -0700365 private Intent mResultIntentData;
366
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700367 public SwitchBar getSwitchBar() {
368 return mSwitchBar;
369 }
370
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800371 @Override
372 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
373 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400374 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800375 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400376 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800377 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500378 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800379 null, 0);
380 return true;
381 }
382
383 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400384 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800385 return false;
386 }
387
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800388 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800389 public void onConfigurationChanged(Configuration newConfig) {
390 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800391 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800392 }
393
394 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700395 protected void onStart() {
396 super.onStart();
397
398 if (mNeedToRevertToInitialFragment) {
399 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800400 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800401 }
402
403 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700404 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700405 if (!mDisplaySearch) {
406 return false;
407 }
408
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700409 MenuInflater inflater = getMenuInflater();
410 inflater.inflate(R.menu.options_menu, menu);
411
412 // Cache the search query (can be overriden by the OnQueryTextListener)
413 final String query = mSearchQuery;
414
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700415 mSearchMenuItem = menu.findItem(R.id.search);
416 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700417
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700418 if (mSearchMenuItem == null || mSearchView == null) {
419 return false;
420 }
421
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700422 if (mSearchResultsFragment != null) {
423 mSearchResultsFragment.setSearchView(mSearchView);
424 }
425
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700426 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700427 mSearchView.setOnQueryTextListener(this);
428 mSearchView.setOnCloseListener(this);
429
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700430 if (mSearchMenuItemExpanded) {
431 mSearchMenuItem.expandActionView();
432 }
433 mSearchView.setQuery(query, true /* submit */);
434
435 return true;
436 }
437
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700438 private static boolean isShortCutIntent(final Intent intent) {
439 Set<String> categories = intent.getCategories();
440 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
441 }
442
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700443 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700444 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700445 if (action == null) {
446 return false;
447 }
448 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
449 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
450 }
451 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700452 }
453
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700454 @Override
455 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700456 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500457 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700458
459 // Should happen before any call to getIntent()
460 getMetaData();
461
462 final Intent intent = getIntent();
463 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
464 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800465 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800466
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800467 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
468 Context.MODE_PRIVATE);
469
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700470 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700471 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700472
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700473 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700474 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
475
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700476 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700477 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700478
Jason Monk4da79e02015-09-10 10:54:36 -0400479 mIsShowingDashboard = className.equals(Settings.class.getName())
480 || className.equals(Settings.WirelessSettings.class.getName())
481 || className.equals(Settings.DeviceSettings.class.getName())
482 || className.equals(Settings.PersonalSettings.class.getName())
483 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700484
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700485 // This is a "Sub Settings" when:
486 // - this is a real SubSettings
487 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700488 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700489 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
490
491 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
492 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700493 // Check also that we are not a Theme Dialog as we don't want to override them
494 final int themeResId = getThemeResId();
495 if (themeResId != R.style.Theme_DialogWhenLarge &&
496 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
497 setTheme(R.style.Theme_SubSettings);
498 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700499 }
500
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700501 setContentView(mIsShowingDashboard ?
502 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800503
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700504 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700505
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800506 getFragmentManager().addOnBackStackChangedListener(this);
507
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700508 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800509 // Run the Index update only if we have some space
510 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500511 long indexStartTime = System.currentTimeMillis();
512 AsyncTask.execute(new Runnable() {
513 @Override
514 public void run() {
515 Index.getInstance(getApplicationContext()).update();
516 }
517 });
518 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
519 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800520 } else {
521 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
522 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700523 }
524
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700525 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700526 // We are restarting from a previous saved state; used that to initialize, instead
527 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700528 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
529 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800530
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700531 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800532
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700533 ArrayList<DashboardCategory> categories =
534 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
535 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700536 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700537 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700538 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800539 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700540
541 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700542 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700543 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
544 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800545 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700546 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400547 mDisplaySearch = false;
548 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700549 if (mIsShortcut) {
550 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700551 } else if (isSubSettings) {
552 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700553 } else {
554 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700555 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700556 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700557
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700558 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700559 switchToFragment(initialFragmentName, initialArguments, true, false,
560 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000561 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700562 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700563 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700564 // Show Search affordance
565 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700566 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700567 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700568 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800569 }
570 }
571
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700572 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700573 if (mActionBar != null) {
574 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
575 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
576 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700577 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
578
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800579 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800580 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
581
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700582 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800583 if (buttonBar != null) {
584 buttonBar.setVisibility(View.VISIBLE);
585
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700586 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800587 backButton.setOnClickListener(new OnClickListener() {
588 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700589 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800590 finish();
591 }
592 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700593 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800594 skipButton.setOnClickListener(new OnClickListener() {
595 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700596 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800597 finish();
598 }
599 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700600 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800601 mNextButton.setOnClickListener(new OnClickListener() {
602 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700603 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800604 finish();
605 }
606 });
607
608 // set our various button parameters
609 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
610 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
611 if (TextUtils.isEmpty(buttonText)) {
612 mNextButton.setVisibility(View.GONE);
613 }
614 else {
615 mNextButton.setText(buttonText);
616 }
617 }
618 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
619 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
620 if (TextUtils.isEmpty(buttonText)) {
621 backButton.setVisibility(View.GONE);
622 }
623 else {
624 backButton.setText(buttonText);
625 }
626 }
627 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
628 skipButton.setVisibility(View.VISIBLE);
629 }
630 }
631 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700632
633 mHomeActivitiesCount = getHomeActivitiesCount();
Jason Monkfd2c7222015-12-02 15:38:38 -0500634 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
635 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700636 }
637
638 private int getHomeActivitiesCount() {
639 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
640 getPackageManager().getHomeActivities(homeApps);
641 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800642 }
643
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700644 private void setTitleFromIntent(Intent intent) {
645 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
646 if (initialTitleResId > 0) {
647 mInitialTitle = null;
648 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100649
650 final String initialTitleResPackageName = intent.getStringExtra(
651 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
652 if (initialTitleResPackageName != null) {
653 try {
654 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
655 0 /* flags */, new UserHandle(UserHandle.myUserId()));
656 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
657 setTitle(mInitialTitle);
658 mInitialTitleResId = -1;
659 return;
660 } catch (NameNotFoundException e) {
661 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
662 }
663 } else {
664 setTitle(mInitialTitleResId);
665 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700666 } else {
667 mInitialTitleResId = -1;
668 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
669 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
670 setTitle(mInitialTitle);
671 }
672 }
673
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800674 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800675 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700676 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800677 }
678
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700679 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800680 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700681
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800682 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700683 if (mInitialTitleResId > 0) {
684 setTitle(mInitialTitleResId);
685 } else {
686 setTitle(mInitialTitle);
687 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700688 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800689 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700690
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800691 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
692 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700693
694 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800695 }
696
697 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
698 final CharSequence title;
699 final int titleRes = bse.getBreadCrumbTitleRes();
700 if (titleRes > 0) {
701 title = getText(titleRes);
702 } else {
703 title = bse.getBreadCrumbTitle();
704 }
705 if (title != null) {
706 setTitle(title);
707 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800708 }
709
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800710 @Override
711 protected void onSaveInstanceState(Bundle outState) {
712 super.onSaveInstanceState(outState);
713
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700714 if (mCategories.size() > 0) {
715 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800716 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700717
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700718 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700719 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700720
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700721 if (mDisplaySearch) {
722 // The option menus are created if the ActionBar is visible and they are also created
723 // asynchronously. If you launch Settings with an Intent action like
724 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
725 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
726 // menu item and search view are null.
727 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
728 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700729
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700730 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
731 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
732 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700733
734 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800735 }
736
737 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400738 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800739 super.onResume();
740
741 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
742 @Override
743 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400744 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800745 }
746 };
747 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
748 mDevelopmentPreferencesListener);
749
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800750 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700751
Svetoslav990159a2014-04-14 17:14:59 -0700752 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700753
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700754 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700755 onQueryTextSubmit(mSearchQuery);
756 }
Jason Monk4da79e02015-09-10 10:54:36 -0400757 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800758 }
759
760 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400761 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800762 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800763 unregisterReceiver(mBatteryInfoReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700764 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800765 }
766
767 @Override
768 public void onDestroy() {
769 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700770
771 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
772 mDevelopmentPreferencesListener);
773 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800774 }
775
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800776 protected boolean isValidFragment(String fragmentName) {
777 // Almost all fragments are wrapped in this,
778 // except for a few that have their own activities.
779 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
780 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
781 }
782 return false;
783 }
784
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800785 @Override
786 public Intent getIntent() {
787 Intent superIntent = super.getIntent();
788 String startingFragment = getStartingFragmentClass(superIntent);
789 // This is called from super.onCreate, isMultiPane() is not yet reliable
790 // Do not use onIsHidingHeaders either, which relies itself on this method
791 if (startingFragment != null) {
792 Intent modIntent = new Intent(superIntent);
793 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
794 Bundle args = superIntent.getExtras();
795 if (args != null) {
796 args = new Bundle(args);
797 } else {
798 args = new Bundle();
799 }
800 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100801 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800802 return modIntent;
803 }
804 return superIntent;
805 }
806
807 /**
808 * Checks if the component name in the intent is different from the Settings class and
809 * returns the class name to load as a fragment.
810 */
811 private String getStartingFragmentClass(Intent intent) {
812 if (mFragmentClass != null) return mFragmentClass;
813
814 String intentClass = intent.getComponent().getClassName();
815 if (intentClass.equals(getClass().getName())) return null;
816
817 if ("com.android.settings.ManageApplications".equals(intentClass)
818 || "com.android.settings.RunningServices".equals(intentClass)
819 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
820 // Old names of manage apps.
821 intentClass = com.android.settings.applications.ManageApplications.class.getName();
822 }
823
824 return intentClass;
825 }
826
827 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000828 * Start a new fragment containing a preference panel. If the preferences
829 * are being displayed in multi-pane mode, the given fragment class will
830 * be instantiated and placed in the appropriate pane. If running in
831 * single-pane mode, a new activity will be launched in which to show the
832 * fragment.
833 *
834 * @param fragmentClass Full name of the class implementing the fragment.
835 * @param args Any desired arguments to supply to the fragment.
836 * @param titleRes Optional resource identifier of the title of this
837 * fragment.
838 * @param titleText Optional text of the title of this fragment.
839 * @param resultTo Optional fragment that result data should be sent to.
840 * If non-null, resultTo.onActivityResult() will be called when this
841 * preference panel is done. The launched panel must use
842 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
843 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700844 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000845 */
846 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700847 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700848 String title = null;
849 if (titleRes < 0) {
850 if (titleText != null) {
851 title = titleText.toString();
852 } else {
853 // There not much we can do in that case
854 title = "";
855 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700856 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700857 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700858 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000859 }
860
861 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100862 * Start a new fragment in a new activity containing a preference panel for a given user. If the
863 * preferences are being displayed in multi-pane mode, the given fragment class will be
864 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
865 * activity will be launched in which to show the fragment.
866 *
867 * @param fragmentClass Full name of the class implementing the fragment.
868 * @param args Any desired arguments to supply to the fragment.
869 * @param titleRes Optional resource identifier of the title of this fragment.
870 * @param titleText Optional text of the title of this fragment.
871 * @param userHandle The user for which the panel has to be started.
872 */
873 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
874 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700875 // This is a workaround.
876 //
877 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
878 // starting the fragment could cause a native stack corruption. See b/17523189. However,
879 // adding that flag and start the preference panel with the same UserHandler will make it
880 // impossible to use back button to return to the previous screen. See b/20042570.
881 //
882 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
883 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
884 // when we're calling it as the same user.
885 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
886 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
887 } else {
888 String title = null;
889 if (titleRes < 0) {
890 if (titleText != null) {
891 title = titleText.toString();
892 } else {
893 // There not much we can do in that case
894 title = "";
895 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100896 }
Lifu Tangd0332852015-04-02 12:05:46 -0700897 Utils.startWithFragmentAsUser(this, fragmentClass, args,
898 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100899 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100900 }
901
902 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800903 * Called by a preference panel fragment to finish itself.
904 *
905 * @param caller The fragment that is asking to be finished.
906 * @param resultCode Optional result code to send back to the original
907 * launching fragment.
908 * @param resultData Optional result data to send back to the original
909 * launching fragment.
910 */
911 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
912 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700913 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800914 }
915
916 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000917 * Start a new fragment.
918 *
919 * @param fragment The fragment to start
920 * @param push If true, the current fragment will be pushed onto the back stack. If false,
921 * the current fragment will be replaced.
922 */
923 public void startPreferenceFragment(Fragment fragment, boolean push) {
924 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700925 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000926 if (push) {
927 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
928 transaction.addToBackStack(BACK_STACK_PREFS);
929 } else {
930 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
931 }
932 transaction.commitAllowingStateLoss();
933 }
934
935 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700936 * Switch to a specific Fragment with taking care of validation, Title and BackStack
937 */
938 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700939 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700940 if (validate && !isValidFragment(fragmentName)) {
941 throw new IllegalArgumentException("Invalid fragment for this activity: "
942 + fragmentName);
943 }
944 Fragment f = Fragment.instantiate(this, fragmentName, args);
945 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700946 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700947 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700948 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700949 }
950 if (addToBackStack) {
951 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
952 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700953 if (titleResId > 0) {
954 transaction.setBreadCrumbTitle(titleResId);
955 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700956 transaction.setBreadCrumbTitle(title);
957 }
958 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700959 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700960 return f;
961 }
962
Jason Monk4da79e02015-09-10 10:54:36 -0400963 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500964 // Generally the items that are will be changing from these updates will
965 // not be in the top list of tiles, so run it in the background and the
966 // SettingsDrawerActivity will pick up on the updates automatically.
967 AsyncTask.execute(new Runnable() {
968 @Override
969 public void run() {
970 doUpdateTilesList();
971 }
972 });
973 }
974
975 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400976 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700977 final UserManager um = UserManager.get(this);
978 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700979
Jason Monk4da79e02015-09-10 10:54:36 -0400980 String packageName = getPackageName();
981 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
982 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700983
Jason Monk4da79e02015-09-10 10:54:36 -0400984 setTileEnabled(new ComponentName(packageName,
985 Settings.BluetoothSettingsActivity.class.getName()),
986 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700987
Jason Monk4da79e02015-09-10 10:54:36 -0400988 setTileEnabled(new ComponentName(packageName,
989 Settings.DataUsageSummaryActivity.class.getName()),
990 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700991
Jason Monk4da79e02015-09-10 10:54:36 -0400992 setTileEnabled(new ComponentName(packageName,
993 Settings.SimSettingsActivity.class.getName()),
994 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700995
Jason Monk4da79e02015-09-10 10:54:36 -0400996 setTileEnabled(new ComponentName(packageName,
997 Settings.PowerUsageSummaryActivity.class.getName()),
998 mBatteryPresent, isAdmin, pm);
999
1000 setTileEnabled(new ComponentName(packageName,
1001 Settings.HomeSettingsActivity.class.getName()),
1002 updateHomeSettingTiles(), isAdmin, pm);
1003
1004 setTileEnabled(new ComponentName(packageName,
1005 Settings.UserSettingsActivity.class.getName()),
1006 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1007 && !Utils.isMonkeyRunning(), isAdmin, pm);
1008
1009 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1010 setTileEnabled(new ComponentName(packageName,
1011 Settings.PaymentSettingsActivity.class.getName()),
1012 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1013 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1014 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1015
1016 setTileEnabled(new ComponentName(packageName,
1017 Settings.PrintSettingsActivity.class.getName()),
1018 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1019
1020 final boolean showDev = mDevelopmentPreferences.getBoolean(
1021 DevelopmentSettings.PREF_SHOW,
1022 android.os.Build.TYPE.equals("eng"));
1023 setTileEnabled(new ComponentName(packageName,
1024 Settings.DevelopmentSettingsActivity.class.getName()),
1025 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1026 isAdmin, pm);
1027
1028 if (UserHandle.MU_ENABLED && !isAdmin) {
1029 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001030 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001031 for (DashboardCategory category : categories) {
1032 for (DashboardTile tile : category.tiles) {
1033 ComponentName component = tile.intent.getComponent();
1034 if (packageName.equals(component)&& !ArrayUtils.contains(
1035 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1036 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001037 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001038 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001039 }
1040 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001041 }
1042
Jason Monk4da79e02015-09-10 10:54:36 -04001043 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1044 PackageManager pm) {
1045 if (UserHandle.MU_ENABLED && !isAdmin
1046 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1047 enabled = false;
1048 }
1049 int state = pm.getComponentEnabledSetting(component);
1050 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1051 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1052 if (isEnabled != enabled) {
1053 pm.setComponentEnabledSetting(component, enabled
1054 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1055 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1056 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001057 }
1058 }
1059
Jason Monk4da79e02015-09-10 10:54:36 -04001060 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001061 // Once we decide to show Home settings, keep showing it forever
1062 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1063 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1064 return true;
1065 }
1066
1067 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001068 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001069 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001070 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001071 }
1072 } catch (Exception e) {
1073 // Can't look up the home activity; bail on configuring the icon
1074 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1075 }
1076
1077 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1078 return true;
1079 }
1080
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001081 private void getMetaData() {
1082 try {
1083 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1084 PackageManager.GET_META_DATA);
1085 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001086 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1087 } catch (NameNotFoundException nnfe) {
1088 // No recovery
1089 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1090 }
1091 }
1092
1093 // give subclasses access to the Next button
1094 public boolean hasNextButton() {
1095 return mNextButton != null;
1096 }
1097
1098 public Button getNextButton() {
1099 return mNextButton;
1100 }
1101
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001102 @Override
1103 public boolean shouldUpRecreateTask(Intent targetIntent) {
1104 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1105 }
1106
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001107 @Override
1108 public boolean onQueryTextSubmit(String query) {
1109 switchToSearchResultsFragmentIfNeeded();
1110 mSearchQuery = query;
1111 return mSearchResultsFragment.onQueryTextSubmit(query);
1112 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001113
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001114 @Override
1115 public boolean onQueryTextChange(String newText) {
1116 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001117 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001118 return false;
1119 }
1120 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001121 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001122
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001123 @Override
1124 public boolean onClose() {
1125 return false;
1126 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001127
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001128 @Override
1129 public boolean onMenuItemActionExpand(MenuItem item) {
1130 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001131 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001132 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001133 return true;
1134 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001135
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001136 @Override
1137 public boolean onMenuItemActionCollapse(MenuItem item) {
1138 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001139 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001140 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001141 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001142 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001143 return true;
1144 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001145
Jason Monk4da79e02015-09-10 10:54:36 -04001146 @Override
1147 protected void onTileClicked(DashboardTile tile) {
1148 if (mIsShowingDashboard) {
1149 // If on dashboard, don't finish so the back comes back to here.
1150 openTile(tile);
1151 } else {
1152 super.onTileClicked(tile);
1153 }
1154 }
1155
Jason Monkaf001092015-11-04 13:16:18 -05001156 @Override
1157 public void onProfileTileOpen() {
1158 if (!mIsShowingDashboard) {
1159 finish();
1160 }
1161 }
1162
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001163 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001164 if (mSearchResultsFragment != null) {
1165 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001166 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001167 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001168 if (current != null && current instanceof SearchResultsSummary) {
1169 mSearchResultsFragment = (SearchResultsSummary) current;
1170 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001171 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001172 SearchResultsSummary.class.getName(), null, false, true,
1173 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001174 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001175 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001176 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001177 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001178
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001179 public void needToRevertToInitialFragment() {
1180 mNeedToRevertToInitialFragment = true;
1181 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001182
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001183 private void revertToInitialFragment() {
1184 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001185 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001186 mSearchMenuItemExpanded = false;
1187 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1188 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001189 if (mSearchMenuItem != null) {
1190 mSearchMenuItem.collapseActionView();
1191 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001192 }
Jim Miller0698a212014-10-16 19:49:07 -07001193
1194 public Intent getResultIntentData() {
1195 return mResultIntentData;
1196 }
1197
1198 public void setResultIntentData(Intent resultIntentData) {
1199 mResultIntentData = resultIntentData;
1200 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001201}