Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.settings; |
| 18 | |
| 19 | import android.accounts.Account; |
| 20 | import android.accounts.AccountManager; |
| 21 | import android.accounts.OnAccountsUpdateListener; |
| 22 | import android.app.ActionBar; |
| 23 | import android.app.Activity; |
| 24 | import android.app.Fragment; |
| 25 | import android.app.FragmentManager; |
| 26 | import android.app.FragmentTransaction; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 27 | import android.content.BroadcastReceiver; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 28 | import android.content.ComponentName; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
| 31 | import android.content.IntentFilter; |
| 32 | import android.content.SharedPreferences; |
| 33 | import android.content.pm.ActivityInfo; |
| 34 | import android.content.pm.PackageManager; |
| 35 | import android.content.pm.PackageManager.NameNotFoundException; |
| 36 | import android.content.pm.ResolveInfo; |
| 37 | import android.content.res.Configuration; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 38 | import android.content.res.TypedArray; |
| 39 | import android.content.res.XmlResourceParser; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 40 | import android.nfc.NfcAdapter; |
| 41 | import android.os.Bundle; |
| 42 | import android.os.Handler; |
| 43 | import android.os.INetworkManagementService; |
| 44 | import android.os.Message; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 45 | import android.os.RemoteException; |
| 46 | import android.os.ServiceManager; |
| 47 | import android.os.UserHandle; |
| 48 | import android.os.UserManager; |
| 49 | import android.preference.Preference; |
| 50 | import android.preference.PreferenceFragment; |
| 51 | import android.preference.PreferenceManager; |
| 52 | import android.preference.PreferenceScreen; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 53 | import android.text.TextUtils; |
| 54 | import android.util.AttributeSet; |
| 55 | import android.util.Log; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 56 | import android.util.TypedValue; |
| 57 | import android.util.Xml; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 58 | import android.view.Menu; |
| 59 | import android.view.MenuInflater; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 60 | import android.view.MenuItem; |
| 61 | import android.view.View; |
| 62 | import android.view.View.OnClickListener; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 63 | import android.widget.Button; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 64 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 65 | import android.widget.SearchView; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 66 | import com.android.internal.util.ArrayUtils; |
| 67 | import com.android.internal.util.XmlUtils; |
| 68 | import com.android.settings.accessibility.AccessibilitySettings; |
| 69 | import com.android.settings.accessibility.CaptionPropertiesFragment; |
| 70 | import com.android.settings.accounts.AccountSyncSettings; |
| 71 | import com.android.settings.accounts.AuthenticatorHelper; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 72 | import com.android.settings.accounts.ManageAccountsSettings; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 73 | import com.android.settings.applications.InstalledAppDetails; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 74 | import com.android.settings.applications.ManageApplications; |
| 75 | import com.android.settings.applications.ProcessStatsUi; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 76 | import com.android.settings.bluetooth.BluetoothSettings; |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 77 | import com.android.settings.dashboard.DashboardCategory; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 78 | import com.android.settings.dashboard.DashboardSummary; |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 79 | import com.android.settings.dashboard.DashboardTile; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 80 | import com.android.settings.dashboard.Header; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 81 | import com.android.settings.dashboard.NoHomeDialogFragment; |
| 82 | import com.android.settings.dashboard.SearchResultsSummary; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 83 | import com.android.settings.deviceinfo.Memory; |
| 84 | import com.android.settings.deviceinfo.UsbSettings; |
| 85 | import com.android.settings.fuelgauge.PowerUsageSummary; |
Fabrice Di Meglio | 7a6bfd1 | 2014-04-14 19:49:18 -0700 | [diff] [blame] | 86 | import com.android.settings.search.DynamicIndexableContentMonitor; |
Fabrice Di Meglio | fa7dc24 | 2014-03-12 19:24:43 -0700 | [diff] [blame] | 87 | import com.android.settings.search.Index; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 88 | import com.android.settings.inputmethod.InputMethodAndLanguageSettings; |
| 89 | import com.android.settings.inputmethod.KeyboardLayoutPickerFragment; |
| 90 | import com.android.settings.inputmethod.SpellCheckersSettings; |
| 91 | import com.android.settings.inputmethod.UserDictionaryList; |
| 92 | import com.android.settings.location.LocationSettings; |
| 93 | import com.android.settings.nfc.AndroidBeam; |
| 94 | import com.android.settings.nfc.PaymentSettings; |
John Spurlock | c9afadb | 2014-04-29 18:07:23 -0400 | [diff] [blame] | 95 | import com.android.settings.notification.ConditionProviderSettings; |
John Spurlock | 4a35051 | 2014-04-08 14:08:21 -0400 | [diff] [blame] | 96 | import com.android.settings.notification.NotificationAccessSettings; |
| 97 | import com.android.settings.notification.NotificationSettings; |
| 98 | import com.android.settings.notification.NotificationStation; |
| 99 | import com.android.settings.notification.ZenModeSettings; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 100 | import com.android.settings.print.PrintJobSettingsFragment; |
| 101 | import com.android.settings.print.PrintSettingsFragment; |
| 102 | import com.android.settings.tts.TextToSpeechSettings; |
| 103 | import com.android.settings.users.UserSettings; |
| 104 | import com.android.settings.vpn2.VpnSettings; |
| 105 | import com.android.settings.wfd.WifiDisplaySettings; |
| 106 | import com.android.settings.wifi.AdvancedWifiSettings; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 107 | import com.android.settings.wifi.WifiSettings; |
| 108 | import com.android.settings.wifi.p2p.WifiP2pSettings; |
| 109 | import org.xmlpull.v1.XmlPullParser; |
| 110 | import org.xmlpull.v1.XmlPullParserException; |
| 111 | |
| 112 | import java.io.IOException; |
| 113 | import java.util.ArrayList; |
| 114 | import java.util.Collections; |
| 115 | import java.util.Comparator; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 116 | import java.util.List; |
| 117 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 118 | import static com.android.settings.dashboard.Header.HEADER_ID_UNDEFINED; |
| 119 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 120 | public class SettingsActivity extends Activity |
| 121 | implements PreferenceManager.OnPreferenceTreeClickListener, |
| 122 | PreferenceFragment.OnPreferenceStartFragmentCallback, |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 123 | ButtonBarHandler, OnAccountsUpdateListener, FragmentManager.OnBackStackChangedListener, |
| 124 | SearchView.OnQueryTextListener, SearchView.OnCloseListener, |
| 125 | MenuItem.OnActionExpandListener { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 126 | |
| 127 | private static final String LOG_TAG = "Settings"; |
| 128 | |
| 129 | // Constants for state save/restore |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 130 | private static final String SAVE_KEY_CATEGORIES = ":settings:categories"; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 131 | private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded"; |
| 132 | private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query"; |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 133 | private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up"; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * When starting this activity, the invoking Intent can contain this extra |
| 137 | * string to specify which fragment should be initially displayed. |
| 138 | * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity |
| 139 | * will call isValidFragment() to confirm that the fragment class name is valid for this |
| 140 | * activity. |
| 141 | */ |
| 142 | public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment"; |
| 143 | |
| 144 | /** |
| 145 | * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, |
| 146 | * this extra can also be specified to supply a Bundle of arguments to pass |
| 147 | * to that fragment when it is instantiated during the initial creation |
| 148 | * of the activity. |
| 149 | */ |
| 150 | public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args"; |
| 151 | |
| 152 | /** |
Fabrice Di Meglio | c145732 | 2014-04-04 19:07:50 -0700 | [diff] [blame] | 153 | * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS} |
| 154 | */ |
| 155 | public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"; |
| 156 | |
| 157 | /** |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 158 | * When starting this activity, the invoking Intent can contain this extra |
| 159 | * boolean that the header list should not be displayed. This is most often |
| 160 | * used in conjunction with {@link #EXTRA_SHOW_FRAGMENT} to launch |
| 161 | * the activity to display a specific fragment that the user has navigated |
| 162 | * to. |
| 163 | */ |
| 164 | public static final String EXTRA_NO_HEADERS = ":settings:no_headers"; |
| 165 | |
Fabrice Di Meglio | 6f0739a | 2014-02-03 18:12:25 -0800 | [diff] [blame] | 166 | public static final String BACK_STACK_PREFS = ":settings:prefs"; |
| 167 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 168 | // 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}, |
| 184 | * this extra can also be specify to supply the title to be shown for |
| 185 | * that fragment. |
| 186 | */ |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 187 | public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title"; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 188 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 189 | private static final String META_DATA_KEY_FRAGMENT_CLASS = |
| 190 | "com.android.settings.FRAGMENT_CLASS"; |
| 191 | |
| 192 | private static final String EXTRA_UI_OPTIONS = "settings:ui_options"; |
| 193 | |
Fabrice Di Meglio | d6985df | 2014-04-03 16:43:26 -0700 | [diff] [blame] | 194 | private static final String EMPTY_QUERY = ""; |
| 195 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 196 | private static boolean sShowNoHomeNotice = false; |
| 197 | |
| 198 | private String mFragmentClass; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 199 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 200 | private CharSequence mInitialTitle; |
| 201 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 202 | // Show only these settings for restricted users |
| 203 | private int[] SETTINGS_FOR_RESTRICTED = { |
| 204 | R.id.wireless_section, |
| 205 | R.id.wifi_settings, |
| 206 | R.id.bluetooth_settings, |
| 207 | R.id.data_usage_settings, |
| 208 | R.id.wireless_settings, |
| 209 | R.id.device_section, |
| 210 | R.id.sound_settings, |
| 211 | R.id.display_settings, |
| 212 | R.id.storage_settings, |
| 213 | R.id.application_settings, |
| 214 | R.id.battery_settings, |
| 215 | R.id.personal_section, |
| 216 | R.id.location_settings, |
| 217 | R.id.security_settings, |
| 218 | R.id.language_settings, |
| 219 | R.id.user_settings, |
| 220 | R.id.account_settings, |
| 221 | R.id.account_add, |
| 222 | R.id.system_section, |
| 223 | R.id.date_time_settings, |
| 224 | R.id.about_settings, |
| 225 | R.id.accessibility_settings, |
| 226 | R.id.print_settings, |
| 227 | R.id.nfc_payment_settings, |
Fabrice Di Meglio | 2858b79 | 2014-02-18 19:35:08 -0800 | [diff] [blame] | 228 | R.id.home_settings, |
| 229 | R.id.dashboard |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | private static final String[] ENTRY_FRAGMENTS = { |
| 233 | WirelessSettings.class.getName(), |
| 234 | WifiSettings.class.getName(), |
| 235 | AdvancedWifiSettings.class.getName(), |
| 236 | BluetoothSettings.class.getName(), |
| 237 | TetherSettings.class.getName(), |
| 238 | WifiP2pSettings.class.getName(), |
| 239 | VpnSettings.class.getName(), |
| 240 | DateTimeSettings.class.getName(), |
| 241 | LocalePicker.class.getName(), |
| 242 | InputMethodAndLanguageSettings.class.getName(), |
| 243 | SpellCheckersSettings.class.getName(), |
| 244 | UserDictionaryList.class.getName(), |
| 245 | UserDictionarySettings.class.getName(), |
| 246 | SoundSettings.class.getName(), |
| 247 | DisplaySettings.class.getName(), |
| 248 | DeviceInfoSettings.class.getName(), |
| 249 | ManageApplications.class.getName(), |
| 250 | ProcessStatsUi.class.getName(), |
| 251 | NotificationStation.class.getName(), |
| 252 | LocationSettings.class.getName(), |
| 253 | SecuritySettings.class.getName(), |
| 254 | PrivacySettings.class.getName(), |
| 255 | DeviceAdminSettings.class.getName(), |
| 256 | AccessibilitySettings.class.getName(), |
| 257 | CaptionPropertiesFragment.class.getName(), |
| 258 | com.android.settings.accessibility.ToggleInversionPreferenceFragment.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 259 | com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(), |
| 260 | TextToSpeechSettings.class.getName(), |
| 261 | Memory.class.getName(), |
| 262 | DevelopmentSettings.class.getName(), |
| 263 | UsbSettings.class.getName(), |
| 264 | AndroidBeam.class.getName(), |
| 265 | WifiDisplaySettings.class.getName(), |
| 266 | PowerUsageSummary.class.getName(), |
| 267 | AccountSyncSettings.class.getName(), |
| 268 | CryptKeeperSettings.class.getName(), |
| 269 | DataUsageSummary.class.getName(), |
| 270 | DreamSettings.class.getName(), |
| 271 | UserSettings.class.getName(), |
| 272 | NotificationAccessSettings.class.getName(), |
John Spurlock | c9afadb | 2014-04-29 18:07:23 -0400 | [diff] [blame] | 273 | ConditionProviderSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 274 | ManageAccountsSettings.class.getName(), |
| 275 | PrintSettingsFragment.class.getName(), |
| 276 | PrintJobSettingsFragment.class.getName(), |
| 277 | TrustedCredentialsSettings.class.getName(), |
| 278 | PaymentSettings.class.getName(), |
| 279 | KeyboardLayoutPickerFragment.class.getName(), |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 280 | ZenModeSettings.class.getName(), |
| 281 | NotificationSettings.class.getName(), |
| 282 | ChooseLockPassword.ChooseLockPasswordFragment.class.getName(), |
| 283 | ChooseLockPattern.ChooseLockPatternFragment.class.getName(), |
| 284 | InstalledAppDetails.class.getName() |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 285 | }; |
| 286 | |
| 287 | private SharedPreferences mDevelopmentPreferences; |
| 288 | private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener; |
| 289 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 290 | private AuthenticatorHelper mAuthenticatorHelper; |
| 291 | private boolean mListeningToAccountUpdates; |
| 292 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 293 | private boolean mBatteryPresent = true; |
| 294 | private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() { |
| 295 | |
| 296 | @Override |
| 297 | public void onReceive(Context context, Intent intent) { |
| 298 | String action = intent.getAction(); |
| 299 | if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { |
| 300 | boolean batteryPresent = Utils.isBatteryPresent(intent); |
| 301 | |
| 302 | if (mBatteryPresent != batteryPresent) { |
| 303 | mBatteryPresent = batteryPresent; |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 304 | invalidateCategories(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | } |
| 308 | }; |
| 309 | |
Svetoslav | 990159a | 2014-04-14 17:14:59 -0700 | [diff] [blame] | 310 | private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor = |
| 311 | new DynamicIndexableContentMonitor(); |
Svetoslav | 853e471 | 2014-04-14 10:10:25 -0700 | [diff] [blame] | 312 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 313 | private Button mNextButton; |
| 314 | private ActionBar mActionBar; |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 315 | private boolean mDisplayHomeAsUpEnabled; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 316 | |
| 317 | private SearchView mSearchView; |
| 318 | private MenuItem mSearchMenuItem; |
| 319 | private boolean mSearchMenuItemExpanded = false; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 320 | private SearchResultsSummary mSearchResultsFragment; |
| 321 | private String mSearchQuery; |
| 322 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 323 | // Categories |
| 324 | private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>(); |
| 325 | private boolean mNeedToRebuildCategories; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 326 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 327 | private static final int MSG_BUILD_CATEGORIES = 1; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 328 | private Handler mHandler = new Handler() { |
| 329 | @Override |
| 330 | public void handleMessage(Message msg) { |
| 331 | switch (msg.what) { |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 332 | case MSG_BUILD_CATEGORIES: { |
| 333 | buildDashboardCategories(mCategories); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 334 | } break; |
| 335 | } |
| 336 | } |
| 337 | }; |
| 338 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 339 | private boolean mNeedToRevertToInitialFragment = false; |
| 340 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 341 | public AuthenticatorHelper getAuthenticatorHelper() { |
| 342 | return mAuthenticatorHelper; |
| 343 | } |
| 344 | |
| 345 | public List<DashboardCategory> getDashboardCategories() { |
| 346 | if (mNeedToRebuildCategories) { |
| 347 | buildDashboardCategories(mCategories); |
| 348 | mNeedToRebuildCategories = false; |
| 349 | } |
| 350 | return mCategories; |
| 351 | } |
| 352 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 353 | @Override |
| 354 | public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { |
| 355 | // Override the fragment title for Wallpaper settings |
| 356 | int titleRes = pref.getTitleRes(); |
| 357 | if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) { |
| 358 | titleRes = R.string.wallpaper_settings_fragment_title; |
| 359 | } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName()) |
| 360 | && UserHandle.myUserId() != UserHandle.USER_OWNER) { |
| 361 | if (UserManager.get(this).isLinkedUser()) { |
| 362 | titleRes = R.string.profile_info_settings_title; |
| 363 | } else { |
| 364 | titleRes = R.string.user_info_settings_title; |
| 365 | } |
| 366 | } |
| 367 | startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(), |
| 368 | null, 0); |
| 369 | return true; |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
| 374 | return false; |
| 375 | } |
| 376 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 377 | private void invalidateCategories() { |
| 378 | if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) { |
| 379 | mHandler.sendEmptyMessage(MSG_BUILD_CATEGORIES); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
| 383 | @Override |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 384 | public void onConfigurationChanged(Configuration newConfig) { |
| 385 | super.onConfigurationChanged(newConfig); |
Fabrice Di Meglio | 6f0739a | 2014-02-03 18:12:25 -0800 | [diff] [blame] | 386 | Index.getInstance(this).update(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | @Override |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 390 | protected void onStart() { |
| 391 | super.onStart(); |
| 392 | |
| 393 | if (mNeedToRevertToInitialFragment) { |
| 394 | revertToInitialFragment(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 395 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | @Override |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 399 | public boolean onCreateOptionsMenu(Menu menu) { |
| 400 | MenuInflater inflater = getMenuInflater(); |
| 401 | inflater.inflate(R.menu.options_menu, menu); |
| 402 | |
| 403 | // Cache the search query (can be overriden by the OnQueryTextListener) |
| 404 | final String query = mSearchQuery; |
| 405 | |
Fabrice Di Meglio | 9593782 | 2014-03-31 19:46:42 -0700 | [diff] [blame] | 406 | mSearchMenuItem = menu.findItem(R.id.search); |
| 407 | mSearchView = (SearchView) mSearchMenuItem.getActionView(); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 408 | |
Fabrice Di Meglio | 23ae00c | 2014-04-21 12:43:20 -0700 | [diff] [blame] | 409 | if (mSearchMenuItem == null || mSearchView == null) { |
| 410 | return false; |
| 411 | } |
| 412 | |
Fabrice Di Meglio | 8c3b0ce | 2014-05-12 18:54:32 -0700 | [diff] [blame] | 413 | if (mSearchResultsFragment != null) { |
| 414 | mSearchResultsFragment.setSearchView(mSearchView); |
| 415 | } |
| 416 | |
Fabrice Di Meglio | 9593782 | 2014-03-31 19:46:42 -0700 | [diff] [blame] | 417 | mSearchMenuItem.setOnActionExpandListener(this); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 418 | mSearchView.setOnQueryTextListener(this); |
| 419 | mSearchView.setOnCloseListener(this); |
| 420 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 421 | if (mSearchMenuItemExpanded) { |
| 422 | mSearchMenuItem.expandActionView(); |
| 423 | } |
| 424 | mSearchView.setQuery(query, true /* submit */); |
| 425 | |
| 426 | return true; |
| 427 | } |
| 428 | |
| 429 | @Override |
| 430 | protected void onCreate(Bundle savedState) { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 431 | if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) { |
| 432 | getWindow().setUiOptions(getIntent().getIntExtra(EXTRA_UI_OPTIONS, 0)); |
| 433 | } |
Fabrice Di Meglio | 5ebabfc | 2014-04-21 09:40:46 -0700 | [diff] [blame] | 434 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 435 | mAuthenticatorHelper = new AuthenticatorHelper(); |
| 436 | mAuthenticatorHelper.updateAuthDescriptions(this); |
| 437 | mAuthenticatorHelper.onAccountsUpdated(this, null); |
| 438 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 439 | mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, |
| 440 | Context.MODE_PRIVATE); |
| 441 | |
| 442 | getMetaData(); |
| 443 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 444 | super.onCreate(savedState); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 445 | |
| 446 | setContentView(R.layout.settings_main); |
| 447 | |
| 448 | getFragmentManager().addOnBackStackChangedListener(this); |
| 449 | |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 450 | mDisplayHomeAsUpEnabled = true; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 451 | |
Fabrice Di Meglio | 5cda21b | 2014-04-21 10:14:28 -0700 | [diff] [blame] | 452 | // Getting Intent properties can only be done after the super.onCreate(...) |
| 453 | final String initialFragmentName = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT); |
| 454 | |
| 455 | if (initialFragmentName == null) { |
| 456 | Index.getInstance(this).update(); |
| 457 | } |
| 458 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 459 | if (savedState != null) { |
Fabrice Di Meglio | 1800a9f | 2014-04-03 19:31:07 -0700 | [diff] [blame] | 460 | // We are restarting from a previous saved state; used that to initialize, instead |
| 461 | // of starting fresh. |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 462 | mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED); |
| 463 | mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 464 | |
Fabrice Di Meglio | 1800a9f | 2014-04-03 19:31:07 -0700 | [diff] [blame] | 465 | final String initialTitle = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); |
| 466 | mInitialTitle = (initialTitle != null) ? initialTitle : getTitle(); |
| 467 | setTitle(mInitialTitle); |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 468 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 469 | ArrayList<DashboardCategory> categories = |
| 470 | savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); |
| 471 | if (categories != null) { |
| 472 | mCategories.addAll(categories); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 473 | setTitleFromBackStack(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 474 | } |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 475 | |
| 476 | mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 477 | } else { |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 478 | // We need to build the Categories in all cases |
| 479 | buildDashboardCategories(mCategories); |
Fabrice Di Meglio | 6d534a1 | 2014-03-03 11:34:18 -0800 | [diff] [blame] | 480 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 481 | if (initialFragmentName != null) { |
| 482 | final ComponentName cn = getIntent().getComponent(); |
| 483 | // No UP is we are launched thru a Settings shortcut |
| 484 | if (!cn.getClassName().equals(SubSettings.class.getName())) { |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 485 | mDisplayHomeAsUpEnabled = false; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 486 | } |
| 487 | final String initialTitle = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); |
| 488 | mInitialTitle = (initialTitle != null) ? initialTitle : getTitle(); |
Fabrice Di Meglio | 832e546 | 2014-03-06 19:12:14 -0800 | [diff] [blame] | 489 | setTitle(mInitialTitle); |
Fabrice Di Meglio | c145732 | 2014-04-04 19:07:50 -0700 | [diff] [blame] | 490 | |
Fabrice Di Meglio | 5ebabfc | 2014-04-21 09:40:46 -0700 | [diff] [blame] | 491 | Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 492 | switchToFragment( initialFragmentName, initialArguments, true, false, |
| 493 | mInitialTitle, false); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 494 | } else { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 495 | // No UP if we are displaying the Headers |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 496 | mDisplayHomeAsUpEnabled = false; |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 497 | if (mCategories.size() > 0) { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 498 | mInitialTitle = getText(R.string.dashboard_title); |
| 499 | switchToFragment(DashboardSummary.class.getName(), null, false, false, |
| 500 | mInitialTitle, false); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 501 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 505 | mActionBar = getActionBar(); |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 506 | mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); |
Fabrice Di Meglio | 7cae7f4 | 2014-05-09 16:48:36 -0700 | [diff] [blame] | 507 | mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 508 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 509 | // see if we should show Back/Next buttons |
| 510 | Intent intent = getIntent(); |
| 511 | if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) { |
| 512 | |
| 513 | View buttonBar = findViewById(com.android.internal.R.id.button_bar); |
| 514 | if (buttonBar != null) { |
| 515 | buttonBar.setVisibility(View.VISIBLE); |
| 516 | |
| 517 | Button backButton = (Button)findViewById(com.android.internal.R.id.back_button); |
| 518 | backButton.setOnClickListener(new OnClickListener() { |
| 519 | public void onClick(View v) { |
| 520 | setResult(RESULT_CANCELED); |
| 521 | finish(); |
| 522 | } |
| 523 | }); |
| 524 | Button skipButton = (Button)findViewById(com.android.internal.R.id.skip_button); |
| 525 | skipButton.setOnClickListener(new OnClickListener() { |
| 526 | public void onClick(View v) { |
| 527 | setResult(RESULT_OK); |
| 528 | finish(); |
| 529 | } |
| 530 | }); |
| 531 | mNextButton = (Button)findViewById(com.android.internal.R.id.next_button); |
| 532 | mNextButton.setOnClickListener(new OnClickListener() { |
| 533 | public void onClick(View v) { |
| 534 | setResult(RESULT_OK); |
| 535 | finish(); |
| 536 | } |
| 537 | }); |
| 538 | |
| 539 | // set our various button parameters |
| 540 | if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) { |
| 541 | String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT); |
| 542 | if (TextUtils.isEmpty(buttonText)) { |
| 543 | mNextButton.setVisibility(View.GONE); |
| 544 | } |
| 545 | else { |
| 546 | mNextButton.setText(buttonText); |
| 547 | } |
| 548 | } |
| 549 | if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) { |
| 550 | String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT); |
| 551 | if (TextUtils.isEmpty(buttonText)) { |
| 552 | backButton.setVisibility(View.GONE); |
| 553 | } |
| 554 | else { |
| 555 | backButton.setText(buttonText); |
| 556 | } |
| 557 | } |
| 558 | if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) { |
| 559 | skipButton.setVisibility(View.VISIBLE); |
| 560 | } |
| 561 | } |
| 562 | } |
Fabrice Di Meglio | c95be4f | 2014-03-07 12:57:38 -0800 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | @Override |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 566 | public void onBackStackChanged() { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 567 | setTitleFromBackStack(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 568 | } |
| 569 | |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 570 | private int setTitleFromBackStack() { |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 571 | final int count = getFragmentManager().getBackStackEntryCount(); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 572 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 573 | if (count == 0) { |
| 574 | setTitle(mInitialTitle); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 575 | return 0; |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 576 | } |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 577 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 578 | FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1); |
| 579 | setTitleFromBackStackEntry(bse); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 580 | |
| 581 | return count; |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) { |
| 585 | final CharSequence title; |
| 586 | final int titleRes = bse.getBreadCrumbTitleRes(); |
| 587 | if (titleRes > 0) { |
| 588 | title = getText(titleRes); |
| 589 | } else { |
| 590 | title = bse.getBreadCrumbTitle(); |
| 591 | } |
| 592 | if (title != null) { |
| 593 | setTitle(title); |
| 594 | } |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 597 | @Override |
| 598 | protected void onSaveInstanceState(Bundle outState) { |
| 599 | super.onSaveInstanceState(outState); |
| 600 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 601 | if (mCategories.size() > 0) { |
| 602 | outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 603 | } |
Fabrice Di Meglio | d6985df | 2014-04-03 16:43:26 -0700 | [diff] [blame] | 604 | |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 605 | outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled); |
| 606 | |
Fabrice Di Meglio | d6985df | 2014-04-03 16:43:26 -0700 | [diff] [blame] | 607 | // The option menus are created if the ActionBar is visible and they are also created |
| 608 | // asynchronously. If you launch Settings with an Intent action like |
| 609 | // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked |
| 610 | // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search |
| 611 | // menu item and search view are null. |
| 612 | boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded(); |
| 613 | outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded); |
| 614 | |
| 615 | String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY; |
| 616 | outState.putString(SAVE_KEY_SEARCH_QUERY, query); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | @Override |
| 620 | public void onResume() { |
| 621 | super.onResume(); |
| 622 | |
| 623 | mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { |
| 624 | @Override |
| 625 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 626 | invalidateCategories(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 627 | } |
| 628 | }; |
| 629 | mDevelopmentPreferences.registerOnSharedPreferenceChangeListener( |
| 630 | mDevelopmentPreferencesListener); |
| 631 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 632 | invalidateCategories(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 633 | |
| 634 | registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); |
Svetoslav | 853e471 | 2014-04-14 10:10:25 -0700 | [diff] [blame] | 635 | |
Svetoslav | 990159a | 2014-04-14 17:14:59 -0700 | [diff] [blame] | 636 | mDynamicIndexableContentMonitor.register(this); |
Fabrice Di Meglio | a327076 | 2014-04-16 16:54:56 -0700 | [diff] [blame] | 637 | |
| 638 | if(!TextUtils.isEmpty(mSearchQuery)) { |
| 639 | onQueryTextSubmit(mSearchQuery); |
| 640 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | @Override |
| 644 | public void onPause() { |
| 645 | super.onPause(); |
| 646 | |
| 647 | unregisterReceiver(mBatteryInfoReceiver); |
| 648 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 649 | mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener( |
| 650 | mDevelopmentPreferencesListener); |
| 651 | |
| 652 | mDevelopmentPreferencesListener = null; |
Svetoslav | 853e471 | 2014-04-14 10:10:25 -0700 | [diff] [blame] | 653 | |
Svetoslav | 990159a | 2014-04-14 17:14:59 -0700 | [diff] [blame] | 654 | mDynamicIndexableContentMonitor.unregister(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | @Override |
| 658 | public void onDestroy() { |
| 659 | super.onDestroy(); |
| 660 | if (mListeningToAccountUpdates) { |
| 661 | AccountManager.get(this).removeOnAccountsUpdatedListener(this); |
| 662 | } |
| 663 | } |
| 664 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 665 | protected boolean isValidFragment(String fragmentName) { |
| 666 | // Almost all fragments are wrapped in this, |
| 667 | // except for a few that have their own activities. |
| 668 | for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) { |
| 669 | if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true; |
| 670 | } |
| 671 | return false; |
| 672 | } |
| 673 | |
Fabrice Di Meglio | 6d534a1 | 2014-03-03 11:34:18 -0800 | [diff] [blame] | 674 | /** |
| 675 | * When in two-pane mode, switch to the fragment pane to show the given |
| 676 | * preference fragment. |
| 677 | * |
| 678 | * @param header The new header to display. |
Fabrice Di Meglio | bbdada8 | 2014-04-04 10:16:59 -0700 | [diff] [blame] | 679 | * @param position The position of the Header in the list. |
Fabrice Di Meglio | 6d534a1 | 2014-03-03 11:34:18 -0800 | [diff] [blame] | 680 | */ |
Fabrice Di Meglio | bbdada8 | 2014-04-04 10:16:59 -0700 | [diff] [blame] | 681 | private void onHeaderClick(Header header, int position) { |
Fabrice Di Meglio | 6d534a1 | 2014-03-03 11:34:18 -0800 | [diff] [blame] | 682 | if (header == null) { |
| 683 | return; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 684 | } |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 685 | if (header.fragment != null) { |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 686 | Utils.startWithFragment(this, header.fragment, header.fragmentArguments, null, 0, |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 687 | header.getTitle(getResources())); |
| 688 | } else if (header.intent != null) { |
| 689 | startActivity(header.intent); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * Called to determine whether the header list should be hidden. |
| 695 | * The default implementation returns the |
| 696 | * value given in {@link #EXTRA_NO_HEADERS} or false if it is not supplied. |
| 697 | * This is set to false, for example, when the activity is being re-launched |
| 698 | * to show a particular preference activity. |
| 699 | */ |
| 700 | public boolean onIsHidingHeaders() { |
| 701 | return getIntent().getBooleanExtra(EXTRA_NO_HEADERS, false); |
| 702 | } |
| 703 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 704 | @Override |
| 705 | public Intent getIntent() { |
| 706 | Intent superIntent = super.getIntent(); |
| 707 | String startingFragment = getStartingFragmentClass(superIntent); |
| 708 | // This is called from super.onCreate, isMultiPane() is not yet reliable |
| 709 | // Do not use onIsHidingHeaders either, which relies itself on this method |
| 710 | if (startingFragment != null) { |
| 711 | Intent modIntent = new Intent(superIntent); |
| 712 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); |
| 713 | Bundle args = superIntent.getExtras(); |
| 714 | if (args != null) { |
| 715 | args = new Bundle(args); |
| 716 | } else { |
| 717 | args = new Bundle(); |
| 718 | } |
| 719 | args.putParcelable("intent", superIntent); |
| 720 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, superIntent.getExtras()); |
| 721 | return modIntent; |
| 722 | } |
| 723 | return superIntent; |
| 724 | } |
| 725 | |
| 726 | /** |
| 727 | * Checks if the component name in the intent is different from the Settings class and |
| 728 | * returns the class name to load as a fragment. |
| 729 | */ |
| 730 | private String getStartingFragmentClass(Intent intent) { |
| 731 | if (mFragmentClass != null) return mFragmentClass; |
| 732 | |
| 733 | String intentClass = intent.getComponent().getClassName(); |
| 734 | if (intentClass.equals(getClass().getName())) return null; |
| 735 | |
| 736 | if ("com.android.settings.ManageApplications".equals(intentClass) |
| 737 | || "com.android.settings.RunningServices".equals(intentClass) |
| 738 | || "com.android.settings.applications.StorageUse".equals(intentClass)) { |
| 739 | // Old names of manage apps. |
| 740 | intentClass = com.android.settings.applications.ManageApplications.class.getName(); |
| 741 | } |
| 742 | |
| 743 | return intentClass; |
| 744 | } |
| 745 | |
| 746 | /** |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 747 | * Start a new fragment containing a preference panel. If the preferences |
| 748 | * are being displayed in multi-pane mode, the given fragment class will |
| 749 | * be instantiated and placed in the appropriate pane. If running in |
| 750 | * single-pane mode, a new activity will be launched in which to show the |
| 751 | * fragment. |
| 752 | * |
| 753 | * @param fragmentClass Full name of the class implementing the fragment. |
| 754 | * @param args Any desired arguments to supply to the fragment. |
| 755 | * @param titleRes Optional resource identifier of the title of this |
| 756 | * fragment. |
| 757 | * @param titleText Optional text of the title of this fragment. |
| 758 | * @param resultTo Optional fragment that result data should be sent to. |
| 759 | * If non-null, resultTo.onActivityResult() will be called when this |
| 760 | * preference panel is done. The launched panel must use |
| 761 | * {@link #finishPreferencePanel(Fragment, int, Intent)} when done. |
| 762 | * @param resultRequestCode If resultTo is non-null, this is the caller's |
| 763 | * request code to be received with the resut. |
| 764 | */ |
| 765 | public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes, |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 766 | CharSequence titleText, Fragment resultTo, int resultRequestCode) { |
Fabrice Di Meglio | 911fb2a | 2014-04-04 17:55:57 -0700 | [diff] [blame] | 767 | String title; |
| 768 | if (titleRes > 0) { |
| 769 | title = getString(titleRes); |
Fabrice Di Meglio | 821a072 | 2014-04-08 13:56:06 -0700 | [diff] [blame] | 770 | } else if (titleText != null) { |
Fabrice Di Meglio | 911fb2a | 2014-04-04 17:55:57 -0700 | [diff] [blame] | 771 | title = titleText.toString(); |
Fabrice Di Meglio | 821a072 | 2014-04-08 13:56:06 -0700 | [diff] [blame] | 772 | } else { |
| 773 | // There not much we can do in that case |
| 774 | title = ""; |
Fabrice Di Meglio | 911fb2a | 2014-04-04 17:55:57 -0700 | [diff] [blame] | 775 | } |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 776 | Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode, title); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | /** |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 780 | * Called by a preference panel fragment to finish itself. |
| 781 | * |
| 782 | * @param caller The fragment that is asking to be finished. |
| 783 | * @param resultCode Optional result code to send back to the original |
| 784 | * launching fragment. |
| 785 | * @param resultData Optional result data to send back to the original |
| 786 | * launching fragment. |
| 787 | */ |
| 788 | public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) { |
| 789 | setResult(resultCode, resultData); |
| 790 | } |
| 791 | |
| 792 | /** |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 793 | * Start a new fragment. |
| 794 | * |
| 795 | * @param fragment The fragment to start |
| 796 | * @param push If true, the current fragment will be pushed onto the back stack. If false, |
| 797 | * the current fragment will be replaced. |
| 798 | */ |
| 799 | public void startPreferenceFragment(Fragment fragment, boolean push) { |
| 800 | FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
| 801 | transaction.replace(R.id.prefs, fragment); |
| 802 | if (push) { |
| 803 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); |
| 804 | transaction.addToBackStack(BACK_STACK_PREFS); |
| 805 | } else { |
| 806 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); |
| 807 | } |
| 808 | transaction.commitAllowingStateLoss(); |
| 809 | } |
| 810 | |
| 811 | /** |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 812 | * Switch to a specific Fragment with taking care of validation, Title and BackStack |
| 813 | */ |
| 814 | private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate, |
| 815 | boolean addToBackStack, CharSequence title, boolean withTransition) { |
| 816 | if (validate && !isValidFragment(fragmentName)) { |
| 817 | throw new IllegalArgumentException("Invalid fragment for this activity: " |
| 818 | + fragmentName); |
| 819 | } |
| 820 | Fragment f = Fragment.instantiate(this, fragmentName, args); |
| 821 | FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
| 822 | transaction.replace(R.id.prefs, f); |
| 823 | if (withTransition) { |
| 824 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); |
| 825 | } |
| 826 | if (addToBackStack) { |
| 827 | transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS); |
| 828 | } |
| 829 | if (title != null) { |
| 830 | transaction.setBreadCrumbTitle(title); |
| 831 | } |
| 832 | transaction.commitAllowingStateLoss(); |
| 833 | return f; |
| 834 | } |
| 835 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 836 | public void setNeedToRebuildCategories(boolean need) { |
| 837 | mNeedToRebuildCategories = need; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | /** |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 841 | * Called when the activity needs its list of categories/tiles built. |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 842 | * |
| 843 | * @param categories The list in which to place the tiles categories. |
| 844 | */ |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 845 | private void buildDashboardCategories(List<DashboardCategory> categories) { |
| 846 | mCategories.clear(); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 847 | loadCategoriesFromResource(R.xml.dashboard_categories, categories); |
| 848 | updateTilesList(categories); |
| 849 | } |
| 850 | |
| 851 | /** |
| 852 | * Parse the given XML file as a categories description, adding each |
| 853 | * parsed categories and tiles into the target list. |
| 854 | * |
| 855 | * @param resid The XML resource to load and parse. |
| 856 | * @param target The list in which the parsed categories and tiles should be placed. |
| 857 | */ |
| 858 | private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) { |
| 859 | XmlResourceParser parser = null; |
| 860 | try { |
| 861 | parser = getResources().getXml(resid); |
| 862 | AttributeSet attrs = Xml.asAttributeSet(parser); |
| 863 | |
| 864 | int type; |
| 865 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 866 | && type != XmlPullParser.START_TAG) { |
| 867 | // Parse next until start tag is found |
| 868 | } |
| 869 | |
| 870 | String nodeName = parser.getName(); |
| 871 | if (!"dashboard-categories".equals(nodeName)) { |
| 872 | throw new RuntimeException( |
| 873 | "XML document must start with <preference-categories> tag; found" |
| 874 | + nodeName + " at " + parser.getPositionDescription()); |
| 875 | } |
| 876 | |
| 877 | Bundle curBundle = null; |
| 878 | |
| 879 | final int outerDepth = parser.getDepth(); |
| 880 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 881 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 882 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 883 | continue; |
| 884 | } |
| 885 | |
| 886 | nodeName = parser.getName(); |
| 887 | if ("dashboard-category".equals(nodeName)) { |
| 888 | DashboardCategory category = new DashboardCategory(); |
| 889 | |
| 890 | TypedArray sa = obtainStyledAttributes( |
| 891 | attrs, com.android.internal.R.styleable.PreferenceHeader); |
| 892 | category.id = sa.getResourceId( |
| 893 | com.android.internal.R.styleable.PreferenceHeader_id, |
| 894 | (int)DashboardCategory.CAT_ID_UNDEFINED); |
| 895 | |
| 896 | TypedValue tv = sa.peekValue( |
| 897 | com.android.internal.R.styleable.PreferenceHeader_title); |
| 898 | if (tv != null && tv.type == TypedValue.TYPE_STRING) { |
| 899 | if (tv.resourceId != 0) { |
| 900 | category.titleRes = tv.resourceId; |
| 901 | } else { |
| 902 | category.title = tv.string; |
| 903 | } |
| 904 | } |
| 905 | sa.recycle(); |
| 906 | |
| 907 | final int innerDepth = parser.getDepth(); |
| 908 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 909 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 910 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 911 | continue; |
| 912 | } |
| 913 | |
| 914 | String innerNodeName = parser.getName(); |
| 915 | if (innerNodeName.equals("dashboard-tile")) { |
| 916 | DashboardTile tile = new DashboardTile(); |
| 917 | |
| 918 | sa = obtainStyledAttributes( |
| 919 | attrs, com.android.internal.R.styleable.PreferenceHeader); |
| 920 | tile.id = sa.getResourceId( |
| 921 | com.android.internal.R.styleable.PreferenceHeader_id, |
| 922 | (int)HEADER_ID_UNDEFINED); |
| 923 | tv = sa.peekValue( |
| 924 | com.android.internal.R.styleable.PreferenceHeader_title); |
| 925 | if (tv != null && tv.type == TypedValue.TYPE_STRING) { |
| 926 | if (tv.resourceId != 0) { |
| 927 | tile.titleRes = tv.resourceId; |
| 928 | } else { |
| 929 | tile.title = tv.string; |
| 930 | } |
| 931 | } |
| 932 | tv = sa.peekValue( |
| 933 | com.android.internal.R.styleable.PreferenceHeader_summary); |
| 934 | if (tv != null && tv.type == TypedValue.TYPE_STRING) { |
| 935 | if (tv.resourceId != 0) { |
| 936 | tile.summaryRes = tv.resourceId; |
| 937 | } else { |
| 938 | tile.summary = tv.string; |
| 939 | } |
| 940 | } |
| 941 | tile.iconRes = sa.getResourceId( |
| 942 | com.android.internal.R.styleable.PreferenceHeader_icon, 0); |
| 943 | tile.fragment = sa.getString( |
| 944 | com.android.internal.R.styleable.PreferenceHeader_fragment); |
| 945 | sa.recycle(); |
| 946 | |
| 947 | if (curBundle == null) { |
| 948 | curBundle = new Bundle(); |
| 949 | } |
| 950 | |
| 951 | final int innerDepth2 = parser.getDepth(); |
| 952 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 953 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) { |
| 954 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 955 | continue; |
| 956 | } |
| 957 | |
| 958 | String innerNodeName2 = parser.getName(); |
| 959 | if (innerNodeName2.equals("extra")) { |
| 960 | getResources().parseBundleExtra("extra", attrs, curBundle); |
| 961 | XmlUtils.skipCurrentTag(parser); |
| 962 | |
| 963 | } else if (innerNodeName2.equals("intent")) { |
| 964 | tile.intent = Intent.parseIntent(getResources(), parser, attrs); |
| 965 | |
| 966 | } else { |
| 967 | XmlUtils.skipCurrentTag(parser); |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | if (curBundle.size() > 0) { |
| 972 | tile.fragmentArguments = curBundle; |
| 973 | curBundle = null; |
| 974 | } |
| 975 | |
| 976 | category.addTile(tile); |
| 977 | |
| 978 | } else { |
| 979 | XmlUtils.skipCurrentTag(parser); |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | target.add(category); |
| 984 | } else { |
| 985 | XmlUtils.skipCurrentTag(parser); |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | } catch (XmlPullParserException e) { |
| 990 | throw new RuntimeException("Error parsing categories", e); |
| 991 | } catch (IOException e) { |
| 992 | throw new RuntimeException("Error parsing categories", e); |
| 993 | } finally { |
| 994 | if (parser != null) parser.close(); |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | private void updateTilesList(List<DashboardCategory> target) { |
| 999 | final boolean showDev = mDevelopmentPreferences.getBoolean( |
| 1000 | DevelopmentSettings.PREF_SHOW, |
| 1001 | android.os.Build.TYPE.equals("eng")); |
| 1002 | |
| 1003 | final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); |
| 1004 | |
| 1005 | final int size = target.size(); |
| 1006 | for (int i = 0; i < size; i++) { |
| 1007 | |
| 1008 | DashboardCategory category = target.get(i); |
| 1009 | |
| 1010 | // Ids are integers, so downcasting is ok |
| 1011 | int id = (int) category.id; |
| 1012 | if (id == R.id.account_settings) { |
| 1013 | insertAccountsTiles(category); |
| 1014 | continue; |
| 1015 | } |
| 1016 | int n = category.getTilesCount() - 1; |
| 1017 | while (n >= 0) { |
| 1018 | |
| 1019 | DashboardTile tile = category.getTile(n); |
| 1020 | |
| 1021 | id = (int) tile.id; |
| 1022 | if (id == R.id.operator_settings || id == R.id.manufacturer_settings) { |
| 1023 | Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, category, tile); |
| 1024 | } else if (id == R.id.wifi_settings) { |
| 1025 | // Remove WiFi Settings if WiFi service is not available. |
| 1026 | if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) { |
| 1027 | category.removeTile(n); |
| 1028 | } |
| 1029 | } else if (id == R.id.bluetooth_settings) { |
| 1030 | // Remove Bluetooth Settings if Bluetooth service is not available. |
| 1031 | if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) { |
| 1032 | category.removeTile(n); |
| 1033 | } |
| 1034 | } else if (id == R.id.data_usage_settings) { |
| 1035 | // Remove data usage when kernel module not enabled |
| 1036 | final INetworkManagementService netManager = INetworkManagementService.Stub |
| 1037 | .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)); |
| 1038 | try { |
| 1039 | if (!netManager.isBandwidthControlEnabled()) { |
| 1040 | category.removeTile(n); |
| 1041 | } |
| 1042 | } catch (RemoteException e) { |
| 1043 | // ignored |
| 1044 | } |
| 1045 | } else if (id == R.id.battery_settings) { |
| 1046 | // Remove battery settings when battery is not available. (e.g. TV) |
| 1047 | |
| 1048 | if (!mBatteryPresent) { |
| 1049 | category.removeTile(n); |
| 1050 | } |
| 1051 | } else if (id == R.id.home_settings) { |
| 1052 | if (!updateHomeSettingTiles(tile)) { |
| 1053 | category.removeTile(n); |
| 1054 | } |
| 1055 | } else if (id == R.id.user_settings) { |
| 1056 | if (!UserHandle.MU_ENABLED |
| 1057 | || !UserManager.supportsMultipleUsers() |
| 1058 | || Utils.isMonkeyRunning()) { |
| 1059 | category.removeTile(n); |
| 1060 | } |
| 1061 | } else if (id == R.id.nfc_payment_settings) { |
| 1062 | if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) { |
| 1063 | category.removeTile(n); |
| 1064 | } else { |
| 1065 | // Only show if NFC is on and we have the HCE feature |
| 1066 | NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); |
| 1067 | if (!adapter.isEnabled() || !getPackageManager().hasSystemFeature( |
| 1068 | PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) { |
| 1069 | category.removeTile(n); |
| 1070 | } |
| 1071 | } |
| 1072 | } else if (id == R.id.development_settings) { |
Julia Reynolds | 6c088cb | 2014-05-08 09:29:41 -0400 | [diff] [blame] | 1073 | if (!showDev || um.hasUserRestriction( |
| 1074 | UserManager.DISALLOW_DEBUGGING_FEATURES)) { |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1075 | category.removeTile(n); |
| 1076 | } |
| 1077 | } else if (id == R.id.account_add) { |
| 1078 | if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) { |
| 1079 | category.removeTile(n); |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0 |
Amith Yamasani | a97089d | 2014-04-30 10:58:09 -0700 | [diff] [blame] | 1084 | && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id) |
| 1085 | && n < category.getTilesCount()) { |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1086 | category.removeTile(n); |
| 1087 | } |
| 1088 | |
| 1089 | n--; |
| 1090 | } |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | private boolean updateHomeSettingTiles(DashboardTile tile) { |
| 1095 | // Once we decide to show Home settings, keep showing it forever |
| 1096 | SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE); |
| 1097 | if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) { |
| 1098 | return true; |
| 1099 | } |
| 1100 | |
| 1101 | try { |
| 1102 | final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>(); |
| 1103 | getPackageManager().getHomeActivities(homeApps); |
| 1104 | if (homeApps.size() < 2) { |
| 1105 | // When there's only one available home app, omit this settings |
| 1106 | // category entirely at the top level UI. If the user just |
| 1107 | // uninstalled the penultimate home app candidiate, we also |
| 1108 | // now tell them about why they aren't seeing 'Home' in the list. |
| 1109 | if (sShowNoHomeNotice) { |
| 1110 | sShowNoHomeNotice = false; |
| 1111 | NoHomeDialogFragment.show(this); |
| 1112 | } |
| 1113 | return false; |
| 1114 | } else { |
| 1115 | // Okay, we're allowing the Home settings category. Tell it, when |
| 1116 | // invoked via this front door, that we'll need to be told about the |
| 1117 | // case when the user uninstalls all but one home app. |
| 1118 | if (tile.fragmentArguments == null) { |
| 1119 | tile.fragmentArguments = new Bundle(); |
| 1120 | } |
| 1121 | tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true); |
| 1122 | } |
| 1123 | } catch (Exception e) { |
| 1124 | // Can't look up the home activity; bail on configuring the icon |
| 1125 | Log.w(LOG_TAG, "Problem looking up home activity!", e); |
| 1126 | } |
| 1127 | |
| 1128 | sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply(); |
| 1129 | return true; |
| 1130 | } |
| 1131 | |
| 1132 | private void insertAccountsTiles(DashboardCategory target) { |
| 1133 | String[] accountTypes = mAuthenticatorHelper.getEnabledAccountTypes(); |
| 1134 | List<DashboardTile> dashboardTiles = new ArrayList<DashboardTile>(accountTypes.length); |
| 1135 | for (String accountType : accountTypes) { |
| 1136 | CharSequence label = mAuthenticatorHelper.getLabelForType(this, accountType); |
| 1137 | if (label == null) { |
| 1138 | continue; |
| 1139 | } |
| 1140 | |
| 1141 | Account[] accounts = AccountManager.get(this).getAccountsByType(accountType); |
| 1142 | boolean skipToAccount = accounts.length == 1 |
| 1143 | && !mAuthenticatorHelper.hasAccountPreferences(accountType); |
| 1144 | DashboardTile accountTile = new DashboardTile(); |
| 1145 | accountTile.title = label; |
| 1146 | if (accountTile.extras == null) { |
| 1147 | accountTile.extras = new Bundle(); |
| 1148 | } |
| 1149 | if (skipToAccount) { |
| 1150 | accountTile.fragment = AccountSyncSettings.class.getName(); |
| 1151 | accountTile.fragmentArguments = new Bundle(); |
| 1152 | // Need this for the icon |
| 1153 | accountTile.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); |
| 1154 | accountTile.extras.putParcelable(AccountSyncSettings.ACCOUNT_KEY, accounts[0]); |
| 1155 | accountTile.fragmentArguments.putParcelable(AccountSyncSettings.ACCOUNT_KEY, |
| 1156 | accounts[0]); |
| 1157 | } else { |
| 1158 | accountTile.fragment = ManageAccountsSettings.class.getName(); |
| 1159 | accountTile.fragmentArguments = new Bundle(); |
| 1160 | accountTile.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); |
| 1161 | accountTile.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, |
| 1162 | accountType); |
| 1163 | accountTile.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL, |
| 1164 | label.toString()); |
| 1165 | } |
| 1166 | dashboardTiles.add(accountTile); |
| 1167 | mAuthenticatorHelper.preloadDrawableForType(this, accountType); |
| 1168 | } |
| 1169 | |
| 1170 | // Sort by label |
| 1171 | Collections.sort(dashboardTiles, new Comparator<DashboardTile>() { |
| 1172 | @Override |
| 1173 | public int compare(DashboardTile t1, DashboardTile t2) { |
| 1174 | return t1.title.toString().compareTo(t2.title.toString()); |
| 1175 | } |
| 1176 | }); |
| 1177 | int index = 0; |
| 1178 | for (DashboardTile tile : dashboardTiles) { |
| 1179 | target.addTile(index, tile); |
| 1180 | index++; |
| 1181 | } |
| 1182 | if (!mListeningToAccountUpdates) { |
| 1183 | AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true); |
| 1184 | mListeningToAccountUpdates = true; |
| 1185 | } |
| 1186 | } |
| 1187 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1188 | private void getMetaData() { |
| 1189 | try { |
| 1190 | ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), |
| 1191 | PackageManager.GET_META_DATA); |
| 1192 | if (ai == null || ai.metaData == null) return; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1193 | mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); |
| 1194 | } catch (NameNotFoundException nnfe) { |
| 1195 | // No recovery |
| 1196 | Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString()); |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | // give subclasses access to the Next button |
| 1201 | public boolean hasNextButton() { |
| 1202 | return mNextButton != null; |
| 1203 | } |
| 1204 | |
| 1205 | public Button getNextButton() { |
| 1206 | return mNextButton; |
| 1207 | } |
| 1208 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1209 | @Override |
| 1210 | public boolean shouldUpRecreateTask(Intent targetIntent) { |
| 1211 | return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class)); |
| 1212 | } |
| 1213 | |
| 1214 | @Override |
| 1215 | public void onAccountsUpdated(Account[] accounts) { |
| 1216 | // TODO: watch for package upgrades to invalidate cache; see 7206643 |
| 1217 | mAuthenticatorHelper.updateAuthDescriptions(this); |
| 1218 | mAuthenticatorHelper.onAccountsUpdated(this, accounts); |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 1219 | invalidateCategories(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | public static void requestHomeNotice() { |
| 1223 | sShowNoHomeNotice = true; |
| 1224 | } |
| 1225 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1226 | @Override |
| 1227 | public boolean onQueryTextSubmit(String query) { |
| 1228 | switchToSearchResultsFragmentIfNeeded(); |
| 1229 | mSearchQuery = query; |
| 1230 | return mSearchResultsFragment.onQueryTextSubmit(query); |
| 1231 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1232 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1233 | @Override |
| 1234 | public boolean onQueryTextChange(String newText) { |
| 1235 | mSearchQuery = newText; |
Fabrice Di Meglio | 3d5aeb7 | 2014-05-09 14:59:19 -0700 | [diff] [blame] | 1236 | if (TextUtils.isEmpty(newText) || mSearchResultsFragment == null) { |
Fabrice Di Meglio | a327076 | 2014-04-16 16:54:56 -0700 | [diff] [blame] | 1237 | return false; |
| 1238 | } |
| 1239 | return mSearchResultsFragment.onQueryTextChange(newText); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1240 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1241 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1242 | @Override |
| 1243 | public boolean onClose() { |
| 1244 | return false; |
| 1245 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1246 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1247 | @Override |
| 1248 | public boolean onMenuItemActionExpand(MenuItem item) { |
| 1249 | if (item.getItemId() == mSearchMenuItem.getItemId()) { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1250 | switchToSearchResultsFragmentIfNeeded(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1251 | } |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1252 | return true; |
| 1253 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1254 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1255 | @Override |
| 1256 | public boolean onMenuItemActionCollapse(MenuItem item) { |
| 1257 | if (item.getItemId() == mSearchMenuItem.getItemId()) { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1258 | if (mSearchMenuItemExpanded) { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1259 | revertToInitialFragment(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1260 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1261 | } |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1262 | return true; |
| 1263 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1264 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1265 | private void switchToSearchResultsFragmentIfNeeded() { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1266 | if (mSearchResultsFragment != null) { |
| 1267 | return; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1268 | } |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1269 | Fragment current = getFragmentManager().findFragmentById(R.id.prefs); |
| 1270 | if (current != null && current instanceof SearchResultsSummary) { |
| 1271 | mSearchResultsFragment = (SearchResultsSummary) current; |
| 1272 | } else { |
| 1273 | String title = getString(R.string.search_results_title); |
| 1274 | mSearchResultsFragment = (SearchResultsSummary) switchToFragment( |
| 1275 | SearchResultsSummary.class.getName(), null, false, true, title, true); |
| 1276 | } |
Fabrice Di Meglio | d297a58 | 2014-04-22 17:23:23 -0700 | [diff] [blame] | 1277 | mSearchResultsFragment.setSearchView(mSearchView); |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1278 | mSearchMenuItemExpanded = true; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1279 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1280 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1281 | public void needToRevertToInitialFragment() { |
| 1282 | mNeedToRevertToInitialFragment = true; |
| 1283 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1284 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1285 | private void revertToInitialFragment() { |
| 1286 | mNeedToRevertToInitialFragment = false; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1287 | mSearchResultsFragment = null; |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1288 | mSearchMenuItemExpanded = false; |
| 1289 | getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS, |
| 1290 | FragmentManager.POP_BACK_STACK_INCLUSIVE); |
Fabrice Di Meglio | 23ae00c | 2014-04-21 12:43:20 -0700 | [diff] [blame] | 1291 | if (mSearchMenuItem != null) { |
| 1292 | mSearchMenuItem.collapseActionView(); |
| 1293 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1294 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1295 | } |