blob: cbffa86e6df55582771568421db8191f5a270f48 [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;
Alexandra Gherghina6d839872014-07-22 12:04:58 +000069import com.android.settings.accounts.AccountSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080070import com.android.settings.accounts.AccountSyncSettings;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070071import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080072import com.android.settings.applications.ManageApplications;
73import com.android.settings.applications.ProcessStatsUi;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080074import com.android.settings.bluetooth.BluetoothSettings;
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;
John Spurlock802ddf92014-07-18 11:51:13 -040084import com.android.settings.notification.NotificationAppList;
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -070085import com.android.settings.notification.OtherSoundSettings;
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -070086import com.android.settings.quicklaunch.QuickLaunchSettings;
Fabrice Di Meglio7a6bfd12014-04-14 19:49:18 -070087import com.android.settings.search.DynamicIndexableContentMonitor;
Fabrice Di Megliofa7dc242014-03-12 19:24:43 -070088import com.android.settings.search.Index;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080089import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
90import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
91import com.android.settings.inputmethod.SpellCheckersSettings;
92import com.android.settings.inputmethod.UserDictionaryList;
93import com.android.settings.location.LocationSettings;
94import com.android.settings.nfc.AndroidBeam;
95import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -040096import com.android.settings.notification.AppNotificationSettings;
John Spurlockc9afadb2014-04-29 18:07:23 -040097import com.android.settings.notification.ConditionProviderSettings;
John Spurlock4a350512014-04-08 14:08:21 -040098import com.android.settings.notification.NotificationAccessSettings;
99import com.android.settings.notification.NotificationSettings;
100import com.android.settings.notification.NotificationStation;
101import com.android.settings.notification.ZenModeSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800102import com.android.settings.print.PrintJobSettingsFragment;
103import com.android.settings.print.PrintSettingsFragment;
PauloftheWest38155612014-06-30 10:02:36 -0700104import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800105import com.android.settings.tts.TextToSpeechSettings;
106import com.android.settings.users.UserSettings;
Dianne Hackbornb51253c2014-08-12 15:08:04 -0700107import com.android.settings.voice.VoiceInputSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800108import com.android.settings.vpn2.VpnSettings;
109import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700110import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800111import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700112import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800113import com.android.settings.wifi.WifiSettings;
114import com.android.settings.wifi.p2p.WifiP2pSettings;
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800115import com.android.settings.WifiCallingSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400116
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800117import org.xmlpull.v1.XmlPullParser;
118import org.xmlpull.v1.XmlPullParserException;
119
120import java.io.IOException;
121import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800122import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700123import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800124
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -0700125import static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700126
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800127public class SettingsActivity extends Activity
128 implements PreferenceManager.OnPreferenceTreeClickListener,
129 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100130 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700131 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100132 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800133
134 private static final String LOG_TAG = "Settings";
135
136 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700137 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700138 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
139 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700140 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700141 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700142 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800143
144 /**
145 * When starting this activity, the invoking Intent can contain this extra
146 * string to specify which fragment should be initially displayed.
147 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
148 * will call isValidFragment() to confirm that the fragment class name is valid for this
149 * activity.
150 */
151 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
152
153 /**
154 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
155 * this extra can also be specified to supply a Bundle of arguments to pass
156 * to that fragment when it is instantiated during the initial creation
157 * of the activity.
158 */
159 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
160
161 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700162 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
163 */
164 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
165
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800166 public static final String BACK_STACK_PREFS = ":settings:prefs";
167
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800168 // extras that allow any preference activity to be launched as part of a wizard
169
170 // show Back and Next buttons? takes boolean parameter
171 // Back will then return RESULT_CANCELED and Next RESULT_OK
172 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
173
174 // add a Skip button?
175 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
176
177 // specify custom text for the Back or Next buttons, or cause a button to not appear
178 // at all by setting it to null
179 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
180 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
181
182 /**
183 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700184 * 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 -0800185 * that fragment.
186 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700187 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100188 /**
189 * The package name used to resolve the title resource id.
190 */
191 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
192 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700193 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
194 ":settings:show_fragment_title_resid";
195 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
196 ":settings:show_fragment_as_shortcut";
197
198 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
199 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800200
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800201 private static final String META_DATA_KEY_FRAGMENT_CLASS =
202 "com.android.settings.FRAGMENT_CLASS";
203
204 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
205
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700206 private static final String EMPTY_QUERY = "";
207
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800208 private static boolean sShowNoHomeNotice = false;
209
210 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800211
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800212 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700213 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800214
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800215 // Show only these settings for restricted users
216 private int[] SETTINGS_FOR_RESTRICTED = {
217 R.id.wireless_section,
218 R.id.wifi_settings,
219 R.id.bluetooth_settings,
220 R.id.data_usage_settings,
PauloftheWest38155612014-06-30 10:02:36 -0700221 R.id.sim_settings,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800222 R.id.wireless_settings,
223 R.id.device_section,
John Spurlock4e4cdef2014-05-28 09:43:45 -0400224 R.id.notification_settings,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800225 R.id.display_settings,
226 R.id.storage_settings,
227 R.id.application_settings,
228 R.id.battery_settings,
229 R.id.personal_section,
230 R.id.location_settings,
231 R.id.security_settings,
232 R.id.language_settings,
233 R.id.user_settings,
234 R.id.account_settings,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800235 R.id.system_section,
236 R.id.date_time_settings,
237 R.id.about_settings,
238 R.id.accessibility_settings,
239 R.id.print_settings,
240 R.id.nfc_payment_settings,
Fabrice Di Meglio2858b792014-02-18 19:35:08 -0800241 R.id.home_settings,
242 R.id.dashboard
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800243 };
244
245 private static final String[] ENTRY_FRAGMENTS = {
246 WirelessSettings.class.getName(),
247 WifiSettings.class.getName(),
248 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700249 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800250 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700251 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800252 TetherSettings.class.getName(),
253 WifiP2pSettings.class.getName(),
254 VpnSettings.class.getName(),
255 DateTimeSettings.class.getName(),
256 LocalePicker.class.getName(),
257 InputMethodAndLanguageSettings.class.getName(),
Dianne Hackbornb51253c2014-08-12 15:08:04 -0700258 VoiceInputSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800259 SpellCheckersSettings.class.getName(),
260 UserDictionaryList.class.getName(),
261 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700262 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800263 DisplaySettings.class.getName(),
264 DeviceInfoSettings.class.getName(),
265 ManageApplications.class.getName(),
266 ProcessStatsUi.class.getName(),
267 NotificationStation.class.getName(),
268 LocationSettings.class.getName(),
269 SecuritySettings.class.getName(),
Dianne Hackbornb51253c2014-08-12 15:08:04 -0700270 UsageAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800271 PrivacySettings.class.getName(),
272 DeviceAdminSettings.class.getName(),
273 AccessibilitySettings.class.getName(),
274 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800275 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
276 TextToSpeechSettings.class.getName(),
277 Memory.class.getName(),
278 DevelopmentSettings.class.getName(),
279 UsbSettings.class.getName(),
280 AndroidBeam.class.getName(),
281 WifiDisplaySettings.class.getName(),
282 PowerUsageSummary.class.getName(),
283 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000284 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800285 CryptKeeperSettings.class.getName(),
286 DataUsageSummary.class.getName(),
287 DreamSettings.class.getName(),
288 UserSettings.class.getName(),
289 NotificationAccessSettings.class.getName(),
John Spurlockc9afadb2014-04-29 18:07:23 -0400290 ConditionProviderSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800291 PrintSettingsFragment.class.getName(),
292 PrintJobSettingsFragment.class.getName(),
293 TrustedCredentialsSettings.class.getName(),
294 PaymentSettings.class.getName(),
295 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700296 ZenModeSettings.class.getName(),
297 NotificationSettings.class.getName(),
298 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
299 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400300 InstalledAppDetails.class.getName(),
301 BatterySaverSettings.class.getName(),
John Spurlock802ddf92014-07-18 11:51:13 -0400302 NotificationAppList.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700303 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700304 OtherSoundSettings.class.getName(),
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700305 QuickLaunchSettings.class.getName(),
Pavel Zhamaitsiak4ab32562015-02-23 15:34:07 -0800306 ApnSettings.class.getName(),
307 WifiCallingSettings.class.getName()
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800308 };
309
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700310
311 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
312 "android.settings.APPLICATION_DETAILS_SETTINGS"
313 };
314
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800315 private SharedPreferences mDevelopmentPreferences;
316 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
317
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800318 private boolean mBatteryPresent = true;
319 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800320 @Override
321 public void onReceive(Context context, Intent intent) {
322 String action = intent.getAction();
323 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
324 boolean batteryPresent = Utils.isBatteryPresent(intent);
325
326 if (mBatteryPresent != batteryPresent) {
327 mBatteryPresent = batteryPresent;
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700328 invalidateCategories(true);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800329 }
330 }
331 }
332 };
333
Svetoslav990159a2014-04-14 17:14:59 -0700334 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
335 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700336
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700337 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700338 private SwitchBar mSwitchBar;
339
340 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700341
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700342 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700343 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700344
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700345 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700346 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700347
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700348 private ViewGroup mContent;
349
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700350 private SearchView mSearchView;
351 private MenuItem mSearchMenuItem;
352 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700353 private SearchResultsSummary mSearchResultsFragment;
354 private String mSearchQuery;
355
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700356 // Categories
357 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800358
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700359 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700360 private static final int MSG_BUILD_CATEGORIES = 1;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800361 private Handler mHandler = new Handler() {
362 @Override
363 public void handleMessage(Message msg) {
364 switch (msg.what) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700365 case MSG_BUILD_CATEGORIES: {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700366 final boolean forceRefresh = msg.getData().getBoolean(MSG_DATA_FORCE_REFRESH);
367 if (forceRefresh) {
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700368 buildDashboardCategories(mCategories);
369 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800370 } break;
371 }
372 }
373 };
374
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700375 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700376 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700377
Jim Miller0698a212014-10-16 19:49:07 -0700378 private Intent mResultIntentData;
379
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700380 public SwitchBar getSwitchBar() {
381 return mSwitchBar;
382 }
383
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700384 public List<DashboardCategory> getDashboardCategories(boolean forceRefresh) {
385 if (forceRefresh || mCategories.size() == 0) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700386 buildDashboardCategories(mCategories);
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700387 }
388 return mCategories;
389 }
390
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800391 @Override
392 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
393 // Override the fragment title for Wallpaper settings
394 int titleRes = pref.getTitleRes();
395 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
396 titleRes = R.string.wallpaper_settings_fragment_title;
397 } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName())
398 && UserHandle.myUserId() != UserHandle.USER_OWNER) {
399 if (UserManager.get(this).isLinkedUser()) {
400 titleRes = R.string.profile_info_settings_title;
401 } else {
402 titleRes = R.string.user_info_settings_title;
403 }
404 }
405 startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),
406 null, 0);
407 return true;
408 }
409
410 @Override
411 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
412 return false;
413 }
414
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700415 private void invalidateCategories(boolean forceRefresh) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700416 if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700417 Message msg = new Message();
418 msg.what = MSG_BUILD_CATEGORIES;
419 msg.getData().putBoolean(MSG_DATA_FORCE_REFRESH, forceRefresh);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800420 }
421 }
422
423 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800424 public void onConfigurationChanged(Configuration newConfig) {
425 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800426 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800427 }
428
429 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700430 protected void onStart() {
431 super.onStart();
432
433 if (mNeedToRevertToInitialFragment) {
434 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800435 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800436 }
437
438 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700439 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700440 if (!mDisplaySearch) {
441 return false;
442 }
443
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700444 MenuInflater inflater = getMenuInflater();
445 inflater.inflate(R.menu.options_menu, menu);
446
447 // Cache the search query (can be overriden by the OnQueryTextListener)
448 final String query = mSearchQuery;
449
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700450 mSearchMenuItem = menu.findItem(R.id.search);
451 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700452
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700453 if (mSearchMenuItem == null || mSearchView == null) {
454 return false;
455 }
456
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700457 if (mSearchResultsFragment != null) {
458 mSearchResultsFragment.setSearchView(mSearchView);
459 }
460
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700461 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700462 mSearchView.setOnQueryTextListener(this);
463 mSearchView.setOnCloseListener(this);
464
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700465 if (mSearchMenuItemExpanded) {
466 mSearchMenuItem.expandActionView();
467 }
468 mSearchView.setQuery(query, true /* submit */);
469
470 return true;
471 }
472
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700473 private static boolean isShortCutIntent(final Intent intent) {
474 Set<String> categories = intent.getCategories();
475 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
476 }
477
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700478 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700479 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700480 if (action == null) {
481 return false;
482 }
483 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
484 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
485 }
486 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700487 }
488
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700489 @Override
490 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700491 super.onCreate(savedState);
492
493 // Should happen before any call to getIntent()
494 getMetaData();
495
496 final Intent intent = getIntent();
497 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
498 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800499 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800500
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800501 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
502 Context.MODE_PRIVATE);
503
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700504 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700505 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700506
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700507 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700508 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
509
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700510 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700511 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700512
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700513 mIsShowingDashboard = className.equals(Settings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700514
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700515 // This is a "Sub Settings" when:
516 // - this is a real SubSettings
517 // - or :settings:show_fragment_as_subsetting is passed to the Intent
518 final boolean isSubSettings = className.equals(SubSettings.class.getName()) ||
519 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
520
521 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
522 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700523 // Check also that we are not a Theme Dialog as we don't want to override them
524 final int themeResId = getThemeResId();
525 if (themeResId != R.style.Theme_DialogWhenLarge &&
526 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
527 setTheme(R.style.Theme_SubSettings);
528 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700529 }
530
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700531 setContentView(mIsShowingDashboard ?
532 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800533
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700534 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700535
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800536 getFragmentManager().addOnBackStackChangedListener(this);
537
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700538 if (mIsShowingDashboard) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700539 Index.getInstance(getApplicationContext()).update();
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700540 }
541
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700542 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700543 // We are restarting from a previous saved state; used that to initialize, instead
544 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700545 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
546 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800547
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700548 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800549
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700550 ArrayList<DashboardCategory> categories =
551 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
552 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700553 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700554 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700555 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800556 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700557
558 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700559 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700560 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
561 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800562 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700563 if (!mIsShowingDashboard) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700564 // Search is shown we are launched thru a Settings "shortcut". UP will be shown
565 // only if it is a sub settings
566 if (mIsShortcut) {
567 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700568 mDisplaySearch = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700569 } else if (isSubSettings) {
570 mDisplayHomeAsUpEnabled = true;
571 mDisplaySearch = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700572 } else {
573 mDisplayHomeAsUpEnabled = false;
574 mDisplaySearch = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700575 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700576 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700577
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700578 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700579 switchToFragment(initialFragmentName, initialArguments, true, false,
580 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000581 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700582 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700583 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700584 // Show Search affordance
585 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700586 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700587 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700588 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800589 }
590 }
591
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700592 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700593 if (mActionBar != null) {
594 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
595 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
596 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700597 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
598
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800599 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800600 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
601
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700602 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800603 if (buttonBar != null) {
604 buttonBar.setVisibility(View.VISIBLE);
605
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700606 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800607 backButton.setOnClickListener(new OnClickListener() {
608 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700609 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800610 finish();
611 }
612 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700613 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800614 skipButton.setOnClickListener(new OnClickListener() {
615 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700616 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800617 finish();
618 }
619 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700620 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800621 mNextButton.setOnClickListener(new OnClickListener() {
622 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700623 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800624 finish();
625 }
626 });
627
628 // set our various button parameters
629 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
630 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
631 if (TextUtils.isEmpty(buttonText)) {
632 mNextButton.setVisibility(View.GONE);
633 }
634 else {
635 mNextButton.setText(buttonText);
636 }
637 }
638 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
639 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
640 if (TextUtils.isEmpty(buttonText)) {
641 backButton.setVisibility(View.GONE);
642 }
643 else {
644 backButton.setText(buttonText);
645 }
646 }
647 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
648 skipButton.setVisibility(View.VISIBLE);
649 }
650 }
651 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700652
653 mHomeActivitiesCount = getHomeActivitiesCount();
654 }
655
656 private int getHomeActivitiesCount() {
657 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
658 getPackageManager().getHomeActivities(homeApps);
659 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800660 }
661
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700662 private void setTitleFromIntent(Intent intent) {
663 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
664 if (initialTitleResId > 0) {
665 mInitialTitle = null;
666 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100667
668 final String initialTitleResPackageName = intent.getStringExtra(
669 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
670 if (initialTitleResPackageName != null) {
671 try {
672 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
673 0 /* flags */, new UserHandle(UserHandle.myUserId()));
674 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
675 setTitle(mInitialTitle);
676 mInitialTitleResId = -1;
677 return;
678 } catch (NameNotFoundException e) {
679 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
680 }
681 } else {
682 setTitle(mInitialTitleResId);
683 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700684 } else {
685 mInitialTitleResId = -1;
686 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
687 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
688 setTitle(mInitialTitle);
689 }
690 }
691
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800692 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800693 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700694 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800695 }
696
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700697 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800698 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700699
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800700 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700701 if (mInitialTitleResId > 0) {
702 setTitle(mInitialTitleResId);
703 } else {
704 setTitle(mInitialTitle);
705 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700706 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800707 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700708
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800709 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
710 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700711
712 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800713 }
714
715 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
716 final CharSequence title;
717 final int titleRes = bse.getBreadCrumbTitleRes();
718 if (titleRes > 0) {
719 title = getText(titleRes);
720 } else {
721 title = bse.getBreadCrumbTitle();
722 }
723 if (title != null) {
724 setTitle(title);
725 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800726 }
727
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800728 @Override
729 protected void onSaveInstanceState(Bundle outState) {
730 super.onSaveInstanceState(outState);
731
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700732 if (mCategories.size() > 0) {
733 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800734 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700735
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700736 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700737 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700738
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700739 if (mDisplaySearch) {
740 // The option menus are created if the ActionBar is visible and they are also created
741 // asynchronously. If you launch Settings with an Intent action like
742 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
743 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
744 // menu item and search view are null.
745 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
746 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700747
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700748 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
749 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
750 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700751
752 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800753 }
754
755 @Override
756 public void onResume() {
757 super.onResume();
758
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700759 final int newHomeActivityCount = getHomeActivitiesCount();
760 if (newHomeActivityCount != mHomeActivitiesCount) {
761 mHomeActivitiesCount = newHomeActivityCount;
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700762 invalidateCategories(true);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700763 }
764
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800765 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
766 @Override
767 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700768 invalidateCategories(true);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800769 }
770 };
771 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
772 mDevelopmentPreferencesListener);
773
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800774 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700775
Svetoslav990159a2014-04-14 17:14:59 -0700776 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700777
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700778 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700779 onQueryTextSubmit(mSearchQuery);
780 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800781 }
782
783 @Override
784 public void onPause() {
785 super.onPause();
786
787 unregisterReceiver(mBatteryInfoReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700788 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800789 }
790
791 @Override
792 public void onDestroy() {
793 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700794
795 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
796 mDevelopmentPreferencesListener);
797 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800798 }
799
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800800 protected boolean isValidFragment(String fragmentName) {
801 // Almost all fragments are wrapped in this,
802 // except for a few that have their own activities.
803 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
804 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
805 }
806 return false;
807 }
808
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800809 @Override
810 public Intent getIntent() {
811 Intent superIntent = super.getIntent();
812 String startingFragment = getStartingFragmentClass(superIntent);
813 // This is called from super.onCreate, isMultiPane() is not yet reliable
814 // Do not use onIsHidingHeaders either, which relies itself on this method
815 if (startingFragment != null) {
816 Intent modIntent = new Intent(superIntent);
817 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
818 Bundle args = superIntent.getExtras();
819 if (args != null) {
820 args = new Bundle(args);
821 } else {
822 args = new Bundle();
823 }
824 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100825 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800826 return modIntent;
827 }
828 return superIntent;
829 }
830
831 /**
832 * Checks if the component name in the intent is different from the Settings class and
833 * returns the class name to load as a fragment.
834 */
835 private String getStartingFragmentClass(Intent intent) {
836 if (mFragmentClass != null) return mFragmentClass;
837
838 String intentClass = intent.getComponent().getClassName();
839 if (intentClass.equals(getClass().getName())) return null;
840
841 if ("com.android.settings.ManageApplications".equals(intentClass)
842 || "com.android.settings.RunningServices".equals(intentClass)
843 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
844 // Old names of manage apps.
845 intentClass = com.android.settings.applications.ManageApplications.class.getName();
846 }
847
848 return intentClass;
849 }
850
851 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000852 * Start a new fragment containing a preference panel. If the preferences
853 * are being displayed in multi-pane mode, the given fragment class will
854 * be instantiated and placed in the appropriate pane. If running in
855 * single-pane mode, a new activity will be launched in which to show the
856 * fragment.
857 *
858 * @param fragmentClass Full name of the class implementing the fragment.
859 * @param args Any desired arguments to supply to the fragment.
860 * @param titleRes Optional resource identifier of the title of this
861 * fragment.
862 * @param titleText Optional text of the title of this fragment.
863 * @param resultTo Optional fragment that result data should be sent to.
864 * If non-null, resultTo.onActivityResult() will be called when this
865 * preference panel is done. The launched panel must use
866 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
867 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700868 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000869 */
870 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700871 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700872 String title = null;
873 if (titleRes < 0) {
874 if (titleText != null) {
875 title = titleText.toString();
876 } else {
877 // There not much we can do in that case
878 title = "";
879 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700880 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700881 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700882 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000883 }
884
885 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100886 * Start a new fragment in a new activity containing a preference panel for a given user. If the
887 * preferences are being displayed in multi-pane mode, the given fragment class will be
888 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
889 * activity will be launched in which to show the fragment.
890 *
891 * @param fragmentClass Full name of the class implementing the fragment.
892 * @param args Any desired arguments to supply to the fragment.
893 * @param titleRes Optional resource identifier of the title of this fragment.
894 * @param titleText Optional text of the title of this fragment.
895 * @param userHandle The user for which the panel has to be started.
896 */
897 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
898 CharSequence titleText, UserHandle userHandle) {
899 String title = null;
900 if (titleRes < 0) {
901 if (titleText != null) {
902 title = titleText.toString();
903 } else {
904 // There not much we can do in that case
905 title = "";
906 }
907 }
908 Utils.startWithFragmentAsUser(this, fragmentClass, args,
909 titleRes, title, mIsShortcut, userHandle);
910 }
911
912 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800913 * Called by a preference panel fragment to finish itself.
914 *
915 * @param caller The fragment that is asking to be finished.
916 * @param resultCode Optional result code to send back to the original
917 * launching fragment.
918 * @param resultData Optional result data to send back to the original
919 * launching fragment.
920 */
921 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
922 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700923 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800924 }
925
926 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000927 * Start a new fragment.
928 *
929 * @param fragment The fragment to start
930 * @param push If true, the current fragment will be pushed onto the back stack. If false,
931 * the current fragment will be replaced.
932 */
933 public void startPreferenceFragment(Fragment fragment, boolean push) {
934 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700935 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000936 if (push) {
937 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
938 transaction.addToBackStack(BACK_STACK_PREFS);
939 } else {
940 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
941 }
942 transaction.commitAllowingStateLoss();
943 }
944
945 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700946 * Switch to a specific Fragment with taking care of validation, Title and BackStack
947 */
948 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700949 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700950 if (validate && !isValidFragment(fragmentName)) {
951 throw new IllegalArgumentException("Invalid fragment for this activity: "
952 + fragmentName);
953 }
954 Fragment f = Fragment.instantiate(this, fragmentName, args);
955 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700956 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700957 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700958 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700959 }
960 if (addToBackStack) {
961 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
962 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700963 if (titleResId > 0) {
964 transaction.setBreadCrumbTitle(titleResId);
965 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700966 transaction.setBreadCrumbTitle(title);
967 }
968 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700969 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700970 return f;
971 }
972
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700973 /**
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700974 * Called when the activity needs its list of categories/tiles built.
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700975 *
976 * @param categories The list in which to place the tiles categories.
977 */
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700978 private void buildDashboardCategories(List<DashboardCategory> categories) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700979 categories.clear();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700980 loadCategoriesFromResource(R.xml.dashboard_categories, categories);
981 updateTilesList(categories);
982 }
983
984 /**
985 * Parse the given XML file as a categories description, adding each
986 * parsed categories and tiles into the target list.
987 *
988 * @param resid The XML resource to load and parse.
989 * @param target The list in which the parsed categories and tiles should be placed.
990 */
991 private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) {
992 XmlResourceParser parser = null;
993 try {
994 parser = getResources().getXml(resid);
995 AttributeSet attrs = Xml.asAttributeSet(parser);
996
997 int type;
998 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
999 && type != XmlPullParser.START_TAG) {
1000 // Parse next until start tag is found
1001 }
1002
1003 String nodeName = parser.getName();
1004 if (!"dashboard-categories".equals(nodeName)) {
1005 throw new RuntimeException(
1006 "XML document must start with <preference-categories> tag; found"
1007 + nodeName + " at " + parser.getPositionDescription());
1008 }
1009
1010 Bundle curBundle = null;
1011
1012 final int outerDepth = parser.getDepth();
1013 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1014 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
1015 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1016 continue;
1017 }
1018
1019 nodeName = parser.getName();
1020 if ("dashboard-category".equals(nodeName)) {
1021 DashboardCategory category = new DashboardCategory();
1022
1023 TypedArray sa = obtainStyledAttributes(
1024 attrs, com.android.internal.R.styleable.PreferenceHeader);
1025 category.id = sa.getResourceId(
1026 com.android.internal.R.styleable.PreferenceHeader_id,
1027 (int)DashboardCategory.CAT_ID_UNDEFINED);
1028
1029 TypedValue tv = sa.peekValue(
1030 com.android.internal.R.styleable.PreferenceHeader_title);
1031 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
1032 if (tv.resourceId != 0) {
1033 category.titleRes = tv.resourceId;
1034 } else {
1035 category.title = tv.string;
1036 }
1037 }
1038 sa.recycle();
1039
1040 final int innerDepth = parser.getDepth();
1041 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1042 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1043 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1044 continue;
1045 }
1046
1047 String innerNodeName = parser.getName();
1048 if (innerNodeName.equals("dashboard-tile")) {
1049 DashboardTile tile = new DashboardTile();
1050
1051 sa = obtainStyledAttributes(
1052 attrs, com.android.internal.R.styleable.PreferenceHeader);
1053 tile.id = sa.getResourceId(
1054 com.android.internal.R.styleable.PreferenceHeader_id,
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -07001055 (int)TILE_ID_UNDEFINED);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001056 tv = sa.peekValue(
1057 com.android.internal.R.styleable.PreferenceHeader_title);
1058 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
1059 if (tv.resourceId != 0) {
1060 tile.titleRes = tv.resourceId;
1061 } else {
1062 tile.title = tv.string;
1063 }
1064 }
1065 tv = sa.peekValue(
1066 com.android.internal.R.styleable.PreferenceHeader_summary);
1067 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
1068 if (tv.resourceId != 0) {
1069 tile.summaryRes = tv.resourceId;
1070 } else {
1071 tile.summary = tv.string;
1072 }
1073 }
1074 tile.iconRes = sa.getResourceId(
1075 com.android.internal.R.styleable.PreferenceHeader_icon, 0);
1076 tile.fragment = sa.getString(
1077 com.android.internal.R.styleable.PreferenceHeader_fragment);
1078 sa.recycle();
1079
1080 if (curBundle == null) {
1081 curBundle = new Bundle();
1082 }
1083
1084 final int innerDepth2 = parser.getDepth();
1085 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1086 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) {
1087 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1088 continue;
1089 }
1090
1091 String innerNodeName2 = parser.getName();
1092 if (innerNodeName2.equals("extra")) {
1093 getResources().parseBundleExtra("extra", attrs, curBundle);
1094 XmlUtils.skipCurrentTag(parser);
1095
1096 } else if (innerNodeName2.equals("intent")) {
1097 tile.intent = Intent.parseIntent(getResources(), parser, attrs);
1098
1099 } else {
1100 XmlUtils.skipCurrentTag(parser);
1101 }
1102 }
1103
1104 if (curBundle.size() > 0) {
1105 tile.fragmentArguments = curBundle;
1106 curBundle = null;
1107 }
1108
PauloftheWest38155612014-06-30 10:02:36 -07001109 // Show the SIM Cards setting if there are more than 2 SIMs installed.
Fabrice Di Meglio22a2a492014-08-08 12:27:57 -07001110 if(tile.id != R.id.sim_settings || Utils.showSimCardTile(this)){
PauloftheWest38155612014-06-30 10:02:36 -07001111 category.addTile(tile);
1112 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001113
1114 } else {
1115 XmlUtils.skipCurrentTag(parser);
1116 }
1117 }
1118
1119 target.add(category);
1120 } else {
1121 XmlUtils.skipCurrentTag(parser);
1122 }
1123 }
1124
1125 } catch (XmlPullParserException e) {
1126 throw new RuntimeException("Error parsing categories", e);
1127 } catch (IOException e) {
1128 throw new RuntimeException("Error parsing categories", e);
1129 } finally {
1130 if (parser != null) parser.close();
1131 }
1132 }
1133
1134 private void updateTilesList(List<DashboardCategory> target) {
1135 final boolean showDev = mDevelopmentPreferences.getBoolean(
1136 DevelopmentSettings.PREF_SHOW,
1137 android.os.Build.TYPE.equals("eng"));
1138
1139 final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
1140
1141 final int size = target.size();
1142 for (int i = 0; i < size; i++) {
1143
1144 DashboardCategory category = target.get(i);
1145
1146 // Ids are integers, so downcasting is ok
1147 int id = (int) category.id;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001148 int n = category.getTilesCount() - 1;
1149 while (n >= 0) {
1150
1151 DashboardTile tile = category.getTile(n);
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001152 boolean removeTile = false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001153 id = (int) tile.id;
1154 if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001155 if (!Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile)) {
1156 removeTile = true;
1157 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001158 } else if (id == R.id.wifi_settings) {
1159 // Remove WiFi Settings if WiFi service is not available.
1160 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001161 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001162 }
1163 } else if (id == R.id.bluetooth_settings) {
1164 // Remove Bluetooth Settings if Bluetooth service is not available.
1165 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001166 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001167 }
1168 } else if (id == R.id.data_usage_settings) {
1169 // Remove data usage when kernel module not enabled
1170 final INetworkManagementService netManager = INetworkManagementService.Stub
1171 .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
1172 try {
1173 if (!netManager.isBandwidthControlEnabled()) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001174 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001175 }
1176 } catch (RemoteException e) {
1177 // ignored
1178 }
1179 } else if (id == R.id.battery_settings) {
1180 // Remove battery settings when battery is not available. (e.g. TV)
1181
1182 if (!mBatteryPresent) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001183 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001184 }
1185 } else if (id == R.id.home_settings) {
1186 if (!updateHomeSettingTiles(tile)) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001187 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001188 }
1189 } else if (id == R.id.user_settings) {
Amith Yamasani4093e402014-06-06 14:31:37 -07001190 boolean hasMultipleUsers =
1191 ((UserManager) getSystemService(Context.USER_SERVICE))
1192 .getUserCount() > 1;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001193 if (!UserHandle.MU_ENABLED
Amith Yamasani4093e402014-06-06 14:31:37 -07001194 || (!UserManager.supportsMultipleUsers()
1195 && !hasMultipleUsers)
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001196 || Utils.isMonkeyRunning()) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001197 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001198 }
1199 } else if (id == R.id.nfc_payment_settings) {
1200 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001201 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001202 } else {
1203 // Only show if NFC is on and we have the HCE feature
1204 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
Fabrice Di Megliob3c7a172014-09-23 11:36:44 -07001205 if (adapter == null || !adapter.isEnabled() ||
1206 !getPackageManager().hasSystemFeature(
1207 PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001208 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001209 }
1210 }
Fabrice Di Meglio488cae32014-05-13 11:26:34 -07001211 } else if (id == R.id.print_settings) {
1212 boolean hasPrintingSupport = getPackageManager().hasSystemFeature(
1213 PackageManager.FEATURE_PRINTING);
1214 if (!hasPrintingSupport) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001215 removeTile = true;
Fabrice Di Meglio488cae32014-05-13 11:26:34 -07001216 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001217 } else if (id == R.id.development_settings) {
Julia Reynolds6c088cb2014-05-08 09:29:41 -04001218 if (!showDev || um.hasUserRestriction(
1219 UserManager.DISALLOW_DEBUGGING_FEATURES)) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001220 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001221 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001222 }
1223
1224 if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001225 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
1226 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001227 }
1228
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001229 if (removeTile && n < category.getTilesCount()) {
1230 category.removeTile(n);
1231 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001232 n--;
1233 }
1234 }
1235 }
1236
1237 private boolean updateHomeSettingTiles(DashboardTile tile) {
1238 // Once we decide to show Home settings, keep showing it forever
1239 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1240 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1241 return true;
1242 }
1243
1244 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001245 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001246 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001247 // When there's only one available home app, omit this settings
1248 // category entirely at the top level UI. If the user just
1249 // uninstalled the penultimate home app candidiate, we also
1250 // now tell them about why they aren't seeing 'Home' in the list.
1251 if (sShowNoHomeNotice) {
1252 sShowNoHomeNotice = false;
1253 NoHomeDialogFragment.show(this);
1254 }
1255 return false;
1256 } else {
1257 // Okay, we're allowing the Home settings category. Tell it, when
1258 // invoked via this front door, that we'll need to be told about the
1259 // case when the user uninstalls all but one home app.
1260 if (tile.fragmentArguments == null) {
1261 tile.fragmentArguments = new Bundle();
1262 }
1263 tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true);
1264 }
1265 } catch (Exception e) {
1266 // Can't look up the home activity; bail on configuring the icon
1267 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1268 }
1269
1270 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1271 return true;
1272 }
1273
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001274 private void getMetaData() {
1275 try {
1276 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1277 PackageManager.GET_META_DATA);
1278 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001279 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1280 } catch (NameNotFoundException nnfe) {
1281 // No recovery
1282 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1283 }
1284 }
1285
1286 // give subclasses access to the Next button
1287 public boolean hasNextButton() {
1288 return mNextButton != null;
1289 }
1290
1291 public Button getNextButton() {
1292 return mNextButton;
1293 }
1294
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001295 @Override
1296 public boolean shouldUpRecreateTask(Intent targetIntent) {
1297 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1298 }
1299
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001300 public static void requestHomeNotice() {
1301 sShowNoHomeNotice = true;
1302 }
1303
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001304 @Override
1305 public boolean onQueryTextSubmit(String query) {
1306 switchToSearchResultsFragmentIfNeeded();
1307 mSearchQuery = query;
1308 return mSearchResultsFragment.onQueryTextSubmit(query);
1309 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001310
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001311 @Override
1312 public boolean onQueryTextChange(String newText) {
1313 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001314 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001315 return false;
1316 }
1317 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001318 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001319
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001320 @Override
1321 public boolean onClose() {
1322 return false;
1323 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001324
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001325 @Override
1326 public boolean onMenuItemActionExpand(MenuItem item) {
1327 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001328 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001329 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001330 return true;
1331 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001332
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001333 @Override
1334 public boolean onMenuItemActionCollapse(MenuItem item) {
1335 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001336 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001337 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001338 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001339 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001340 return true;
1341 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001342
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001343 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001344 if (mSearchResultsFragment != null) {
1345 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001346 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001347 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001348 if (current != null && current instanceof SearchResultsSummary) {
1349 mSearchResultsFragment = (SearchResultsSummary) current;
1350 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001351 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001352 SearchResultsSummary.class.getName(), null, false, true,
1353 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001354 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001355 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001356 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001357 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001358
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001359 public void needToRevertToInitialFragment() {
1360 mNeedToRevertToInitialFragment = true;
1361 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001362
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001363 private void revertToInitialFragment() {
1364 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001365 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001366 mSearchMenuItemExpanded = false;
1367 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1368 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001369 if (mSearchMenuItem != null) {
1370 mSearchMenuItem.collapseActionView();
1371 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001372 }
Jim Miller0698a212014-10-16 19:49:07 -07001373
1374 public Intent getResultIntentData() {
1375 return mResultIntentData;
1376 }
1377
1378 public void setResultIntentData(Intent resultIntentData) {
1379 mResultIntentData = resultIntentData;
1380 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001381}