blob: 37fcc871967a53ca1baa3fea3c5e4faec59b4092 [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;
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400115
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800116import org.xmlpull.v1.XmlPullParser;
117import org.xmlpull.v1.XmlPullParserException;
118
119import java.io.IOException;
120import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800121import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700122import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800123
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -0700124import static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700125
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800126public class SettingsActivity extends Activity
127 implements PreferenceManager.OnPreferenceTreeClickListener,
128 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100129 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700130 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100131 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800132
133 private static final String LOG_TAG = "Settings";
134
135 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700136 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700137 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
138 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700139 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700140 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700141 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800142
143 /**
144 * When starting this activity, the invoking Intent can contain this extra
145 * string to specify which fragment should be initially displayed.
146 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
147 * will call isValidFragment() to confirm that the fragment class name is valid for this
148 * activity.
149 */
150 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
151
152 /**
153 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
154 * this extra can also be specified to supply a Bundle of arguments to pass
155 * to that fragment when it is instantiated during the initial creation
156 * of the activity.
157 */
158 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
159
160 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700161 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
162 */
163 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
164
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800165 public static final String BACK_STACK_PREFS = ":settings:prefs";
166
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800167 // extras that allow any preference activity to be launched as part of a wizard
168
169 // show Back and Next buttons? takes boolean parameter
170 // Back will then return RESULT_CANCELED and Next RESULT_OK
171 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
172
173 // add a Skip button?
174 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
175
176 // specify custom text for the Back or Next buttons, or cause a button to not appear
177 // at all by setting it to null
178 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
179 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
180
181 /**
182 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700183 * 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 -0800184 * that fragment.
185 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700186 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700187 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
188 ":settings:show_fragment_title_resid";
189 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
190 ":settings:show_fragment_as_shortcut";
191
192 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
193 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800194
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800195 private static final String META_DATA_KEY_FRAGMENT_CLASS =
196 "com.android.settings.FRAGMENT_CLASS";
197
198 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
199
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700200 private static final String EMPTY_QUERY = "";
201
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800202 private static boolean sShowNoHomeNotice = false;
203
204 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800205
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800206 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700207 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800208
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800209 // Show only these settings for restricted users
210 private int[] SETTINGS_FOR_RESTRICTED = {
211 R.id.wireless_section,
212 R.id.wifi_settings,
213 R.id.bluetooth_settings,
214 R.id.data_usage_settings,
PauloftheWest38155612014-06-30 10:02:36 -0700215 R.id.sim_settings,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800216 R.id.wireless_settings,
217 R.id.device_section,
John Spurlock4e4cdef2014-05-28 09:43:45 -0400218 R.id.notification_settings,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800219 R.id.display_settings,
220 R.id.storage_settings,
221 R.id.application_settings,
222 R.id.battery_settings,
223 R.id.personal_section,
224 R.id.location_settings,
225 R.id.security_settings,
226 R.id.language_settings,
227 R.id.user_settings,
228 R.id.account_settings,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800229 R.id.system_section,
230 R.id.date_time_settings,
231 R.id.about_settings,
232 R.id.accessibility_settings,
233 R.id.print_settings,
234 R.id.nfc_payment_settings,
Fabrice Di Meglio2858b792014-02-18 19:35:08 -0800235 R.id.home_settings,
236 R.id.dashboard
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800237 };
238
239 private static final String[] ENTRY_FRAGMENTS = {
240 WirelessSettings.class.getName(),
241 WifiSettings.class.getName(),
242 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700243 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800244 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700245 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800246 TetherSettings.class.getName(),
247 WifiP2pSettings.class.getName(),
248 VpnSettings.class.getName(),
249 DateTimeSettings.class.getName(),
250 LocalePicker.class.getName(),
251 InputMethodAndLanguageSettings.class.getName(),
Dianne Hackbornb51253c2014-08-12 15:08:04 -0700252 VoiceInputSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800253 SpellCheckersSettings.class.getName(),
254 UserDictionaryList.class.getName(),
255 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700256 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800257 DisplaySettings.class.getName(),
258 DeviceInfoSettings.class.getName(),
259 ManageApplications.class.getName(),
260 ProcessStatsUi.class.getName(),
261 NotificationStation.class.getName(),
262 LocationSettings.class.getName(),
263 SecuritySettings.class.getName(),
Dianne Hackbornb51253c2014-08-12 15:08:04 -0700264 UsageAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800265 PrivacySettings.class.getName(),
266 DeviceAdminSettings.class.getName(),
267 AccessibilitySettings.class.getName(),
268 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800269 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
270 TextToSpeechSettings.class.getName(),
271 Memory.class.getName(),
272 DevelopmentSettings.class.getName(),
273 UsbSettings.class.getName(),
274 AndroidBeam.class.getName(),
275 WifiDisplaySettings.class.getName(),
276 PowerUsageSummary.class.getName(),
277 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000278 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800279 CryptKeeperSettings.class.getName(),
280 DataUsageSummary.class.getName(),
281 DreamSettings.class.getName(),
282 UserSettings.class.getName(),
283 NotificationAccessSettings.class.getName(),
John Spurlockc9afadb2014-04-29 18:07:23 -0400284 ConditionProviderSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800285 PrintSettingsFragment.class.getName(),
286 PrintJobSettingsFragment.class.getName(),
287 TrustedCredentialsSettings.class.getName(),
288 PaymentSettings.class.getName(),
289 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700290 ZenModeSettings.class.getName(),
291 NotificationSettings.class.getName(),
292 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
293 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400294 InstalledAppDetails.class.getName(),
295 BatterySaverSettings.class.getName(),
John Spurlock802ddf92014-07-18 11:51:13 -0400296 NotificationAppList.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700297 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700298 OtherSoundSettings.class.getName(),
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700299 QuickLaunchSettings.class.getName(),
300 ApnSettings.class.getName()
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800301 };
302
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700303
304 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
305 "android.settings.APPLICATION_DETAILS_SETTINGS"
306 };
307
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800308 private SharedPreferences mDevelopmentPreferences;
309 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
310
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800311 private boolean mBatteryPresent = true;
312 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800313 @Override
314 public void onReceive(Context context, Intent intent) {
315 String action = intent.getAction();
316 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
317 boolean batteryPresent = Utils.isBatteryPresent(intent);
318
319 if (mBatteryPresent != batteryPresent) {
320 mBatteryPresent = batteryPresent;
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700321 invalidateCategories(true);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800322 }
323 }
324 }
325 };
326
Svetoslav990159a2014-04-14 17:14:59 -0700327 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
328 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700329
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700330 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700331 private SwitchBar mSwitchBar;
332
333 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700334
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700335 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700336 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700337
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700338 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700339 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700340
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700341 private ViewGroup mContent;
342
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700343 private SearchView mSearchView;
344 private MenuItem mSearchMenuItem;
345 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700346 private SearchResultsSummary mSearchResultsFragment;
347 private String mSearchQuery;
348
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700349 // Categories
350 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800351
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700352 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700353 private static final int MSG_BUILD_CATEGORIES = 1;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800354 private Handler mHandler = new Handler() {
355 @Override
356 public void handleMessage(Message msg) {
357 switch (msg.what) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700358 case MSG_BUILD_CATEGORIES: {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700359 final boolean forceRefresh = msg.getData().getBoolean(MSG_DATA_FORCE_REFRESH);
360 if (forceRefresh) {
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700361 buildDashboardCategories(mCategories);
362 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800363 } break;
364 }
365 }
366 };
367
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700368 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700369 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700370
Jim Miller0698a212014-10-16 19:49:07 -0700371 private Intent mResultIntentData;
372
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700373 public SwitchBar getSwitchBar() {
374 return mSwitchBar;
375 }
376
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700377 public List<DashboardCategory> getDashboardCategories(boolean forceRefresh) {
378 if (forceRefresh || mCategories.size() == 0) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700379 buildDashboardCategories(mCategories);
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700380 }
381 return mCategories;
382 }
383
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800384 @Override
385 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
386 // Override the fragment title for Wallpaper settings
387 int titleRes = pref.getTitleRes();
388 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
389 titleRes = R.string.wallpaper_settings_fragment_title;
390 } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName())
391 && UserHandle.myUserId() != UserHandle.USER_OWNER) {
392 if (UserManager.get(this).isLinkedUser()) {
393 titleRes = R.string.profile_info_settings_title;
394 } else {
395 titleRes = R.string.user_info_settings_title;
396 }
397 }
398 startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),
399 null, 0);
400 return true;
401 }
402
403 @Override
404 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
405 return false;
406 }
407
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700408 private void invalidateCategories(boolean forceRefresh) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700409 if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700410 Message msg = new Message();
411 msg.what = MSG_BUILD_CATEGORIES;
412 msg.getData().putBoolean(MSG_DATA_FORCE_REFRESH, forceRefresh);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800413 }
414 }
415
416 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800417 public void onConfigurationChanged(Configuration newConfig) {
418 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800419 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800420 }
421
422 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700423 protected void onStart() {
424 super.onStart();
425
426 if (mNeedToRevertToInitialFragment) {
427 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800428 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800429 }
430
431 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700432 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700433 if (!mDisplaySearch) {
434 return false;
435 }
436
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700437 MenuInflater inflater = getMenuInflater();
438 inflater.inflate(R.menu.options_menu, menu);
439
440 // Cache the search query (can be overriden by the OnQueryTextListener)
441 final String query = mSearchQuery;
442
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700443 mSearchMenuItem = menu.findItem(R.id.search);
444 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700445
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700446 if (mSearchMenuItem == null || mSearchView == null) {
447 return false;
448 }
449
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700450 if (mSearchResultsFragment != null) {
451 mSearchResultsFragment.setSearchView(mSearchView);
452 }
453
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700454 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700455 mSearchView.setOnQueryTextListener(this);
456 mSearchView.setOnCloseListener(this);
457
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700458 if (mSearchMenuItemExpanded) {
459 mSearchMenuItem.expandActionView();
460 }
461 mSearchView.setQuery(query, true /* submit */);
462
463 return true;
464 }
465
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700466 private static boolean isShortCutIntent(final Intent intent) {
467 Set<String> categories = intent.getCategories();
468 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
469 }
470
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700471 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700472 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700473 if (action == null) {
474 return false;
475 }
476 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
477 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
478 }
479 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700480 }
481
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700482 @Override
483 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700484 super.onCreate(savedState);
485
486 // Should happen before any call to getIntent()
487 getMetaData();
488
489 final Intent intent = getIntent();
490 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
491 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800492 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800493
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800494 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
495 Context.MODE_PRIVATE);
496
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700497 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700498 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700499
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700500 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700501 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
502
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700503 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700504 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700505
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700506 mIsShowingDashboard = className.equals(Settings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700507
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700508 // This is a "Sub Settings" when:
509 // - this is a real SubSettings
510 // - or :settings:show_fragment_as_subsetting is passed to the Intent
511 final boolean isSubSettings = className.equals(SubSettings.class.getName()) ||
512 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
513
514 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
515 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700516 // Check also that we are not a Theme Dialog as we don't want to override them
517 final int themeResId = getThemeResId();
518 if (themeResId != R.style.Theme_DialogWhenLarge &&
519 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
520 setTheme(R.style.Theme_SubSettings);
521 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700522 }
523
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700524 setContentView(mIsShowingDashboard ?
525 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800526
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700527 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700528
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800529 getFragmentManager().addOnBackStackChangedListener(this);
530
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700531 if (mIsShowingDashboard) {
Fabrice Di Megliodba577f2014-06-06 16:31:45 -0700532 Index.getInstance(getApplicationContext()).update();
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700533 }
534
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700535 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700536 // We are restarting from a previous saved state; used that to initialize, instead
537 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700538 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
539 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800540
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700541 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800542
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700543 ArrayList<DashboardCategory> categories =
544 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
545 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700546 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700547 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700548 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800549 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700550
551 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700552 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700553 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
554 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800555 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700556 if (!mIsShowingDashboard) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700557 // Search is shown we are launched thru a Settings "shortcut". UP will be shown
558 // only if it is a sub settings
559 if (mIsShortcut) {
560 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700561 mDisplaySearch = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700562 } else if (isSubSettings) {
563 mDisplayHomeAsUpEnabled = true;
564 mDisplaySearch = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700565 } else {
566 mDisplayHomeAsUpEnabled = false;
567 mDisplaySearch = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700568 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700569 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700570
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700571 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700572 switchToFragment(initialFragmentName, initialArguments, true, false,
573 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000574 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700575 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700576 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700577 // Show Search affordance
578 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700579 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700580 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700581 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800582 }
583 }
584
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700585 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700586 if (mActionBar != null) {
587 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
588 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
589 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700590 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
591
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800592 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800593 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
594
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700595 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800596 if (buttonBar != null) {
597 buttonBar.setVisibility(View.VISIBLE);
598
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700599 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800600 backButton.setOnClickListener(new OnClickListener() {
601 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700602 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800603 finish();
604 }
605 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700606 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800607 skipButton.setOnClickListener(new OnClickListener() {
608 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700609 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800610 finish();
611 }
612 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700613 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800614 mNextButton.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 });
620
621 // set our various button parameters
622 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
623 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
624 if (TextUtils.isEmpty(buttonText)) {
625 mNextButton.setVisibility(View.GONE);
626 }
627 else {
628 mNextButton.setText(buttonText);
629 }
630 }
631 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
632 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
633 if (TextUtils.isEmpty(buttonText)) {
634 backButton.setVisibility(View.GONE);
635 }
636 else {
637 backButton.setText(buttonText);
638 }
639 }
640 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
641 skipButton.setVisibility(View.VISIBLE);
642 }
643 }
644 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700645
646 mHomeActivitiesCount = getHomeActivitiesCount();
647 }
648
649 private int getHomeActivitiesCount() {
650 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
651 getPackageManager().getHomeActivities(homeApps);
652 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800653 }
654
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700655 private void setTitleFromIntent(Intent intent) {
656 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
657 if (initialTitleResId > 0) {
658 mInitialTitle = null;
659 mInitialTitleResId = initialTitleResId;
660 setTitle(mInitialTitleResId);
661 } else {
662 mInitialTitleResId = -1;
663 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
664 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
665 setTitle(mInitialTitle);
666 }
667 }
668
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800669 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800670 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700671 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800672 }
673
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700674 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800675 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700676
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800677 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700678 if (mInitialTitleResId > 0) {
679 setTitle(mInitialTitleResId);
680 } else {
681 setTitle(mInitialTitle);
682 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700683 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800684 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700685
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800686 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
687 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700688
689 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800690 }
691
692 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
693 final CharSequence title;
694 final int titleRes = bse.getBreadCrumbTitleRes();
695 if (titleRes > 0) {
696 title = getText(titleRes);
697 } else {
698 title = bse.getBreadCrumbTitle();
699 }
700 if (title != null) {
701 setTitle(title);
702 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800703 }
704
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800705 @Override
706 protected void onSaveInstanceState(Bundle outState) {
707 super.onSaveInstanceState(outState);
708
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700709 if (mCategories.size() > 0) {
710 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800711 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700712
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700713 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700714 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700715
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700716 if (mDisplaySearch) {
717 // The option menus are created if the ActionBar is visible and they are also created
718 // asynchronously. If you launch Settings with an Intent action like
719 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
720 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
721 // menu item and search view are null.
722 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
723 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700724
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700725 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
726 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
727 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700728
729 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800730 }
731
732 @Override
733 public void onResume() {
734 super.onResume();
735
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700736 final int newHomeActivityCount = getHomeActivitiesCount();
737 if (newHomeActivityCount != mHomeActivitiesCount) {
738 mHomeActivitiesCount = newHomeActivityCount;
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700739 invalidateCategories(true);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700740 }
741
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800742 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
743 @Override
744 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700745 invalidateCategories(true);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800746 }
747 };
748 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
749 mDevelopmentPreferencesListener);
750
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800751 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700752
Svetoslav990159a2014-04-14 17:14:59 -0700753 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700754
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700755 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700756 onQueryTextSubmit(mSearchQuery);
757 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800758 }
759
760 @Override
761 public void onPause() {
762 super.onPause();
763
764 unregisterReceiver(mBatteryInfoReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700765 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800766 }
767
768 @Override
769 public void onDestroy() {
770 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700771
772 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
773 mDevelopmentPreferencesListener);
774 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800775 }
776
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800777 protected boolean isValidFragment(String fragmentName) {
778 // Almost all fragments are wrapped in this,
779 // except for a few that have their own activities.
780 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
781 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
782 }
783 return false;
784 }
785
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800786 @Override
787 public Intent getIntent() {
788 Intent superIntent = super.getIntent();
789 String startingFragment = getStartingFragmentClass(superIntent);
790 // This is called from super.onCreate, isMultiPane() is not yet reliable
791 // Do not use onIsHidingHeaders either, which relies itself on this method
792 if (startingFragment != null) {
793 Intent modIntent = new Intent(superIntent);
794 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
795 Bundle args = superIntent.getExtras();
796 if (args != null) {
797 args = new Bundle(args);
798 } else {
799 args = new Bundle();
800 }
801 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100802 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800803 return modIntent;
804 }
805 return superIntent;
806 }
807
808 /**
809 * Checks if the component name in the intent is different from the Settings class and
810 * returns the class name to load as a fragment.
811 */
812 private String getStartingFragmentClass(Intent intent) {
813 if (mFragmentClass != null) return mFragmentClass;
814
815 String intentClass = intent.getComponent().getClassName();
816 if (intentClass.equals(getClass().getName())) return null;
817
818 if ("com.android.settings.ManageApplications".equals(intentClass)
819 || "com.android.settings.RunningServices".equals(intentClass)
820 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
821 // Old names of manage apps.
822 intentClass = com.android.settings.applications.ManageApplications.class.getName();
823 }
824
825 return intentClass;
826 }
827
828 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000829 * Start a new fragment containing a preference panel. If the preferences
830 * are being displayed in multi-pane mode, the given fragment class will
831 * be instantiated and placed in the appropriate pane. If running in
832 * single-pane mode, a new activity will be launched in which to show the
833 * fragment.
834 *
835 * @param fragmentClass Full name of the class implementing the fragment.
836 * @param args Any desired arguments to supply to the fragment.
837 * @param titleRes Optional resource identifier of the title of this
838 * fragment.
839 * @param titleText Optional text of the title of this fragment.
840 * @param resultTo Optional fragment that result data should be sent to.
841 * If non-null, resultTo.onActivityResult() will be called when this
842 * preference panel is done. The launched panel must use
843 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
844 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700845 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000846 */
847 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700848 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700849 String title = null;
850 if (titleRes < 0) {
851 if (titleText != null) {
852 title = titleText.toString();
853 } else {
854 // There not much we can do in that case
855 title = "";
856 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700857 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700858 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700859 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000860 }
861
862 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100863 * Start a new fragment in a new activity containing a preference panel for a given user. If the
864 * preferences are being displayed in multi-pane mode, the given fragment class will be
865 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
866 * activity will be launched in which to show the fragment.
867 *
868 * @param fragmentClass Full name of the class implementing the fragment.
869 * @param args Any desired arguments to supply to the fragment.
870 * @param titleRes Optional resource identifier of the title of this fragment.
871 * @param titleText Optional text of the title of this fragment.
872 * @param userHandle The user for which the panel has to be started.
873 */
874 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
875 CharSequence titleText, UserHandle userHandle) {
876 String title = null;
877 if (titleRes < 0) {
878 if (titleText != null) {
879 title = titleText.toString();
880 } else {
881 // There not much we can do in that case
882 title = "";
883 }
884 }
885 Utils.startWithFragmentAsUser(this, fragmentClass, args,
886 titleRes, title, mIsShortcut, userHandle);
887 }
888
889 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800890 * Called by a preference panel fragment to finish itself.
891 *
892 * @param caller The fragment that is asking to be finished.
893 * @param resultCode Optional result code to send back to the original
894 * launching fragment.
895 * @param resultData Optional result data to send back to the original
896 * launching fragment.
897 */
898 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
899 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700900 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800901 }
902
903 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000904 * Start a new fragment.
905 *
906 * @param fragment The fragment to start
907 * @param push If true, the current fragment will be pushed onto the back stack. If false,
908 * the current fragment will be replaced.
909 */
910 public void startPreferenceFragment(Fragment fragment, boolean push) {
911 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700912 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000913 if (push) {
914 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
915 transaction.addToBackStack(BACK_STACK_PREFS);
916 } else {
917 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
918 }
919 transaction.commitAllowingStateLoss();
920 }
921
922 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700923 * Switch to a specific Fragment with taking care of validation, Title and BackStack
924 */
925 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700926 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700927 if (validate && !isValidFragment(fragmentName)) {
928 throw new IllegalArgumentException("Invalid fragment for this activity: "
929 + fragmentName);
930 }
931 Fragment f = Fragment.instantiate(this, fragmentName, args);
932 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700933 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700934 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700935 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700936 }
937 if (addToBackStack) {
938 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
939 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700940 if (titleResId > 0) {
941 transaction.setBreadCrumbTitle(titleResId);
942 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700943 transaction.setBreadCrumbTitle(title);
944 }
945 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700946 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700947 return f;
948 }
949
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700950 /**
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700951 * Called when the activity needs its list of categories/tiles built.
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700952 *
953 * @param categories The list in which to place the tiles categories.
954 */
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700955 private void buildDashboardCategories(List<DashboardCategory> categories) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700956 categories.clear();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700957 loadCategoriesFromResource(R.xml.dashboard_categories, categories);
958 updateTilesList(categories);
959 }
960
961 /**
962 * Parse the given XML file as a categories description, adding each
963 * parsed categories and tiles into the target list.
964 *
965 * @param resid The XML resource to load and parse.
966 * @param target The list in which the parsed categories and tiles should be placed.
967 */
968 private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) {
969 XmlResourceParser parser = null;
970 try {
971 parser = getResources().getXml(resid);
972 AttributeSet attrs = Xml.asAttributeSet(parser);
973
974 int type;
975 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
976 && type != XmlPullParser.START_TAG) {
977 // Parse next until start tag is found
978 }
979
980 String nodeName = parser.getName();
981 if (!"dashboard-categories".equals(nodeName)) {
982 throw new RuntimeException(
983 "XML document must start with <preference-categories> tag; found"
984 + nodeName + " at " + parser.getPositionDescription());
985 }
986
987 Bundle curBundle = null;
988
989 final int outerDepth = parser.getDepth();
990 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
991 && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
992 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
993 continue;
994 }
995
996 nodeName = parser.getName();
997 if ("dashboard-category".equals(nodeName)) {
998 DashboardCategory category = new DashboardCategory();
999
1000 TypedArray sa = obtainStyledAttributes(
1001 attrs, com.android.internal.R.styleable.PreferenceHeader);
1002 category.id = sa.getResourceId(
1003 com.android.internal.R.styleable.PreferenceHeader_id,
1004 (int)DashboardCategory.CAT_ID_UNDEFINED);
1005
1006 TypedValue tv = sa.peekValue(
1007 com.android.internal.R.styleable.PreferenceHeader_title);
1008 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
1009 if (tv.resourceId != 0) {
1010 category.titleRes = tv.resourceId;
1011 } else {
1012 category.title = tv.string;
1013 }
1014 }
1015 sa.recycle();
1016
1017 final int innerDepth = parser.getDepth();
1018 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1019 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
1020 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1021 continue;
1022 }
1023
1024 String innerNodeName = parser.getName();
1025 if (innerNodeName.equals("dashboard-tile")) {
1026 DashboardTile tile = new DashboardTile();
1027
1028 sa = obtainStyledAttributes(
1029 attrs, com.android.internal.R.styleable.PreferenceHeader);
1030 tile.id = sa.getResourceId(
1031 com.android.internal.R.styleable.PreferenceHeader_id,
Fabrice Di Meglioe9326d22014-05-13 12:49:14 -07001032 (int)TILE_ID_UNDEFINED);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001033 tv = sa.peekValue(
1034 com.android.internal.R.styleable.PreferenceHeader_title);
1035 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
1036 if (tv.resourceId != 0) {
1037 tile.titleRes = tv.resourceId;
1038 } else {
1039 tile.title = tv.string;
1040 }
1041 }
1042 tv = sa.peekValue(
1043 com.android.internal.R.styleable.PreferenceHeader_summary);
1044 if (tv != null && tv.type == TypedValue.TYPE_STRING) {
1045 if (tv.resourceId != 0) {
1046 tile.summaryRes = tv.resourceId;
1047 } else {
1048 tile.summary = tv.string;
1049 }
1050 }
1051 tile.iconRes = sa.getResourceId(
1052 com.android.internal.R.styleable.PreferenceHeader_icon, 0);
1053 tile.fragment = sa.getString(
1054 com.android.internal.R.styleable.PreferenceHeader_fragment);
1055 sa.recycle();
1056
1057 if (curBundle == null) {
1058 curBundle = new Bundle();
1059 }
1060
1061 final int innerDepth2 = parser.getDepth();
1062 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
1063 && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) {
1064 if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
1065 continue;
1066 }
1067
1068 String innerNodeName2 = parser.getName();
1069 if (innerNodeName2.equals("extra")) {
1070 getResources().parseBundleExtra("extra", attrs, curBundle);
1071 XmlUtils.skipCurrentTag(parser);
1072
1073 } else if (innerNodeName2.equals("intent")) {
1074 tile.intent = Intent.parseIntent(getResources(), parser, attrs);
1075
1076 } else {
1077 XmlUtils.skipCurrentTag(parser);
1078 }
1079 }
1080
1081 if (curBundle.size() > 0) {
1082 tile.fragmentArguments = curBundle;
1083 curBundle = null;
1084 }
1085
PauloftheWest38155612014-06-30 10:02:36 -07001086 // Show the SIM Cards setting if there are more than 2 SIMs installed.
Fabrice Di Meglio22a2a492014-08-08 12:27:57 -07001087 if(tile.id != R.id.sim_settings || Utils.showSimCardTile(this)){
PauloftheWest38155612014-06-30 10:02:36 -07001088 category.addTile(tile);
1089 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001090
1091 } else {
1092 XmlUtils.skipCurrentTag(parser);
1093 }
1094 }
1095
1096 target.add(category);
1097 } else {
1098 XmlUtils.skipCurrentTag(parser);
1099 }
1100 }
1101
1102 } catch (XmlPullParserException e) {
1103 throw new RuntimeException("Error parsing categories", e);
1104 } catch (IOException e) {
1105 throw new RuntimeException("Error parsing categories", e);
1106 } finally {
1107 if (parser != null) parser.close();
1108 }
1109 }
1110
1111 private void updateTilesList(List<DashboardCategory> target) {
1112 final boolean showDev = mDevelopmentPreferences.getBoolean(
1113 DevelopmentSettings.PREF_SHOW,
1114 android.os.Build.TYPE.equals("eng"));
1115
1116 final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
1117
1118 final int size = target.size();
1119 for (int i = 0; i < size; i++) {
1120
1121 DashboardCategory category = target.get(i);
1122
1123 // Ids are integers, so downcasting is ok
1124 int id = (int) category.id;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001125 int n = category.getTilesCount() - 1;
1126 while (n >= 0) {
1127
1128 DashboardTile tile = category.getTile(n);
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001129 boolean removeTile = false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001130 id = (int) tile.id;
1131 if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001132 if (!Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile)) {
1133 removeTile = true;
1134 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001135 } else if (id == R.id.wifi_settings) {
1136 // Remove WiFi Settings if WiFi service is not available.
1137 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001138 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001139 }
1140 } else if (id == R.id.bluetooth_settings) {
1141 // Remove Bluetooth Settings if Bluetooth service is not available.
1142 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001143 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001144 }
1145 } else if (id == R.id.data_usage_settings) {
1146 // Remove data usage when kernel module not enabled
1147 final INetworkManagementService netManager = INetworkManagementService.Stub
1148 .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
1149 try {
1150 if (!netManager.isBandwidthControlEnabled()) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001151 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001152 }
1153 } catch (RemoteException e) {
1154 // ignored
1155 }
1156 } else if (id == R.id.battery_settings) {
1157 // Remove battery settings when battery is not available. (e.g. TV)
1158
1159 if (!mBatteryPresent) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001160 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001161 }
1162 } else if (id == R.id.home_settings) {
1163 if (!updateHomeSettingTiles(tile)) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001164 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001165 }
1166 } else if (id == R.id.user_settings) {
Amith Yamasani4093e402014-06-06 14:31:37 -07001167 boolean hasMultipleUsers =
1168 ((UserManager) getSystemService(Context.USER_SERVICE))
1169 .getUserCount() > 1;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001170 if (!UserHandle.MU_ENABLED
Amith Yamasani4093e402014-06-06 14:31:37 -07001171 || (!UserManager.supportsMultipleUsers()
1172 && !hasMultipleUsers)
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001173 || Utils.isMonkeyRunning()) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001174 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001175 }
1176 } else if (id == R.id.nfc_payment_settings) {
1177 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001178 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001179 } else {
1180 // Only show if NFC is on and we have the HCE feature
1181 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
Fabrice Di Megliob3c7a172014-09-23 11:36:44 -07001182 if (adapter == null || !adapter.isEnabled() ||
1183 !getPackageManager().hasSystemFeature(
1184 PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001185 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001186 }
1187 }
Fabrice Di Meglio488cae32014-05-13 11:26:34 -07001188 } else if (id == R.id.print_settings) {
1189 boolean hasPrintingSupport = getPackageManager().hasSystemFeature(
1190 PackageManager.FEATURE_PRINTING);
1191 if (!hasPrintingSupport) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001192 removeTile = true;
Fabrice Di Meglio488cae32014-05-13 11:26:34 -07001193 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001194 } else if (id == R.id.development_settings) {
Julia Reynolds6c088cb2014-05-08 09:29:41 -04001195 if (!showDev || um.hasUserRestriction(
1196 UserManager.DISALLOW_DEBUGGING_FEATURES)) {
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001197 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001198 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001199 }
1200
1201 if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001202 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) {
1203 removeTile = true;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001204 }
1205
Amith Yamasani57fd5fd2014-08-06 15:48:10 -07001206 if (removeTile && n < category.getTilesCount()) {
1207 category.removeTile(n);
1208 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001209 n--;
1210 }
1211 }
1212 }
1213
1214 private boolean updateHomeSettingTiles(DashboardTile tile) {
1215 // Once we decide to show Home settings, keep showing it forever
1216 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1217 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1218 return true;
1219 }
1220
1221 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001222 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001223 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001224 // When there's only one available home app, omit this settings
1225 // category entirely at the top level UI. If the user just
1226 // uninstalled the penultimate home app candidiate, we also
1227 // now tell them about why they aren't seeing 'Home' in the list.
1228 if (sShowNoHomeNotice) {
1229 sShowNoHomeNotice = false;
1230 NoHomeDialogFragment.show(this);
1231 }
1232 return false;
1233 } else {
1234 // Okay, we're allowing the Home settings category. Tell it, when
1235 // invoked via this front door, that we'll need to be told about the
1236 // case when the user uninstalls all but one home app.
1237 if (tile.fragmentArguments == null) {
1238 tile.fragmentArguments = new Bundle();
1239 }
1240 tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true);
1241 }
1242 } catch (Exception e) {
1243 // Can't look up the home activity; bail on configuring the icon
1244 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1245 }
1246
1247 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1248 return true;
1249 }
1250
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001251 private void getMetaData() {
1252 try {
1253 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1254 PackageManager.GET_META_DATA);
1255 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001256 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1257 } catch (NameNotFoundException nnfe) {
1258 // No recovery
1259 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1260 }
1261 }
1262
1263 // give subclasses access to the Next button
1264 public boolean hasNextButton() {
1265 return mNextButton != null;
1266 }
1267
1268 public Button getNextButton() {
1269 return mNextButton;
1270 }
1271
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001272 @Override
1273 public boolean shouldUpRecreateTask(Intent targetIntent) {
1274 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1275 }
1276
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001277 public static void requestHomeNotice() {
1278 sShowNoHomeNotice = true;
1279 }
1280
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001281 @Override
1282 public boolean onQueryTextSubmit(String query) {
1283 switchToSearchResultsFragmentIfNeeded();
1284 mSearchQuery = query;
1285 return mSearchResultsFragment.onQueryTextSubmit(query);
1286 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001287
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001288 @Override
1289 public boolean onQueryTextChange(String newText) {
1290 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001291 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001292 return false;
1293 }
1294 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001295 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001296
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001297 @Override
1298 public boolean onClose() {
1299 return false;
1300 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001301
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001302 @Override
1303 public boolean onMenuItemActionExpand(MenuItem item) {
1304 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001305 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001306 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001307 return true;
1308 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001309
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001310 @Override
1311 public boolean onMenuItemActionCollapse(MenuItem item) {
1312 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001313 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001314 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001315 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001316 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001317 return true;
1318 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001319
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001320 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001321 if (mSearchResultsFragment != null) {
1322 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001323 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001324 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001325 if (current != null && current instanceof SearchResultsSummary) {
1326 mSearchResultsFragment = (SearchResultsSummary) current;
1327 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001328 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001329 SearchResultsSummary.class.getName(), null, false, true,
1330 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001331 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001332 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001333 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001334 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001335
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001336 public void needToRevertToInitialFragment() {
1337 mNeedToRevertToInitialFragment = true;
1338 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001339
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001340 private void revertToInitialFragment() {
1341 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001342 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001343 mSearchMenuItemExpanded = false;
1344 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1345 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001346 if (mSearchMenuItem != null) {
1347 mSearchMenuItem.collapseActionView();
1348 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001349 }
Jim Miller0698a212014-10-16 19:49:07 -07001350
1351 public Intent getResultIntentData() {
1352 return mResultIntentData;
1353 }
1354
1355 public void setResultIntentData(Intent resultIntentData) {
1356 mResultIntentData = resultIntentData;
1357 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001358}