blob: a0f43fbeb59b55f27d91e23090370c4ee1e28a47 [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
485 // If this is a sub settings or not the main Dashboard and not a Shortcut and not initial
486 // Fragment then apply the correct theme for the ActionBar content inset
487 if (isSubSettings ||
488 (!mIsShowingDashboard && !mIsShortcut && (initialFragmentName == null))) {
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700489 setTheme(R.style.Theme_SubSettings);
490 }
491
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700492 setContentView(mIsShowingDashboard ?
493 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800494
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700495 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700496
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800497 getFragmentManager().addOnBackStackChangedListener(this);
498
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700499 if (mIsShowingDashboard) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700500 Index.getInstance(getApplicationContext()).update();
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700501 }
502
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700503 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700504 // We are restarting from a previous saved state; used that to initialize, instead
505 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700506 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
507 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800508
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700509 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800510
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700511 ArrayList<DashboardCategory> categories =
512 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
513 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700514 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700515 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700516 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800517 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700518
519 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700520 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800521 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700522 if (!mIsShowingDashboard) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700523 // Search is shown we are launched thru a Settings "shortcut". UP will be shown
524 // only if it is a sub settings
525 if (mIsShortcut) {
526 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700527 mDisplaySearch = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700528 } else if (isSubSettings) {
529 mDisplayHomeAsUpEnabled = true;
530 mDisplaySearch = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700531 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700532 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700533
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700534 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700535 switchToFragment(initialFragmentName, initialArguments, true, false,
536 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000537 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700538 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700539 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700540 // Show Search affordance
541 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700542 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700543 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700544 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800545 }
546 }
547
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700548 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700549 if (mActionBar != null) {
550 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
551 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
552 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700553 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
554
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800555 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800556 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
557
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700558 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800559 if (buttonBar != null) {
560 buttonBar.setVisibility(View.VISIBLE);
561
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700562 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800563 backButton.setOnClickListener(new OnClickListener() {
564 public void onClick(View v) {
565 setResult(RESULT_CANCELED);
566 finish();
567 }
568 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700569 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800570 skipButton.setOnClickListener(new OnClickListener() {
571 public void onClick(View v) {
572 setResult(RESULT_OK);
573 finish();
574 }
575 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700576 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800577 mNextButton.setOnClickListener(new OnClickListener() {
578 public void onClick(View v) {
579 setResult(RESULT_OK);
580 finish();
581 }
582 });
583
584 // set our various button parameters
585 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
586 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
587 if (TextUtils.isEmpty(buttonText)) {
588 mNextButton.setVisibility(View.GONE);
589 }
590 else {
591 mNextButton.setText(buttonText);
592 }
593 }
594 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
595 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
596 if (TextUtils.isEmpty(buttonText)) {
597 backButton.setVisibility(View.GONE);
598 }
599 else {
600 backButton.setText(buttonText);
601 }
602 }
603 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
604 skipButton.setVisibility(View.VISIBLE);
605 }
606 }
607 }
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800608 }
609
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700610 private void setTitleFromIntent(Intent intent) {
611 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
612 if (initialTitleResId > 0) {
613 mInitialTitle = null;
614 mInitialTitleResId = initialTitleResId;
615 setTitle(mInitialTitleResId);
616 } else {
617 mInitialTitleResId = -1;
618 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
619 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
620 setTitle(mInitialTitle);
621 }
622 }
623
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800624 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800625 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700626 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800627 }
628
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700629 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800630 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700631
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800632 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700633 if (mInitialTitleResId > 0) {
634 setTitle(mInitialTitleResId);
635 } else {
636 setTitle(mInitialTitle);
637 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700638 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800639 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700640
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800641 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
642 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700643
644 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800645 }
646
647 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
648 final CharSequence title;
649 final int titleRes = bse.getBreadCrumbTitleRes();
650 if (titleRes > 0) {
651 title = getText(titleRes);
652 } else {
653 title = bse.getBreadCrumbTitle();
654 }
655 if (title != null) {
656 setTitle(title);
657 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800658 }
659
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800660 @Override
661 protected void onSaveInstanceState(Bundle outState) {
662 super.onSaveInstanceState(outState);
663
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700664 if (mCategories.size() > 0) {
665 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800666 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700667
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700668 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700669 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700670
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700671 if (mDisplaySearch) {
672 // The option menus are created if the ActionBar is visible and they are also created
673 // asynchronously. If you launch Settings with an Intent action like
674 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
675 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
676 // menu item and search view are null.
677 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
678 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700679
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700680 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
681 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
682 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800683 }
684
685 @Override
686 public void onResume() {
687 super.onResume();
688
689 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
690 @Override
691 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Fabrice Di Megliobb051782014-06-04 17:33:25 -0700692 setNeedToRebuildCategories(true);
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700693 invalidateCategories();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800694 }
695 };
696 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
697 mDevelopmentPreferencesListener);
698
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800699 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700700
Svetoslav990159a2014-04-14 17:14:59 -0700701 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700702
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700703 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700704 onQueryTextSubmit(mSearchQuery);
705 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800706 }
707
708 @Override
709 public void onPause() {
710 super.onPause();
711
712 unregisterReceiver(mBatteryInfoReceiver);
713
Svetoslav990159a2014-04-14 17:14:59 -0700714 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800715 }
716
717 @Override
718 public void onDestroy() {
719 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700720
721 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
722 mDevelopmentPreferencesListener);
723 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800724 }
725
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800726 protected boolean isValidFragment(String fragmentName) {
727 // Almost all fragments are wrapped in this,
728 // except for a few that have their own activities.
729 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
730 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
731 }
732 return false;
733 }
734
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800735 @Override
736 public Intent getIntent() {
737 Intent superIntent = super.getIntent();
738 String startingFragment = getStartingFragmentClass(superIntent);
739 // This is called from super.onCreate, isMultiPane() is not yet reliable
740 // Do not use onIsHidingHeaders either, which relies itself on this method
741 if (startingFragment != null) {
742 Intent modIntent = new Intent(superIntent);
743 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
744 Bundle args = superIntent.getExtras();
745 if (args != null) {
746 args = new Bundle(args);
747 } else {
748 args = new Bundle();
749 }
750 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100751 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800752 return modIntent;
753 }
754 return superIntent;
755 }
756
757 /**
758 * Checks if the component name in the intent is different from the Settings class and
759 * returns the class name to load as a fragment.
760 */
761 private String getStartingFragmentClass(Intent intent) {
762 if (mFragmentClass != null) return mFragmentClass;
763
764 String intentClass = intent.getComponent().getClassName();
765 if (intentClass.equals(getClass().getName())) return null;
766
767 if ("com.android.settings.ManageApplications".equals(intentClass)
768 || "com.android.settings.RunningServices".equals(intentClass)
769 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
770 // Old names of manage apps.
771 intentClass = com.android.settings.applications.ManageApplications.class.getName();
772 }
773
774 return intentClass;
775 }
776
777 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000778 * Start a new fragment containing a preference panel. If the preferences
779 * are being displayed in multi-pane mode, the given fragment class will
780 * be instantiated and placed in the appropriate pane. If running in
781 * single-pane mode, a new activity will be launched in which to show the
782 * fragment.
783 *
784 * @param fragmentClass Full name of the class implementing the fragment.
785 * @param args Any desired arguments to supply to the fragment.
786 * @param titleRes Optional resource identifier of the title of this
787 * fragment.
788 * @param titleText Optional text of the title of this fragment.
789 * @param resultTo Optional fragment that result data should be sent to.
790 * If non-null, resultTo.onActivityResult() will be called when this
791 * preference panel is done. The launched panel must use
792 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
793 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700794 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000795 */
796 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700797 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700798 String title = null;
799 if (titleRes < 0) {
800 if (titleText != null) {
801 title = titleText.toString();
802 } else {
803 // There not much we can do in that case
804 title = "";
805 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700806 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700807 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700808 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000809 }
810
811 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800812 * Called by a preference panel fragment to finish itself.
813 *
814 * @param caller The fragment that is asking to be finished.
815 * @param resultCode Optional result code to send back to the original
816 * launching fragment.
817 * @param resultData Optional result data to send back to the original
818 * launching fragment.
819 */
820 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
821 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700822 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800823 }
824
825 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000826 * Start a new fragment.
827 *
828 * @param fragment The fragment to start
829 * @param push If true, the current fragment will be pushed onto the back stack. If false,
830 * the current fragment will be replaced.
831 */
832 public void startPreferenceFragment(Fragment fragment, boolean push) {
833 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700834 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000835 if (push) {
836 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
837 transaction.addToBackStack(BACK_STACK_PREFS);
838 } else {
839 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
840 }
841 transaction.commitAllowingStateLoss();
842 }
843
844 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700845 * Switch to a specific Fragment with taking care of validation, Title and BackStack
846 */
847 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700848 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700849 if (validate && !isValidFragment(fragmentName)) {
850 throw new IllegalArgumentException("Invalid fragment for this activity: "
851 + fragmentName);
852 }
853 Fragment f = Fragment.instantiate(this, fragmentName, args);
854 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700855 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700856 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700857 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700858 }
859 if (addToBackStack) {
860 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
861 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700862 if (titleResId > 0) {
863 transaction.setBreadCrumbTitle(titleResId);
864 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700865 transaction.setBreadCrumbTitle(title);
866 }
867 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700868 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700869 return f;
870 }
871
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700872 public void setNeedToRebuildCategories(boolean need) {
873 mNeedToRebuildCategories = need;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700874 }
875
876 /**
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700877 * Called when the activity needs its list of categories/tiles built.
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700878 *
879 * @param categories The list in which to place the tiles categories.
880 */
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700881 private void buildDashboardCategories(List<DashboardCategory> categories) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700882 categories.clear();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700883 loadCategoriesFromResource(R.xml.dashboard_categories, categories);
884 updateTilesList(categories);
885 }
886
887 /**
888 * Parse the given XML file as a categories description, adding each
889 * parsed categories and tiles into the target list.
890 *
891 * @param resid The XML resource to load and parse.
892 * @param target The list in which the parsed categories and tiles should be placed.
893 */
894 private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) {
895 XmlResourceParser parser = null;
896 try {
897 parser = getResources().getXml(resid);
898 AttributeSet attrs = Xml.asAttributeSet(parser);
899
900 int type;
901 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
902 && type != XmlPullParser.START_TAG) {
903 // Parse next until start tag is found
904 }
905
906 String nodeName = parser.getName();
907 if (!"dashboard-categories".equals(nodeName)) {
908 throw new RuntimeException(
909 "XML document must start with <preference-categories> tag; found"
910 + nodeName + " at " + parser.getPositionDescription());
911 }
912
913 Bundle curBundle = null;
914
915 final int outerDepth = parser.getDepth();
916 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
917 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
918 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
919 continue;
920 }
921
922 nodeName = parser.getName();
923 if ("dashboard-category".equals(nodeName)) {
924 DashboardCategory category = new DashboardCategory();
925
926 TypedArray sa = obtainStyledAttributes(
927 attrs, com.android.internal.R.styleable.PreferenceHeader);
928 category.id = sa.getResourceId(
929 com.android.internal.R.styleable.PreferenceHeader_id,
930 (int)DashboardCategory.CAT_ID_UNDEFINED);
931
932 TypedValue tv = sa.peekValue(
933 com.android.internal.R.styleable.PreferenceHeader_title);
934 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
935 if (tv.resourceId != 0) {
936 category.titleRes = tv.resourceId;
937 } else {
938 category.title = tv.string;
939 }
940 }
941 sa.recycle();
942
943 final int innerDepth = parser.getDepth();
944 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
945 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
946 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
947 continue;
948 }
949
950 String innerNodeName = parser.getName();
951 if (innerNodeName.equals("dashboard-tile")) {
952 DashboardTile tile = new DashboardTile();
953
954 sa = obtainStyledAttributes(
955 attrs, com.android.internal.R.styleable.PreferenceHeader);
956 tile.id = sa.getResourceId(
957 com.android.internal.R.styleable.PreferenceHeader_id,
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -0700958 (int)TILE_ID_UNDEFINED);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700959 tv = sa.peekValue(
960 com.android.internal.R.styleable.PreferenceHeader_title);
961 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
962 if (tv.resourceId != 0) {
963 tile.titleRes = tv.resourceId;
964 } else {
965 tile.title = tv.string;
966 }
967 }
968 tv = sa.peekValue(
969 com.android.internal.R.styleable.PreferenceHeader_summary);
970 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
971 if (tv.resourceId != 0) {
972 tile.summaryRes = tv.resourceId;
973 } else {
974 tile.summary = tv.string;
975 }
976 }
977 tile.iconRes = sa.getResourceId(
978 com.android.internal.R.styleable.PreferenceHeader_icon, 0);
979 tile.fragment = sa.getString(
980 com.android.internal.R.styleable.PreferenceHeader_fragment);
981 sa.recycle();
982
983 if (curBundle == null) {
984 curBundle = new Bundle();
985 }
986
987 final int innerDepth2 = parser.getDepth();
988 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
989 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) {
990 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
991 continue;
992 }
993
994 String innerNodeName2 = parser.getName();
995 if (innerNodeName2.equals("extra")) {
996 getResources().parseBundleExtra("extra", attrs, curBundle);
997 XmlUtils.skipCurrentTag(parser);
998
999 } else if (innerNodeName2.equals("intent")) {
1000 tile.intent = Intent.parseIntent(getResources(), parser, attrs);
1001
1002 } else {
1003 XmlUtils.skipCurrentTag(parser);
1004 }
1005 }
1006
1007 if (curBundle.size() > 0) {
1008 tile.fragmentArguments = curBundle;
1009 curBundle = null;
1010 }
1011
1012 category.addTile(tile);
1013
1014 } else {
1015 XmlUtils.skipCurrentTag(parser);
1016 }
1017 }
1018
1019 target.add(category);
1020 } else {
1021 XmlUtils.skipCurrentTag(parser);
1022 }
1023 }
1024
1025 } catch (XmlPullParserException e) {
1026 throw new RuntimeException("Error parsing categories", e);
1027 } catch (IOException e) {
1028 throw new RuntimeException("Error parsing categories", e);
1029 } finally {
1030 if (parser != null) parser.close();
1031 }
1032 }
1033
1034 private void updateTilesList(List<DashboardCategory> target) {
1035 final boolean showDev = mDevelopmentPreferences.getBoolean(
1036 DevelopmentSettings.PREF_SHOW,
1037 android.os.Build.TYPE.equals("eng"));
1038
1039 final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
1040
1041 final int size = target.size();
1042 for (int i = 0; i < size; i++) {
1043
1044 DashboardCategory category = target.get(i);
1045
1046 // Ids are integers, so downcasting is ok
1047 int id = (int) category.id;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001048 int n = category.getTilesCount() - 1;
1049 while (n >= 0) {
1050
1051 DashboardTile tile = category.getTile(n);
1052
1053 id = (int) tile.id;
1054 if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
1055 Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, category, tile);
1056 } else if (id == R.id.wifi_settings) {
1057 // Remove WiFi Settings if WiFi service is not available.
1058 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
1059 category.removeTile(n);
1060 }
1061 } else if (id == R.id.bluetooth_settings) {
1062 // Remove Bluetooth Settings if Bluetooth service is not available.
1063 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
1064 category.removeTile(n);
1065 }
1066 } else if (id == R.id.data_usage_settings) {
1067 // Remove data usage when kernel module not enabled
1068 final INetworkManagementService netManager = INetworkManagementService.Stub
1069 .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
1070 try {
1071 if (!netManager.isBandwidthControlEnabled()) {
1072 category.removeTile(n);
1073 }
1074 } catch (RemoteException e) {
1075 // ignored
1076 }
1077 } else if (id == R.id.battery_settings) {
1078 // Remove battery settings when battery is not available. (e.g. TV)
1079
1080 if (!mBatteryPresent) {
1081 category.removeTile(n);
1082 }
1083 } else if (id == R.id.home_settings) {
1084 if (!updateHomeSettingTiles(tile)) {
1085 category.removeTile(n);
1086 }
1087 } else if (id == R.id.user_settings) {
Amith Yamasani4093e402014-06-06 14:31:37 -07001088 boolean hasMultipleUsers =
1089 ((UserManager) getSystemService(Context.USER_SERVICE))
1090 .getUserCount() > 1;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001091 if (!UserHandle.MU_ENABLED
Amith Yamasani4093e402014-06-06 14:31:37 -07001092 || (!UserManager.supportsMultipleUsers()
1093 && !hasMultipleUsers)
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001094 || Utils.isMonkeyRunning()) {
1095 category.removeTile(n);
1096 }
1097 } else if (id == R.id.nfc_payment_settings) {
1098 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
1099 category.removeTile(n);
1100 } else {
1101 // Only show if NFC is on and we have the HCE feature
1102 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1103 if (!adapter.isEnabled() || !getPackageManager().hasSystemFeature(
1104 PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
1105 category.removeTile(n);
1106 }
1107 }
Fabrice Di Meglio488cae32014-05-13 11:26:34 -07001108 } else if (id == R.id.print_settings) {
1109 boolean hasPrintingSupport = getPackageManager().hasSystemFeature(
1110 PackageManager.FEATURE_PRINTING);
1111 if (!hasPrintingSupport) {
1112 category.removeTile(n);
1113 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001114 } else if (id == R.id.development_settings) {
Julia Reynolds6c088cb2014-05-08 09:29:41 -04001115 if (!showDev || um.hasUserRestriction(
1116 UserManager.DISALLOW_DEBUGGING_FEATURES)) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001117 category.removeTile(n);
1118 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001119 }
1120
1121 if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
Amith Yamasania97089d2014-04-30 10:58:09 -07001122 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)
1123 && n < category.getTilesCount()) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001124 category.removeTile(n);
1125 }
1126
1127 n--;
1128 }
1129 }
1130 }
1131
1132 private boolean updateHomeSettingTiles(DashboardTile tile) {
1133 // Once we decide to show Home settings, keep showing it forever
1134 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1135 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1136 return true;
1137 }
1138
1139 try {
1140 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
1141 getPackageManager().getHomeActivities(homeApps);
1142 if (homeApps.size() < 2) {
1143 // When there's only one available home app, omit this settings
1144 // category entirely at the top level UI. If the user just
1145 // uninstalled the penultimate home app candidiate, we also
1146 // now tell them about why they aren't seeing 'Home' in the list.
1147 if (sShowNoHomeNotice) {
1148 sShowNoHomeNotice = false;
1149 NoHomeDialogFragment.show(this);
1150 }
1151 return false;
1152 } else {
1153 // Okay, we're allowing the Home settings category. Tell it, when
1154 // invoked via this front door, that we'll need to be told about the
1155 // case when the user uninstalls all but one home app.
1156 if (tile.fragmentArguments == null) {
1157 tile.fragmentArguments = new Bundle();
1158 }
1159 tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true);
1160 }
1161 } catch (Exception e) {
1162 // Can't look up the home activity; bail on configuring the icon
1163 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1164 }
1165
1166 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1167 return true;
1168 }
1169
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001170 private void getMetaData() {
1171 try {
1172 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1173 PackageManager.GET_META_DATA);
1174 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001175 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1176 } catch (NameNotFoundException nnfe) {
1177 // No recovery
1178 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1179 }
1180 }
1181
1182 // give subclasses access to the Next button
1183 public boolean hasNextButton() {
1184 return mNextButton != null;
1185 }
1186
1187 public Button getNextButton() {
1188 return mNextButton;
1189 }
1190
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001191 @Override
1192 public boolean shouldUpRecreateTask(Intent targetIntent) {
1193 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1194 }
1195
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001196 public static void requestHomeNotice() {
1197 sShowNoHomeNotice = true;
1198 }
1199
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001200 @Override
1201 public boolean onQueryTextSubmit(String query) {
1202 switchToSearchResultsFragmentIfNeeded();
1203 mSearchQuery = query;
1204 return mSearchResultsFragment.onQueryTextSubmit(query);
1205 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001206
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001207 @Override
1208 public boolean onQueryTextChange(String newText) {
1209 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001210 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001211 return false;
1212 }
1213 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001214 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001215
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001216 @Override
1217 public boolean onClose() {
1218 return false;
1219 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001220
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001221 @Override
1222 public boolean onMenuItemActionExpand(MenuItem item) {
1223 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001224 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001225 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001226 return true;
1227 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001228
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001229 @Override
1230 public boolean onMenuItemActionCollapse(MenuItem item) {
1231 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001232 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001233 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001234 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001235 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001236 return true;
1237 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001238
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001239 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001240 if (mSearchResultsFragment != null) {
1241 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001242 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001243 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001244 if (current != null && current instanceof SearchResultsSummary) {
1245 mSearchResultsFragment = (SearchResultsSummary) current;
1246 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001247 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001248 SearchResultsSummary.class.getName(), null, false, true,
1249 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001250 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001251 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001252 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001253 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001254
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001255 public void needToRevertToInitialFragment() {
1256 mNeedToRevertToInitialFragment = true;
1257 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001258
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001259 private void revertToInitialFragment() {
1260 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001261 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001262 mSearchMenuItemExpanded = false;
1263 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1264 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001265 if (mSearchMenuItem != null) {
1266 mSearchMenuItem.collapseActionView();
1267 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001268 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001269}