blob: bb13fc37633982a70d8e677391bc005e8633bd65 [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;
20import android.app.Activity;
21import android.app.Fragment;
22import android.app.FragmentManager;
23import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080024import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070025import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080026import android.content.Context;
27import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.SharedPreferences;
30import android.content.pm.ActivityInfo;
31import android.content.pm.PackageManager;
32import android.content.pm.PackageManager.NameNotFoundException;
33import android.content.pm.ResolveInfo;
34import android.content.res.Configuration;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080035import android.content.res.TypedArray;
36import android.content.res.XmlResourceParser;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080037import android.nfc.NfcAdapter;
38import android.os.Bundle;
39import android.os.Handler;
40import android.os.INetworkManagementService;
41import android.os.Message;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080042import android.os.RemoteException;
43import android.os.ServiceManager;
44import android.os.UserHandle;
45import android.os.UserManager;
46import android.preference.Preference;
47import android.preference.PreferenceFragment;
48import android.preference.PreferenceManager;
49import android.preference.PreferenceScreen;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080050import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070051import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080052import android.util.AttributeSet;
53import android.util.Log;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080054import android.util.TypedValue;
55import android.util.Xml;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070056import android.view.Menu;
57import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080058import android.view.MenuItem;
59import android.view.View;
60import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070061import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080062import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070063import android.widget.SearchView;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040064
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080065import com.android.internal.util.ArrayUtils;
66import com.android.internal.util.XmlUtils;
67import com.android.settings.accessibility.AccessibilitySettings;
68import com.android.settings.accessibility.CaptionPropertiesFragment;
69import com.android.settings.accounts.AccountSyncSettings;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070070import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080071import com.android.settings.applications.ManageApplications;
72import com.android.settings.applications.ProcessStatsUi;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080073import com.android.settings.bluetooth.BluetoothSettings;
PauloftheWestc9dc66d2014-07-01 05:19:58 -070074import com.android.settings.bluetooth.MessageAccessSettings;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -070075import com.android.settings.dashboard.DashboardCategory;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080076import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -070077import com.android.settings.dashboard.DashboardTile;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070078import com.android.settings.dashboard.NoHomeDialogFragment;
79import com.android.settings.dashboard.SearchResultsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080080import com.android.settings.deviceinfo.Memory;
81import com.android.settings.deviceinfo.UsbSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040082import com.android.settings.fuelgauge.BatterySaverSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080083import com.android.settings.fuelgauge.PowerUsageSummary;
Fabrice Di Meglio7a6bfd12014-04-14 19:49:18 -070084import com.android.settings.search.DynamicIndexableContentMonitor;
Fabrice Di Megliofa7dc242014-03-12 19:24:43 -070085import com.android.settings.search.Index;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080086import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
87import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
88import com.android.settings.inputmethod.SpellCheckersSettings;
89import com.android.settings.inputmethod.UserDictionaryList;
90import com.android.settings.location.LocationSettings;
91import com.android.settings.nfc.AndroidBeam;
92import com.android.settings.nfc.PaymentSettings;
John Spurlockc9afadb2014-04-29 18:07:23 -040093import com.android.settings.notification.ConditionProviderSettings;
John Spurlock4a350512014-04-08 14:08:21 -040094import com.android.settings.notification.NotificationAccessSettings;
95import com.android.settings.notification.NotificationSettings;
96import com.android.settings.notification.NotificationStation;
97import com.android.settings.notification.ZenModeSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080098import com.android.settings.print.PrintJobSettingsFragment;
99import com.android.settings.print.PrintSettingsFragment;
100import com.android.settings.tts.TextToSpeechSettings;
101import com.android.settings.users.UserSettings;
102import com.android.settings.vpn2.VpnSettings;
103import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700104import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800105import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700106import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800107import com.android.settings.wifi.WifiSettings;
108import com.android.settings.wifi.p2p.WifiP2pSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400109
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800110import org.xmlpull.v1.XmlPullParser;
111import org.xmlpull.v1.XmlPullParserException;
112
113import java.io.IOException;
114import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800115import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700116import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800117
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -0700118import static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700119
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800120public class SettingsActivity extends Activity
121 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 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";
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700180 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = ":settings:show_fragment_title_resid";
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700181 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT = ":settings:show_fragment_as_shortcut";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800182
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800183 private static final String META_DATA_KEY_FRAGMENT_CLASS =
184 "com.android.settings.FRAGMENT_CLASS";
185
186 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
187
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700188 private static final String EMPTY_QUERY = "";
189
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800190 private static boolean sShowNoHomeNotice = false;
191
192 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800193
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800194 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700195 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800196
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800197 // Show only these settings for restricted users
198 private int[] SETTINGS_FOR_RESTRICTED = {
199 R.id.wireless_section,
200 R.id.wifi_settings,
201 R.id.bluetooth_settings,
202 R.id.data_usage_settings,
203 R.id.wireless_settings,
204 R.id.device_section,
John Spurlock4e4cdef2014-05-28 09:43:45 -0400205 R.id.notification_settings,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800206 R.id.display_settings,
207 R.id.storage_settings,
208 R.id.application_settings,
209 R.id.battery_settings,
210 R.id.personal_section,
211 R.id.location_settings,
212 R.id.security_settings,
213 R.id.language_settings,
214 R.id.user_settings,
215 R.id.account_settings,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800216 R.id.system_section,
217 R.id.date_time_settings,
218 R.id.about_settings,
219 R.id.accessibility_settings,
220 R.id.print_settings,
221 R.id.nfc_payment_settings,
Fabrice Di Meglio2858b792014-02-18 19:35:08 -0800222 R.id.home_settings,
223 R.id.dashboard
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800224 };
225
226 private static final String[] ENTRY_FRAGMENTS = {
227 WirelessSettings.class.getName(),
228 WifiSettings.class.getName(),
229 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700230 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800231 BluetoothSettings.class.getName(),
PauloftheWestc9dc66d2014-07-01 05:19:58 -0700232 MessageAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800233 TetherSettings.class.getName(),
234 WifiP2pSettings.class.getName(),
235 VpnSettings.class.getName(),
236 DateTimeSettings.class.getName(),
237 LocalePicker.class.getName(),
238 InputMethodAndLanguageSettings.class.getName(),
239 SpellCheckersSettings.class.getName(),
240 UserDictionaryList.class.getName(),
241 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700242 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800243 DisplaySettings.class.getName(),
244 DeviceInfoSettings.class.getName(),
245 ManageApplications.class.getName(),
246 ProcessStatsUi.class.getName(),
247 NotificationStation.class.getName(),
248 LocationSettings.class.getName(),
249 SecuritySettings.class.getName(),
250 PrivacySettings.class.getName(),
251 DeviceAdminSettings.class.getName(),
252 AccessibilitySettings.class.getName(),
253 CaptionPropertiesFragment.class.getName(),
254 com.android.settings.accessibility.ToggleInversionPreferenceFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800255 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
256 TextToSpeechSettings.class.getName(),
257 Memory.class.getName(),
258 DevelopmentSettings.class.getName(),
259 UsbSettings.class.getName(),
260 AndroidBeam.class.getName(),
261 WifiDisplaySettings.class.getName(),
262 PowerUsageSummary.class.getName(),
263 AccountSyncSettings.class.getName(),
264 CryptKeeperSettings.class.getName(),
265 DataUsageSummary.class.getName(),
266 DreamSettings.class.getName(),
267 UserSettings.class.getName(),
268 NotificationAccessSettings.class.getName(),
John Spurlockc9afadb2014-04-29 18:07:23 -0400269 ConditionProviderSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800270 PrintSettingsFragment.class.getName(),
271 PrintJobSettingsFragment.class.getName(),
272 TrustedCredentialsSettings.class.getName(),
273 PaymentSettings.class.getName(),
274 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700275 ZenModeSettings.class.getName(),
276 NotificationSettings.class.getName(),
277 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
278 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400279 InstalledAppDetails.class.getName(),
280 BatterySaverSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800281 };
282
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700283
284 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
285 "android.settings.APPLICATION_DETAILS_SETTINGS"
286 };
287
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800288 private SharedPreferences mDevelopmentPreferences;
289 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
290
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800291 private boolean mBatteryPresent = true;
292 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
293
294 @Override
295 public void onReceive(Context context, Intent intent) {
296 String action = intent.getAction();
297 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
298 boolean batteryPresent = Utils.isBatteryPresent(intent);
299
300 if (mBatteryPresent != batteryPresent) {
301 mBatteryPresent = batteryPresent;
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700302 invalidateCategories();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800303 }
304 }
305 }
306 };
307
Svetoslav990159a2014-04-14 17:14:59 -0700308 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
309 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700310
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700311 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700312 private SwitchBar mSwitchBar;
313
314 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700315
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700316 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700317 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700318
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700319 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700320 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700321
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700322 private ViewGroup mContent;
323
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700324 private SearchView mSearchView;
325 private MenuItem mSearchMenuItem;
326 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700327 private SearchResultsSummary mSearchResultsFragment;
328 private String mSearchQuery;
329
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700330 // Categories
331 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
332 private boolean mNeedToRebuildCategories;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800333
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700334 private static final int MSG_BUILD_CATEGORIES = 1;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800335 private Handler mHandler = new Handler() {
336 @Override
337 public void handleMessage(Message msg) {
338 switch (msg.what) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700339 case MSG_BUILD_CATEGORIES: {
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700340 if(mNeedToRebuildCategories) {
341 buildDashboardCategories(mCategories);
342 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800343 } break;
344 }
345 }
346 };
347
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700348 private boolean mNeedToRevertToInitialFragment = false;
349
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700350 public SwitchBar getSwitchBar() {
351 return mSwitchBar;
352 }
353
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700354 public List<DashboardCategory> getDashboardCategories() {
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700355 if (mNeedToRebuildCategories || mCategories.size() == 0) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700356 buildDashboardCategories(mCategories);
357 mNeedToRebuildCategories = false;
358 }
359 return mCategories;
360 }
361
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800362 @Override
363 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
364 // Override the fragment title for Wallpaper settings
365 int titleRes = pref.getTitleRes();
366 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
367 titleRes = R.string.wallpaper_settings_fragment_title;
368 } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName())
369 && UserHandle.myUserId() != UserHandle.USER_OWNER) {
370 if (UserManager.get(this).isLinkedUser()) {
371 titleRes = R.string.profile_info_settings_title;
372 } else {
373 titleRes = R.string.user_info_settings_title;
374 }
375 }
376 startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),
377 null, 0);
378 return true;
379 }
380
381 @Override
382 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
383 return false;
384 }
385
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700386 private void invalidateCategories() {
387 if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) {
388 mHandler.sendEmptyMessage(MSG_BUILD_CATEGORIES);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800389 }
390 }
391
392 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800393 public void onConfigurationChanged(Configuration newConfig) {
394 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800395 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800396 }
397
398 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700399 protected void onStart() {
400 super.onStart();
401
402 if (mNeedToRevertToInitialFragment) {
403 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800404 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800405 }
406
407 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700408 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700409 if (!mDisplaySearch) {
410 return false;
411 }
412
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700413 MenuInflater inflater = getMenuInflater();
414 inflater.inflate(R.menu.options_menu, menu);
415
416 // Cache the search query (can be overriden by the OnQueryTextListener)
417 final String query = mSearchQuery;
418
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700419 mSearchMenuItem = menu.findItem(R.id.search);
420 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700421
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700422 if (mSearchMenuItem == null || mSearchView == null) {
423 return false;
424 }
425
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700426 if (mSearchResultsFragment != null) {
427 mSearchResultsFragment.setSearchView(mSearchView);
428 }
429
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700430 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700431 mSearchView.setOnQueryTextListener(this);
432 mSearchView.setOnCloseListener(this);
433
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700434 if (mSearchMenuItemExpanded) {
435 mSearchMenuItem.expandActionView();
436 }
437 mSearchView.setQuery(query, true /* submit */);
438
439 return true;
440 }
441
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700442 private static boolean isShortCutIntent(final Intent intent) {
443 Set<String> categories = intent.getCategories();
444 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
445 }
446
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700447 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700448 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700449 if (action == null) {
450 return false;
451 }
452 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
453 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
454 }
455 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700456 }
457
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700458 @Override
459 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700460 super.onCreate(savedState);
461
462 // Should happen before any call to getIntent()
463 getMetaData();
464
465 final Intent intent = getIntent();
466 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
467 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800468 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800469
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800470 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
471 Context.MODE_PRIVATE);
472
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700473 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700474 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700475
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700476 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700477 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
478
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700479 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700480 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700481
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700482 mIsShowingDashboard = className.equals(Settings.class.getName());
483 final boolean isSubSettings = className.equals(SubSettings.class.getName());
484
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700485 // If this is a sub settings or not the main Dashboard and not a Shortcut and an initial
486 // Fragment then apply the SubSettings theme for the ActionBar content insets
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700487 if (isSubSettings ||
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700488 (!mIsShowingDashboard && !mIsShortcut && (initialFragmentName != null))) {
489 // Check also that we are not a Theme Dialog as we don't want to override them
490 final int themeResId = getThemeResId();
491 if (themeResId != R.style.Theme_DialogWhenLarge &&
492 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
493 setTheme(R.style.Theme_SubSettings);
494 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700495 }
496
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700497 setContentView(mIsShowingDashboard ?
498 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800499
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700500 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700501
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800502 getFragmentManager().addOnBackStackChangedListener(this);
503
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700504 if (mIsShowingDashboard) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700505 Index.getInstance(getApplicationContext()).update();
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700506 }
507
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700508 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700509 // We are restarting from a previous saved state; used that to initialize, instead
510 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700511 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
512 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800513
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700514 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800515
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700516 ArrayList<DashboardCategory> categories =
517 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
518 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700519 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700520 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700521 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800522 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700523
524 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700525 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800526 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700527 if (!mIsShowingDashboard) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700528 // Search is shown we are launched thru a Settings "shortcut". UP will be shown
529 // only if it is a sub settings
530 if (mIsShortcut) {
531 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700532 mDisplaySearch = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700533 } else if (isSubSettings) {
534 mDisplayHomeAsUpEnabled = true;
535 mDisplaySearch = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700536 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700537 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700538
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700539 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700540 switchToFragment(initialFragmentName, initialArguments, true, false,
541 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000542 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700543 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700544 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700545 // Show Search affordance
546 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700547 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700548 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700549 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800550 }
551 }
552
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700553 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700554 if (mActionBar != null) {
555 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
556 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
557 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700558 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
559
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800560 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800561 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
562
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700563 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800564 if (buttonBar != null) {
565 buttonBar.setVisibility(View.VISIBLE);
566
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700567 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800568 backButton.setOnClickListener(new OnClickListener() {
569 public void onClick(View v) {
570 setResult(RESULT_CANCELED);
571 finish();
572 }
573 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700574 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800575 skipButton.setOnClickListener(new OnClickListener() {
576 public void onClick(View v) {
577 setResult(RESULT_OK);
578 finish();
579 }
580 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700581 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800582 mNextButton.setOnClickListener(new OnClickListener() {
583 public void onClick(View v) {
584 setResult(RESULT_OK);
585 finish();
586 }
587 });
588
589 // set our various button parameters
590 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
591 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
592 if (TextUtils.isEmpty(buttonText)) {
593 mNextButton.setVisibility(View.GONE);
594 }
595 else {
596 mNextButton.setText(buttonText);
597 }
598 }
599 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
600 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
601 if (TextUtils.isEmpty(buttonText)) {
602 backButton.setVisibility(View.GONE);
603 }
604 else {
605 backButton.setText(buttonText);
606 }
607 }
608 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
609 skipButton.setVisibility(View.VISIBLE);
610 }
611 }
612 }
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800613 }
614
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700615 private void setTitleFromIntent(Intent intent) {
616 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
617 if (initialTitleResId > 0) {
618 mInitialTitle = null;
619 mInitialTitleResId = initialTitleResId;
620 setTitle(mInitialTitleResId);
621 } else {
622 mInitialTitleResId = -1;
623 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
624 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
625 setTitle(mInitialTitle);
626 }
627 }
628
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800629 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800630 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700631 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800632 }
633
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700634 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800635 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700636
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800637 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700638 if (mInitialTitleResId > 0) {
639 setTitle(mInitialTitleResId);
640 } else {
641 setTitle(mInitialTitle);
642 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700643 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800644 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700645
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800646 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
647 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700648
649 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800650 }
651
652 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
653 final CharSequence title;
654 final int titleRes = bse.getBreadCrumbTitleRes();
655 if (titleRes > 0) {
656 title = getText(titleRes);
657 } else {
658 title = bse.getBreadCrumbTitle();
659 }
660 if (title != null) {
661 setTitle(title);
662 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800663 }
664
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800665 @Override
666 protected void onSaveInstanceState(Bundle outState) {
667 super.onSaveInstanceState(outState);
668
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700669 if (mCategories.size() > 0) {
670 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800671 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700672
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700673 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700674 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700675
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700676 if (mDisplaySearch) {
677 // The option menus are created if the ActionBar is visible and they are also created
678 // asynchronously. If you launch Settings with an Intent action like
679 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
680 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
681 // menu item and search view are null.
682 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
683 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700684
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700685 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
686 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
687 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800688 }
689
690 @Override
691 public void onResume() {
692 super.onResume();
693
694 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
695 @Override
696 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Fabrice Di Megliobb051782014-06-04 17:33:25 -0700697 setNeedToRebuildCategories(true);
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700698 invalidateCategories();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800699 }
700 };
701 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
702 mDevelopmentPreferencesListener);
703
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800704 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700705
Svetoslav990159a2014-04-14 17:14:59 -0700706 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700707
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700708 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700709 onQueryTextSubmit(mSearchQuery);
710 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800711 }
712
713 @Override
714 public void onPause() {
715 super.onPause();
716
717 unregisterReceiver(mBatteryInfoReceiver);
718
Svetoslav990159a2014-04-14 17:14:59 -0700719 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800720 }
721
722 @Override
723 public void onDestroy() {
724 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700725
726 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
727 mDevelopmentPreferencesListener);
728 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800729 }
730
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800731 protected boolean isValidFragment(String fragmentName) {
732 // Almost all fragments are wrapped in this,
733 // except for a few that have their own activities.
734 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
735 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
736 }
737 return false;
738 }
739
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800740 @Override
741 public Intent getIntent() {
742 Intent superIntent = super.getIntent();
743 String startingFragment = getStartingFragmentClass(superIntent);
744 // This is called from super.onCreate, isMultiPane() is not yet reliable
745 // Do not use onIsHidingHeaders either, which relies itself on this method
746 if (startingFragment != null) {
747 Intent modIntent = new Intent(superIntent);
748 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
749 Bundle args = superIntent.getExtras();
750 if (args != null) {
751 args = new Bundle(args);
752 } else {
753 args = new Bundle();
754 }
755 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100756 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800757 return modIntent;
758 }
759 return superIntent;
760 }
761
762 /**
763 * Checks if the component name in the intent is different from the Settings class and
764 * returns the class name to load as a fragment.
765 */
766 private String getStartingFragmentClass(Intent intent) {
767 if (mFragmentClass != null) return mFragmentClass;
768
769 String intentClass = intent.getComponent().getClassName();
770 if (intentClass.equals(getClass().getName())) return null;
771
772 if ("com.android.settings.ManageApplications".equals(intentClass)
773 || "com.android.settings.RunningServices".equals(intentClass)
774 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
775 // Old names of manage apps.
776 intentClass = com.android.settings.applications.ManageApplications.class.getName();
777 }
778
779 return intentClass;
780 }
781
782 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000783 * Start a new fragment containing a preference panel. If the preferences
784 * are being displayed in multi-pane mode, the given fragment class will
785 * be instantiated and placed in the appropriate pane. If running in
786 * single-pane mode, a new activity will be launched in which to show the
787 * fragment.
788 *
789 * @param fragmentClass Full name of the class implementing the fragment.
790 * @param args Any desired arguments to supply to the fragment.
791 * @param titleRes Optional resource identifier of the title of this
792 * fragment.
793 * @param titleText Optional text of the title of this fragment.
794 * @param resultTo Optional fragment that result data should be sent to.
795 * If non-null, resultTo.onActivityResult() will be called when this
796 * preference panel is done. The launched panel must use
797 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
798 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700799 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000800 */
801 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700802 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700803 String title = null;
804 if (titleRes < 0) {
805 if (titleText != null) {
806 title = titleText.toString();
807 } else {
808 // There not much we can do in that case
809 title = "";
810 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700811 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700812 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700813 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000814 }
815
816 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800817 * Called by a preference panel fragment to finish itself.
818 *
819 * @param caller The fragment that is asking to be finished.
820 * @param resultCode Optional result code to send back to the original
821 * launching fragment.
822 * @param resultData Optional result data to send back to the original
823 * launching fragment.
824 */
825 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
826 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700827 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800828 }
829
830 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000831 * Start a new fragment.
832 *
833 * @param fragment The fragment to start
834 * @param push If true, the current fragment will be pushed onto the back stack. If false,
835 * the current fragment will be replaced.
836 */
837 public void startPreferenceFragment(Fragment fragment, boolean push) {
838 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700839 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000840 if (push) {
841 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
842 transaction.addToBackStack(BACK_STACK_PREFS);
843 } else {
844 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
845 }
846 transaction.commitAllowingStateLoss();
847 }
848
849 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700850 * Switch to a specific Fragment with taking care of validation, Title and BackStack
851 */
852 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700853 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700854 if (validate && !isValidFragment(fragmentName)) {
855 throw new IllegalArgumentException("Invalid fragment for this activity: "
856 + fragmentName);
857 }
858 Fragment f = Fragment.instantiate(this, fragmentName, args);
859 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700860 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700861 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700862 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700863 }
864 if (addToBackStack) {
865 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
866 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700867 if (titleResId > 0) {
868 transaction.setBreadCrumbTitle(titleResId);
869 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700870 transaction.setBreadCrumbTitle(title);
871 }
872 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700873 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700874 return f;
875 }
876
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700877 public void setNeedToRebuildCategories(boolean need) {
878 mNeedToRebuildCategories = need;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700879 }
880
881 /**
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700882 * Called when the activity needs its list of categories/tiles built.
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700883 *
884 * @param categories The list in which to place the tiles categories.
885 */
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700886 private void buildDashboardCategories(List<DashboardCategory> categories) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700887 categories.clear();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700888 loadCategoriesFromResource(R.xml.dashboard_categories, categories);
889 updateTilesList(categories);
890 }
891
892 /**
893 * Parse the given XML file as a categories description, adding each
894 * parsed categories and tiles into the target list.
895 *
896 * @param resid The XML resource to load and parse.
897 * @param target The list in which the parsed categories and tiles should be placed.
898 */
899 private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) {
900 XmlResourceParser parser = null;
901 try {
902 parser = getResources().getXml(resid);
903 AttributeSet attrs = Xml.asAttributeSet(parser);
904
905 int type;
906 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
907 && type != XmlPullParser.START_TAG) {
908 // Parse next until start tag is found
909 }
910
911 String nodeName = parser.getName();
912 if (!"dashboard-categories".equals(nodeName)) {
913 throw new RuntimeException(
914 "XML document must start with <preference-categories> tag; found"
915 + nodeName + " at " + parser.getPositionDescription());
916 }
917
918 Bundle curBundle = null;
919
920 final int outerDepth = parser.getDepth();
921 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
922 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
923 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
924 continue;
925 }
926
927 nodeName = parser.getName();
928 if ("dashboard-category".equals(nodeName)) {
929 DashboardCategory category = new DashboardCategory();
930
931 TypedArray sa = obtainStyledAttributes(
932 attrs, com.android.internal.R.styleable.PreferenceHeader);
933 category.id = sa.getResourceId(
934 com.android.internal.R.styleable.PreferenceHeader_id,
935 (int)DashboardCategory.CAT_ID_UNDEFINED);
936
937 TypedValue tv = sa.peekValue(
938 com.android.internal.R.styleable.PreferenceHeader_title);
939 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
940 if (tv.resourceId != 0) {
941 category.titleRes = tv.resourceId;
942 } else {
943 category.title = tv.string;
944 }
945 }
946 sa.recycle();
947
948 final int innerDepth = parser.getDepth();
949 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
950 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
951 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
952 continue;
953 }
954
955 String innerNodeName = parser.getName();
956 if (innerNodeName.equals("dashboard-tile")) {
957 DashboardTile tile = new DashboardTile();
958
959 sa = obtainStyledAttributes(
960 attrs, com.android.internal.R.styleable.PreferenceHeader);
961 tile.id = sa.getResourceId(
962 com.android.internal.R.styleable.PreferenceHeader_id,
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -0700963 (int)TILE_ID_UNDEFINED);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700964 tv = sa.peekValue(
965 com.android.internal.R.styleable.PreferenceHeader_title);
966 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
967 if (tv.resourceId != 0) {
968 tile.titleRes = tv.resourceId;
969 } else {
970 tile.title = tv.string;
971 }
972 }
973 tv = sa.peekValue(
974 com.android.internal.R.styleable.PreferenceHeader_summary);
975 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
976 if (tv.resourceId != 0) {
977 tile.summaryRes = tv.resourceId;
978 } else {
979 tile.summary = tv.string;
980 }
981 }
982 tile.iconRes = sa.getResourceId(
983 com.android.internal.R.styleable.PreferenceHeader_icon, 0);
984 tile.fragment = sa.getString(
985 com.android.internal.R.styleable.PreferenceHeader_fragment);
986 sa.recycle();
987
988 if (curBundle == null) {
989 curBundle = new Bundle();
990 }
991
992 final int innerDepth2 = parser.getDepth();
993 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
994 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) {
995 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
996 continue;
997 }
998
999 String innerNodeName2 = parser.getName();
1000 if (innerNodeName2.equals("extra")) {
1001 getResources().parseBundleExtra("extra", attrs, curBundle);
1002 XmlUtils.skipCurrentTag(parser);
1003
1004 } else if (innerNodeName2.equals("intent")) {
1005 tile.intent = Intent.parseIntent(getResources(), parser, attrs);
1006
1007 } else {
1008 XmlUtils.skipCurrentTag(parser);
1009 }
1010 }
1011
1012 if (curBundle.size() > 0) {
1013 tile.fragmentArguments = curBundle;
1014 curBundle = null;
1015 }
1016
1017 category.addTile(tile);
1018
1019 } else {
1020 XmlUtils.skipCurrentTag(parser);
1021 }
1022 }
1023
1024 target.add(category);
1025 } else {
1026 XmlUtils.skipCurrentTag(parser);
1027 }
1028 }
1029
1030 } catch (XmlPullParserException e) {
1031 throw new RuntimeException("Error parsing categories", e);
1032 } catch (IOException e) {
1033 throw new RuntimeException("Error parsing categories", e);
1034 } finally {
1035 if (parser != null) parser.close();
1036 }
1037 }
1038
1039 private void updateTilesList(List<DashboardCategory> target) {
1040 final boolean showDev = mDevelopmentPreferences.getBoolean(
1041 DevelopmentSettings.PREF_SHOW,
1042 android.os.Build.TYPE.equals("eng"));
1043
1044 final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
1045
1046 final int size = target.size();
1047 for (int i = 0; i < size; i++) {
1048
1049 DashboardCategory category = target.get(i);
1050
1051 // Ids are integers, so downcasting is ok
1052 int id = (int) category.id;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001053 int n = category.getTilesCount() - 1;
1054 while (n >= 0) {
1055
1056 DashboardTile tile = category.getTile(n);
1057
1058 id = (int) tile.id;
1059 if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
1060 Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, category, tile);
1061 } else if (id == R.id.wifi_settings) {
1062 // Remove WiFi Settings if WiFi service is not available.
1063 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
1064 category.removeTile(n);
1065 }
1066 } else if (id == R.id.bluetooth_settings) {
1067 // Remove Bluetooth Settings if Bluetooth service is not available.
1068 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
1069 category.removeTile(n);
1070 }
1071 } else if (id == R.id.data_usage_settings) {
1072 // Remove data usage when kernel module not enabled
1073 final INetworkManagementService netManager = INetworkManagementService.Stub
1074 .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
1075 try {
1076 if (!netManager.isBandwidthControlEnabled()) {
1077 category.removeTile(n);
1078 }
1079 } catch (RemoteException e) {
1080 // ignored
1081 }
1082 } else if (id == R.id.battery_settings) {
1083 // Remove battery settings when battery is not available. (e.g. TV)
1084
1085 if (!mBatteryPresent) {
1086 category.removeTile(n);
1087 }
1088 } else if (id == R.id.home_settings) {
1089 if (!updateHomeSettingTiles(tile)) {
1090 category.removeTile(n);
1091 }
1092 } else if (id == R.id.user_settings) {
Amith Yamasani4093e402014-06-06 14:31:37 -07001093 boolean hasMultipleUsers =
1094 ((UserManager) getSystemService(Context.USER_SERVICE))
1095 .getUserCount() > 1;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001096 if (!UserHandle.MU_ENABLED
Amith Yamasani4093e402014-06-06 14:31:37 -07001097 || (!UserManager.supportsMultipleUsers()
1098 && !hasMultipleUsers)
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001099 || Utils.isMonkeyRunning()) {
1100 category.removeTile(n);
1101 }
1102 } else if (id == R.id.nfc_payment_settings) {
1103 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
1104 category.removeTile(n);
1105 } else {
1106 // Only show if NFC is on and we have the HCE feature
1107 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1108 if (!adapter.isEnabled() || !getPackageManager().hasSystemFeature(
1109 PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
1110 category.removeTile(n);
1111 }
1112 }
Fabrice Di Meglio488cae32014-05-13 11:26:34 -07001113 } else if (id == R.id.print_settings) {
1114 boolean hasPrintingSupport = getPackageManager().hasSystemFeature(
1115 PackageManager.FEATURE_PRINTING);
1116 if (!hasPrintingSupport) {
1117 category.removeTile(n);
1118 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001119 } else if (id == R.id.development_settings) {
Julia Reynolds6c088cb2014-05-08 09:29:41 -04001120 if (!showDev || um.hasUserRestriction(
1121 UserManager.DISALLOW_DEBUGGING_FEATURES)) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001122 category.removeTile(n);
1123 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001124 }
1125
1126 if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
Amith Yamasania97089d2014-04-30 10:58:09 -07001127 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)
1128 && n < category.getTilesCount()) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001129 category.removeTile(n);
1130 }
1131
1132 n--;
1133 }
1134 }
1135 }
1136
1137 private boolean updateHomeSettingTiles(DashboardTile tile) {
1138 // Once we decide to show Home settings, keep showing it forever
1139 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1140 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1141 return true;
1142 }
1143
1144 try {
1145 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
1146 getPackageManager().getHomeActivities(homeApps);
1147 if (homeApps.size() < 2) {
1148 // When there's only one available home app, omit this settings
1149 // category entirely at the top level UI. If the user just
1150 // uninstalled the penultimate home app candidiate, we also
1151 // now tell them about why they aren't seeing 'Home' in the list.
1152 if (sShowNoHomeNotice) {
1153 sShowNoHomeNotice = false;
1154 NoHomeDialogFragment.show(this);
1155 }
1156 return false;
1157 } else {
1158 // Okay, we're allowing the Home settings category. Tell it, when
1159 // invoked via this front door, that we'll need to be told about the
1160 // case when the user uninstalls all but one home app.
1161 if (tile.fragmentArguments == null) {
1162 tile.fragmentArguments = new Bundle();
1163 }
1164 tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true);
1165 }
1166 } catch (Exception e) {
1167 // Can't look up the home activity; bail on configuring the icon
1168 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1169 }
1170
1171 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1172 return true;
1173 }
1174
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001175 private void getMetaData() {
1176 try {
1177 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1178 PackageManager.GET_META_DATA);
1179 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001180 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1181 } catch (NameNotFoundException nnfe) {
1182 // No recovery
1183 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1184 }
1185 }
1186
1187 // give subclasses access to the Next button
1188 public boolean hasNextButton() {
1189 return mNextButton != null;
1190 }
1191
1192 public Button getNextButton() {
1193 return mNextButton;
1194 }
1195
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001196 @Override
1197 public boolean shouldUpRecreateTask(Intent targetIntent) {
1198 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1199 }
1200
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001201 public static void requestHomeNotice() {
1202 sShowNoHomeNotice = true;
1203 }
1204
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001205 @Override
1206 public boolean onQueryTextSubmit(String query) {
1207 switchToSearchResultsFragmentIfNeeded();
1208 mSearchQuery = query;
1209 return mSearchResultsFragment.onQueryTextSubmit(query);
1210 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001211
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001212 @Override
1213 public boolean onQueryTextChange(String newText) {
1214 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001215 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001216 return false;
1217 }
1218 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001219 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001220
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001221 @Override
1222 public boolean onClose() {
1223 return false;
1224 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001225
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001226 @Override
1227 public boolean onMenuItemActionExpand(MenuItem item) {
1228 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001229 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001230 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001231 return true;
1232 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001233
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001234 @Override
1235 public boolean onMenuItemActionCollapse(MenuItem item) {
1236 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001237 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001238 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001239 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001240 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001241 return true;
1242 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001243
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001244 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001245 if (mSearchResultsFragment != null) {
1246 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001247 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001248 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001249 if (current != null && current instanceof SearchResultsSummary) {
1250 mSearchResultsFragment = (SearchResultsSummary) current;
1251 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001252 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001253 SearchResultsSummary.class.getName(), null, false, true,
1254 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001255 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001256 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001257 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001258 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001259
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001260 public void needToRevertToInitialFragment() {
1261 mNeedToRevertToInitialFragment = true;
1262 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001263
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001264 private void revertToInitialFragment() {
1265 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001266 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001267 mSearchMenuItemExpanded = false;
1268 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1269 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001270 if (mSearchMenuItem != null) {
1271 mSearchMenuItem.collapseActionView();
1272 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001273 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001274}