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