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