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