blob: 751d478f978dcdc6bb2eb836330d6b15d877be86 [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 Megliodcf59dd2014-07-21 11:22:20 -070084import com.android.settings.notification.AppNotificationSettings;
85import com.android.settings.notification.OtherSoundSettings;
Fabrice Di Meglio7a6bfd12014-04-14 19:49:18 -070086import com.android.settings.search.DynamicIndexableContentMonitor;
Fabrice Di Megliofa7dc242014-03-12 19:24:43 -070087import com.android.settings.search.Index;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080088import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
89import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
90import com.android.settings.inputmethod.SpellCheckersSettings;
91import com.android.settings.inputmethod.UserDictionaryList;
92import com.android.settings.location.LocationSettings;
93import com.android.settings.nfc.AndroidBeam;
94import com.android.settings.nfc.PaymentSettings;
John Spurlockc9afadb2014-04-29 18:07:23 -040095import com.android.settings.notification.ConditionProviderSettings;
John Spurlock4a350512014-04-08 14:08:21 -040096import com.android.settings.notification.NotificationAccessSettings;
97import com.android.settings.notification.NotificationSettings;
98import com.android.settings.notification.NotificationStation;
99import com.android.settings.notification.ZenModeSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800100import com.android.settings.print.PrintJobSettingsFragment;
101import com.android.settings.print.PrintSettingsFragment;
102import com.android.settings.tts.TextToSpeechSettings;
103import com.android.settings.users.UserSettings;
104import com.android.settings.vpn2.VpnSettings;
105import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700106import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800107import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700108import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800109import com.android.settings.wifi.WifiSettings;
110import com.android.settings.wifi.p2p.WifiP2pSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400111
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800112import org.xmlpull.v1.XmlPullParser;
113import org.xmlpull.v1.XmlPullParserException;
114
115import java.io.IOException;
116import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800117import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700118import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800119
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -0700120import static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700121
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800122public class SettingsActivity extends Activity
123 implements PreferenceManager.OnPreferenceTreeClickListener,
124 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100125 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700126 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100127 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800128
129 private static final String LOG_TAG = "Settings";
130
131 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700132 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700133 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
134 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700135 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700136 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800137
138 /**
139 * When starting this activity, the invoking Intent can contain this extra
140 * string to specify which fragment should be initially displayed.
141 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
142 * will call isValidFragment() to confirm that the fragment class name is valid for this
143 * activity.
144 */
145 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
146
147 /**
148 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
149 * this extra can also be specified to supply a Bundle of arguments to pass
150 * to that fragment when it is instantiated during the initial creation
151 * of the activity.
152 */
153 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
154
155 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700156 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
157 */
158 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
159
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800160 public static final String BACK_STACK_PREFS = ":settings:prefs";
161
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800162 // extras that allow any preference activity to be launched as part of a wizard
163
164 // show Back and Next buttons? takes boolean parameter
165 // Back will then return RESULT_CANCELED and Next RESULT_OK
166 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
167
168 // add a Skip button?
169 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
170
171 // specify custom text for the Back or Next buttons, or cause a button to not appear
172 // at all by setting it to null
173 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
174 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
175
176 /**
177 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700178 * 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 -0800179 * that fragment.
180 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700181 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700182 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = ":settings:show_fragment_title_resid";
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700183 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT = ":settings:show_fragment_as_shortcut";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800184
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800185 private static final String META_DATA_KEY_FRAGMENT_CLASS =
186 "com.android.settings.FRAGMENT_CLASS";
187
188 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
189
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700190 private static final String EMPTY_QUERY = "";
191
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800192 private static boolean sShowNoHomeNotice = false;
193
194 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800195
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800196 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700197 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800198
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800199 // Show only these settings for restricted users
200 private int[] SETTINGS_FOR_RESTRICTED = {
201 R.id.wireless_section,
202 R.id.wifi_settings,
203 R.id.bluetooth_settings,
204 R.id.data_usage_settings,
205 R.id.wireless_settings,
206 R.id.device_section,
John Spurlock4e4cdef2014-05-28 09:43:45 -0400207 R.id.notification_settings,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800208 R.id.display_settings,
209 R.id.storage_settings,
210 R.id.application_settings,
211 R.id.battery_settings,
212 R.id.personal_section,
213 R.id.location_settings,
214 R.id.security_settings,
215 R.id.language_settings,
216 R.id.user_settings,
217 R.id.account_settings,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800218 R.id.system_section,
219 R.id.date_time_settings,
220 R.id.about_settings,
221 R.id.accessibility_settings,
222 R.id.print_settings,
223 R.id.nfc_payment_settings,
Fabrice Di Meglio2858b792014-02-18 19:35:08 -0800224 R.id.home_settings,
225 R.id.dashboard
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800226 };
227
228 private static final String[] ENTRY_FRAGMENTS = {
229 WirelessSettings.class.getName(),
230 WifiSettings.class.getName(),
231 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700232 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800233 BluetoothSettings.class.getName(),
PauloftheWestc9dc66d2014-07-01 05:19:58 -0700234 MessageAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800235 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(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700244 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800245 DisplaySettings.class.getName(),
246 DeviceInfoSettings.class.getName(),
247 ManageApplications.class.getName(),
248 ProcessStatsUi.class.getName(),
249 NotificationStation.class.getName(),
250 LocationSettings.class.getName(),
251 SecuritySettings.class.getName(),
252 PrivacySettings.class.getName(),
253 DeviceAdminSettings.class.getName(),
254 AccessibilitySettings.class.getName(),
255 CaptionPropertiesFragment.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 PrintSettingsFragment.class.getName(),
272 PrintJobSettingsFragment.class.getName(),
273 TrustedCredentialsSettings.class.getName(),
274 PaymentSettings.class.getName(),
275 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700276 ZenModeSettings.class.getName(),
277 NotificationSettings.class.getName(),
278 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
279 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400280 InstalledAppDetails.class.getName(),
281 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700282 AppNotificationSettings.class.getName(),
283 OtherSoundSettings.class.getName()
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800284 };
285
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700286
287 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
288 "android.settings.APPLICATION_DETAILS_SETTINGS"
289 };
290
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800291 private SharedPreferences mDevelopmentPreferences;
292 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
293
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800294 private boolean mBatteryPresent = true;
295 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
296
297 @Override
298 public void onReceive(Context context, Intent intent) {
299 String action = intent.getAction();
300 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
301 boolean batteryPresent = Utils.isBatteryPresent(intent);
302
303 if (mBatteryPresent != batteryPresent) {
304 mBatteryPresent = batteryPresent;
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700305 invalidateCategories();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800306 }
307 }
308 }
309 };
310
Svetoslav990159a2014-04-14 17:14:59 -0700311 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
312 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700313
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700314 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700315 private SwitchBar mSwitchBar;
316
317 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700318
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700319 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700320 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700321
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700322 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700323 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700324
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700325 private ViewGroup mContent;
326
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700327 private SearchView mSearchView;
328 private MenuItem mSearchMenuItem;
329 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700330 private SearchResultsSummary mSearchResultsFragment;
331 private String mSearchQuery;
332
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700333 // Categories
334 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
335 private boolean mNeedToRebuildCategories;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800336
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700337 private static final int MSG_BUILD_CATEGORIES = 1;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800338 private Handler mHandler = new Handler() {
339 @Override
340 public void handleMessage(Message msg) {
341 switch (msg.what) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700342 case MSG_BUILD_CATEGORIES: {
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700343 if(mNeedToRebuildCategories) {
344 buildDashboardCategories(mCategories);
345 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800346 } break;
347 }
348 }
349 };
350
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700351 private boolean mNeedToRevertToInitialFragment = false;
352
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700353 public SwitchBar getSwitchBar() {
354 return mSwitchBar;
355 }
356
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700357 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
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700445 private static boolean isShortCutIntent(final Intent intent) {
446 Set<String> categories = intent.getCategories();
447 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
448 }
449
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700450 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700451 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700452 if (action == null) {
453 return false;
454 }
455 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
456 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
457 }
458 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700459 }
460
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700461 @Override
462 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700463 super.onCreate(savedState);
464
465 // Should happen before any call to getIntent()
466 getMetaData();
467
468 final Intent intent = getIntent();
469 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
470 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800471 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800472
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800473 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
474 Context.MODE_PRIVATE);
475
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700476 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700477 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700478
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700479 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700480 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
481
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700482 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700483 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700484
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700485 mIsShowingDashboard = className.equals(Settings.class.getName());
486 final boolean isSubSettings = className.equals(SubSettings.class.getName());
487
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700488 // If this is a sub settings or not the main Dashboard and not a Shortcut and an initial
489 // Fragment then apply the SubSettings theme for the ActionBar content insets
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700490 if (isSubSettings ||
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700491 (!mIsShowingDashboard && !mIsShortcut && (initialFragmentName != null))) {
492 // Check also that we are not a Theme Dialog as we don't want to override them
493 final int themeResId = getThemeResId();
494 if (themeResId != R.style.Theme_DialogWhenLarge &&
495 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
496 setTheme(R.style.Theme_SubSettings);
497 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700498 }
499
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700500 setContentView(mIsShowingDashboard ?
501 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800502
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700503 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700504
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800505 getFragmentManager().addOnBackStackChangedListener(this);
506
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700507 if (mIsShowingDashboard) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700508 Index.getInstance(getApplicationContext()).update();
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700509 }
510
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700511 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700512 // We are restarting from a previous saved state; used that to initialize, instead
513 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700514 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
515 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800516
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700517 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800518
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700519 ArrayList<DashboardCategory> categories =
520 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
521 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700522 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700523 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700524 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800525 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700526
527 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700528 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800529 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700530 if (!mIsShowingDashboard) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700531 // Search is shown we are launched thru a Settings "shortcut". UP will be shown
532 // only if it is a sub settings
533 if (mIsShortcut) {
534 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700535 mDisplaySearch = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700536 } else if (isSubSettings) {
537 mDisplayHomeAsUpEnabled = true;
538 mDisplaySearch = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700539 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700540 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700541
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700542 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700543 switchToFragment(initialFragmentName, initialArguments, true, false,
544 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000545 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700546 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700547 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700548 // Show Search affordance
549 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700550 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700551 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700552 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800553 }
554 }
555
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700556 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700557 if (mActionBar != null) {
558 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
559 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
560 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700561 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
562
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800563 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800564 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
565
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700566 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800567 if (buttonBar != null) {
568 buttonBar.setVisibility(View.VISIBLE);
569
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700570 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800571 backButton.setOnClickListener(new OnClickListener() {
572 public void onClick(View v) {
573 setResult(RESULT_CANCELED);
574 finish();
575 }
576 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700577 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800578 skipButton.setOnClickListener(new OnClickListener() {
579 public void onClick(View v) {
580 setResult(RESULT_OK);
581 finish();
582 }
583 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700584 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800585 mNextButton.setOnClickListener(new OnClickListener() {
586 public void onClick(View v) {
587 setResult(RESULT_OK);
588 finish();
589 }
590 });
591
592 // set our various button parameters
593 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
594 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
595 if (TextUtils.isEmpty(buttonText)) {
596 mNextButton.setVisibility(View.GONE);
597 }
598 else {
599 mNextButton.setText(buttonText);
600 }
601 }
602 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
603 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
604 if (TextUtils.isEmpty(buttonText)) {
605 backButton.setVisibility(View.GONE);
606 }
607 else {
608 backButton.setText(buttonText);
609 }
610 }
611 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
612 skipButton.setVisibility(View.VISIBLE);
613 }
614 }
615 }
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800616 }
617
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700618 private void setTitleFromIntent(Intent intent) {
619 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
620 if (initialTitleResId > 0) {
621 mInitialTitle = null;
622 mInitialTitleResId = initialTitleResId;
623 setTitle(mInitialTitleResId);
624 } else {
625 mInitialTitleResId = -1;
626 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
627 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
628 setTitle(mInitialTitle);
629 }
630 }
631
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800632 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800633 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700634 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800635 }
636
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700637 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800638 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700639
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800640 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700641 if (mInitialTitleResId > 0) {
642 setTitle(mInitialTitleResId);
643 } else {
644 setTitle(mInitialTitle);
645 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700646 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800647 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700648
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800649 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
650 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700651
652 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800653 }
654
655 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
656 final CharSequence title;
657 final int titleRes = bse.getBreadCrumbTitleRes();
658 if (titleRes > 0) {
659 title = getText(titleRes);
660 } else {
661 title = bse.getBreadCrumbTitle();
662 }
663 if (title != null) {
664 setTitle(title);
665 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800666 }
667
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800668 @Override
669 protected void onSaveInstanceState(Bundle outState) {
670 super.onSaveInstanceState(outState);
671
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700672 if (mCategories.size() > 0) {
673 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800674 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700675
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700676 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700677 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700678
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700679 if (mDisplaySearch) {
680 // The option menus are created if the ActionBar is visible and they are also created
681 // asynchronously. If you launch Settings with an Intent action like
682 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
683 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
684 // menu item and search view are null.
685 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
686 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700687
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700688 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
689 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
690 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800691 }
692
693 @Override
694 public void onResume() {
695 super.onResume();
696
697 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
698 @Override
699 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Fabrice Di Megliobb051782014-06-04 17:33:25 -0700700 setNeedToRebuildCategories(true);
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700701 invalidateCategories();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800702 }
703 };
704 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
705 mDevelopmentPreferencesListener);
706
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800707 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700708
Svetoslav990159a2014-04-14 17:14:59 -0700709 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700710
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700711 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700712 onQueryTextSubmit(mSearchQuery);
713 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800714 }
715
716 @Override
717 public void onPause() {
718 super.onPause();
719
720 unregisterReceiver(mBatteryInfoReceiver);
721
Svetoslav990159a2014-04-14 17:14:59 -0700722 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800723 }
724
725 @Override
726 public void onDestroy() {
727 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700728
729 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
730 mDevelopmentPreferencesListener);
731 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800732 }
733
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800734 protected boolean isValidFragment(String fragmentName) {
735 // Almost all fragments are wrapped in this,
736 // except for a few that have their own activities.
737 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
738 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
739 }
740 return false;
741 }
742
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800743 @Override
744 public Intent getIntent() {
745 Intent superIntent = super.getIntent();
746 String startingFragment = getStartingFragmentClass(superIntent);
747 // This is called from super.onCreate, isMultiPane() is not yet reliable
748 // Do not use onIsHidingHeaders either, which relies itself on this method
749 if (startingFragment != null) {
750 Intent modIntent = new Intent(superIntent);
751 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
752 Bundle args = superIntent.getExtras();
753 if (args != null) {
754 args = new Bundle(args);
755 } else {
756 args = new Bundle();
757 }
758 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100759 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800760 return modIntent;
761 }
762 return superIntent;
763 }
764
765 /**
766 * Checks if the component name in the intent is different from the Settings class and
767 * returns the class name to load as a fragment.
768 */
769 private String getStartingFragmentClass(Intent intent) {
770 if (mFragmentClass != null) return mFragmentClass;
771
772 String intentClass = intent.getComponent().getClassName();
773 if (intentClass.equals(getClass().getName())) return null;
774
775 if ("com.android.settings.ManageApplications".equals(intentClass)
776 || "com.android.settings.RunningServices".equals(intentClass)
777 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
778 // Old names of manage apps.
779 intentClass = com.android.settings.applications.ManageApplications.class.getName();
780 }
781
782 return intentClass;
783 }
784
785 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000786 * Start a new fragment containing a preference panel. If the preferences
787 * are being displayed in multi-pane mode, the given fragment class will
788 * be instantiated and placed in the appropriate pane. If running in
789 * single-pane mode, a new activity will be launched in which to show the
790 * fragment.
791 *
792 * @param fragmentClass Full name of the class implementing the fragment.
793 * @param args Any desired arguments to supply to the fragment.
794 * @param titleRes Optional resource identifier of the title of this
795 * fragment.
796 * @param titleText Optional text of the title of this fragment.
797 * @param resultTo Optional fragment that result data should be sent to.
798 * If non-null, resultTo.onActivityResult() will be called when this
799 * preference panel is done. The launched panel must use
800 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
801 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700802 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000803 */
804 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700805 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700806 String title = null;
807 if (titleRes < 0) {
808 if (titleText != null) {
809 title = titleText.toString();
810 } else {
811 // There not much we can do in that case
812 title = "";
813 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700814 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700815 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700816 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000817 }
818
819 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800820 * Called by a preference panel fragment to finish itself.
821 *
822 * @param caller The fragment that is asking to be finished.
823 * @param resultCode Optional result code to send back to the original
824 * launching fragment.
825 * @param resultData Optional result data to send back to the original
826 * launching fragment.
827 */
828 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
829 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700830 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800831 }
832
833 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000834 * Start a new fragment.
835 *
836 * @param fragment The fragment to start
837 * @param push If true, the current fragment will be pushed onto the back stack. If false,
838 * the current fragment will be replaced.
839 */
840 public void startPreferenceFragment(Fragment fragment, boolean push) {
841 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700842 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000843 if (push) {
844 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
845 transaction.addToBackStack(BACK_STACK_PREFS);
846 } else {
847 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
848 }
849 transaction.commitAllowingStateLoss();
850 }
851
852 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700853 * Switch to a specific Fragment with taking care of validation, Title and BackStack
854 */
855 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700856 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700857 if (validate && !isValidFragment(fragmentName)) {
858 throw new IllegalArgumentException("Invalid fragment for this activity: "
859 + fragmentName);
860 }
861 Fragment f = Fragment.instantiate(this, fragmentName, args);
862 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700863 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700864 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700865 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700866 }
867 if (addToBackStack) {
868 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
869 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700870 if (titleResId > 0) {
871 transaction.setBreadCrumbTitle(titleResId);
872 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700873 transaction.setBreadCrumbTitle(title);
874 }
875 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700876 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700877 return f;
878 }
879
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700880 public void setNeedToRebuildCategories(boolean need) {
881 mNeedToRebuildCategories = need;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700882 }
883
884 /**
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700885 * Called when the activity needs its list of categories/tiles built.
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700886 *
887 * @param categories The list in which to place the tiles categories.
888 */
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700889 private void buildDashboardCategories(List<DashboardCategory> categories) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700890 categories.clear();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700891 loadCategoriesFromResource(R.xml.dashboard_categories, categories);
892 updateTilesList(categories);
893 }
894
895 /**
896 * Parse the given XML file as a categories description, adding each
897 * parsed categories and tiles into the target list.
898 *
899 * @param resid The XML resource to load and parse.
900 * @param target The list in which the parsed categories and tiles should be placed.
901 */
902 private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) {
903 XmlResourceParser parser = null;
904 try {
905 parser = getResources().getXml(resid);
906 AttributeSet attrs = Xml.asAttributeSet(parser);
907
908 int type;
909 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
910 && type != XmlPullParser.START_TAG) {
911 // Parse next until start tag is found
912 }
913
914 String nodeName = parser.getName();
915 if (!"dashboard-categories".equals(nodeName)) {
916 throw new RuntimeException(
917 "XML document must start with <preference-categories> tag; found"
918 + nodeName + " at " + parser.getPositionDescription());
919 }
920
921 Bundle curBundle = null;
922
923 final int outerDepth = parser.getDepth();
924 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
925 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
926 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
927 continue;
928 }
929
930 nodeName = parser.getName();
931 if ("dashboard-category".equals(nodeName)) {
932 DashboardCategory category = new DashboardCategory();
933
934 TypedArray sa = obtainStyledAttributes(
935 attrs, com.android.internal.R.styleable.PreferenceHeader);
936 category.id = sa.getResourceId(
937 com.android.internal.R.styleable.PreferenceHeader_id,
938 (int)DashboardCategory.CAT_ID_UNDEFINED);
939
940 TypedValue tv = sa.peekValue(
941 com.android.internal.R.styleable.PreferenceHeader_title);
942 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
943 if (tv.resourceId != 0) {
944 category.titleRes = tv.resourceId;
945 } else {
946 category.title = tv.string;
947 }
948 }
949 sa.recycle();
950
951 final int innerDepth = parser.getDepth();
952 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
953 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
954 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
955 continue;
956 }
957
958 String innerNodeName = parser.getName();
959 if (innerNodeName.equals("dashboard-tile")) {
960 DashboardTile tile = new DashboardTile();
961
962 sa = obtainStyledAttributes(
963 attrs, com.android.internal.R.styleable.PreferenceHeader);
964 tile.id = sa.getResourceId(
965 com.android.internal.R.styleable.PreferenceHeader_id,
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -0700966 (int)TILE_ID_UNDEFINED);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700967 tv = sa.peekValue(
968 com.android.internal.R.styleable.PreferenceHeader_title);
969 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
970 if (tv.resourceId != 0) {
971 tile.titleRes = tv.resourceId;
972 } else {
973 tile.title = tv.string;
974 }
975 }
976 tv = sa.peekValue(
977 com.android.internal.R.styleable.PreferenceHeader_summary);
978 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
979 if (tv.resourceId != 0) {
980 tile.summaryRes = tv.resourceId;
981 } else {
982 tile.summary = tv.string;
983 }
984 }
985 tile.iconRes = sa.getResourceId(
986 com.android.internal.R.styleable.PreferenceHeader_icon, 0);
987 tile.fragment = sa.getString(
988 com.android.internal.R.styleable.PreferenceHeader_fragment);
989 sa.recycle();
990
991 if (curBundle == null) {
992 curBundle = new Bundle();
993 }
994
995 final int innerDepth2 = parser.getDepth();
996 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
997 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) {
998 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
999 continue;
1000 }
1001
1002 String innerNodeName2 = parser.getName();
1003 if (innerNodeName2.equals("extra")) {
1004 getResources().parseBundleExtra("extra", attrs, curBundle);
1005 XmlUtils.skipCurrentTag(parser);
1006
1007 } else if (innerNodeName2.equals("intent")) {
1008 tile.intent = Intent.parseIntent(getResources(), parser, attrs);
1009
1010 } else {
1011 XmlUtils.skipCurrentTag(parser);
1012 }
1013 }
1014
1015 if (curBundle.size() > 0) {
1016 tile.fragmentArguments = curBundle;
1017 curBundle = null;
1018 }
1019
1020 category.addTile(tile);
1021
1022 } else {
1023 XmlUtils.skipCurrentTag(parser);
1024 }
1025 }
1026
1027 target.add(category);
1028 } else {
1029 XmlUtils.skipCurrentTag(parser);
1030 }
1031 }
1032
1033 } catch (XmlPullParserException e) {
1034 throw new RuntimeException("Error parsing categories", e);
1035 } catch (IOException e) {
1036 throw new RuntimeException("Error parsing categories", e);
1037 } finally {
1038 if (parser != null) parser.close();
1039 }
1040 }
1041
1042 private void updateTilesList(List<DashboardCategory> target) {
1043 final boolean showDev = mDevelopmentPreferences.getBoolean(
1044 DevelopmentSettings.PREF_SHOW,
1045 android.os.Build.TYPE.equals("eng"));
1046
1047 final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
1048
1049 final int size = target.size();
1050 for (int i = 0; i < size; i++) {
1051
1052 DashboardCategory category = target.get(i);
1053
1054 // Ids are integers, so downcasting is ok
1055 int id = (int) category.id;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001056 int n = category.getTilesCount() - 1;
1057 while (n >= 0) {
1058
1059 DashboardTile tile = category.getTile(n);
1060
1061 id = (int) tile.id;
1062 if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
1063 Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, category, tile);
1064 } else if (id == R.id.wifi_settings) {
1065 // Remove WiFi Settings if WiFi service is not available.
1066 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
1067 category.removeTile(n);
1068 }
1069 } else if (id == R.id.bluetooth_settings) {
1070 // Remove Bluetooth Settings if Bluetooth service is not available.
1071 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
1072 category.removeTile(n);
1073 }
1074 } else if (id == R.id.data_usage_settings) {
1075 // Remove data usage when kernel module not enabled
1076 final INetworkManagementService netManager = INetworkManagementService.Stub
1077 .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
1078 try {
1079 if (!netManager.isBandwidthControlEnabled()) {
1080 category.removeTile(n);
1081 }
1082 } catch (RemoteException e) {
1083 // ignored
1084 }
1085 } else if (id == R.id.battery_settings) {
1086 // Remove battery settings when battery is not available. (e.g. TV)
1087
1088 if (!mBatteryPresent) {
1089 category.removeTile(n);
1090 }
1091 } else if (id == R.id.home_settings) {
1092 if (!updateHomeSettingTiles(tile)) {
1093 category.removeTile(n);
1094 }
1095 } else if (id == R.id.user_settings) {
Amith Yamasani4093e402014-06-06 14:31:37 -07001096 boolean hasMultipleUsers =
1097 ((UserManager) getSystemService(Context.USER_SERVICE))
1098 .getUserCount() > 1;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001099 if (!UserHandle.MU_ENABLED
Amith Yamasani4093e402014-06-06 14:31:37 -07001100 || (!UserManager.supportsMultipleUsers()
1101 && !hasMultipleUsers)
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001102 || Utils.isMonkeyRunning()) {
1103 category.removeTile(n);
1104 }
1105 } else if (id == R.id.nfc_payment_settings) {
1106 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
1107 category.removeTile(n);
1108 } else {
1109 // Only show if NFC is on and we have the HCE feature
1110 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1111 if (!adapter.isEnabled() || !getPackageManager().hasSystemFeature(
1112 PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
1113 category.removeTile(n);
1114 }
1115 }
Fabrice Di Meglio488cae32014-05-13 11:26:34 -07001116 } else if (id == R.id.print_settings) {
1117 boolean hasPrintingSupport = getPackageManager().hasSystemFeature(
1118 PackageManager.FEATURE_PRINTING);
1119 if (!hasPrintingSupport) {
1120 category.removeTile(n);
1121 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001122 } else if (id == R.id.development_settings) {
Julia Reynolds6c088cb2014-05-08 09:29:41 -04001123 if (!showDev || um.hasUserRestriction(
1124 UserManager.DISALLOW_DEBUGGING_FEATURES)) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001125 category.removeTile(n);
1126 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001127 }
1128
1129 if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
Amith Yamasania97089d2014-04-30 10:58:09 -07001130 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)
1131 && n < category.getTilesCount()) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001132 category.removeTile(n);
1133 }
1134
1135 n--;
1136 }
1137 }
1138 }
1139
1140 private boolean updateHomeSettingTiles(DashboardTile tile) {
1141 // Once we decide to show Home settings, keep showing it forever
1142 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1143 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1144 return true;
1145 }
1146
1147 try {
1148 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
1149 getPackageManager().getHomeActivities(homeApps);
1150 if (homeApps.size() < 2) {
1151 // When there's only one available home app, omit this settings
1152 // category entirely at the top level UI. If the user just
1153 // uninstalled the penultimate home app candidiate, we also
1154 // now tell them about why they aren't seeing 'Home' in the list.
1155 if (sShowNoHomeNotice) {
1156 sShowNoHomeNotice = false;
1157 NoHomeDialogFragment.show(this);
1158 }
1159 return false;
1160 } else {
1161 // Okay, we're allowing the Home settings category. Tell it, when
1162 // invoked via this front door, that we'll need to be told about the
1163 // case when the user uninstalls all but one home app.
1164 if (tile.fragmentArguments == null) {
1165 tile.fragmentArguments = new Bundle();
1166 }
1167 tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true);
1168 }
1169 } catch (Exception e) {
1170 // Can't look up the home activity; bail on configuring the icon
1171 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1172 }
1173
1174 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1175 return true;
1176 }
1177
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001178 private void getMetaData() {
1179 try {
1180 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1181 PackageManager.GET_META_DATA);
1182 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001183 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1184 } catch (NameNotFoundException nnfe) {
1185 // No recovery
1186 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1187 }
1188 }
1189
1190 // give subclasses access to the Next button
1191 public boolean hasNextButton() {
1192 return mNextButton != null;
1193 }
1194
1195 public Button getNextButton() {
1196 return mNextButton;
1197 }
1198
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001199 @Override
1200 public boolean shouldUpRecreateTask(Intent targetIntent) {
1201 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1202 }
1203
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001204 public static void requestHomeNotice() {
1205 sShowNoHomeNotice = true;
1206 }
1207
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001208 @Override
1209 public boolean onQueryTextSubmit(String query) {
1210 switchToSearchResultsFragmentIfNeeded();
1211 mSearchQuery = query;
1212 return mSearchResultsFragment.onQueryTextSubmit(query);
1213 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001214
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001215 @Override
1216 public boolean onQueryTextChange(String newText) {
1217 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001218 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001219 return false;
1220 }
1221 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001222 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001223
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001224 @Override
1225 public boolean onClose() {
1226 return false;
1227 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001228
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001229 @Override
1230 public boolean onMenuItemActionExpand(MenuItem item) {
1231 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001232 switchToSearchResultsFragmentIfNeeded();
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 @Override
1238 public boolean onMenuItemActionCollapse(MenuItem item) {
1239 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001240 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001241 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001242 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001243 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001244 return true;
1245 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001246
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001247 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001248 if (mSearchResultsFragment != null) {
1249 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001250 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001251 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001252 if (current != null && current instanceof SearchResultsSummary) {
1253 mSearchResultsFragment = (SearchResultsSummary) current;
1254 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001255 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001256 SearchResultsSummary.class.getName(), null, false, true,
1257 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001258 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001259 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001260 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001261 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001262
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001263 public void needToRevertToInitialFragment() {
1264 mNeedToRevertToInitialFragment = true;
1265 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001266
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001267 private void revertToInitialFragment() {
1268 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001269 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001270 mSearchMenuItemExpanded = false;
1271 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1272 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001273 if (mSearchMenuItem != null) {
1274 mSearchMenuItem.collapseActionView();
1275 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001276 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001277}