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