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