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