blob: 9cce9a102df29a3ebf2dbaf9d01fd5b2a4e8ee3b [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
19import android.accounts.Account;
20import android.accounts.AccountManager;
21import android.accounts.OnAccountsUpdateListener;
22import android.app.ActionBar;
23import android.app.Activity;
24import android.app.Fragment;
25import android.app.FragmentManager;
26import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080027import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070028import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080029import android.content.Context;
30import android.content.Intent;
31import android.content.IntentFilter;
32import android.content.SharedPreferences;
33import android.content.pm.ActivityInfo;
34import android.content.pm.PackageManager;
35import android.content.pm.PackageManager.NameNotFoundException;
36import android.content.pm.ResolveInfo;
37import android.content.res.Configuration;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080038import android.content.res.TypedArray;
39import android.content.res.XmlResourceParser;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080040import android.nfc.NfcAdapter;
41import android.os.Bundle;
42import android.os.Handler;
43import android.os.INetworkManagementService;
44import android.os.Message;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080045import android.os.RemoteException;
46import android.os.ServiceManager;
47import android.os.UserHandle;
48import android.os.UserManager;
49import android.preference.Preference;
50import android.preference.PreferenceFragment;
51import android.preference.PreferenceManager;
52import android.preference.PreferenceScreen;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080053import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070054import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080055import android.util.AttributeSet;
56import android.util.Log;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080057import android.util.TypedValue;
58import android.util.Xml;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070059import android.view.Menu;
60import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080061import android.view.MenuItem;
62import android.view.View;
63import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070064import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080065import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070066import android.widget.SearchView;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040067
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080068import com.android.internal.util.ArrayUtils;
69import com.android.internal.util.XmlUtils;
70import com.android.settings.accessibility.AccessibilitySettings;
71import com.android.settings.accessibility.CaptionPropertiesFragment;
72import com.android.settings.accounts.AccountSyncSettings;
73import com.android.settings.accounts.AuthenticatorHelper;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080074import com.android.settings.accounts.ManageAccountsSettings;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070075import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080076import com.android.settings.applications.ManageApplications;
77import com.android.settings.applications.ProcessStatsUi;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080078import com.android.settings.bluetooth.BluetoothSettings;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -070079import com.android.settings.dashboard.DashboardCategory;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080080import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -070081import com.android.settings.dashboard.DashboardTile;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070082import com.android.settings.dashboard.NoHomeDialogFragment;
83import com.android.settings.dashboard.SearchResultsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080084import com.android.settings.deviceinfo.Memory;
85import com.android.settings.deviceinfo.UsbSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040086import com.android.settings.fuelgauge.BatterySaverSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080087import com.android.settings.fuelgauge.PowerUsageSummary;
Fabrice Di Meglio7a6bfd12014-04-14 19:49:18 -070088import com.android.settings.search.DynamicIndexableContentMonitor;
Fabrice Di Megliofa7dc242014-03-12 19:24:43 -070089import com.android.settings.search.Index;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080090import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
91import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
92import com.android.settings.inputmethod.SpellCheckersSettings;
93import com.android.settings.inputmethod.UserDictionaryList;
94import com.android.settings.location.LocationSettings;
95import com.android.settings.nfc.AndroidBeam;
96import com.android.settings.nfc.PaymentSettings;
John Spurlockc9afadb2014-04-29 18:07:23 -040097import com.android.settings.notification.ConditionProviderSettings;
John Spurlock4a350512014-04-08 14:08:21 -040098import com.android.settings.notification.NotificationAccessSettings;
99import com.android.settings.notification.NotificationSettings;
100import com.android.settings.notification.NotificationStation;
101import com.android.settings.notification.ZenModeSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800102import com.android.settings.print.PrintJobSettingsFragment;
103import com.android.settings.print.PrintSettingsFragment;
104import com.android.settings.tts.TextToSpeechSettings;
105import com.android.settings.users.UserSettings;
106import com.android.settings.vpn2.VpnSettings;
107import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700108import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800109import com.android.settings.wifi.AdvancedWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800110import com.android.settings.wifi.WifiSettings;
111import com.android.settings.wifi.p2p.WifiP2pSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400112
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800113import org.xmlpull.v1.XmlPullParser;
114import org.xmlpull.v1.XmlPullParserException;
115
116import java.io.IOException;
117import java.util.ArrayList;
118import java.util.Collections;
119import java.util.Comparator;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800120import java.util.List;
121
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -0700122import static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700123
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800124public class SettingsActivity extends Activity
125 implements PreferenceManager.OnPreferenceTreeClickListener,
126 PreferenceFragment.OnPreferenceStartFragmentCallback,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700127 ButtonBarHandler, OnAccountsUpdateListener, FragmentManager.OnBackStackChangedListener,
128 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
129 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800130
131 private static final String LOG_TAG = "Settings";
132
133 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700134 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700135 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
136 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700137 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700138 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800139
140 /**
141 * When starting this activity, the invoking Intent can contain this extra
142 * string to specify which fragment should be initially displayed.
143 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
144 * will call isValidFragment() to confirm that the fragment class name is valid for this
145 * activity.
146 */
147 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
148
149 /**
150 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
151 * this extra can also be specified to supply a Bundle of arguments to pass
152 * to that fragment when it is instantiated during the initial creation
153 * of the activity.
154 */
155 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
156
157 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700158 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
159 */
160 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
161
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800162 public static final String BACK_STACK_PREFS = ":settings:prefs";
163
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800164 // extras that allow any preference activity to be launched as part of a wizard
165
166 // show Back and Next buttons? takes boolean parameter
167 // Back will then return RESULT_CANCELED and Next RESULT_OK
168 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
169
170 // add a Skip button?
171 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
172
173 // specify custom text for the Back or Next buttons, or cause a button to not appear
174 // at all by setting it to null
175 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
176 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
177
178 /**
179 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700180 * 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 -0800181 * that fragment.
182 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700183 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700184 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = ":settings:show_fragment_title_resid";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800185
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800186 private static final String META_DATA_KEY_FRAGMENT_CLASS =
187 "com.android.settings.FRAGMENT_CLASS";
188
189 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
190
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700191 private static final String EMPTY_QUERY = "";
192
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800193 private static boolean sShowNoHomeNotice = false;
194
195 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800196
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800197 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700198 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800199
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800200 // Show only these settings for restricted users
201 private int[] SETTINGS_FOR_RESTRICTED = {
202 R.id.wireless_section,
203 R.id.wifi_settings,
204 R.id.bluetooth_settings,
205 R.id.data_usage_settings,
206 R.id.wireless_settings,
207 R.id.device_section,
John Spurlock4e4cdef2014-05-28 09:43:45 -0400208 R.id.notification_settings,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800209 R.id.display_settings,
210 R.id.storage_settings,
211 R.id.application_settings,
212 R.id.battery_settings,
213 R.id.personal_section,
214 R.id.location_settings,
215 R.id.security_settings,
216 R.id.language_settings,
217 R.id.user_settings,
218 R.id.account_settings,
219 R.id.account_add,
220 R.id.system_section,
221 R.id.date_time_settings,
222 R.id.about_settings,
223 R.id.accessibility_settings,
224 R.id.print_settings,
225 R.id.nfc_payment_settings,
Fabrice Di Meglio2858b792014-02-18 19:35:08 -0800226 R.id.home_settings,
227 R.id.dashboard
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800228 };
229
230 private static final String[] ENTRY_FRAGMENTS = {
231 WirelessSettings.class.getName(),
232 WifiSettings.class.getName(),
233 AdvancedWifiSettings.class.getName(),
234 BluetoothSettings.class.getName(),
235 TetherSettings.class.getName(),
236 WifiP2pSettings.class.getName(),
237 VpnSettings.class.getName(),
238 DateTimeSettings.class.getName(),
239 LocalePicker.class.getName(),
240 InputMethodAndLanguageSettings.class.getName(),
241 SpellCheckersSettings.class.getName(),
242 UserDictionaryList.class.getName(),
243 UserDictionarySettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800244 DisplaySettings.class.getName(),
245 DeviceInfoSettings.class.getName(),
246 ManageApplications.class.getName(),
247 ProcessStatsUi.class.getName(),
248 NotificationStation.class.getName(),
249 LocationSettings.class.getName(),
250 SecuritySettings.class.getName(),
251 PrivacySettings.class.getName(),
252 DeviceAdminSettings.class.getName(),
253 AccessibilitySettings.class.getName(),
254 CaptionPropertiesFragment.class.getName(),
255 com.android.settings.accessibility.ToggleInversionPreferenceFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800256 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
257 TextToSpeechSettings.class.getName(),
258 Memory.class.getName(),
259 DevelopmentSettings.class.getName(),
260 UsbSettings.class.getName(),
261 AndroidBeam.class.getName(),
262 WifiDisplaySettings.class.getName(),
263 PowerUsageSummary.class.getName(),
264 AccountSyncSettings.class.getName(),
265 CryptKeeperSettings.class.getName(),
266 DataUsageSummary.class.getName(),
267 DreamSettings.class.getName(),
268 UserSettings.class.getName(),
269 NotificationAccessSettings.class.getName(),
John Spurlockc9afadb2014-04-29 18:07:23 -0400270 ConditionProviderSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800271 ManageAccountsSettings.class.getName(),
272 PrintSettingsFragment.class.getName(),
273 PrintJobSettingsFragment.class.getName(),
274 TrustedCredentialsSettings.class.getName(),
275 PaymentSettings.class.getName(),
276 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700277 ZenModeSettings.class.getName(),
278 NotificationSettings.class.getName(),
279 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
280 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400281 InstalledAppDetails.class.getName(),
282 BatterySaverSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800283 };
284
285 private SharedPreferences mDevelopmentPreferences;
286 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
287
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800288 private AuthenticatorHelper mAuthenticatorHelper;
289 private boolean mListeningToAccountUpdates;
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;
320
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 AuthenticatorHelper getAuthenticatorHelper() {
354 return mAuthenticatorHelper;
355 }
356
357 public List<DashboardCategory> getDashboardCategories() {
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700358 if (mNeedToRebuildCategories || mCategories.size() == 0) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700359 buildDashboardCategories(mCategories);
360 mNeedToRebuildCategories = false;
361 }
362 return mCategories;
363 }
364
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800365 @Override
366 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
367 // Override the fragment title for Wallpaper settings
368 int titleRes = pref.getTitleRes();
369 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
370 titleRes = R.string.wallpaper_settings_fragment_title;
371 } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName())
372 && UserHandle.myUserId() != UserHandle.USER_OWNER) {
373 if (UserManager.get(this).isLinkedUser()) {
374 titleRes = R.string.profile_info_settings_title;
375 } else {
376 titleRes = R.string.user_info_settings_title;
377 }
378 }
379 startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),
380 null, 0);
381 return true;
382 }
383
384 @Override
385 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
386 return false;
387 }
388
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700389 private void invalidateCategories() {
390 if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) {
391 mHandler.sendEmptyMessage(MSG_BUILD_CATEGORIES);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800392 }
393 }
394
395 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800396 public void onConfigurationChanged(Configuration newConfig) {
397 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800398 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800399 }
400
401 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700402 protected void onStart() {
403 super.onStart();
404
405 if (mNeedToRevertToInitialFragment) {
406 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800407 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800408 }
409
410 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700411 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700412 if (!mDisplaySearch) {
413 return false;
414 }
415
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700416 MenuInflater inflater = getMenuInflater();
417 inflater.inflate(R.menu.options_menu, menu);
418
419 // Cache the search query (can be overriden by the OnQueryTextListener)
420 final String query = mSearchQuery;
421
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700422 mSearchMenuItem = menu.findItem(R.id.search);
423 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700424
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700425 if (mSearchMenuItem == null || mSearchView == null) {
426 return false;
427 }
428
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700429 if (mSearchResultsFragment != null) {
430 mSearchResultsFragment.setSearchView(mSearchView);
431 }
432
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700433 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700434 mSearchView.setOnQueryTextListener(this);
435 mSearchView.setOnCloseListener(this);
436
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700437 if (mSearchMenuItemExpanded) {
438 mSearchMenuItem.expandActionView();
439 }
440 mSearchView.setQuery(query, true /* submit */);
441
442 return true;
443 }
444
445 @Override
446 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800447 if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) {
448 getWindow().setUiOptions(getIntent().getIntExtra(EXTRA_UI_OPTIONS, 0));
449 }
Fabrice Di Meglio5ebabfc2014-04-21 09:40:46 -0700450
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800451 mAuthenticatorHelper = new AuthenticatorHelper();
452 mAuthenticatorHelper.updateAuthDescriptions(this);
453 mAuthenticatorHelper.onAccountsUpdated(this, null);
454
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800455 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
456 Context.MODE_PRIVATE);
457
458 getMetaData();
459
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700460 super.onCreate(savedState);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800461
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700462 // Getting Intent properties can only be done after the super.onCreate(...)
463 final String initialFragmentName = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
464
465 mIsShowingDashboard = (initialFragmentName == null);
466
467 final ComponentName cn = getIntent().getComponent();
468 final boolean isShortcut = !cn.getClassName().equals(SubSettings.class.getName());
469
470 // If this is a subsettings (but not a Shortcut) then apply the correct theme for
471 // the ActionBar content inset
472 if (!mIsShowingDashboard && !isShortcut) {
473 setTheme(R.style.Theme_SubSettings);
474 }
475
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800476 setContentView(R.layout.settings_main);
477
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700478 mContent = (ViewGroup) findViewById(R.id.prefs);
479
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800480 getFragmentManager().addOnBackStackChangedListener(this);
481
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700482 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700483 mDisplaySearch = true;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800484
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700485 if (mIsShowingDashboard) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700486 Index.getInstance(getApplicationContext()).update();
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700487 }
488
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700489 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700490 // We are restarting from a previous saved state; used that to initialize, instead
491 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700492 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
493 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800494
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700495 setTitleFromIntent(getIntent());
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800496
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700497 ArrayList<DashboardCategory> categories =
498 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
499 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700500 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700501 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700502 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800503 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700504
505 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700506 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800507 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700508 if (!mIsShowingDashboard) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700509 // No UP nor Search is shown we are launched thru a Settings "shortcut"
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700510 if (isShortcut) {
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700511 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700512 mDisplaySearch = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700513 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700514 setTitleFromIntent(getIntent());
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700515
Fabrice Di Meglio5ebabfc2014-04-21 09:40:46 -0700516 Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700517 switchToFragment(initialFragmentName, initialArguments, true, false,
518 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000519 } else {
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -0700520 // No UP if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700521 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700522 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700523 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700524 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800525 }
526 }
527
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700528 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700529 if (mActionBar != null) {
530 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
531 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
532 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700533 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
534
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800535 // see if we should show Back/Next buttons
536 Intent intent = getIntent();
537 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
538
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700539 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800540 if (buttonBar != null) {
541 buttonBar.setVisibility(View.VISIBLE);
542
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700543 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800544 backButton.setOnClickListener(new OnClickListener() {
545 public void onClick(View v) {
546 setResult(RESULT_CANCELED);
547 finish();
548 }
549 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700550 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800551 skipButton.setOnClickListener(new OnClickListener() {
552 public void onClick(View v) {
553 setResult(RESULT_OK);
554 finish();
555 }
556 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700557 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800558 mNextButton.setOnClickListener(new OnClickListener() {
559 public void onClick(View v) {
560 setResult(RESULT_OK);
561 finish();
562 }
563 });
564
565 // set our various button parameters
566 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
567 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
568 if (TextUtils.isEmpty(buttonText)) {
569 mNextButton.setVisibility(View.GONE);
570 }
571 else {
572 mNextButton.setText(buttonText);
573 }
574 }
575 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
576 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
577 if (TextUtils.isEmpty(buttonText)) {
578 backButton.setVisibility(View.GONE);
579 }
580 else {
581 backButton.setText(buttonText);
582 }
583 }
584 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
585 skipButton.setVisibility(View.VISIBLE);
586 }
587 }
588 }
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800589 }
590
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700591 private void setTitleFromIntent(Intent intent) {
592 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
593 if (initialTitleResId > 0) {
594 mInitialTitle = null;
595 mInitialTitleResId = initialTitleResId;
596 setTitle(mInitialTitleResId);
597 } else {
598 mInitialTitleResId = -1;
599 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
600 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
601 setTitle(mInitialTitle);
602 }
603 }
604
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800605 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800606 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700607 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800608 }
609
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700610 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800611 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700612
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800613 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700614 if (mInitialTitleResId > 0) {
615 setTitle(mInitialTitleResId);
616 } else {
617 setTitle(mInitialTitle);
618 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700619 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800620 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700621
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800622 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
623 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700624
625 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800626 }
627
628 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
629 final CharSequence title;
630 final int titleRes = bse.getBreadCrumbTitleRes();
631 if (titleRes > 0) {
632 title = getText(titleRes);
633 } else {
634 title = bse.getBreadCrumbTitle();
635 }
636 if (title != null) {
637 setTitle(title);
638 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800639 }
640
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800641 @Override
642 protected void onSaveInstanceState(Bundle outState) {
643 super.onSaveInstanceState(outState);
644
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700645 if (mCategories.size() > 0) {
646 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800647 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700648
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700649 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700650 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700651
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700652 if (mDisplaySearch) {
653 // The option menus are created if the ActionBar is visible and they are also created
654 // asynchronously. If you launch Settings with an Intent action like
655 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
656 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
657 // menu item and search view are null.
658 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
659 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700660
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700661 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
662 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
663 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800664 }
665
666 @Override
667 public void onResume() {
668 super.onResume();
669
670 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
671 @Override
672 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Fabrice Di Megliobb051782014-06-04 17:33:25 -0700673 setNeedToRebuildCategories(true);
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700674 invalidateCategories();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800675 }
676 };
677 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
678 mDevelopmentPreferencesListener);
679
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800680 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700681
Svetoslav990159a2014-04-14 17:14:59 -0700682 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700683
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700684 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700685 onQueryTextSubmit(mSearchQuery);
686 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800687 }
688
689 @Override
690 public void onPause() {
691 super.onPause();
692
693 unregisterReceiver(mBatteryInfoReceiver);
694
Svetoslav990159a2014-04-14 17:14:59 -0700695 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800696 }
697
698 @Override
699 public void onDestroy() {
700 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700701
702 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
703 mDevelopmentPreferencesListener);
704 mDevelopmentPreferencesListener = null;
705
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800706 if (mListeningToAccountUpdates) {
707 AccountManager.get(this).removeOnAccountsUpdatedListener(this);
708 }
709 }
710
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800711 protected boolean isValidFragment(String fragmentName) {
712 // Almost all fragments are wrapped in this,
713 // except for a few that have their own activities.
714 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
715 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
716 }
717 return false;
718 }
719
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800720 @Override
721 public Intent getIntent() {
722 Intent superIntent = super.getIntent();
723 String startingFragment = getStartingFragmentClass(superIntent);
724 // This is called from super.onCreate, isMultiPane() is not yet reliable
725 // Do not use onIsHidingHeaders either, which relies itself on this method
726 if (startingFragment != null) {
727 Intent modIntent = new Intent(superIntent);
728 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
729 Bundle args = superIntent.getExtras();
730 if (args != null) {
731 args = new Bundle(args);
732 } else {
733 args = new Bundle();
734 }
735 args.putParcelable("intent", superIntent);
736 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, superIntent.getExtras());
737 return modIntent;
738 }
739 return superIntent;
740 }
741
742 /**
743 * Checks if the component name in the intent is different from the Settings class and
744 * returns the class name to load as a fragment.
745 */
746 private String getStartingFragmentClass(Intent intent) {
747 if (mFragmentClass != null) return mFragmentClass;
748
749 String intentClass = intent.getComponent().getClassName();
750 if (intentClass.equals(getClass().getName())) return null;
751
752 if ("com.android.settings.ManageApplications".equals(intentClass)
753 || "com.android.settings.RunningServices".equals(intentClass)
754 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
755 // Old names of manage apps.
756 intentClass = com.android.settings.applications.ManageApplications.class.getName();
757 }
758
759 return intentClass;
760 }
761
762 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000763 * Start a new fragment containing a preference panel. If the preferences
764 * are being displayed in multi-pane mode, the given fragment class will
765 * be instantiated and placed in the appropriate pane. If running in
766 * single-pane mode, a new activity will be launched in which to show the
767 * fragment.
768 *
769 * @param fragmentClass Full name of the class implementing the fragment.
770 * @param args Any desired arguments to supply to the fragment.
771 * @param titleRes Optional resource identifier of the title of this
772 * fragment.
773 * @param titleText Optional text of the title of this fragment.
774 * @param resultTo Optional fragment that result data should be sent to.
775 * If non-null, resultTo.onActivityResult() will be called when this
776 * preference panel is done. The launched panel must use
777 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
778 * @param resultRequestCode If resultTo is non-null, this is the caller's
779 * request code to be received with the resut.
780 */
781 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700782 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700783 String title = null;
784 if (titleRes < 0) {
785 if (titleText != null) {
786 title = titleText.toString();
787 } else {
788 // There not much we can do in that case
789 title = "";
790 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700791 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700792 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
793 titleRes, title);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000794 }
795
796 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800797 * Called by a preference panel fragment to finish itself.
798 *
799 * @param caller The fragment that is asking to be finished.
800 * @param resultCode Optional result code to send back to the original
801 * launching fragment.
802 * @param resultData Optional result data to send back to the original
803 * launching fragment.
804 */
805 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
806 setResult(resultCode, resultData);
807 }
808
809 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000810 * Start a new fragment.
811 *
812 * @param fragment The fragment to start
813 * @param push If true, the current fragment will be pushed onto the back stack. If false,
814 * the current fragment will be replaced.
815 */
816 public void startPreferenceFragment(Fragment fragment, boolean push) {
817 FragmentTransaction transaction = getFragmentManager().beginTransaction();
818 transaction.replace(R.id.prefs, fragment);
819 if (push) {
820 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
821 transaction.addToBackStack(BACK_STACK_PREFS);
822 } else {
823 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
824 }
825 transaction.commitAllowingStateLoss();
826 }
827
828 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700829 * Switch to a specific Fragment with taking care of validation, Title and BackStack
830 */
831 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700832 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700833 if (validate && !isValidFragment(fragmentName)) {
834 throw new IllegalArgumentException("Invalid fragment for this activity: "
835 + fragmentName);
836 }
837 Fragment f = Fragment.instantiate(this, fragmentName, args);
838 FragmentTransaction transaction = getFragmentManager().beginTransaction();
839 transaction.replace(R.id.prefs, f);
840 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700841 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700842 }
843 if (addToBackStack) {
844 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
845 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700846 if (titleResId > 0) {
847 transaction.setBreadCrumbTitle(titleResId);
848 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700849 transaction.setBreadCrumbTitle(title);
850 }
851 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700852 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700853 return f;
854 }
855
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700856 public void setNeedToRebuildCategories(boolean need) {
857 mNeedToRebuildCategories = need;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700858 }
859
860 /**
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700861 * Called when the activity needs its list of categories/tiles built.
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700862 *
863 * @param categories The list in which to place the tiles categories.
864 */
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700865 private void buildDashboardCategories(List<DashboardCategory> categories) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700866 categories.clear();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700867 loadCategoriesFromResource(R.xml.dashboard_categories, categories);
868 updateTilesList(categories);
869 }
870
871 /**
872 * Parse the given XML file as a categories description, adding each
873 * parsed categories and tiles into the target list.
874 *
875 * @param resid The XML resource to load and parse.
876 * @param target The list in which the parsed categories and tiles should be placed.
877 */
878 private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) {
879 XmlResourceParser parser = null;
880 try {
881 parser = getResources().getXml(resid);
882 AttributeSet attrs = Xml.asAttributeSet(parser);
883
884 int type;
885 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
886 && type != XmlPullParser.START_TAG) {
887 // Parse next until start tag is found
888 }
889
890 String nodeName = parser.getName();
891 if (!"dashboard-categories".equals(nodeName)) {
892 throw new RuntimeException(
893 "XML document must start with <preference-categories> tag; found"
894 + nodeName + " at " + parser.getPositionDescription());
895 }
896
897 Bundle curBundle = null;
898
899 final int outerDepth = parser.getDepth();
900 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
901 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
902 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
903 continue;
904 }
905
906 nodeName = parser.getName();
907 if ("dashboard-category".equals(nodeName)) {
908 DashboardCategory category = new DashboardCategory();
909
910 TypedArray sa = obtainStyledAttributes(
911 attrs, com.android.internal.R.styleable.PreferenceHeader);
912 category.id = sa.getResourceId(
913 com.android.internal.R.styleable.PreferenceHeader_id,
914 (int)DashboardCategory.CAT_ID_UNDEFINED);
915
916 TypedValue tv = sa.peekValue(
917 com.android.internal.R.styleable.PreferenceHeader_title);
918 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
919 if (tv.resourceId != 0) {
920 category.titleRes = tv.resourceId;
921 } else {
922 category.title = tv.string;
923 }
924 }
925 sa.recycle();
926
927 final int innerDepth = parser.getDepth();
928 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
929 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
930 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
931 continue;
932 }
933
934 String innerNodeName = parser.getName();
935 if (innerNodeName.equals("dashboard-tile")) {
936 DashboardTile tile = new DashboardTile();
937
938 sa = obtainStyledAttributes(
939 attrs, com.android.internal.R.styleable.PreferenceHeader);
940 tile.id = sa.getResourceId(
941 com.android.internal.R.styleable.PreferenceHeader_id,
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -0700942 (int)TILE_ID_UNDEFINED);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700943 tv = sa.peekValue(
944 com.android.internal.R.styleable.PreferenceHeader_title);
945 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
946 if (tv.resourceId != 0) {
947 tile.titleRes = tv.resourceId;
948 } else {
949 tile.title = tv.string;
950 }
951 }
952 tv = sa.peekValue(
953 com.android.internal.R.styleable.PreferenceHeader_summary);
954 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
955 if (tv.resourceId != 0) {
956 tile.summaryRes = tv.resourceId;
957 } else {
958 tile.summary = tv.string;
959 }
960 }
961 tile.iconRes = sa.getResourceId(
962 com.android.internal.R.styleable.PreferenceHeader_icon, 0);
963 tile.fragment = sa.getString(
964 com.android.internal.R.styleable.PreferenceHeader_fragment);
965 sa.recycle();
966
967 if (curBundle == null) {
968 curBundle = new Bundle();
969 }
970
971 final int innerDepth2 = parser.getDepth();
972 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
973 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) {
974 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
975 continue;
976 }
977
978 String innerNodeName2 = parser.getName();
979 if (innerNodeName2.equals("extra")) {
980 getResources().parseBundleExtra("extra", attrs, curBundle);
981 XmlUtils.skipCurrentTag(parser);
982
983 } else if (innerNodeName2.equals("intent")) {
984 tile.intent = Intent.parseIntent(getResources(), parser, attrs);
985
986 } else {
987 XmlUtils.skipCurrentTag(parser);
988 }
989 }
990
991 if (curBundle.size() > 0) {
992 tile.fragmentArguments = curBundle;
993 curBundle = null;
994 }
995
996 category.addTile(tile);
997
998 } else {
999 XmlUtils.skipCurrentTag(parser);
1000 }
1001 }
1002
1003 target.add(category);
1004 } else {
1005 XmlUtils.skipCurrentTag(parser);
1006 }
1007 }
1008
1009 } catch (XmlPullParserException e) {
1010 throw new RuntimeException("Error parsing categories", e);
1011 } catch (IOException e) {
1012 throw new RuntimeException("Error parsing categories", e);
1013 } finally {
1014 if (parser != null) parser.close();
1015 }
1016 }
1017
1018 private void updateTilesList(List<DashboardCategory> target) {
1019 final boolean showDev = mDevelopmentPreferences.getBoolean(
1020 DevelopmentSettings.PREF_SHOW,
1021 android.os.Build.TYPE.equals("eng"));
1022
1023 final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
1024
1025 final int size = target.size();
1026 for (int i = 0; i < size; i++) {
1027
1028 DashboardCategory category = target.get(i);
1029
1030 // Ids are integers, so downcasting is ok
1031 int id = (int) category.id;
1032 if (id == R.id.account_settings) {
1033 insertAccountsTiles(category);
1034 continue;
1035 }
1036 int n = category.getTilesCount() - 1;
1037 while (n >= 0) {
1038
1039 DashboardTile tile = category.getTile(n);
1040
1041 id = (int) tile.id;
1042 if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
1043 Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, category, tile);
1044 } else if (id == R.id.wifi_settings) {
1045 // Remove WiFi Settings if WiFi service is not available.
1046 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
1047 category.removeTile(n);
1048 }
1049 } else if (id == R.id.bluetooth_settings) {
1050 // Remove Bluetooth Settings if Bluetooth service is not available.
1051 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
1052 category.removeTile(n);
1053 }
1054 } else if (id == R.id.data_usage_settings) {
1055 // Remove data usage when kernel module not enabled
1056 final INetworkManagementService netManager = INetworkManagementService.Stub
1057 .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
1058 try {
1059 if (!netManager.isBandwidthControlEnabled()) {
1060 category.removeTile(n);
1061 }
1062 } catch (RemoteException e) {
1063 // ignored
1064 }
1065 } else if (id == R.id.battery_settings) {
1066 // Remove battery settings when battery is not available. (e.g. TV)
1067
1068 if (!mBatteryPresent) {
1069 category.removeTile(n);
1070 }
1071 } else if (id == R.id.home_settings) {
1072 if (!updateHomeSettingTiles(tile)) {
1073 category.removeTile(n);
1074 }
1075 } else if (id == R.id.user_settings) {
Amith Yamasani4093e402014-06-06 14:31:37 -07001076 boolean hasMultipleUsers =
1077 ((UserManager) getSystemService(Context.USER_SERVICE))
1078 .getUserCount() > 1;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001079 if (!UserHandle.MU_ENABLED
Amith Yamasani4093e402014-06-06 14:31:37 -07001080 || (!UserManager.supportsMultipleUsers()
1081 && !hasMultipleUsers)
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001082 || Utils.isMonkeyRunning()) {
1083 category.removeTile(n);
1084 }
1085 } else if (id == R.id.nfc_payment_settings) {
1086 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
1087 category.removeTile(n);
1088 } else {
1089 // Only show if NFC is on and we have the HCE feature
1090 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1091 if (!adapter.isEnabled() || !getPackageManager().hasSystemFeature(
1092 PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
1093 category.removeTile(n);
1094 }
1095 }
Fabrice Di Meglio488cae32014-05-13 11:26:34 -07001096 } else if (id == R.id.print_settings) {
1097 boolean hasPrintingSupport = getPackageManager().hasSystemFeature(
1098 PackageManager.FEATURE_PRINTING);
1099 if (!hasPrintingSupport) {
1100 category.removeTile(n);
1101 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001102 } else if (id == R.id.development_settings) {
Julia Reynolds6c088cb2014-05-08 09:29:41 -04001103 if (!showDev || um.hasUserRestriction(
1104 UserManager.DISALLOW_DEBUGGING_FEATURES)) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001105 category.removeTile(n);
1106 }
1107 } else if (id == R.id.account_add) {
1108 if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
1109 category.removeTile(n);
1110 }
1111 }
1112
1113 if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
Amith Yamasania97089d2014-04-30 10:58:09 -07001114 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)
1115 && n < category.getTilesCount()) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001116 category.removeTile(n);
1117 }
1118
1119 n--;
1120 }
1121 }
1122 }
1123
1124 private boolean updateHomeSettingTiles(DashboardTile tile) {
1125 // Once we decide to show Home settings, keep showing it forever
1126 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1127 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1128 return true;
1129 }
1130
1131 try {
1132 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
1133 getPackageManager().getHomeActivities(homeApps);
1134 if (homeApps.size() < 2) {
1135 // When there's only one available home app, omit this settings
1136 // category entirely at the top level UI. If the user just
1137 // uninstalled the penultimate home app candidiate, we also
1138 // now tell them about why they aren't seeing 'Home' in the list.
1139 if (sShowNoHomeNotice) {
1140 sShowNoHomeNotice = false;
1141 NoHomeDialogFragment.show(this);
1142 }
1143 return false;
1144 } else {
1145 // Okay, we're allowing the Home settings category. Tell it, when
1146 // invoked via this front door, that we'll need to be told about the
1147 // case when the user uninstalls all but one home app.
1148 if (tile.fragmentArguments == null) {
1149 tile.fragmentArguments = new Bundle();
1150 }
1151 tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true);
1152 }
1153 } catch (Exception e) {
1154 // Can't look up the home activity; bail on configuring the icon
1155 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1156 }
1157
1158 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1159 return true;
1160 }
1161
1162 private void insertAccountsTiles(DashboardCategory target) {
1163 String[] accountTypes = mAuthenticatorHelper.getEnabledAccountTypes();
1164 List<DashboardTile> dashboardTiles = new ArrayList<DashboardTile>(accountTypes.length);
1165 for (String accountType : accountTypes) {
1166 CharSequence label = mAuthenticatorHelper.getLabelForType(this, accountType);
1167 if (label == null) {
1168 continue;
1169 }
1170
1171 Account[] accounts = AccountManager.get(this).getAccountsByType(accountType);
1172 boolean skipToAccount = accounts.length == 1
1173 && !mAuthenticatorHelper.hasAccountPreferences(accountType);
1174 DashboardTile accountTile = new DashboardTile();
1175 accountTile.title = label;
1176 if (accountTile.extras == null) {
1177 accountTile.extras = new Bundle();
1178 }
1179 if (skipToAccount) {
1180 accountTile.fragment = AccountSyncSettings.class.getName();
1181 accountTile.fragmentArguments = new Bundle();
1182 // Need this for the icon
1183 accountTile.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType);
1184 accountTile.extras.putParcelable(AccountSyncSettings.ACCOUNT_KEY, accounts[0]);
1185 accountTile.fragmentArguments.putParcelable(AccountSyncSettings.ACCOUNT_KEY,
1186 accounts[0]);
1187 } else {
1188 accountTile.fragment = ManageAccountsSettings.class.getName();
1189 accountTile.fragmentArguments = new Bundle();
1190 accountTile.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType);
1191 accountTile.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE,
1192 accountType);
1193 accountTile.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL,
1194 label.toString());
1195 }
1196 dashboardTiles.add(accountTile);
1197 mAuthenticatorHelper.preloadDrawableForType(this, accountType);
1198 }
1199
1200 // Sort by label
1201 Collections.sort(dashboardTiles, new Comparator<DashboardTile>() {
1202 @Override
1203 public int compare(DashboardTile t1, DashboardTile t2) {
1204 return t1.title.toString().compareTo(t2.title.toString());
1205 }
1206 });
1207 int index = 0;
1208 for (DashboardTile tile : dashboardTiles) {
1209 target.addTile(index, tile);
1210 index++;
1211 }
1212 if (!mListeningToAccountUpdates) {
1213 AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true);
1214 mListeningToAccountUpdates = true;
1215 }
1216 }
1217
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001218 private void getMetaData() {
1219 try {
1220 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1221 PackageManager.GET_META_DATA);
1222 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001223 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1224 } catch (NameNotFoundException nnfe) {
1225 // No recovery
1226 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1227 }
1228 }
1229
1230 // give subclasses access to the Next button
1231 public boolean hasNextButton() {
1232 return mNextButton != null;
1233 }
1234
1235 public Button getNextButton() {
1236 return mNextButton;
1237 }
1238
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001239 @Override
1240 public boolean shouldUpRecreateTask(Intent targetIntent) {
1241 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1242 }
1243
1244 @Override
1245 public void onAccountsUpdated(Account[] accounts) {
1246 // TODO: watch for package upgrades to invalidate cache; see 7206643
1247 mAuthenticatorHelper.updateAuthDescriptions(this);
1248 mAuthenticatorHelper.onAccountsUpdated(this, accounts);
Fabrice Di Meglio769630c2014-04-24 14:48:48 -07001249 invalidateCategories();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001250 }
1251
1252 public static void requestHomeNotice() {
1253 sShowNoHomeNotice = true;
1254 }
1255
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001256 @Override
1257 public boolean onQueryTextSubmit(String query) {
1258 switchToSearchResultsFragmentIfNeeded();
1259 mSearchQuery = query;
1260 return mSearchResultsFragment.onQueryTextSubmit(query);
1261 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001262
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001263 @Override
1264 public boolean onQueryTextChange(String newText) {
1265 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001266 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001267 return false;
1268 }
1269 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001270 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001271
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001272 @Override
1273 public boolean onClose() {
1274 return false;
1275 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001276
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001277 @Override
1278 public boolean onMenuItemActionExpand(MenuItem item) {
1279 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001280 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001281 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001282 return true;
1283 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001284
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001285 @Override
1286 public boolean onMenuItemActionCollapse(MenuItem item) {
1287 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001288 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001289 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001290 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001291 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001292 return true;
1293 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001294
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001295 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001296 if (mSearchResultsFragment != null) {
1297 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001298 }
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001299 Fragment current = getFragmentManager().findFragmentById(R.id.prefs);
1300 if (current != null && current instanceof SearchResultsSummary) {
1301 mSearchResultsFragment = (SearchResultsSummary) current;
1302 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001303 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001304 SearchResultsSummary.class.getName(), null, false, true,
1305 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001306 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001307 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001308 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001309 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001310
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001311 public void needToRevertToInitialFragment() {
1312 mNeedToRevertToInitialFragment = true;
1313 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001314
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001315 private void revertToInitialFragment() {
1316 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001317 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001318 mSearchMenuItemExpanded = false;
1319 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1320 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001321 if (mSearchMenuItem != null) {
1322 mSearchMenuItem.collapseActionView();
1323 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001324 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001325}