blob: e2aeaf2d35f04b7068805b366040cd418fcac41a [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(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800242 DisplaySettings.class.getName(),
243 DeviceInfoSettings.class.getName(),
244 ManageApplications.class.getName(),
245 ProcessStatsUi.class.getName(),
246 NotificationStation.class.getName(),
247 LocationSettings.class.getName(),
248 SecuritySettings.class.getName(),
249 PrivacySettings.class.getName(),
250 DeviceAdminSettings.class.getName(),
251 AccessibilitySettings.class.getName(),
252 CaptionPropertiesFragment.class.getName(),
253 com.android.settings.accessibility.ToggleInversionPreferenceFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800254 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
255 TextToSpeechSettings.class.getName(),
256 Memory.class.getName(),
257 DevelopmentSettings.class.getName(),
258 UsbSettings.class.getName(),
259 AndroidBeam.class.getName(),
260 WifiDisplaySettings.class.getName(),
261 PowerUsageSummary.class.getName(),
262 AccountSyncSettings.class.getName(),
263 CryptKeeperSettings.class.getName(),
264 DataUsageSummary.class.getName(),
265 DreamSettings.class.getName(),
266 UserSettings.class.getName(),
267 NotificationAccessSettings.class.getName(),
John Spurlockc9afadb2014-04-29 18:07:23 -0400268 ConditionProviderSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800269 PrintSettingsFragment.class.getName(),
270 PrintJobSettingsFragment.class.getName(),
271 TrustedCredentialsSettings.class.getName(),
272 PaymentSettings.class.getName(),
273 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700274 ZenModeSettings.class.getName(),
275 NotificationSettings.class.getName(),
276 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
277 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400278 InstalledAppDetails.class.getName(),
279 BatterySaverSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800280 };
281
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700282
283 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
284 "android.settings.APPLICATION_DETAILS_SETTINGS"
285 };
286
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800287 private SharedPreferences mDevelopmentPreferences;
288 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
289
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800290 private boolean mBatteryPresent = true;
291 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
292
293 @Override
294 public void onReceive(Context context, Intent intent) {
295 String action = intent.getAction();
296 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
297 boolean batteryPresent = Utils.isBatteryPresent(intent);
298
299 if (mBatteryPresent != batteryPresent) {
300 mBatteryPresent = batteryPresent;
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700301 invalidateCategories();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800302 }
303 }
304 }
305 };
306
Svetoslav990159a2014-04-14 17:14:59 -0700307 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
308 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700309
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700310 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700311 private SwitchBar mSwitchBar;
312
313 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700314
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700315 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700316 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700317
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700318 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700319 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700320
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700321 private ViewGroup mContent;
322
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700323 private SearchView mSearchView;
324 private MenuItem mSearchMenuItem;
325 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700326 private SearchResultsSummary mSearchResultsFragment;
327 private String mSearchQuery;
328
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700329 // Categories
330 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
331 private boolean mNeedToRebuildCategories;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800332
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700333 private static final int MSG_BUILD_CATEGORIES = 1;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800334 private Handler mHandler = new Handler() {
335 @Override
336 public void handleMessage(Message msg) {
337 switch (msg.what) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700338 case MSG_BUILD_CATEGORIES: {
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700339 if(mNeedToRebuildCategories) {
340 buildDashboardCategories(mCategories);
341 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800342 } break;
343 }
344 }
345 };
346
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700347 private boolean mNeedToRevertToInitialFragment = false;
348
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700349 public SwitchBar getSwitchBar() {
350 return mSwitchBar;
351 }
352
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700353 public List<DashboardCategory> getDashboardCategories() {
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700354 if (mNeedToRebuildCategories || mCategories.size() == 0) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700355 buildDashboardCategories(mCategories);
356 mNeedToRebuildCategories = false;
357 }
358 return mCategories;
359 }
360
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800361 @Override
362 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
363 // Override the fragment title for Wallpaper settings
364 int titleRes = pref.getTitleRes();
365 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
366 titleRes = R.string.wallpaper_settings_fragment_title;
367 } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName())
368 && UserHandle.myUserId() != UserHandle.USER_OWNER) {
369 if (UserManager.get(this).isLinkedUser()) {
370 titleRes = R.string.profile_info_settings_title;
371 } else {
372 titleRes = R.string.user_info_settings_title;
373 }
374 }
375 startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),
376 null, 0);
377 return true;
378 }
379
380 @Override
381 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
382 return false;
383 }
384
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700385 private void invalidateCategories() {
386 if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) {
387 mHandler.sendEmptyMessage(MSG_BUILD_CATEGORIES);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800388 }
389 }
390
391 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800392 public void onConfigurationChanged(Configuration newConfig) {
393 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800394 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800395 }
396
397 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700398 protected void onStart() {
399 super.onStart();
400
401 if (mNeedToRevertToInitialFragment) {
402 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800403 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800404 }
405
406 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700407 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700408 if (!mDisplaySearch) {
409 return false;
410 }
411
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700412 MenuInflater inflater = getMenuInflater();
413 inflater.inflate(R.menu.options_menu, menu);
414
415 // Cache the search query (can be overriden by the OnQueryTextListener)
416 final String query = mSearchQuery;
417
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700418 mSearchMenuItem = menu.findItem(R.id.search);
419 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700420
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700421 if (mSearchMenuItem == null || mSearchView == null) {
422 return false;
423 }
424
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700425 if (mSearchResultsFragment != null) {
426 mSearchResultsFragment.setSearchView(mSearchView);
427 }
428
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700429 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700430 mSearchView.setOnQueryTextListener(this);
431 mSearchView.setOnCloseListener(this);
432
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700433 if (mSearchMenuItemExpanded) {
434 mSearchMenuItem.expandActionView();
435 }
436 mSearchView.setQuery(query, true /* submit */);
437
438 return true;
439 }
440
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700441 private static boolean isShortCutIntent(final Intent intent) {
442 Set<String> categories = intent.getCategories();
443 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
444 }
445
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700446 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700447 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700448 if (action == null) {
449 return false;
450 }
451 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
452 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
453 }
454 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700455 }
456
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700457 @Override
458 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700459 super.onCreate(savedState);
460
461 // Should happen before any call to getIntent()
462 getMetaData();
463
464 final Intent intent = getIntent();
465 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
466 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800467 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800468
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800469 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
470 Context.MODE_PRIVATE);
471
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700472 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700473 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700474
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700475 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700476 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
477
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700478 final ComponentName cn = getIntent().getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700479 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700480
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700481 mIsShowingDashboard = className.equals(Settings.class.getName());
482 final boolean isSubSettings = className.equals(SubSettings.class.getName());
483
484 // If this is a sub settings or not the main Dashboard and not a Shortcut and not initial
485 // Fragment then apply the correct theme for the ActionBar content inset
486 if (isSubSettings ||
487 (!mIsShowingDashboard && !mIsShortcut && (initialFragmentName == null))) {
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700488 setTheme(R.style.Theme_SubSettings);
489 }
490
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800491 setContentView(R.layout.settings_main);
492
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700493 mContent = (ViewGroup) findViewById(R.id.prefs);
494
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800495 getFragmentManager().addOnBackStackChangedListener(this);
496
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700497 if (mIsShowingDashboard) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700498 Index.getInstance(getApplicationContext()).update();
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700499 }
500
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700501 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700502 // We are restarting from a previous saved state; used that to initialize, instead
503 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700504 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
505 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800506
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700507 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800508
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700509 ArrayList<DashboardCategory> categories =
510 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
511 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700512 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700513 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700514 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800515 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700516
517 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700518 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800519 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700520 if (!mIsShowingDashboard) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700521 // Search is shown we are launched thru a Settings "shortcut". UP will be shown
522 // only if it is a sub settings
523 if (mIsShortcut) {
524 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700525 mDisplaySearch = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700526 } else if (isSubSettings) {
527 mDisplayHomeAsUpEnabled = true;
528 mDisplaySearch = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700529 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700530 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700531
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700532 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700533 switchToFragment(initialFragmentName, initialArguments, true, false,
534 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000535 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700536 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700537 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700538 // Show Search affordance
539 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700540 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700541 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700542 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800543 }
544 }
545
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700546 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700547 if (mActionBar != null) {
548 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
549 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
550 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700551 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
552
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800553 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800554 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
555
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700556 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800557 if (buttonBar != null) {
558 buttonBar.setVisibility(View.VISIBLE);
559
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700560 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800561 backButton.setOnClickListener(new OnClickListener() {
562 public void onClick(View v) {
563 setResult(RESULT_CANCELED);
564 finish();
565 }
566 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700567 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800568 skipButton.setOnClickListener(new OnClickListener() {
569 public void onClick(View v) {
570 setResult(RESULT_OK);
571 finish();
572 }
573 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700574 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800575 mNextButton.setOnClickListener(new OnClickListener() {
576 public void onClick(View v) {
577 setResult(RESULT_OK);
578 finish();
579 }
580 });
581
582 // set our various button parameters
583 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
584 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
585 if (TextUtils.isEmpty(buttonText)) {
586 mNextButton.setVisibility(View.GONE);
587 }
588 else {
589 mNextButton.setText(buttonText);
590 }
591 }
592 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
593 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
594 if (TextUtils.isEmpty(buttonText)) {
595 backButton.setVisibility(View.GONE);
596 }
597 else {
598 backButton.setText(buttonText);
599 }
600 }
601 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
602 skipButton.setVisibility(View.VISIBLE);
603 }
604 }
605 }
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800606 }
607
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700608 private void setTitleFromIntent(Intent intent) {
609 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
610 if (initialTitleResId > 0) {
611 mInitialTitle = null;
612 mInitialTitleResId = initialTitleResId;
613 setTitle(mInitialTitleResId);
614 } else {
615 mInitialTitleResId = -1;
616 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
617 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
618 setTitle(mInitialTitle);
619 }
620 }
621
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800622 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800623 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700624 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800625 }
626
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700627 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800628 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700629
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800630 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700631 if (mInitialTitleResId > 0) {
632 setTitle(mInitialTitleResId);
633 } else {
634 setTitle(mInitialTitle);
635 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700636 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800637 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700638
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800639 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
640 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700641
642 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800643 }
644
645 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
646 final CharSequence title;
647 final int titleRes = bse.getBreadCrumbTitleRes();
648 if (titleRes > 0) {
649 title = getText(titleRes);
650 } else {
651 title = bse.getBreadCrumbTitle();
652 }
653 if (title != null) {
654 setTitle(title);
655 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800656 }
657
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800658 @Override
659 protected void onSaveInstanceState(Bundle outState) {
660 super.onSaveInstanceState(outState);
661
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700662 if (mCategories.size() > 0) {
663 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800664 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700665
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700666 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700667 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700668
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700669 if (mDisplaySearch) {
670 // The option menus are created if the ActionBar is visible and they are also created
671 // asynchronously. If you launch Settings with an Intent action like
672 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
673 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
674 // menu item and search view are null.
675 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
676 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700677
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700678 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
679 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
680 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800681 }
682
683 @Override
684 public void onResume() {
685 super.onResume();
686
687 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
688 @Override
689 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Fabrice Di Megliobb051782014-06-04 17:33:25 -0700690 setNeedToRebuildCategories(true);
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700691 invalidateCategories();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800692 }
693 };
694 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
695 mDevelopmentPreferencesListener);
696
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800697 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700698
Svetoslav990159a2014-04-14 17:14:59 -0700699 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700700
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700701 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700702 onQueryTextSubmit(mSearchQuery);
703 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800704 }
705
706 @Override
707 public void onPause() {
708 super.onPause();
709
710 unregisterReceiver(mBatteryInfoReceiver);
711
Svetoslav990159a2014-04-14 17:14:59 -0700712 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800713 }
714
715 @Override
716 public void onDestroy() {
717 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700718
719 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
720 mDevelopmentPreferencesListener);
721 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800722 }
723
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800724 protected boolean isValidFragment(String fragmentName) {
725 // Almost all fragments are wrapped in this,
726 // except for a few that have their own activities.
727 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
728 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
729 }
730 return false;
731 }
732
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800733 @Override
734 public Intent getIntent() {
735 Intent superIntent = super.getIntent();
736 String startingFragment = getStartingFragmentClass(superIntent);
737 // This is called from super.onCreate, isMultiPane() is not yet reliable
738 // Do not use onIsHidingHeaders either, which relies itself on this method
739 if (startingFragment != null) {
740 Intent modIntent = new Intent(superIntent);
741 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
742 Bundle args = superIntent.getExtras();
743 if (args != null) {
744 args = new Bundle(args);
745 } else {
746 args = new Bundle();
747 }
748 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100749 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800750 return modIntent;
751 }
752 return superIntent;
753 }
754
755 /**
756 * Checks if the component name in the intent is different from the Settings class and
757 * returns the class name to load as a fragment.
758 */
759 private String getStartingFragmentClass(Intent intent) {
760 if (mFragmentClass != null) return mFragmentClass;
761
762 String intentClass = intent.getComponent().getClassName();
763 if (intentClass.equals(getClass().getName())) return null;
764
765 if ("com.android.settings.ManageApplications".equals(intentClass)
766 || "com.android.settings.RunningServices".equals(intentClass)
767 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
768 // Old names of manage apps.
769 intentClass = com.android.settings.applications.ManageApplications.class.getName();
770 }
771
772 return intentClass;
773 }
774
775 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000776 * Start a new fragment containing a preference panel. If the preferences
777 * are being displayed in multi-pane mode, the given fragment class will
778 * be instantiated and placed in the appropriate pane. If running in
779 * single-pane mode, a new activity will be launched in which to show the
780 * fragment.
781 *
782 * @param fragmentClass Full name of the class implementing the fragment.
783 * @param args Any desired arguments to supply to the fragment.
784 * @param titleRes Optional resource identifier of the title of this
785 * fragment.
786 * @param titleText Optional text of the title of this fragment.
787 * @param resultTo Optional fragment that result data should be sent to.
788 * If non-null, resultTo.onActivityResult() will be called when this
789 * preference panel is done. The launched panel must use
790 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
791 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700792 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000793 */
794 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700795 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700796 String title = null;
797 if (titleRes < 0) {
798 if (titleText != null) {
799 title = titleText.toString();
800 } else {
801 // There not much we can do in that case
802 title = "";
803 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700804 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700805 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700806 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000807 }
808
809 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800810 * Called by a preference panel fragment to finish itself.
811 *
812 * @param caller The fragment that is asking to be finished.
813 * @param resultCode Optional result code to send back to the original
814 * launching fragment.
815 * @param resultData Optional result data to send back to the original
816 * launching fragment.
817 */
818 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
819 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700820 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800821 }
822
823 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000824 * Start a new fragment.
825 *
826 * @param fragment The fragment to start
827 * @param push If true, the current fragment will be pushed onto the back stack. If false,
828 * the current fragment will be replaced.
829 */
830 public void startPreferenceFragment(Fragment fragment, boolean push) {
831 FragmentTransaction transaction = getFragmentManager().beginTransaction();
832 transaction.replace(R.id.prefs, fragment);
833 if (push) {
834 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
835 transaction.addToBackStack(BACK_STACK_PREFS);
836 } else {
837 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
838 }
839 transaction.commitAllowingStateLoss();
840 }
841
842 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700843 * Switch to a specific Fragment with taking care of validation, Title and BackStack
844 */
845 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700846 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700847 if (validate && !isValidFragment(fragmentName)) {
848 throw new IllegalArgumentException("Invalid fragment for this activity: "
849 + fragmentName);
850 }
851 Fragment f = Fragment.instantiate(this, fragmentName, args);
852 FragmentTransaction transaction = getFragmentManager().beginTransaction();
853 transaction.replace(R.id.prefs, f);
854 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700855 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700856 }
857 if (addToBackStack) {
858 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
859 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700860 if (titleResId > 0) {
861 transaction.setBreadCrumbTitle(titleResId);
862 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700863 transaction.setBreadCrumbTitle(title);
864 }
865 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700866 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700867 return f;
868 }
869
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700870 public void setNeedToRebuildCategories(boolean need) {
871 mNeedToRebuildCategories = need;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700872 }
873
874 /**
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700875 * Called when the activity needs its list of categories/tiles built.
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700876 *
877 * @param categories The list in which to place the tiles categories.
878 */
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700879 private void buildDashboardCategories(List<DashboardCategory> categories) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700880 categories.clear();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700881 loadCategoriesFromResource(R.xml.dashboard_categories, categories);
882 updateTilesList(categories);
883 }
884
885 /**
886 * Parse the given XML file as a categories description, adding each
887 * parsed categories and tiles into the target list.
888 *
889 * @param resid The XML resource to load and parse.
890 * @param target The list in which the parsed categories and tiles should be placed.
891 */
892 private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) {
893 XmlResourceParser parser = null;
894 try {
895 parser = getResources().getXml(resid);
896 AttributeSet attrs = Xml.asAttributeSet(parser);
897
898 int type;
899 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
900 && type != XmlPullParser.START_TAG) {
901 // Parse next until start tag is found
902 }
903
904 String nodeName = parser.getName();
905 if (!"dashboard-categories".equals(nodeName)) {
906 throw new RuntimeException(
907 "XML document must start with <preference-categories> tag; found"
908 + nodeName + " at " + parser.getPositionDescription());
909 }
910
911 Bundle curBundle = null;
912
913 final int outerDepth = parser.getDepth();
914 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
915 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
916 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
917 continue;
918 }
919
920 nodeName = parser.getName();
921 if ("dashboard-category".equals(nodeName)) {
922 DashboardCategory category = new DashboardCategory();
923
924 TypedArray sa = obtainStyledAttributes(
925 attrs, com.android.internal.R.styleable.PreferenceHeader);
926 category.id = sa.getResourceId(
927 com.android.internal.R.styleable.PreferenceHeader_id,
928 (int)DashboardCategory.CAT_ID_UNDEFINED);
929
930 TypedValue tv = sa.peekValue(
931 com.android.internal.R.styleable.PreferenceHeader_title);
932 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
933 if (tv.resourceId != 0) {
934 category.titleRes = tv.resourceId;
935 } else {
936 category.title = tv.string;
937 }
938 }
939 sa.recycle();
940
941 final int innerDepth = parser.getDepth();
942 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
943 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
944 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
945 continue;
946 }
947
948 String innerNodeName = parser.getName();
949 if (innerNodeName.equals("dashboard-tile")) {
950 DashboardTile tile = new DashboardTile();
951
952 sa = obtainStyledAttributes(
953 attrs, com.android.internal.R.styleable.PreferenceHeader);
954 tile.id = sa.getResourceId(
955 com.android.internal.R.styleable.PreferenceHeader_id,
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -0700956 (int)TILE_ID_UNDEFINED);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700957 tv = sa.peekValue(
958 com.android.internal.R.styleable.PreferenceHeader_title);
959 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
960 if (tv.resourceId != 0) {
961 tile.titleRes = tv.resourceId;
962 } else {
963 tile.title = tv.string;
964 }
965 }
966 tv = sa.peekValue(
967 com.android.internal.R.styleable.PreferenceHeader_summary);
968 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
969 if (tv.resourceId != 0) {
970 tile.summaryRes = tv.resourceId;
971 } else {
972 tile.summary = tv.string;
973 }
974 }
975 tile.iconRes = sa.getResourceId(
976 com.android.internal.R.styleable.PreferenceHeader_icon, 0);
977 tile.fragment = sa.getString(
978 com.android.internal.R.styleable.PreferenceHeader_fragment);
979 sa.recycle();
980
981 if (curBundle == null) {
982 curBundle = new Bundle();
983 }
984
985 final int innerDepth2 = parser.getDepth();
986 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
987 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) {
988 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
989 continue;
990 }
991
992 String innerNodeName2 = parser.getName();
993 if (innerNodeName2.equals("extra")) {
994 getResources().parseBundleExtra("extra", attrs, curBundle);
995 XmlUtils.skipCurrentTag(parser);
996
997 } else if (innerNodeName2.equals("intent")) {
998 tile.intent = Intent.parseIntent(getResources(), parser, attrs);
999
1000 } else {
1001 XmlUtils.skipCurrentTag(parser);
1002 }
1003 }
1004
1005 if (curBundle.size() > 0) {
1006 tile.fragmentArguments = curBundle;
1007 curBundle = null;
1008 }
1009
1010 category.addTile(tile);
1011
1012 } else {
1013 XmlUtils.skipCurrentTag(parser);
1014 }
1015 }
1016
1017 target.add(category);
1018 } else {
1019 XmlUtils.skipCurrentTag(parser);
1020 }
1021 }
1022
1023 } catch (XmlPullParserException e) {
1024 throw new RuntimeException("Error parsing categories", e);
1025 } catch (IOException e) {
1026 throw new RuntimeException("Error parsing categories", e);
1027 } finally {
1028 if (parser != null) parser.close();
1029 }
1030 }
1031
1032 private void updateTilesList(List<DashboardCategory> target) {
1033 final boolean showDev = mDevelopmentPreferences.getBoolean(
1034 DevelopmentSettings.PREF_SHOW,
1035 android.os.Build.TYPE.equals("eng"));
1036
1037 final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
1038
1039 final int size = target.size();
1040 for (int i = 0; i < size; i++) {
1041
1042 DashboardCategory category = target.get(i);
1043
1044 // Ids are integers, so downcasting is ok
1045 int id = (int) category.id;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001046 int n = category.getTilesCount() - 1;
1047 while (n >= 0) {
1048
1049 DashboardTile tile = category.getTile(n);
1050
1051 id = (int) tile.id;
1052 if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
1053 Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, category, tile);
1054 } else if (id == R.id.wifi_settings) {
1055 // Remove WiFi Settings if WiFi service is not available.
1056 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
1057 category.removeTile(n);
1058 }
1059 } else if (id == R.id.bluetooth_settings) {
1060 // Remove Bluetooth Settings if Bluetooth service is not available.
1061 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
1062 category.removeTile(n);
1063 }
1064 } else if (id == R.id.data_usage_settings) {
1065 // Remove data usage when kernel module not enabled
1066 final INetworkManagementService netManager = INetworkManagementService.Stub
1067 .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
1068 try {
1069 if (!netManager.isBandwidthControlEnabled()) {
1070 category.removeTile(n);
1071 }
1072 } catch (RemoteException e) {
1073 // ignored
1074 }
1075 } else if (id == R.id.battery_settings) {
1076 // Remove battery settings when battery is not available. (e.g. TV)
1077
1078 if (!mBatteryPresent) {
1079 category.removeTile(n);
1080 }
1081 } else if (id == R.id.home_settings) {
1082 if (!updateHomeSettingTiles(tile)) {
1083 category.removeTile(n);
1084 }
1085 } else if (id == R.id.user_settings) {
Amith Yamasani4093e402014-06-06 14:31:37 -07001086 boolean hasMultipleUsers =
1087 ((UserManager) getSystemService(Context.USER_SERVICE))
1088 .getUserCount() > 1;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001089 if (!UserHandle.MU_ENABLED
Amith Yamasani4093e402014-06-06 14:31:37 -07001090 || (!UserManager.supportsMultipleUsers()
1091 && !hasMultipleUsers)
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001092 || Utils.isMonkeyRunning()) {
1093 category.removeTile(n);
1094 }
1095 } else if (id == R.id.nfc_payment_settings) {
1096 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
1097 category.removeTile(n);
1098 } else {
1099 // Only show if NFC is on and we have the HCE feature
1100 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1101 if (!adapter.isEnabled() || !getPackageManager().hasSystemFeature(
1102 PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
1103 category.removeTile(n);
1104 }
1105 }
Fabrice Di Meglio488cae32014-05-13 11:26:34 -07001106 } else if (id == R.id.print_settings) {
1107 boolean hasPrintingSupport = getPackageManager().hasSystemFeature(
1108 PackageManager.FEATURE_PRINTING);
1109 if (!hasPrintingSupport) {
1110 category.removeTile(n);
1111 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001112 } else if (id == R.id.development_settings) {
Julia Reynolds6c088cb2014-05-08 09:29:41 -04001113 if (!showDev || um.hasUserRestriction(
1114 UserManager.DISALLOW_DEBUGGING_FEATURES)) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001115 category.removeTile(n);
1116 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001117 }
1118
1119 if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
Amith Yamasania97089d2014-04-30 10:58:09 -07001120 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)
1121 && n < category.getTilesCount()) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001122 category.removeTile(n);
1123 }
1124
1125 n--;
1126 }
1127 }
1128 }
1129
1130 private boolean updateHomeSettingTiles(DashboardTile tile) {
1131 // Once we decide to show Home settings, keep showing it forever
1132 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1133 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1134 return true;
1135 }
1136
1137 try {
1138 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
1139 getPackageManager().getHomeActivities(homeApps);
1140 if (homeApps.size() < 2) {
1141 // When there's only one available home app, omit this settings
1142 // category entirely at the top level UI. If the user just
1143 // uninstalled the penultimate home app candidiate, we also
1144 // now tell them about why they aren't seeing 'Home' in the list.
1145 if (sShowNoHomeNotice) {
1146 sShowNoHomeNotice = false;
1147 NoHomeDialogFragment.show(this);
1148 }
1149 return false;
1150 } else {
1151 // Okay, we're allowing the Home settings category. Tell it, when
1152 // invoked via this front door, that we'll need to be told about the
1153 // case when the user uninstalls all but one home app.
1154 if (tile.fragmentArguments == null) {
1155 tile.fragmentArguments = new Bundle();
1156 }
1157 tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true);
1158 }
1159 } catch (Exception e) {
1160 // Can't look up the home activity; bail on configuring the icon
1161 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1162 }
1163
1164 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1165 return true;
1166 }
1167
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001168 private void getMetaData() {
1169 try {
1170 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1171 PackageManager.GET_META_DATA);
1172 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001173 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1174 } catch (NameNotFoundException nnfe) {
1175 // No recovery
1176 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1177 }
1178 }
1179
1180 // give subclasses access to the Next button
1181 public boolean hasNextButton() {
1182 return mNextButton != null;
1183 }
1184
1185 public Button getNextButton() {
1186 return mNextButton;
1187 }
1188
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001189 @Override
1190 public boolean shouldUpRecreateTask(Intent targetIntent) {
1191 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1192 }
1193
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001194 public static void requestHomeNotice() {
1195 sShowNoHomeNotice = true;
1196 }
1197
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001198 @Override
1199 public boolean onQueryTextSubmit(String query) {
1200 switchToSearchResultsFragmentIfNeeded();
1201 mSearchQuery = query;
1202 return mSearchResultsFragment.onQueryTextSubmit(query);
1203 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001204
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001205 @Override
1206 public boolean onQueryTextChange(String newText) {
1207 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001208 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001209 return false;
1210 }
1211 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001212 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001213
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001214 @Override
1215 public boolean onClose() {
1216 return false;
1217 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001218
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001219 @Override
1220 public boolean onMenuItemActionExpand(MenuItem item) {
1221 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001222 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001223 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001224 return true;
1225 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001226
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001227 @Override
1228 public boolean onMenuItemActionCollapse(MenuItem item) {
1229 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001230 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001231 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001232 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001233 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001234 return true;
1235 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001236
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001237 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001238 if (mSearchResultsFragment != null) {
1239 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001240 }
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001241 Fragment current = getFragmentManager().findFragmentById(R.id.prefs);
1242 if (current != null && current instanceof SearchResultsSummary) {
1243 mSearchResultsFragment = (SearchResultsSummary) current;
1244 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001245 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001246 SearchResultsSummary.class.getName(), null, false, true,
1247 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001248 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001249 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001250 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001251 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001252
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001253 public void needToRevertToInitialFragment() {
1254 mNeedToRevertToInitialFragment = true;
1255 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001256
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001257 private void revertToInitialFragment() {
1258 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001259 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001260 mSearchMenuItemExpanded = false;
1261 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1262 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001263 if (mSearchMenuItem != null) {
1264 mSearchMenuItem.collapseActionView();
1265 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001266 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001267}