blob: b227c6b930c4f6c49d490eaeb70841de6eccf5ec [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(),
256 com.android.settings.accessibility.ToggleInversionPreferenceFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800257 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
258 TextToSpeechSettings.class.getName(),
259 Memory.class.getName(),
260 DevelopmentSettings.class.getName(),
261 UsbSettings.class.getName(),
262 AndroidBeam.class.getName(),
263 WifiDisplaySettings.class.getName(),
264 PowerUsageSummary.class.getName(),
265 AccountSyncSettings.class.getName(),
266 CryptKeeperSettings.class.getName(),
267 DataUsageSummary.class.getName(),
268 DreamSettings.class.getName(),
269 UserSettings.class.getName(),
270 NotificationAccessSettings.class.getName(),
John Spurlockc9afadb2014-04-29 18:07:23 -0400271 ConditionProviderSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800272 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 Megliodcf59dd2014-07-21 11:22:20 -0700283 AppNotificationSettings.class.getName(),
284 OtherSoundSettings.class.getName()
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800285 };
286
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700287
288 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
289 "android.settings.APPLICATION_DETAILS_SETTINGS"
290 };
291
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800292 private SharedPreferences mDevelopmentPreferences;
293 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
294
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800295 private boolean mBatteryPresent = true;
296 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
297
298 @Override
299 public void onReceive(Context context, Intent intent) {
300 String action = intent.getAction();
301 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
302 boolean batteryPresent = Utils.isBatteryPresent(intent);
303
304 if (mBatteryPresent != batteryPresent) {
305 mBatteryPresent = batteryPresent;
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700306 invalidateCategories();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800307 }
308 }
309 }
310 };
311
Svetoslav990159a2014-04-14 17:14:59 -0700312 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
313 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700314
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700315 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700316 private SwitchBar mSwitchBar;
317
318 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700319
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700320 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700321 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700322
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700323 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700324 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700325
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700326 private ViewGroup mContent;
327
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700328 private SearchView mSearchView;
329 private MenuItem mSearchMenuItem;
330 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700331 private SearchResultsSummary mSearchResultsFragment;
332 private String mSearchQuery;
333
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700334 // Categories
335 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
336 private boolean mNeedToRebuildCategories;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800337
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700338 private static final int MSG_BUILD_CATEGORIES = 1;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800339 private Handler mHandler = new Handler() {
340 @Override
341 public void handleMessage(Message msg) {
342 switch (msg.what) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700343 case MSG_BUILD_CATEGORIES: {
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700344 if(mNeedToRebuildCategories) {
345 buildDashboardCategories(mCategories);
346 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800347 } break;
348 }
349 }
350 };
351
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700352 private boolean mNeedToRevertToInitialFragment = false;
353
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700354 public SwitchBar getSwitchBar() {
355 return mSwitchBar;
356 }
357
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700358 public List<DashboardCategory> getDashboardCategories() {
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700359 if (mNeedToRebuildCategories || mCategories.size() == 0) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700360 buildDashboardCategories(mCategories);
361 mNeedToRebuildCategories = false;
362 }
363 return mCategories;
364 }
365
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800366 @Override
367 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
368 // Override the fragment title for Wallpaper settings
369 int titleRes = pref.getTitleRes();
370 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
371 titleRes = R.string.wallpaper_settings_fragment_title;
372 } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName())
373 && UserHandle.myUserId() != UserHandle.USER_OWNER) {
374 if (UserManager.get(this).isLinkedUser()) {
375 titleRes = R.string.profile_info_settings_title;
376 } else {
377 titleRes = R.string.user_info_settings_title;
378 }
379 }
380 startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),
381 null, 0);
382 return true;
383 }
384
385 @Override
386 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
387 return false;
388 }
389
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700390 private void invalidateCategories() {
391 if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) {
392 mHandler.sendEmptyMessage(MSG_BUILD_CATEGORIES);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800393 }
394 }
395
396 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800397 public void onConfigurationChanged(Configuration newConfig) {
398 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800399 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800400 }
401
402 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700403 protected void onStart() {
404 super.onStart();
405
406 if (mNeedToRevertToInitialFragment) {
407 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800408 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800409 }
410
411 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700412 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700413 if (!mDisplaySearch) {
414 return false;
415 }
416
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700417 MenuInflater inflater = getMenuInflater();
418 inflater.inflate(R.menu.options_menu, menu);
419
420 // Cache the search query (can be overriden by the OnQueryTextListener)
421 final String query = mSearchQuery;
422
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700423 mSearchMenuItem = menu.findItem(R.id.search);
424 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700425
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700426 if (mSearchMenuItem == null || mSearchView == null) {
427 return false;
428 }
429
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700430 if (mSearchResultsFragment != null) {
431 mSearchResultsFragment.setSearchView(mSearchView);
432 }
433
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700434 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700435 mSearchView.setOnQueryTextListener(this);
436 mSearchView.setOnCloseListener(this);
437
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700438 if (mSearchMenuItemExpanded) {
439 mSearchMenuItem.expandActionView();
440 }
441 mSearchView.setQuery(query, true /* submit */);
442
443 return true;
444 }
445
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700446 private static boolean isShortCutIntent(final Intent intent) {
447 Set<String> categories = intent.getCategories();
448 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
449 }
450
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700451 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700452 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700453 if (action == null) {
454 return false;
455 }
456 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
457 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
458 }
459 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700460 }
461
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700462 @Override
463 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700464 super.onCreate(savedState);
465
466 // Should happen before any call to getIntent()
467 getMetaData();
468
469 final Intent intent = getIntent();
470 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
471 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800472 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800473
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800474 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
475 Context.MODE_PRIVATE);
476
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700477 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700478 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700479
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700480 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700481 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
482
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700483 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700484 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700485
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700486 mIsShowingDashboard = className.equals(Settings.class.getName());
487 final boolean isSubSettings = className.equals(SubSettings.class.getName());
488
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700489 // If this is a sub settings or not the main Dashboard and not a Shortcut and an initial
490 // Fragment then apply the SubSettings theme for the ActionBar content insets
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700491 if (isSubSettings ||
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700492 (!mIsShowingDashboard && !mIsShortcut && (initialFragmentName != null))) {
493 // Check also that we are not a Theme Dialog as we don't want to override them
494 final int themeResId = getThemeResId();
495 if (themeResId != R.style.Theme_DialogWhenLarge &&
496 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
497 setTheme(R.style.Theme_SubSettings);
498 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700499 }
500
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700501 setContentView(mIsShowingDashboard ?
502 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800503
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700504 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700505
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800506 getFragmentManager().addOnBackStackChangedListener(this);
507
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700508 if (mIsShowingDashboard) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700509 Index.getInstance(getApplicationContext()).update();
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700510 }
511
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700512 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700513 // We are restarting from a previous saved state; used that to initialize, instead
514 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700515 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
516 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800517
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700518 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800519
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700520 ArrayList<DashboardCategory> categories =
521 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
522 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700523 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700524 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700525 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800526 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700527
528 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700529 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800530 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700531 if (!mIsShowingDashboard) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700532 // Search is shown we are launched thru a Settings "shortcut". UP will be shown
533 // only if it is a sub settings
534 if (mIsShortcut) {
535 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700536 mDisplaySearch = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700537 } else if (isSubSettings) {
538 mDisplayHomeAsUpEnabled = true;
539 mDisplaySearch = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700540 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700541 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700542
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700543 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700544 switchToFragment(initialFragmentName, initialArguments, true, false,
545 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000546 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700547 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700548 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700549 // Show Search affordance
550 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700551 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700552 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700553 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800554 }
555 }
556
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700557 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700558 if (mActionBar != null) {
559 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
560 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
561 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700562 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
563
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800564 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800565 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
566
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700567 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800568 if (buttonBar != null) {
569 buttonBar.setVisibility(View.VISIBLE);
570
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700571 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800572 backButton.setOnClickListener(new OnClickListener() {
573 public void onClick(View v) {
574 setResult(RESULT_CANCELED);
575 finish();
576 }
577 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700578 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800579 skipButton.setOnClickListener(new OnClickListener() {
580 public void onClick(View v) {
581 setResult(RESULT_OK);
582 finish();
583 }
584 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700585 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800586 mNextButton.setOnClickListener(new OnClickListener() {
587 public void onClick(View v) {
588 setResult(RESULT_OK);
589 finish();
590 }
591 });
592
593 // set our various button parameters
594 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
595 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
596 if (TextUtils.isEmpty(buttonText)) {
597 mNextButton.setVisibility(View.GONE);
598 }
599 else {
600 mNextButton.setText(buttonText);
601 }
602 }
603 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
604 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
605 if (TextUtils.isEmpty(buttonText)) {
606 backButton.setVisibility(View.GONE);
607 }
608 else {
609 backButton.setText(buttonText);
610 }
611 }
612 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
613 skipButton.setVisibility(View.VISIBLE);
614 }
615 }
616 }
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800617 }
618
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700619 private void setTitleFromIntent(Intent intent) {
620 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
621 if (initialTitleResId > 0) {
622 mInitialTitle = null;
623 mInitialTitleResId = initialTitleResId;
624 setTitle(mInitialTitleResId);
625 } else {
626 mInitialTitleResId = -1;
627 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
628 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
629 setTitle(mInitialTitle);
630 }
631 }
632
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800633 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800634 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700635 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800636 }
637
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700638 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800639 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700640
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800641 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700642 if (mInitialTitleResId > 0) {
643 setTitle(mInitialTitleResId);
644 } else {
645 setTitle(mInitialTitle);
646 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700647 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800648 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700649
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800650 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
651 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700652
653 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800654 }
655
656 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
657 final CharSequence title;
658 final int titleRes = bse.getBreadCrumbTitleRes();
659 if (titleRes > 0) {
660 title = getText(titleRes);
661 } else {
662 title = bse.getBreadCrumbTitle();
663 }
664 if (title != null) {
665 setTitle(title);
666 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800667 }
668
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800669 @Override
670 protected void onSaveInstanceState(Bundle outState) {
671 super.onSaveInstanceState(outState);
672
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700673 if (mCategories.size() > 0) {
674 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800675 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700676
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700677 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700678 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700679
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700680 if (mDisplaySearch) {
681 // The option menus are created if the ActionBar is visible and they are also created
682 // asynchronously. If you launch Settings with an Intent action like
683 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
684 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
685 // menu item and search view are null.
686 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
687 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700688
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700689 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
690 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
691 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800692 }
693
694 @Override
695 public void onResume() {
696 super.onResume();
697
698 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
699 @Override
700 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Fabrice Di Megliobb051782014-06-04 17:33:25 -0700701 setNeedToRebuildCategories(true);
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700702 invalidateCategories();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800703 }
704 };
705 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
706 mDevelopmentPreferencesListener);
707
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800708 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700709
Svetoslav990159a2014-04-14 17:14:59 -0700710 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700711
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700712 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700713 onQueryTextSubmit(mSearchQuery);
714 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800715 }
716
717 @Override
718 public void onPause() {
719 super.onPause();
720
721 unregisterReceiver(mBatteryInfoReceiver);
722
Svetoslav990159a2014-04-14 17:14:59 -0700723 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800724 }
725
726 @Override
727 public void onDestroy() {
728 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700729
730 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
731 mDevelopmentPreferencesListener);
732 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800733 }
734
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800735 protected boolean isValidFragment(String fragmentName) {
736 // Almost all fragments are wrapped in this,
737 // except for a few that have their own activities.
738 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
739 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
740 }
741 return false;
742 }
743
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800744 @Override
745 public Intent getIntent() {
746 Intent superIntent = super.getIntent();
747 String startingFragment = getStartingFragmentClass(superIntent);
748 // This is called from super.onCreate, isMultiPane() is not yet reliable
749 // Do not use onIsHidingHeaders either, which relies itself on this method
750 if (startingFragment != null) {
751 Intent modIntent = new Intent(superIntent);
752 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
753 Bundle args = superIntent.getExtras();
754 if (args != null) {
755 args = new Bundle(args);
756 } else {
757 args = new Bundle();
758 }
759 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100760 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800761 return modIntent;
762 }
763 return superIntent;
764 }
765
766 /**
767 * Checks if the component name in the intent is different from the Settings class and
768 * returns the class name to load as a fragment.
769 */
770 private String getStartingFragmentClass(Intent intent) {
771 if (mFragmentClass != null) return mFragmentClass;
772
773 String intentClass = intent.getComponent().getClassName();
774 if (intentClass.equals(getClass().getName())) return null;
775
776 if ("com.android.settings.ManageApplications".equals(intentClass)
777 || "com.android.settings.RunningServices".equals(intentClass)
778 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
779 // Old names of manage apps.
780 intentClass = com.android.settings.applications.ManageApplications.class.getName();
781 }
782
783 return intentClass;
784 }
785
786 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000787 * Start a new fragment containing a preference panel. If the preferences
788 * are being displayed in multi-pane mode, the given fragment class will
789 * be instantiated and placed in the appropriate pane. If running in
790 * single-pane mode, a new activity will be launched in which to show the
791 * fragment.
792 *
793 * @param fragmentClass Full name of the class implementing the fragment.
794 * @param args Any desired arguments to supply to the fragment.
795 * @param titleRes Optional resource identifier of the title of this
796 * fragment.
797 * @param titleText Optional text of the title of this fragment.
798 * @param resultTo Optional fragment that result data should be sent to.
799 * If non-null, resultTo.onActivityResult() will be called when this
800 * preference panel is done. The launched panel must use
801 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
802 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700803 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000804 */
805 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700806 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700807 String title = null;
808 if (titleRes < 0) {
809 if (titleText != null) {
810 title = titleText.toString();
811 } else {
812 // There not much we can do in that case
813 title = "";
814 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700815 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700816 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700817 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000818 }
819
820 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800821 * Called by a preference panel fragment to finish itself.
822 *
823 * @param caller The fragment that is asking to be finished.
824 * @param resultCode Optional result code to send back to the original
825 * launching fragment.
826 * @param resultData Optional result data to send back to the original
827 * launching fragment.
828 */
829 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
830 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700831 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800832 }
833
834 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000835 * Start a new fragment.
836 *
837 * @param fragment The fragment to start
838 * @param push If true, the current fragment will be pushed onto the back stack. If false,
839 * the current fragment will be replaced.
840 */
841 public void startPreferenceFragment(Fragment fragment, boolean push) {
842 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700843 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000844 if (push) {
845 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
846 transaction.addToBackStack(BACK_STACK_PREFS);
847 } else {
848 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
849 }
850 transaction.commitAllowingStateLoss();
851 }
852
853 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700854 * Switch to a specific Fragment with taking care of validation, Title and BackStack
855 */
856 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700857 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700858 if (validate && !isValidFragment(fragmentName)) {
859 throw new IllegalArgumentException("Invalid fragment for this activity: "
860 + fragmentName);
861 }
862 Fragment f = Fragment.instantiate(this, fragmentName, args);
863 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700864 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700865 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700866 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700867 }
868 if (addToBackStack) {
869 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
870 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700871 if (titleResId > 0) {
872 transaction.setBreadCrumbTitle(titleResId);
873 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700874 transaction.setBreadCrumbTitle(title);
875 }
876 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700877 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700878 return f;
879 }
880
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700881 public void setNeedToRebuildCategories(boolean need) {
882 mNeedToRebuildCategories = need;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700883 }
884
885 /**
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700886 * Called when the activity needs its list of categories/tiles built.
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700887 *
888 * @param categories The list in which to place the tiles categories.
889 */
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700890 private void buildDashboardCategories(List<DashboardCategory> categories) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700891 categories.clear();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700892 loadCategoriesFromResource(R.xml.dashboard_categories, categories);
893 updateTilesList(categories);
894 }
895
896 /**
897 * Parse the given XML file as a categories description, adding each
898 * parsed categories and tiles into the target list.
899 *
900 * @param resid The XML resource to load and parse.
901 * @param target The list in which the parsed categories and tiles should be placed.
902 */
903 private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) {
904 XmlResourceParser parser = null;
905 try {
906 parser = getResources().getXml(resid);
907 AttributeSet attrs = Xml.asAttributeSet(parser);
908
909 int type;
910 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
911 && type != XmlPullParser.START_TAG) {
912 // Parse next until start tag is found
913 }
914
915 String nodeName = parser.getName();
916 if (!"dashboard-categories".equals(nodeName)) {
917 throw new RuntimeException(
918 "XML document must start with <preference-categories> tag; found"
919 + nodeName + " at " + parser.getPositionDescription());
920 }
921
922 Bundle curBundle = null;
923
924 final int outerDepth = parser.getDepth();
925 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
926 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
927 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
928 continue;
929 }
930
931 nodeName = parser.getName();
932 if ("dashboard-category".equals(nodeName)) {
933 DashboardCategory category = new DashboardCategory();
934
935 TypedArray sa = obtainStyledAttributes(
936 attrs, com.android.internal.R.styleable.PreferenceHeader);
937 category.id = sa.getResourceId(
938 com.android.internal.R.styleable.PreferenceHeader_id,
939 (int)DashboardCategory.CAT_ID_UNDEFINED);
940
941 TypedValue tv = sa.peekValue(
942 com.android.internal.R.styleable.PreferenceHeader_title);
943 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
944 if (tv.resourceId != 0) {
945 category.titleRes = tv.resourceId;
946 } else {
947 category.title = tv.string;
948 }
949 }
950 sa.recycle();
951
952 final int innerDepth = parser.getDepth();
953 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
954 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
955 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
956 continue;
957 }
958
959 String innerNodeName = parser.getName();
960 if (innerNodeName.equals("dashboard-tile")) {
961 DashboardTile tile = new DashboardTile();
962
963 sa = obtainStyledAttributes(
964 attrs, com.android.internal.R.styleable.PreferenceHeader);
965 tile.id = sa.getResourceId(
966 com.android.internal.R.styleable.PreferenceHeader_id,
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -0700967 (int)TILE_ID_UNDEFINED);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700968 tv = sa.peekValue(
969 com.android.internal.R.styleable.PreferenceHeader_title);
970 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
971 if (tv.resourceId != 0) {
972 tile.titleRes = tv.resourceId;
973 } else {
974 tile.title = tv.string;
975 }
976 }
977 tv = sa.peekValue(
978 com.android.internal.R.styleable.PreferenceHeader_summary);
979 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
980 if (tv.resourceId != 0) {
981 tile.summaryRes = tv.resourceId;
982 } else {
983 tile.summary = tv.string;
984 }
985 }
986 tile.iconRes = sa.getResourceId(
987 com.android.internal.R.styleable.PreferenceHeader_icon, 0);
988 tile.fragment = sa.getString(
989 com.android.internal.R.styleable.PreferenceHeader_fragment);
990 sa.recycle();
991
992 if (curBundle == null) {
993 curBundle = new Bundle();
994 }
995
996 final int innerDepth2 = parser.getDepth();
997 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
998 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) {
999 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1000 continue;
1001 }
1002
1003 String innerNodeName2 = parser.getName();
1004 if (innerNodeName2.equals("extra")) {
1005 getResources().parseBundleExtra("extra", attrs, curBundle);
1006 XmlUtils.skipCurrentTag(parser);
1007
1008 } else if (innerNodeName2.equals("intent")) {
1009 tile.intent = Intent.parseIntent(getResources(), parser, attrs);
1010
1011 } else {
1012 XmlUtils.skipCurrentTag(parser);
1013 }
1014 }
1015
1016 if (curBundle.size() > 0) {
1017 tile.fragmentArguments = curBundle;
1018 curBundle = null;
1019 }
1020
1021 category.addTile(tile);
1022
1023 } else {
1024 XmlUtils.skipCurrentTag(parser);
1025 }
1026 }
1027
1028 target.add(category);
1029 } else {
1030 XmlUtils.skipCurrentTag(parser);
1031 }
1032 }
1033
1034 } catch (XmlPullParserException e) {
1035 throw new RuntimeException("Error parsing categories", e);
1036 } catch (IOException e) {
1037 throw new RuntimeException("Error parsing categories", e);
1038 } finally {
1039 if (parser != null) parser.close();
1040 }
1041 }
1042
1043 private void updateTilesList(List<DashboardCategory> target) {
1044 final boolean showDev = mDevelopmentPreferences.getBoolean(
1045 DevelopmentSettings.PREF_SHOW,
1046 android.os.Build.TYPE.equals("eng"));
1047
1048 final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
1049
1050 final int size = target.size();
1051 for (int i = 0; i < size; i++) {
1052
1053 DashboardCategory category = target.get(i);
1054
1055 // Ids are integers, so downcasting is ok
1056 int id = (int) category.id;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001057 int n = category.getTilesCount() - 1;
1058 while (n >= 0) {
1059
1060 DashboardTile tile = category.getTile(n);
1061
1062 id = (int) tile.id;
1063 if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
1064 Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, category, tile);
1065 } else if (id == R.id.wifi_settings) {
1066 // Remove WiFi Settings if WiFi service is not available.
1067 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
1068 category.removeTile(n);
1069 }
1070 } else if (id == R.id.bluetooth_settings) {
1071 // Remove Bluetooth Settings if Bluetooth service is not available.
1072 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
1073 category.removeTile(n);
1074 }
1075 } else if (id == R.id.data_usage_settings) {
1076 // Remove data usage when kernel module not enabled
1077 final INetworkManagementService netManager = INetworkManagementService.Stub
1078 .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
1079 try {
1080 if (!netManager.isBandwidthControlEnabled()) {
1081 category.removeTile(n);
1082 }
1083 } catch (RemoteException e) {
1084 // ignored
1085 }
1086 } else if (id == R.id.battery_settings) {
1087 // Remove battery settings when battery is not available. (e.g. TV)
1088
1089 if (!mBatteryPresent) {
1090 category.removeTile(n);
1091 }
1092 } else if (id == R.id.home_settings) {
1093 if (!updateHomeSettingTiles(tile)) {
1094 category.removeTile(n);
1095 }
1096 } else if (id == R.id.user_settings) {
Amith Yamasani4093e402014-06-06 14:31:37 -07001097 boolean hasMultipleUsers =
1098 ((UserManager) getSystemService(Context.USER_SERVICE))
1099 .getUserCount() > 1;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001100 if (!UserHandle.MU_ENABLED
Amith Yamasani4093e402014-06-06 14:31:37 -07001101 || (!UserManager.supportsMultipleUsers()
1102 && !hasMultipleUsers)
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001103 || Utils.isMonkeyRunning()) {
1104 category.removeTile(n);
1105 }
1106 } else if (id == R.id.nfc_payment_settings) {
1107 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
1108 category.removeTile(n);
1109 } else {
1110 // Only show if NFC is on and we have the HCE feature
1111 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1112 if (!adapter.isEnabled() || !getPackageManager().hasSystemFeature(
1113 PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
1114 category.removeTile(n);
1115 }
1116 }
Fabrice Di Meglio488cae32014-05-13 11:26:34 -07001117 } else if (id == R.id.print_settings) {
1118 boolean hasPrintingSupport = getPackageManager().hasSystemFeature(
1119 PackageManager.FEATURE_PRINTING);
1120 if (!hasPrintingSupport) {
1121 category.removeTile(n);
1122 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001123 } else if (id == R.id.development_settings) {
Julia Reynolds6c088cb2014-05-08 09:29:41 -04001124 if (!showDev || um.hasUserRestriction(
1125 UserManager.DISALLOW_DEBUGGING_FEATURES)) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001126 category.removeTile(n);
1127 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001128 }
1129
1130 if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
Amith Yamasania97089d2014-04-30 10:58:09 -07001131 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)
1132 && n < category.getTilesCount()) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001133 category.removeTile(n);
1134 }
1135
1136 n--;
1137 }
1138 }
1139 }
1140
1141 private boolean updateHomeSettingTiles(DashboardTile tile) {
1142 // Once we decide to show Home settings, keep showing it forever
1143 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1144 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1145 return true;
1146 }
1147
1148 try {
1149 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
1150 getPackageManager().getHomeActivities(homeApps);
1151 if (homeApps.size() < 2) {
1152 // When there's only one available home app, omit this settings
1153 // category entirely at the top level UI. If the user just
1154 // uninstalled the penultimate home app candidiate, we also
1155 // now tell them about why they aren't seeing 'Home' in the list.
1156 if (sShowNoHomeNotice) {
1157 sShowNoHomeNotice = false;
1158 NoHomeDialogFragment.show(this);
1159 }
1160 return false;
1161 } else {
1162 // Okay, we're allowing the Home settings category. Tell it, when
1163 // invoked via this front door, that we'll need to be told about the
1164 // case when the user uninstalls all but one home app.
1165 if (tile.fragmentArguments == null) {
1166 tile.fragmentArguments = new Bundle();
1167 }
1168 tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true);
1169 }
1170 } catch (Exception e) {
1171 // Can't look up the home activity; bail on configuring the icon
1172 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1173 }
1174
1175 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1176 return true;
1177 }
1178
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001179 private void getMetaData() {
1180 try {
1181 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1182 PackageManager.GET_META_DATA);
1183 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001184 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1185 } catch (NameNotFoundException nnfe) {
1186 // No recovery
1187 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1188 }
1189 }
1190
1191 // give subclasses access to the Next button
1192 public boolean hasNextButton() {
1193 return mNextButton != null;
1194 }
1195
1196 public Button getNextButton() {
1197 return mNextButton;
1198 }
1199
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001200 @Override
1201 public boolean shouldUpRecreateTask(Intent targetIntent) {
1202 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1203 }
1204
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001205 public static void requestHomeNotice() {
1206 sShowNoHomeNotice = true;
1207 }
1208
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001209 @Override
1210 public boolean onQueryTextSubmit(String query) {
1211 switchToSearchResultsFragmentIfNeeded();
1212 mSearchQuery = query;
1213 return mSearchResultsFragment.onQueryTextSubmit(query);
1214 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001215
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001216 @Override
1217 public boolean onQueryTextChange(String newText) {
1218 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001219 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001220 return false;
1221 }
1222 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001223 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001224
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001225 @Override
1226 public boolean onClose() {
1227 return false;
1228 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001229
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001230 @Override
1231 public boolean onMenuItemActionExpand(MenuItem item) {
1232 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001233 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001234 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001235 return true;
1236 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001237
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001238 @Override
1239 public boolean onMenuItemActionCollapse(MenuItem item) {
1240 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001241 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001242 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001243 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001244 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001245 return true;
1246 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001247
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001248 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001249 if (mSearchResultsFragment != null) {
1250 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001251 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001252 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001253 if (current != null && current instanceof SearchResultsSummary) {
1254 mSearchResultsFragment = (SearchResultsSummary) current;
1255 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001256 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001257 SearchResultsSummary.class.getName(), null, false, true,
1258 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001259 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001260 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001261 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001262 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001263
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001264 public void needToRevertToInitialFragment() {
1265 mNeedToRevertToInitialFragment = true;
1266 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001267
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001268 private void revertToInitialFragment() {
1269 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001270 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001271 mSearchMenuItemExpanded = false;
1272 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1273 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001274 if (mSearchMenuItem != null) {
1275 mSearchMenuItem.collapseActionView();
1276 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001277 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001278}