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