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