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; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 20 | import android.app.Fragment; |
| 21 | import android.app.FragmentManager; |
| 22 | import android.app.FragmentTransaction; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 24 | import android.content.ComponentName; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
| 27 | import android.content.IntentFilter; |
| 28 | import android.content.SharedPreferences; |
| 29 | import android.content.pm.ActivityInfo; |
| 30 | import android.content.pm.PackageManager; |
| 31 | import android.content.pm.PackageManager.NameNotFoundException; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 32 | import android.content.res.Configuration; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 33 | import android.nfc.NfcAdapter; |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 34 | import android.os.AsyncTask; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 35 | import android.os.Bundle; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 36 | import android.os.UserHandle; |
| 37 | import android.os.UserManager; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 38 | import android.support.v14.preference.PreferenceFragment; |
| 39 | import android.support.v7.preference.Preference; |
| 40 | import android.support.v7.preference.PreferenceManager; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 41 | import android.text.TextUtils; |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 42 | import android.transition.TransitionManager; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 43 | import android.util.Log; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 44 | import android.view.Menu; |
| 45 | import android.view.MenuInflater; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 46 | import android.view.MenuItem; |
| 47 | import android.view.View; |
| 48 | import android.view.View.OnClickListener; |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 49 | import android.view.ViewGroup; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 50 | import android.widget.Button; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 51 | import android.widget.SearchView; |
Fan Zhang | 2869157 | 2016-03-23 15:31:08 -0700 | [diff] [blame] | 52 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 53 | import com.android.internal.util.ArrayUtils; |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 54 | import com.android.settings.Settings.WifiSettingsActivity; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 55 | import com.android.settings.accessibility.AccessibilitySettings; |
Anna Galusza | b1795f5 | 2016-01-08 14:37:16 -0800 | [diff] [blame] | 56 | import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 57 | import com.android.settings.accessibility.CaptionPropertiesFragment; |
Fan Zhang | a96a2d8 | 2016-09-27 17:51:11 -0700 | [diff] [blame] | 58 | import com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment; |
Alexandra Gherghina | 6d83987 | 2014-07-22 12:04:58 +0000 | [diff] [blame] | 59 | import com.android.settings.accounts.AccountSettings; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 60 | import com.android.settings.accounts.AccountSyncSettings; |
Jason Monk | b7e4380 | 2016-06-06 16:01:58 -0400 | [diff] [blame] | 61 | import com.android.settings.accounts.ChooseAccountActivity; |
Tony Mak | 64f6d98 | 2016-05-03 18:55:41 +0100 | [diff] [blame] | 62 | import com.android.settings.accounts.ManagedProfileSettings; |
Jason Monk | 91e2f89 | 2016-02-23 15:31:09 -0500 | [diff] [blame] | 63 | import com.android.settings.applications.AdvancedAppSettings; |
Billy Lau | fee7856 | 2015-07-27 12:57:07 +0100 | [diff] [blame] | 64 | import com.android.settings.applications.DrawOverlayDetails; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 65 | import com.android.settings.applications.InstalledAppDetails; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 66 | import com.android.settings.applications.ManageApplications; |
Xiyuan Xia | 86a5540 | 2015-06-02 14:55:32 -0700 | [diff] [blame] | 67 | import com.android.settings.applications.ManageAssist; |
Todd Kennedy | 2ef1aa5 | 2016-09-06 14:02:38 -0700 | [diff] [blame] | 68 | import com.android.settings.applications.ManageDomainUrls; |
Jason Monk | a2d47fc | 2016-03-03 10:49:44 -0500 | [diff] [blame] | 69 | import com.android.settings.applications.NotificationApps; |
Jason Monk | 2cdafc6 | 2015-06-12 12:32:50 -0400 | [diff] [blame] | 70 | import com.android.settings.applications.ProcessStatsSummary; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 71 | import com.android.settings.applications.ProcessStatsUi; |
Jason Monk | d8da51c | 2015-04-17 14:34:12 -0400 | [diff] [blame] | 72 | import com.android.settings.applications.UsageAccessDetails; |
Ruben Brunk | c461d5c | 2016-04-07 21:45:41 -0700 | [diff] [blame] | 73 | import com.android.settings.applications.VrListenerSettings; |
Fan Zhang | ece8ff6 | 2016-06-30 13:20:12 -0700 | [diff] [blame] | 74 | import com.android.settings.applications.WriteSettingsDetails; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 75 | import com.android.settings.bluetooth.BluetoothSettings; |
Fan Zhang | 5f79ae9 | 2016-08-18 16:04:19 -0700 | [diff] [blame] | 76 | import com.android.settings.core.instrumentation.SharedPreferencesLogger; |
Fan Zhang | 2869157 | 2016-03-23 15:31:08 -0700 | [diff] [blame] | 77 | import com.android.settings.dashboard.DashboardContainerFragment; |
Fan Zhang | a96a2d8 | 2016-09-27 17:51:11 -0700 | [diff] [blame] | 78 | import com.android.settings.dashboard.DashboardFeatureProvider; |
| 79 | import com.android.settings.dashboard.DashboardSummary; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 80 | import com.android.settings.dashboard.SearchResultsSummary; |
Fan Zhang | a96a2d8 | 2016-09-27 17:51:11 -0700 | [diff] [blame] | 81 | import com.android.settings.dashboard.SupportFragment; |
Jason Monk | b37e288 | 2016-01-11 14:27:20 -0500 | [diff] [blame] | 82 | import com.android.settings.datausage.DataUsageSummary; |
Daniel Nishi | 3981889 | 2016-09-20 16:40:49 -0700 | [diff] [blame] | 83 | import com.android.settings.deletionhelper.AutomaticStorageManagerSettings; |
Jason Monk | b7e4380 | 2016-06-06 16:01:58 -0400 | [diff] [blame] | 84 | import com.android.settings.deviceinfo.ImeiInformation; |
Jeff Sharkey | a16257d | 2015-04-28 13:41:01 -0700 | [diff] [blame] | 85 | import com.android.settings.deviceinfo.PrivateVolumeForget; |
Jeff Sharkey | e77f068 | 2015-04-29 11:24:57 -0700 | [diff] [blame] | 86 | import com.android.settings.deviceinfo.PrivateVolumeSettings; |
Jeff Sharkey | 42833b2 | 2015-04-11 21:27:33 -0700 | [diff] [blame] | 87 | import com.android.settings.deviceinfo.PublicVolumeSettings; |
Jason Monk | b7e4380 | 2016-06-06 16:01:58 -0400 | [diff] [blame] | 88 | import com.android.settings.deviceinfo.SimStatus; |
| 89 | import com.android.settings.deviceinfo.Status; |
Jeff Sharkey | 42833b2 | 2015-04-11 21:27:33 -0700 | [diff] [blame] | 90 | import com.android.settings.deviceinfo.StorageSettings; |
Justin Klaassen | eae3d9f | 2016-07-21 19:25:17 -0700 | [diff] [blame] | 91 | import com.android.settings.display.NightDisplaySettings; |
John Spurlock | c7f8e8c | 2014-06-04 19:11:22 -0400 | [diff] [blame] | 92 | import com.android.settings.fuelgauge.BatterySaverSettings; |
Jason Monk | 1eb54eb | 2015-04-29 12:46:42 -0400 | [diff] [blame] | 93 | import com.android.settings.fuelgauge.PowerUsageDetail; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 94 | import com.android.settings.fuelgauge.PowerUsageSummary; |
Doris Ling | 9136523 | 2016-05-23 17:06:26 -0700 | [diff] [blame] | 95 | import com.android.settings.gestures.GestureSettings; |
Abodunrinwa Toki | 976bb3f | 2016-01-20 18:43:20 +0000 | [diff] [blame] | 96 | import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 97 | import com.android.settings.inputmethod.InputMethodAndLanguageSettings; |
| 98 | import com.android.settings.inputmethod.KeyboardLayoutPickerFragment; |
Abodunrinwa Toki | 5f0b59b | 2016-01-25 23:02:23 +0000 | [diff] [blame] | 99 | import com.android.settings.inputmethod.KeyboardLayoutPickerFragment2; |
Abodunrinwa Toki | b28b2cc | 2016-03-22 16:29:38 +0000 | [diff] [blame] | 100 | import com.android.settings.inputmethod.PhysicalKeyboardFragment; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 101 | import com.android.settings.inputmethod.SpellCheckersSettings; |
| 102 | import com.android.settings.inputmethod.UserDictionaryList; |
Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 103 | import com.android.settings.localepicker.LocaleListEditor; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 104 | import com.android.settings.location.LocationSettings; |
| 105 | import com.android.settings.nfc.AndroidBeam; |
| 106 | import com.android.settings.nfc.PaymentSettings; |
John Spurlock | 802ddf9 | 2014-07-18 11:51:13 -0400 | [diff] [blame] | 107 | import com.android.settings.notification.AppNotificationSettings; |
Julia Reynolds | 8c0a423 | 2015-11-24 10:08:14 -0500 | [diff] [blame] | 108 | import com.android.settings.notification.ConfigureNotificationSettings; |
John Spurlock | 4a35051 | 2014-04-08 14:08:21 -0400 | [diff] [blame] | 109 | import com.android.settings.notification.NotificationAccessSettings; |
John Spurlock | 4a35051 | 2014-04-08 14:08:21 -0400 | [diff] [blame] | 110 | import com.android.settings.notification.NotificationStation; |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 111 | import com.android.settings.notification.OtherSoundSettings; |
Jason Monk | b37e288 | 2016-01-11 14:27:20 -0500 | [diff] [blame] | 112 | import com.android.settings.notification.SoundSettings; |
John Spurlock | 08531a8 | 2015-05-07 17:45:43 -0400 | [diff] [blame] | 113 | import com.android.settings.notification.ZenAccessSettings; |
John Spurlock | 533a566 | 2015-06-19 10:47:36 -0400 | [diff] [blame] | 114 | import com.android.settings.notification.ZenModeAutomationSettings; |
John Spurlock | f57bad7 | 2015-04-30 09:26:15 -0400 | [diff] [blame] | 115 | import com.android.settings.notification.ZenModeEventRuleSettings; |
John Spurlock | c1df2aa | 2015-04-13 20:57:06 -0400 | [diff] [blame] | 116 | import com.android.settings.notification.ZenModePrioritySettings; |
John Spurlock | 45fa140 | 2015-04-09 12:50:04 -0400 | [diff] [blame] | 117 | import com.android.settings.notification.ZenModeScheduleRuleSettings; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 118 | import com.android.settings.notification.ZenModeSettings; |
Julia Reynolds | 5555d26 | 2015-11-09 10:52:17 -0500 | [diff] [blame] | 119 | import com.android.settings.notification.ZenModeVisualInterruptionSettings; |
Fan Zhang | a96a2d8 | 2016-09-27 17:51:11 -0700 | [diff] [blame] | 120 | import com.android.settings.overlay.FeatureFactory; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 121 | import com.android.settings.print.PrintJobSettingsFragment; |
| 122 | import com.android.settings.print.PrintSettingsFragment; |
Dan Sandler | 12c4ba4 | 2016-03-28 11:13:40 -0400 | [diff] [blame] | 123 | import com.android.settings.qstile.DevelopmentTiles; |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 124 | import com.android.settings.search.DynamicIndexableContentMonitor; |
| 125 | import com.android.settings.search.Index; |
PauloftheWest | 3815561 | 2014-06-30 10:02:36 -0700 | [diff] [blame] | 126 | import com.android.settings.sim.SimSettings; |
Fan Zhang | cc335d9 | 2016-09-29 14:37:14 -0700 | [diff] [blame^] | 127 | import com.android.settings.system.SystemDashboardFragment; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 128 | import com.android.settings.tts.TextToSpeechSettings; |
| 129 | import com.android.settings.users.UserSettings; |
| 130 | import com.android.settings.vpn2.VpnSettings; |
| 131 | import com.android.settings.wfd.WifiDisplaySettings; |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 132 | import com.android.settings.widget.SwitchBar; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 133 | import com.android.settings.wifi.AdvancedWifiSettings; |
PauloftheWest | 7837b99 | 2014-06-24 07:42:27 -0700 | [diff] [blame] | 134 | import com.android.settings.wifi.SavedAccessPointsWifiSettings; |
Jason Monk | b7e4380 | 2016-06-06 16:01:58 -0400 | [diff] [blame] | 135 | import com.android.settings.wifi.WifiAPITest; |
| 136 | import com.android.settings.wifi.WifiInfo; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 137 | import com.android.settings.wifi.WifiSettings; |
| 138 | import com.android.settings.wifi.p2p.WifiP2pSettings; |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 139 | import com.android.settingslib.drawer.DashboardCategory; |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 140 | import com.android.settingslib.drawer.SettingsDrawerActivity; |
Jason Monk | 7ea14c5 | 2016-01-22 14:28:02 -0500 | [diff] [blame] | 141 | import com.android.settingslib.drawer.Tile; |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 142 | |
Doris Ling | 26bf003 | 2016-06-15 18:16:09 -0700 | [diff] [blame] | 143 | import java.net.URISyntaxException; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 144 | import java.util.ArrayList; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 145 | import java.util.List; |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 146 | import java.util.Set; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 147 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 148 | public class SettingsActivity extends SettingsDrawerActivity |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 149 | implements PreferenceManager.OnPreferenceTreeClickListener, |
| 150 | PreferenceFragment.OnPreferenceStartFragmentCallback, |
Alexandra Gherghina | cfc7f9d | 2014-07-04 12:25:38 +0100 | [diff] [blame] | 151 | ButtonBarHandler, FragmentManager.OnBackStackChangedListener, |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 152 | SearchView.OnQueryTextListener, SearchView.OnCloseListener, |
Alexandra Gherghina | cfc7f9d | 2014-07-04 12:25:38 +0100 | [diff] [blame] | 153 | MenuItem.OnActionExpandListener { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 154 | |
| 155 | private static final String LOG_TAG = "Settings"; |
| 156 | |
Philip P. Moltmann | d9779db | 2016-02-24 12:11:05 -0800 | [diff] [blame] | 157 | private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1; |
| 158 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 159 | // Constants for state save/restore |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 160 | private static final String SAVE_KEY_CATEGORIES = ":settings:categories"; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 161 | private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded"; |
| 162 | private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query"; |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 163 | 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] | 164 | private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search"; |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 165 | 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] | 166 | |
| 167 | /** |
| 168 | * When starting this activity, the invoking Intent can contain this extra |
| 169 | * string to specify which fragment should be initially displayed. |
| 170 | * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity |
| 171 | * will call isValidFragment() to confirm that the fragment class name is valid for this |
| 172 | * activity. |
| 173 | */ |
| 174 | public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment"; |
| 175 | |
| 176 | /** |
| 177 | * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, |
| 178 | * this extra can also be specified to supply a Bundle of arguments to pass |
| 179 | * to that fragment when it is instantiated during the initial creation |
| 180 | * of the activity. |
| 181 | */ |
| 182 | public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args"; |
| 183 | |
| 184 | /** |
Fabrice Di Meglio | c145732 | 2014-04-04 19:07:50 -0700 | [diff] [blame] | 185 | * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS} |
| 186 | */ |
| 187 | public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"; |
| 188 | |
Fabrice Di Meglio | 6f0739a | 2014-02-03 18:12:25 -0800 | [diff] [blame] | 189 | public static final String BACK_STACK_PREFS = ":settings:prefs"; |
| 190 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 191 | // extras that allow any preference activity to be launched as part of a wizard |
| 192 | |
| 193 | // show Back and Next buttons? takes boolean parameter |
| 194 | // Back will then return RESULT_CANCELED and Next RESULT_OK |
| 195 | protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; |
| 196 | |
| 197 | // add a Skip button? |
| 198 | private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip"; |
| 199 | |
| 200 | // specify custom text for the Back or Next buttons, or cause a button to not appear |
| 201 | // at all by setting it to null |
| 202 | protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text"; |
| 203 | protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text"; |
| 204 | |
| 205 | /** |
| 206 | * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 207 | * 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] | 208 | * that fragment. |
| 209 | */ |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 210 | public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title"; |
Alexandra Gherghina | 62464b8 | 2014-08-11 12:40:13 +0100 | [diff] [blame] | 211 | /** |
| 212 | * The package name used to resolve the title resource id. |
| 213 | */ |
| 214 | public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME = |
| 215 | ":settings:show_fragment_title_res_package_name"; |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 216 | public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = |
| 217 | ":settings:show_fragment_title_resid"; |
| 218 | public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT = |
| 219 | ":settings:show_fragment_as_shortcut"; |
| 220 | |
| 221 | public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING = |
| 222 | ":settings:show_fragment_as_subsetting"; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 223 | |
Udam Saini | 92779ce | 2016-03-28 14:29:48 -0700 | [diff] [blame] | 224 | public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer"; |
| 225 | |
Jason Monk | 3069581 | 2015-11-17 09:01:08 -0500 | [diff] [blame] | 226 | public static final String META_DATA_KEY_FRAGMENT_CLASS = |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 227 | "com.android.settings.FRAGMENT_CLASS"; |
| 228 | |
| 229 | private static final String EXTRA_UI_OPTIONS = "settings:ui_options"; |
| 230 | |
Fabrice Di Meglio | d6985df | 2014-04-03 16:43:26 -0700 | [diff] [blame] | 231 | private static final String EMPTY_QUERY = ""; |
| 232 | |
Jason Monk | d4f03ec | 2016-01-07 16:25:34 -0500 | [diff] [blame] | 233 | private static final int REQUEST_SUGGESTION = 42; |
| 234 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 235 | private String mFragmentClass; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 236 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 237 | private CharSequence mInitialTitle; |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 238 | private int mInitialTitleResId; |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 239 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 240 | // Show only these settings for restricted users |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 241 | private String[] SETTINGS_FOR_RESTRICTED = { |
| 242 | //wireless_section |
| 243 | WifiSettingsActivity.class.getName(), |
| 244 | Settings.BluetoothSettingsActivity.class.getName(), |
| 245 | Settings.DataUsageSummaryActivity.class.getName(), |
| 246 | Settings.SimSettingsActivity.class.getName(), |
| 247 | Settings.WirelessSettingsActivity.class.getName(), |
| 248 | //device_section |
| 249 | Settings.HomeSettingsActivity.class.getName(), |
Julia Reynolds | 8c0a423 | 2015-11-24 10:08:14 -0500 | [diff] [blame] | 250 | Settings.SoundSettingsActivity.class.getName(), |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 251 | Settings.DisplaySettingsActivity.class.getName(), |
| 252 | Settings.StorageSettingsActivity.class.getName(), |
| 253 | Settings.ManageApplicationsActivity.class.getName(), |
| 254 | Settings.PowerUsageSummaryActivity.class.getName(), |
Doris Ling | 9136523 | 2016-05-23 17:06:26 -0700 | [diff] [blame] | 255 | Settings.GestureSettingsActivity.class.getName(), |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 256 | //personal_section |
| 257 | Settings.LocationSettingsActivity.class.getName(), |
| 258 | Settings.SecuritySettingsActivity.class.getName(), |
| 259 | Settings.InputMethodAndLanguageSettingsActivity.class.getName(), |
| 260 | Settings.UserSettingsActivity.class.getName(), |
| 261 | Settings.AccountSettingsActivity.class.getName(), |
| 262 | //system_section |
| 263 | Settings.DateTimeSettingsActivity.class.getName(), |
| 264 | Settings.DeviceInfoSettingsActivity.class.getName(), |
| 265 | Settings.AccessibilitySettingsActivity.class.getName(), |
| 266 | Settings.PrintSettingsActivity.class.getName(), |
| 267 | Settings.PaymentSettingsActivity.class.getName(), |
Fan Zhang | cc335d9 | 2016-09-29 14:37:14 -0700 | [diff] [blame^] | 268 | |
| 269 | // New IA |
| 270 | // Home page |
| 271 | "com.android.settings.Settings.BatteryDashboardAlias", |
| 272 | Settings.SystemDashboardActivity.class.getName(), |
| 273 | Settings.SupportDashboardActivity.class.getName(), |
| 274 | // Home page > System |
| 275 | "com.android.settings.Settings.LanguageAndInputDashboardAlias", |
| 276 | "com.android.settings.Settings.DateTimeDashboardAlias", |
| 277 | "com.android.settings.Settings.AccessibilityDashboardAlias", |
| 278 | "com.android.settings.Settings.AboutDeviceDashboardAlias", |
| 279 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 280 | }; |
| 281 | |
| 282 | private static final String[] ENTRY_FRAGMENTS = { |
| 283 | WirelessSettings.class.getName(), |
| 284 | WifiSettings.class.getName(), |
| 285 | AdvancedWifiSettings.class.getName(), |
PauloftheWest | 7837b99 | 2014-06-24 07:42:27 -0700 | [diff] [blame] | 286 | SavedAccessPointsWifiSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 287 | BluetoothSettings.class.getName(), |
PauloftheWest | 3815561 | 2014-06-30 10:02:36 -0700 | [diff] [blame] | 288 | SimSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 289 | TetherSettings.class.getName(), |
| 290 | WifiP2pSettings.class.getName(), |
| 291 | VpnSettings.class.getName(), |
| 292 | DateTimeSettings.class.getName(), |
Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 293 | LocaleListEditor.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 294 | InputMethodAndLanguageSettings.class.getName(), |
Abodunrinwa Toki | 976bb3f | 2016-01-20 18:43:20 +0000 | [diff] [blame] | 295 | AvailableVirtualKeyboardFragment.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 296 | SpellCheckersSettings.class.getName(), |
| 297 | UserDictionaryList.class.getName(), |
| 298 | UserDictionarySettings.class.getName(), |
Amith Yamasani | 3033ce0 | 2014-07-14 18:03:15 -0700 | [diff] [blame] | 299 | HomeSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 300 | DisplaySettings.class.getName(), |
| 301 | DeviceInfoSettings.class.getName(), |
| 302 | ManageApplications.class.getName(), |
Jason Monk | a2d47fc | 2016-03-03 10:49:44 -0500 | [diff] [blame] | 303 | NotificationApps.class.getName(), |
Xiyuan Xia | 86a5540 | 2015-06-02 14:55:32 -0700 | [diff] [blame] | 304 | ManageAssist.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 305 | ProcessStatsUi.class.getName(), |
| 306 | NotificationStation.class.getName(), |
| 307 | LocationSettings.class.getName(), |
| 308 | SecuritySettings.class.getName(), |
Jason Monk | d8da51c | 2015-04-17 14:34:12 -0400 | [diff] [blame] | 309 | UsageAccessDetails.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 310 | PrivacySettings.class.getName(), |
| 311 | DeviceAdminSettings.class.getName(), |
| 312 | AccessibilitySettings.class.getName(), |
Anna Galusza | b1795f5 | 2016-01-08 14:37:16 -0800 | [diff] [blame] | 313 | AccessibilitySettingsForSetupWizard.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 314 | CaptionPropertiesFragment.class.getName(), |
Fan Zhang | a96a2d8 | 2016-09-27 17:51:11 -0700 | [diff] [blame] | 315 | ToggleDaltonizerPreferenceFragment.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 316 | TextToSpeechSettings.class.getName(), |
Jeff Sharkey | 42833b2 | 2015-04-11 21:27:33 -0700 | [diff] [blame] | 317 | StorageSettings.class.getName(), |
Jeff Sharkey | a16257d | 2015-04-28 13:41:01 -0700 | [diff] [blame] | 318 | PrivateVolumeForget.class.getName(), |
Jeff Sharkey | e77f068 | 2015-04-29 11:24:57 -0700 | [diff] [blame] | 319 | PrivateVolumeSettings.class.getName(), |
| 320 | PublicVolumeSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 321 | DevelopmentSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 322 | AndroidBeam.class.getName(), |
| 323 | WifiDisplaySettings.class.getName(), |
| 324 | PowerUsageSummary.class.getName(), |
| 325 | AccountSyncSettings.class.getName(), |
Alexandra Gherghina | 6d83987 | 2014-07-22 12:04:58 +0000 | [diff] [blame] | 326 | AccountSettings.class.getName(), |
Doris Ling | 9136523 | 2016-05-23 17:06:26 -0700 | [diff] [blame] | 327 | GestureSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 328 | CryptKeeperSettings.class.getName(), |
| 329 | DataUsageSummary.class.getName(), |
| 330 | DreamSettings.class.getName(), |
| 331 | UserSettings.class.getName(), |
| 332 | NotificationAccessSettings.class.getName(), |
John Spurlock | 08531a8 | 2015-05-07 17:45:43 -0400 | [diff] [blame] | 333 | ZenAccessSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 334 | PrintSettingsFragment.class.getName(), |
| 335 | PrintJobSettingsFragment.class.getName(), |
| 336 | TrustedCredentialsSettings.class.getName(), |
| 337 | PaymentSettings.class.getName(), |
| 338 | KeyboardLayoutPickerFragment.class.getName(), |
Abodunrinwa Toki | 5f0b59b | 2016-01-25 23:02:23 +0000 | [diff] [blame] | 339 | KeyboardLayoutPickerFragment2.class.getName(), |
Abodunrinwa Toki | b28b2cc | 2016-03-22 16:29:38 +0000 | [diff] [blame] | 340 | PhysicalKeyboardFragment.class.getName(), |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 341 | ZenModeSettings.class.getName(), |
Julia Reynolds | 8c0a423 | 2015-11-24 10:08:14 -0500 | [diff] [blame] | 342 | SoundSettings.class.getName(), |
| 343 | ConfigureNotificationSettings.class.getName(), |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 344 | ChooseLockPassword.ChooseLockPasswordFragment.class.getName(), |
| 345 | ChooseLockPattern.ChooseLockPatternFragment.class.getName(), |
John Spurlock | c7f8e8c | 2014-06-04 19:11:22 -0400 | [diff] [blame] | 346 | InstalledAppDetails.class.getName(), |
| 347 | BatterySaverSettings.class.getName(), |
Fabrice Di Meglio | dcf59dd | 2014-07-21 11:22:20 -0700 | [diff] [blame] | 348 | AppNotificationSettings.class.getName(), |
Fabrice Di Meglio | e3ff4d8 | 2014-07-23 20:03:20 -0700 | [diff] [blame] | 349 | OtherSoundSettings.class.getName(), |
Narayan Kamath | 33acb15 | 2015-03-16 12:48:05 +0000 | [diff] [blame] | 350 | ApnSettings.class.getName(), |
Jason Monk | b7e4380 | 2016-06-06 16:01:58 -0400 | [diff] [blame] | 351 | ApnEditor.class.getName(), |
John Spurlock | 45fa140 | 2015-04-09 12:50:04 -0400 | [diff] [blame] | 352 | WifiCallingSettings.class.getName(), |
John Spurlock | c1df2aa | 2015-04-13 20:57:06 -0400 | [diff] [blame] | 353 | ZenModePrioritySettings.class.getName(), |
John Spurlock | 533a566 | 2015-06-19 10:47:36 -0400 | [diff] [blame] | 354 | ZenModeAutomationSettings.class.getName(), |
John Spurlock | 45fa140 | 2015-04-09 12:50:04 -0400 | [diff] [blame] | 355 | ZenModeScheduleRuleSettings.class.getName(), |
John Spurlock | f57bad7 | 2015-04-30 09:26:15 -0400 | [diff] [blame] | 356 | ZenModeEventRuleSettings.class.getName(), |
Julia Reynolds | 5555d26 | 2015-11-09 10:52:17 -0500 | [diff] [blame] | 357 | ZenModeVisualInterruptionSettings.class.getName(), |
Jason Monk | 2583fc1 | 2015-03-25 09:46:30 -0400 | [diff] [blame] | 358 | ProcessStatsUi.class.getName(), |
Jason Monk | 1eb54eb | 2015-04-29 12:46:42 -0400 | [diff] [blame] | 359 | PowerUsageDetail.class.getName(), |
Jason Monk | 2cdafc6 | 2015-06-12 12:32:50 -0400 | [diff] [blame] | 360 | ProcessStatsSummary.class.getName(), |
Billy Lau | fee7856 | 2015-07-27 12:57:07 +0100 | [diff] [blame] | 361 | DrawOverlayDetails.class.getName(), |
| 362 | WriteSettingsDetails.class.getName(), |
Jason Monk | 91e2f89 | 2016-02-23 15:31:09 -0500 | [diff] [blame] | 363 | AdvancedAppSettings.class.getName(), |
Jason Monk | b9e5d23 | 2016-01-26 17:43:57 -0500 | [diff] [blame] | 364 | WallpaperTypeSettings.class.getName(), |
Ruben Brunk | c461d5c | 2016-04-07 21:45:41 -0700 | [diff] [blame] | 365 | VrListenerSettings.class.getName(), |
Tony Mak | 64f6d98 | 2016-05-03 18:55:41 +0100 | [diff] [blame] | 366 | ManagedProfileSettings.class.getName(), |
Jason Monk | b7e4380 | 2016-06-06 16:01:58 -0400 | [diff] [blame] | 367 | ChooseAccountActivity.class.getName(), |
| 368 | IccLockSettings.class.getName(), |
| 369 | ImeiInformation.class.getName(), |
| 370 | SimStatus.class.getName(), |
| 371 | Status.class.getName(), |
| 372 | TestingSettings.class.getName(), |
| 373 | WifiAPITest.class.getName(), |
| 374 | WifiInfo.class.getName(), |
Doris Ling | 7d73a29 | 2016-06-21 18:08:22 -0700 | [diff] [blame] | 375 | MasterClear.class.getName(), |
Justin Klaassen | eae3d9f | 2016-07-21 19:25:17 -0700 | [diff] [blame] | 376 | NightDisplaySettings.class.getName(), |
Todd Kennedy | 2ef1aa5 | 2016-09-06 14:02:38 -0700 | [diff] [blame] | 377 | ManageDomainUrls.class.getName(), |
Fan Zhang | a96a2d8 | 2016-09-27 17:51:11 -0700 | [diff] [blame] | 378 | AutomaticStorageManagerSettings.class.getName(), |
Fan Zhang | cc335d9 | 2016-09-29 14:37:14 -0700 | [diff] [blame^] | 379 | SupportFragment.class.getName(), |
| 380 | SystemDashboardFragment.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 381 | }; |
| 382 | |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 383 | |
| 384 | private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = { |
| 385 | "android.settings.APPLICATION_DETAILS_SETTINGS" |
| 386 | }; |
| 387 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 388 | private SharedPreferences mDevelopmentPreferences; |
| 389 | private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener; |
| 390 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 391 | private boolean mBatteryPresent = true; |
| 392 | private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 393 | @Override |
| 394 | public void onReceive(Context context, Intent intent) { |
| 395 | String action = intent.getAction(); |
| 396 | if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { |
| 397 | boolean batteryPresent = Utils.isBatteryPresent(intent); |
| 398 | |
| 399 | if (mBatteryPresent != batteryPresent) { |
| 400 | mBatteryPresent = batteryPresent; |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 401 | updateTilesList(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | } |
| 405 | }; |
| 406 | |
Clara Bayarri | 6934a04 | 2015-10-14 11:07:35 +0100 | [diff] [blame] | 407 | private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() { |
| 408 | @Override |
| 409 | public void onReceive(Context context, Intent intent) { |
| 410 | String action = intent.getAction(); |
| 411 | if (action.equals(Intent.ACTION_USER_ADDED) |
| 412 | || action.equals(Intent.ACTION_USER_REMOVED)) { |
| 413 | Index.getInstance(getApplicationContext()).update(); |
| 414 | } |
| 415 | } |
| 416 | }; |
| 417 | |
Svetoslav | 990159a | 2014-04-14 17:14:59 -0700 | [diff] [blame] | 418 | private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor = |
| 419 | new DynamicIndexableContentMonitor(); |
Svetoslav | 853e471 | 2014-04-14 10:10:25 -0700 | [diff] [blame] | 420 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 421 | private ActionBar mActionBar; |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 422 | private SwitchBar mSwitchBar; |
| 423 | |
| 424 | private Button mNextButton; |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 425 | |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 426 | private boolean mDisplayHomeAsUpEnabled; |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 427 | private boolean mDisplaySearch; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 428 | |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 429 | private boolean mIsShowingDashboard; |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 430 | private boolean mIsShortcut; |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 431 | |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 432 | private ViewGroup mContent; |
| 433 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 434 | private SearchView mSearchView; |
| 435 | private MenuItem mSearchMenuItem; |
| 436 | private boolean mSearchMenuItemExpanded = false; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 437 | private SearchResultsSummary mSearchResultsFragment; |
| 438 | private String mSearchQuery; |
| 439 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 440 | // Categories |
| 441 | private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 442 | |
Fabrice Di Meglio | b0a464f | 2014-07-23 18:15:42 -0700 | [diff] [blame] | 443 | private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh"; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 444 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 445 | private boolean mNeedToRevertToInitialFragment = false; |
| 446 | |
Fan Zhang | a96a2d8 | 2016-09-27 17:51:11 -0700 | [diff] [blame] | 447 | private DashboardFeatureProvider mDashboardFeatureProvider; |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 448 | private Intent mResultIntentData; |
Jason Monk | d4f03ec | 2016-01-07 16:25:34 -0500 | [diff] [blame] | 449 | private ComponentName mCurrentSuggestion; |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 450 | |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 451 | public SwitchBar getSwitchBar() { |
| 452 | return mSwitchBar; |
| 453 | } |
| 454 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 455 | @Override |
| 456 | public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { |
Sunny Goyal | 21ef89f | 2016-05-25 12:41:16 -0700 | [diff] [blame] | 457 | startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, pref.getTitle(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 458 | null, 0); |
| 459 | return true; |
| 460 | } |
| 461 | |
| 462 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 463 | public boolean onPreferenceTreeClick(Preference preference) { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 464 | return false; |
| 465 | } |
| 466 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 467 | @Override |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 468 | public void onConfigurationChanged(Configuration newConfig) { |
| 469 | super.onConfigurationChanged(newConfig); |
Fabrice Di Meglio | 6f0739a | 2014-02-03 18:12:25 -0800 | [diff] [blame] | 470 | Index.getInstance(this).update(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | @Override |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 474 | protected void onStart() { |
| 475 | super.onStart(); |
| 476 | |
| 477 | if (mNeedToRevertToInitialFragment) { |
| 478 | revertToInitialFragment(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 479 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | @Override |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 483 | public boolean onCreateOptionsMenu(Menu menu) { |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 484 | if (!mDisplaySearch) { |
| 485 | return false; |
| 486 | } |
| 487 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 488 | MenuInflater inflater = getMenuInflater(); |
| 489 | inflater.inflate(R.menu.options_menu, menu); |
| 490 | |
| 491 | // Cache the search query (can be overriden by the OnQueryTextListener) |
| 492 | final String query = mSearchQuery; |
| 493 | |
Fabrice Di Meglio | 9593782 | 2014-03-31 19:46:42 -0700 | [diff] [blame] | 494 | mSearchMenuItem = menu.findItem(R.id.search); |
| 495 | mSearchView = (SearchView) mSearchMenuItem.getActionView(); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 496 | |
Fabrice Di Meglio | 23ae00c | 2014-04-21 12:43:20 -0700 | [diff] [blame] | 497 | if (mSearchMenuItem == null || mSearchView == null) { |
| 498 | return false; |
| 499 | } |
| 500 | |
Fabrice Di Meglio | 8c3b0ce | 2014-05-12 18:54:32 -0700 | [diff] [blame] | 501 | if (mSearchResultsFragment != null) { |
| 502 | mSearchResultsFragment.setSearchView(mSearchView); |
| 503 | } |
| 504 | |
Fabrice Di Meglio | 9593782 | 2014-03-31 19:46:42 -0700 | [diff] [blame] | 505 | mSearchMenuItem.setOnActionExpandListener(this); |
Fan Zhang | b923918 | 2016-08-22 13:59:59 -0700 | [diff] [blame] | 506 | mSearchView.setMaxWidth(Integer.MAX_VALUE); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 507 | mSearchView.setOnQueryTextListener(this); |
| 508 | mSearchView.setOnCloseListener(this); |
| 509 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 510 | if (mSearchMenuItemExpanded) { |
| 511 | mSearchMenuItem.expandActionView(); |
| 512 | } |
| 513 | mSearchView.setQuery(query, true /* submit */); |
| 514 | |
| 515 | return true; |
| 516 | } |
| 517 | |
Jason Monk | 31c7c32 | 2016-01-20 14:41:52 -0500 | [diff] [blame] | 518 | @Override |
| 519 | public SharedPreferences getSharedPreferences(String name, int mode) { |
| 520 | if (name.equals(getPackageName() + "_preferences")) { |
Jason Monk | e4ebcd1 | 2016-02-21 09:37:41 -0500 | [diff] [blame] | 521 | return new SharedPreferencesLogger(this, getMetricsTag()); |
Jason Monk | 31c7c32 | 2016-01-20 14:41:52 -0500 | [diff] [blame] | 522 | } |
| 523 | return super.getSharedPreferences(name, mode); |
| 524 | } |
| 525 | |
Jason Monk | e4ebcd1 | 2016-02-21 09:37:41 -0500 | [diff] [blame] | 526 | private String getMetricsTag() { |
| 527 | String tag = getClass().getName(); |
| 528 | if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) { |
| 529 | tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT); |
| 530 | } |
| 531 | if (tag.startsWith("com.android.settings.")) { |
| 532 | tag = tag.replace("com.android.settings.", ""); |
| 533 | } |
| 534 | return tag; |
| 535 | } |
| 536 | |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 537 | private static boolean isShortCutIntent(final Intent intent) { |
| 538 | Set<String> categories = intent.getCategories(); |
| 539 | return (categories != null) && categories.contains("com.android.settings.SHORTCUT"); |
| 540 | } |
| 541 | |
Fabrice Di Meglio | 5b3c3c0 | 2014-06-30 15:18:08 -0700 | [diff] [blame] | 542 | private static boolean isLikeShortCutIntent(final Intent intent) { |
Fabrice Di Meglio | 5b7a100 | 2014-06-23 17:54:40 -0700 | [diff] [blame] | 543 | String action = intent.getAction(); |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 544 | if (action == null) { |
| 545 | return false; |
| 546 | } |
| 547 | for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) { |
| 548 | if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true; |
| 549 | } |
| 550 | return false; |
Fabrice Di Meglio | 5b7a100 | 2014-06-23 17:54:40 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 553 | @Override |
| 554 | protected void onCreate(Bundle savedState) { |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 555 | super.onCreate(savedState); |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 556 | long startTime = System.currentTimeMillis(); |
Fan Zhang | a96a2d8 | 2016-09-27 17:51:11 -0700 | [diff] [blame] | 557 | mDashboardFeatureProvider = |
| 558 | FeatureFactory.getFactory(this).getDashboardFeatureProvider(this); |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 559 | // Should happen before any call to getIntent() |
| 560 | getMetaData(); |
| 561 | |
| 562 | final Intent intent = getIntent(); |
| 563 | if (intent.hasExtra(EXTRA_UI_OPTIONS)) { |
| 564 | getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0)); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 565 | } |
Udam Saini | 92779ce | 2016-03-28 14:29:48 -0700 | [diff] [blame] | 566 | if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) { |
| 567 | setIsDrawerPresent(false); |
| 568 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 569 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 570 | mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, |
| 571 | Context.MODE_PRIVATE); |
| 572 | |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 573 | // Getting Intent properties can only be done after the super.onCreate(...) |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 574 | final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 575 | |
Fabrice Di Meglio | 5b3c3c0 | 2014-06-30 15:18:08 -0700 | [diff] [blame] | 576 | mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 577 | intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false); |
| 578 | |
Fabrice Di Meglio | e817a66 | 2014-07-16 19:51:06 -0700 | [diff] [blame] | 579 | final ComponentName cn = intent.getComponent(); |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 580 | final String className = cn.getClassName(); |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 581 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 582 | mIsShowingDashboard = className.equals(Settings.class.getName()) |
| 583 | || className.equals(Settings.WirelessSettings.class.getName()) |
| 584 | || className.equals(Settings.DeviceSettings.class.getName()) |
| 585 | || className.equals(Settings.PersonalSettings.class.getName()) |
| 586 | || className.equals(Settings.WirelessSettings.class.getName()); |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 587 | |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 588 | // This is a "Sub Settings" when: |
| 589 | // - this is a real SubSettings |
| 590 | // - or :settings:show_fragment_as_subsetting is passed to the Intent |
Jorim Jaggi | 4dfcb82 | 2015-04-29 17:21:32 -0700 | [diff] [blame] | 591 | final boolean isSubSettings = this instanceof SubSettings || |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 592 | intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false); |
| 593 | |
| 594 | // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets |
| 595 | if (isSubSettings) { |
Fabrice Di Meglio | 712df6c | 2014-07-18 17:44:37 -0700 | [diff] [blame] | 596 | // Check also that we are not a Theme Dialog as we don't want to override them |
| 597 | final int themeResId = getThemeResId(); |
| 598 | if (themeResId != R.style.Theme_DialogWhenLarge && |
| 599 | themeResId != R.style.Theme_SubSettingsDialogWhenLarge) { |
| 600 | setTheme(R.style.Theme_SubSettings); |
| 601 | } |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Fabrice Di Meglio | d40dd45 | 2014-07-18 15:20:34 -0700 | [diff] [blame] | 604 | setContentView(mIsShowingDashboard ? |
| 605 | R.layout.settings_main_dashboard : R.layout.settings_main_prefs); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 606 | |
Anna Galusza | 6b1e9db | 2016-03-30 17:25:36 -0700 | [diff] [blame] | 607 | mContent = (ViewGroup) findViewById(R.id.main_content); |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 608 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 609 | getFragmentManager().addOnBackStackChangedListener(this); |
| 610 | |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 611 | if (mIsShowingDashboard) { |
Fabrice Di Meglio | dff3faa | 2015-02-27 11:14:11 -0800 | [diff] [blame] | 612 | // Run the Index update only if we have some space |
| 613 | if (!Utils.isLowStorage(this)) { |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 614 | long indexStartTime = System.currentTimeMillis(); |
Jason Monk | 6c9e884 | 2016-04-14 14:34:16 -0400 | [diff] [blame] | 615 | Index.getInstance(getApplicationContext()).update(); |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 616 | if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took " |
| 617 | + (System.currentTimeMillis() - indexStartTime) + " ms"); |
Fabrice Di Meglio | dff3faa | 2015-02-27 11:14:11 -0800 | [diff] [blame] | 618 | } else { |
| 619 | Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!"); |
| 620 | } |
Fabrice Di Meglio | 5cda21b | 2014-04-21 10:14:28 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 623 | if (savedState != null) { |
Fabrice Di Meglio | 1800a9f | 2014-04-03 19:31:07 -0700 | [diff] [blame] | 624 | // We are restarting from a previous saved state; used that to initialize, instead |
| 625 | // of starting fresh. |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 626 | mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED); |
| 627 | mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY); |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 628 | setTitleFromIntent(intent); |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 629 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 630 | ArrayList<DashboardCategory> categories = |
| 631 | savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); |
| 632 | if (categories != null) { |
Fabrice Di Meglio | 5f99572 | 2014-05-19 19:51:31 -0700 | [diff] [blame] | 633 | mCategories.clear(); |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 634 | mCategories.addAll(categories); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 635 | setTitleFromBackStack(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 636 | } |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 637 | |
| 638 | mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 639 | mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH); |
Salvador Martinez | 2368e54 | 2016-07-25 18:16:47 -0700 | [diff] [blame] | 640 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 641 | } else { |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 642 | if (!mIsShowingDashboard) { |
Jason Monk | ea8b1a7 | 2015-06-02 16:46:34 -0400 | [diff] [blame] | 643 | mDisplaySearch = false; |
| 644 | // UP will be shown only if it is a sub settings |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 645 | if (mIsShortcut) { |
| 646 | mDisplayHomeAsUpEnabled = isSubSettings; |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 647 | } else if (isSubSettings) { |
| 648 | mDisplayHomeAsUpEnabled = true; |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 649 | } else { |
| 650 | mDisplayHomeAsUpEnabled = false; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 651 | } |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 652 | setTitleFromIntent(intent); |
Fabrice Di Meglio | c145732 | 2014-04-04 19:07:50 -0700 | [diff] [blame] | 653 | |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 654 | Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 655 | switchToFragment(initialFragmentName, initialArguments, true, false, |
| 656 | mInitialTitleResId, mInitialTitle, false); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 657 | } else { |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 658 | // No UP affordance if we are displaying the main Dashboard |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 659 | mDisplayHomeAsUpEnabled = false; |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 660 | // Show Search affordance |
| 661 | mDisplaySearch = true; |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 662 | mInitialTitleResId = R.string.dashboard_title; |
Salvador Martinez | 2368e54 | 2016-07-25 18:16:47 -0700 | [diff] [blame] | 663 | |
| 664 | // add argument to indicate which settings tab should be initially selected |
| 665 | final Bundle args = new Bundle(); |
| 666 | final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB; |
| 667 | args.putString(extraName, intent.getStringExtra(extraName)); |
Fan Zhang | a96a2d8 | 2016-09-27 17:51:11 -0700 | [diff] [blame] | 668 | if (isDashboardFeatureEnabled()) { |
| 669 | switchToFragment(DashboardSummary.class.getName(), args, false, false, |
| 670 | mInitialTitleResId, mInitialTitle, false); |
| 671 | } else { |
| 672 | switchToFragment(DashboardContainerFragment.class.getName(), args, false, false, |
| 673 | mInitialTitleResId, mInitialTitle, false); |
| 674 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 678 | mActionBar = getActionBar(); |
Fabrice Di Meglio | d8aec08 | 2014-05-20 10:49:50 -0700 | [diff] [blame] | 679 | if (mActionBar != null) { |
| 680 | mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); |
| 681 | mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); |
| 682 | } |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 683 | mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar); |
Jason Monk | e4ebcd1 | 2016-02-21 09:37:41 -0500 | [diff] [blame] | 684 | if (mSwitchBar != null) { |
| 685 | mSwitchBar.setMetricsTag(getMetricsTag()); |
| 686 | } |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 687 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 688 | // see if we should show Back/Next buttons |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 689 | if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) { |
| 690 | |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 691 | View buttonBar = findViewById(R.id.button_bar); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 692 | if (buttonBar != null) { |
| 693 | buttonBar.setVisibility(View.VISIBLE); |
| 694 | |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 695 | Button backButton = (Button)findViewById(R.id.back_button); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 696 | backButton.setOnClickListener(new OnClickListener() { |
| 697 | public void onClick(View v) { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 698 | setResult(RESULT_CANCELED, getResultIntentData()); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 699 | finish(); |
| 700 | } |
| 701 | }); |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 702 | Button skipButton = (Button)findViewById(R.id.skip_button); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 703 | skipButton.setOnClickListener(new OnClickListener() { |
| 704 | public void onClick(View v) { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 705 | setResult(RESULT_OK, getResultIntentData()); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 706 | finish(); |
| 707 | } |
| 708 | }); |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 709 | mNextButton = (Button)findViewById(R.id.next_button); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 710 | mNextButton.setOnClickListener(new OnClickListener() { |
| 711 | public void onClick(View v) { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 712 | setResult(RESULT_OK, getResultIntentData()); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 713 | finish(); |
| 714 | } |
| 715 | }); |
| 716 | |
| 717 | // set our various button parameters |
| 718 | if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) { |
| 719 | String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT); |
| 720 | if (TextUtils.isEmpty(buttonText)) { |
| 721 | mNextButton.setVisibility(View.GONE); |
| 722 | } |
| 723 | else { |
| 724 | mNextButton.setText(buttonText); |
| 725 | } |
| 726 | } |
| 727 | if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) { |
| 728 | String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT); |
| 729 | if (TextUtils.isEmpty(buttonText)) { |
| 730 | backButton.setVisibility(View.GONE); |
| 731 | } |
| 732 | else { |
| 733 | backButton.setText(buttonText); |
| 734 | } |
| 735 | } |
| 736 | if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) { |
| 737 | skipButton.setVisibility(View.VISIBLE); |
| 738 | } |
| 739 | } |
| 740 | } |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 741 | |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 742 | if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) |
| 743 | + " ms"); |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Fan Zhang | ece8ff6 | 2016-06-30 13:20:12 -0700 | [diff] [blame] | 746 | public void setDisplaySearchMenu(boolean displaySearch) { |
| 747 | if (displaySearch != mDisplaySearch) { |
| 748 | mDisplaySearch = displaySearch; |
| 749 | invalidateOptionsMenu(); |
| 750 | } |
| 751 | } |
| 752 | |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 753 | private void setTitleFromIntent(Intent intent) { |
| 754 | final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1); |
| 755 | if (initialTitleResId > 0) { |
| 756 | mInitialTitle = null; |
| 757 | mInitialTitleResId = initialTitleResId; |
Alexandra Gherghina | 62464b8 | 2014-08-11 12:40:13 +0100 | [diff] [blame] | 758 | |
| 759 | final String initialTitleResPackageName = intent.getStringExtra( |
| 760 | EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME); |
| 761 | if (initialTitleResPackageName != null) { |
| 762 | try { |
| 763 | Context authContext = createPackageContextAsUser(initialTitleResPackageName, |
| 764 | 0 /* flags */, new UserHandle(UserHandle.myUserId())); |
| 765 | mInitialTitle = authContext.getResources().getText(mInitialTitleResId); |
| 766 | setTitle(mInitialTitle); |
| 767 | mInitialTitleResId = -1; |
| 768 | return; |
| 769 | } catch (NameNotFoundException e) { |
| 770 | Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName); |
| 771 | } |
| 772 | } else { |
| 773 | setTitle(mInitialTitleResId); |
| 774 | } |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 775 | } else { |
| 776 | mInitialTitleResId = -1; |
| 777 | final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); |
| 778 | mInitialTitle = (initialTitle != null) ? initialTitle : getTitle(); |
| 779 | setTitle(mInitialTitle); |
| 780 | } |
| 781 | } |
| 782 | |
Fabrice Di Meglio | c95be4f | 2014-03-07 12:57:38 -0800 | [diff] [blame] | 783 | @Override |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 784 | public void onBackStackChanged() { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 785 | setTitleFromBackStack(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 786 | } |
| 787 | |
Fan Zhang | 2869157 | 2016-03-23 15:31:08 -0700 | [diff] [blame] | 788 | private void setTitleFromBackStack() { |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 789 | final int count = getFragmentManager().getBackStackEntryCount(); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 790 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 791 | if (count == 0) { |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 792 | if (mInitialTitleResId > 0) { |
| 793 | setTitle(mInitialTitleResId); |
| 794 | } else { |
| 795 | setTitle(mInitialTitle); |
| 796 | } |
Fan Zhang | 2869157 | 2016-03-23 15:31:08 -0700 | [diff] [blame] | 797 | return; |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 798 | } |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 799 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 800 | FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1); |
| 801 | setTitleFromBackStackEntry(bse); |
| 802 | } |
| 803 | |
| 804 | private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) { |
| 805 | final CharSequence title; |
| 806 | final int titleRes = bse.getBreadCrumbTitleRes(); |
| 807 | if (titleRes > 0) { |
| 808 | title = getText(titleRes); |
| 809 | } else { |
| 810 | title = bse.getBreadCrumbTitle(); |
| 811 | } |
| 812 | if (title != null) { |
| 813 | setTitle(title); |
| 814 | } |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 817 | @Override |
| 818 | protected void onSaveInstanceState(Bundle outState) { |
| 819 | super.onSaveInstanceState(outState); |
| 820 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 821 | if (mCategories.size() > 0) { |
| 822 | outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 823 | } |
Fabrice Di Meglio | d6985df | 2014-04-03 16:43:26 -0700 | [diff] [blame] | 824 | |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 825 | outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled); |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 826 | outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch); |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 827 | |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 828 | if (mDisplaySearch) { |
| 829 | // The option menus are created if the ActionBar is visible and they are also created |
| 830 | // asynchronously. If you launch Settings with an Intent action like |
| 831 | // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked |
| 832 | // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search |
| 833 | // menu item and search view are null. |
| 834 | boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded(); |
| 835 | outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded); |
Fabrice Di Meglio | d6985df | 2014-04-03 16:43:26 -0700 | [diff] [blame] | 836 | |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 837 | String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY; |
| 838 | outState.putString(SAVE_KEY_SEARCH_QUERY, query); |
| 839 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 843 | protected void onResume() { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 844 | super.onResume(); |
| 845 | |
| 846 | mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { |
| 847 | @Override |
| 848 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 849 | updateTilesList(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 850 | } |
| 851 | }; |
| 852 | mDevelopmentPreferences.registerOnSharedPreferenceChangeListener( |
| 853 | mDevelopmentPreferencesListener); |
| 854 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 855 | registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); |
Clara Bayarri | 6934a04 | 2015-10-14 11:07:35 +0100 | [diff] [blame] | 856 | registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED)); |
| 857 | registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED)); |
Svetoslav | 853e471 | 2014-04-14 10:10:25 -0700 | [diff] [blame] | 858 | |
Philip P. Moltmann | d9779db | 2016-02-24 12:11:05 -0800 | [diff] [blame] | 859 | mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR); |
Fabrice Di Meglio | a327076 | 2014-04-16 16:54:56 -0700 | [diff] [blame] | 860 | |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 861 | if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) { |
Fabrice Di Meglio | a327076 | 2014-04-16 16:54:56 -0700 | [diff] [blame] | 862 | onQueryTextSubmit(mSearchQuery); |
| 863 | } |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 864 | updateTilesList(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 868 | protected void onPause() { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 869 | super.onPause(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 870 | unregisterReceiver(mBatteryInfoReceiver); |
Clara Bayarri | 8c9521f | 2016-01-12 14:10:45 +0000 | [diff] [blame] | 871 | unregisterReceiver(mUserAddRemoveReceiver); |
Svetoslav | 990159a | 2014-04-14 17:14:59 -0700 | [diff] [blame] | 872 | mDynamicIndexableContentMonitor.unregister(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | @Override |
| 876 | public void onDestroy() { |
| 877 | super.onDestroy(); |
Fabrice Di Meglio | 680b064 | 2014-05-20 15:19:29 -0700 | [diff] [blame] | 878 | |
| 879 | mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener( |
| 880 | mDevelopmentPreferencesListener); |
| 881 | mDevelopmentPreferencesListener = null; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 882 | } |
| 883 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 884 | protected boolean isValidFragment(String fragmentName) { |
| 885 | // Almost all fragments are wrapped in this, |
| 886 | // except for a few that have their own activities. |
| 887 | for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) { |
| 888 | if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true; |
| 889 | } |
| 890 | return false; |
| 891 | } |
| 892 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 893 | @Override |
| 894 | public Intent getIntent() { |
| 895 | Intent superIntent = super.getIntent(); |
| 896 | String startingFragment = getStartingFragmentClass(superIntent); |
| 897 | // This is called from super.onCreate, isMultiPane() is not yet reliable |
| 898 | // Do not use onIsHidingHeaders either, which relies itself on this method |
| 899 | if (startingFragment != null) { |
| 900 | Intent modIntent = new Intent(superIntent); |
| 901 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); |
| 902 | Bundle args = superIntent.getExtras(); |
| 903 | if (args != null) { |
| 904 | args = new Bundle(args); |
| 905 | } else { |
| 906 | args = new Bundle(); |
| 907 | } |
| 908 | args.putParcelable("intent", superIntent); |
Kenny Guy | ac1e20e | 2014-06-24 14:34:14 +0100 | [diff] [blame] | 909 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 910 | return modIntent; |
| 911 | } |
| 912 | return superIntent; |
| 913 | } |
| 914 | |
| 915 | /** |
| 916 | * Checks if the component name in the intent is different from the Settings class and |
| 917 | * returns the class name to load as a fragment. |
| 918 | */ |
| 919 | private String getStartingFragmentClass(Intent intent) { |
| 920 | if (mFragmentClass != null) return mFragmentClass; |
| 921 | |
| 922 | String intentClass = intent.getComponent().getClassName(); |
| 923 | if (intentClass.equals(getClass().getName())) return null; |
| 924 | |
| 925 | if ("com.android.settings.ManageApplications".equals(intentClass) |
| 926 | || "com.android.settings.RunningServices".equals(intentClass) |
| 927 | || "com.android.settings.applications.StorageUse".equals(intentClass)) { |
| 928 | // Old names of manage apps. |
| 929 | intentClass = com.android.settings.applications.ManageApplications.class.getName(); |
| 930 | } |
| 931 | |
| 932 | return intentClass; |
| 933 | } |
| 934 | |
| 935 | /** |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 936 | * Start a new fragment containing a preference panel. If the preferences |
| 937 | * are being displayed in multi-pane mode, the given fragment class will |
| 938 | * be instantiated and placed in the appropriate pane. If running in |
| 939 | * single-pane mode, a new activity will be launched in which to show the |
| 940 | * fragment. |
| 941 | * |
| 942 | * @param fragmentClass Full name of the class implementing the fragment. |
| 943 | * @param args Any desired arguments to supply to the fragment. |
| 944 | * @param titleRes Optional resource identifier of the title of this |
| 945 | * fragment. |
| 946 | * @param titleText Optional text of the title of this fragment. |
| 947 | * @param resultTo Optional fragment that result data should be sent to. |
| 948 | * If non-null, resultTo.onActivityResult() will be called when this |
| 949 | * preference panel is done. The launched panel must use |
| 950 | * {@link #finishPreferencePanel(Fragment, int, Intent)} when done. |
| 951 | * @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] | 952 | * request code to be received with the result. |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 953 | */ |
| 954 | public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes, |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 955 | CharSequence titleText, Fragment resultTo, int resultRequestCode) { |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 956 | String title = null; |
| 957 | if (titleRes < 0) { |
| 958 | if (titleText != null) { |
| 959 | title = titleText.toString(); |
| 960 | } else { |
| 961 | // There not much we can do in that case |
| 962 | title = ""; |
| 963 | } |
Fabrice Di Meglio | 911fb2a | 2014-04-04 17:55:57 -0700 | [diff] [blame] | 964 | } |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 965 | Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode, |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 966 | titleRes, title, mIsShortcut); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | /** |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 970 | * Start a new fragment in a new activity containing a preference panel for a given user. If the |
| 971 | * preferences are being displayed in multi-pane mode, the given fragment class will be |
| 972 | * instantiated and placed in the appropriate pane. If running in single-pane mode, a new |
| 973 | * activity will be launched in which to show the fragment. |
| 974 | * |
| 975 | * @param fragmentClass Full name of the class implementing the fragment. |
| 976 | * @param args Any desired arguments to supply to the fragment. |
| 977 | * @param titleRes Optional resource identifier of the title of this fragment. |
| 978 | * @param titleText Optional text of the title of this fragment. |
| 979 | * @param userHandle The user for which the panel has to be started. |
| 980 | */ |
| 981 | public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes, |
| 982 | CharSequence titleText, UserHandle userHandle) { |
Lifu Tang | d033285 | 2015-04-02 12:05:46 -0700 | [diff] [blame] | 983 | // This is a workaround. |
| 984 | // |
| 985 | // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent |
| 986 | // starting the fragment could cause a native stack corruption. See b/17523189. However, |
| 987 | // adding that flag and start the preference panel with the same UserHandler will make it |
| 988 | // impossible to use back button to return to the previous screen. See b/20042570. |
| 989 | // |
| 990 | // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing |
| 991 | // another check here to call startPreferencePanel() instead of startWithFragmentAsUser() |
| 992 | // when we're calling it as the same user. |
| 993 | if (userHandle.getIdentifier() == UserHandle.myUserId()) { |
| 994 | startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0); |
| 995 | } else { |
| 996 | String title = null; |
| 997 | if (titleRes < 0) { |
| 998 | if (titleText != null) { |
| 999 | title = titleText.toString(); |
| 1000 | } else { |
| 1001 | // There not much we can do in that case |
| 1002 | title = ""; |
| 1003 | } |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 1004 | } |
Lifu Tang | d033285 | 2015-04-02 12:05:46 -0700 | [diff] [blame] | 1005 | Utils.startWithFragmentAsUser(this, fragmentClass, args, |
| 1006 | titleRes, title, mIsShortcut, userHandle); |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 1007 | } |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | /** |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1011 | * Called by a preference panel fragment to finish itself. |
| 1012 | * |
| 1013 | * @param caller The fragment that is asking to be finished. |
| 1014 | * @param resultCode Optional result code to send back to the original |
| 1015 | * launching fragment. |
| 1016 | * @param resultData Optional result data to send back to the original |
| 1017 | * launching fragment. |
| 1018 | */ |
| 1019 | public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) { |
| 1020 | setResult(resultCode, resultData); |
Fabrice Di Meglio | 58146c2 | 2014-06-26 16:20:26 -0700 | [diff] [blame] | 1021 | finish(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | /** |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 1025 | * Start a new fragment. |
| 1026 | * |
| 1027 | * @param fragment The fragment to start |
| 1028 | * @param push If true, the current fragment will be pushed onto the back stack. If false, |
| 1029 | * the current fragment will be replaced. |
| 1030 | */ |
| 1031 | public void startPreferenceFragment(Fragment fragment, boolean push) { |
| 1032 | FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Anna Galusza | 6b1e9db | 2016-03-30 17:25:36 -0700 | [diff] [blame] | 1033 | transaction.replace(R.id.main_content, fragment); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 1034 | if (push) { |
| 1035 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); |
| 1036 | transaction.addToBackStack(BACK_STACK_PREFS); |
| 1037 | } else { |
| 1038 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); |
| 1039 | } |
| 1040 | transaction.commitAllowingStateLoss(); |
| 1041 | } |
| 1042 | |
| 1043 | /** |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1044 | * Switch to a specific Fragment with taking care of validation, Title and BackStack |
| 1045 | */ |
| 1046 | private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate, |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 1047 | boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1048 | if (validate && !isValidFragment(fragmentName)) { |
| 1049 | throw new IllegalArgumentException("Invalid fragment for this activity: " |
| 1050 | + fragmentName); |
| 1051 | } |
| 1052 | Fragment f = Fragment.instantiate(this, fragmentName, args); |
| 1053 | FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Anna Galusza | 6b1e9db | 2016-03-30 17:25:36 -0700 | [diff] [blame] | 1054 | transaction.replace(R.id.main_content, f); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1055 | if (withTransition) { |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 1056 | TransitionManager.beginDelayedTransition(mContent); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1057 | } |
| 1058 | if (addToBackStack) { |
| 1059 | transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS); |
| 1060 | } |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 1061 | if (titleResId > 0) { |
| 1062 | transaction.setBreadCrumbTitle(titleResId); |
| 1063 | } else if (title != null) { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1064 | transaction.setBreadCrumbTitle(title); |
| 1065 | } |
| 1066 | transaction.commitAllowingStateLoss(); |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 1067 | getFragmentManager().executePendingTransactions(); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1068 | return f; |
| 1069 | } |
| 1070 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1071 | private void updateTilesList() { |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 1072 | // Generally the items that are will be changing from these updates will |
| 1073 | // not be in the top list of tiles, so run it in the background and the |
| 1074 | // SettingsDrawerActivity will pick up on the updates automatically. |
| 1075 | AsyncTask.execute(new Runnable() { |
| 1076 | @Override |
| 1077 | public void run() { |
| 1078 | doUpdateTilesList(); |
| 1079 | } |
| 1080 | }); |
| 1081 | } |
| 1082 | |
| 1083 | private void doUpdateTilesList() { |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1084 | PackageManager pm = getPackageManager(); |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 1085 | final UserManager um = UserManager.get(this); |
| 1086 | final boolean isAdmin = um.isAdminUser(); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1087 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1088 | String packageName = getPackageName(); |
| 1089 | setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()), |
| 1090 | pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1091 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1092 | setTileEnabled(new ComponentName(packageName, |
| 1093 | Settings.BluetoothSettingsActivity.class.getName()), |
| 1094 | pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1095 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1096 | setTileEnabled(new ComponentName(packageName, |
| 1097 | Settings.DataUsageSummaryActivity.class.getName()), |
| 1098 | Utils.isBandwidthControlEnabled(), isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1099 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1100 | setTileEnabled(new ComponentName(packageName, |
| 1101 | Settings.SimSettingsActivity.class.getName()), |
| 1102 | Utils.showSimCardTile(this), isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1103 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1104 | setTileEnabled(new ComponentName(packageName, |
| 1105 | Settings.PowerUsageSummaryActivity.class.getName()), |
| 1106 | mBatteryPresent, isAdmin, pm); |
| 1107 | |
| 1108 | setTileEnabled(new ComponentName(packageName, |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1109 | Settings.UserSettingsActivity.class.getName()), |
| 1110 | UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers() |
| 1111 | && !Utils.isMonkeyRunning(), isAdmin, pm); |
| 1112 | |
Fyodor Kupolov | ca060e3 | 2016-06-24 13:01:11 -0700 | [diff] [blame] | 1113 | setTileEnabled(new ComponentName(packageName, |
| 1114 | Settings.WirelessSettingsActivity.class.getName()), |
| 1115 | !UserManager.isDeviceInDemoMode(this), isAdmin, pm); |
| 1116 | |
| 1117 | setTileEnabled(new ComponentName(packageName, |
| 1118 | Settings.DateTimeSettingsActivity.class.getName()), |
| 1119 | !UserManager.isDeviceInDemoMode(this), isAdmin, pm); |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1120 | NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); |
| 1121 | setTileEnabled(new ComponentName(packageName, |
| 1122 | Settings.PaymentSettingsActivity.class.getName()), |
| 1123 | pm.hasSystemFeature(PackageManager.FEATURE_NFC) |
| 1124 | && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION) |
| 1125 | && adapter != null && adapter.isEnabled(), isAdmin, pm); |
| 1126 | |
| 1127 | setTileEnabled(new ComponentName(packageName, |
| 1128 | Settings.PrintSettingsActivity.class.getName()), |
| 1129 | pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm); |
| 1130 | |
| 1131 | final boolean showDev = mDevelopmentPreferences.getBoolean( |
Dan Sandler | 12c4ba4 | 2016-03-28 11:13:40 -0400 | [diff] [blame] | 1132 | DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng")) |
| 1133 | && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES); |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1134 | setTileEnabled(new ComponentName(packageName, |
| 1135 | Settings.DevelopmentSettingsActivity.class.getName()), |
Dan Sandler | 12c4ba4 | 2016-03-28 11:13:40 -0400 | [diff] [blame] | 1136 | showDev, isAdmin, pm); |
Fan Zhang | cc335d9 | 2016-09-29 14:37:14 -0700 | [diff] [blame^] | 1137 | setTileEnabled(new ComponentName(packageName, |
| 1138 | Settings.DevelopmentSettingsActivity.DASHBOARD_ALIAS), |
| 1139 | showDev, isAdmin, pm); |
Dan Sandler | 12c4ba4 | 2016-03-28 11:13:40 -0400 | [diff] [blame] | 1140 | |
| 1141 | // Reveal development-only quick settings tiles |
| 1142 | DevelopmentTiles.setTilesEnabled(this, showDev); |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1143 | |
| 1144 | if (UserHandle.MU_ENABLED && !isAdmin) { |
| 1145 | // When on restricted users, disable all extra categories (but only the settings ones). |
Fan Zhang | a96a2d8 | 2016-09-27 17:51:11 -0700 | [diff] [blame] | 1146 | List<DashboardCategory> categories; |
| 1147 | if (isDashboardFeatureEnabled()) { |
| 1148 | categories = mDashboardFeatureProvider.getAllCategories(); |
| 1149 | } else { |
| 1150 | categories = getDashboardCategories(); |
| 1151 | } |
| 1152 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1153 | for (DashboardCategory category : categories) { |
Jason Monk | d4f03ec | 2016-01-07 16:25:34 -0500 | [diff] [blame] | 1154 | for (Tile tile : category.tiles) { |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1155 | ComponentName component = tile.intent.getComponent(); |
Jason Monk | 5862c1e | 2016-06-07 14:02:33 -0400 | [diff] [blame] | 1156 | if (packageName.equals(component.getPackageName()) && !ArrayUtils.contains( |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1157 | SETTINGS_FOR_RESTRICTED, component.getClassName())) { |
| 1158 | setTileEnabled(component, false, isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1159 | } |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1160 | } |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1161 | } |
| 1162 | } |
Doris Ling | 26bf003 | 2016-06-15 18:16:09 -0700 | [diff] [blame] | 1163 | |
| 1164 | String backupIntent = getResources().getString(R.string.config_backup_settings_intent); |
| 1165 | boolean useDefaultBackup = TextUtils.isEmpty(backupIntent); |
| 1166 | setTileEnabled(new ComponentName(packageName, |
| 1167 | Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin, pm); |
| 1168 | boolean hasBackupActivity = false; |
| 1169 | if (!useDefaultBackup) { |
| 1170 | try { |
| 1171 | Intent intent = Intent.parseUri(backupIntent, 0); |
| 1172 | hasBackupActivity = !getPackageManager().queryIntentActivities(intent, 0).isEmpty(); |
| 1173 | } catch (URISyntaxException e) { |
| 1174 | Log.e(LOG_TAG, "Invalid backup intent URI!", e); |
| 1175 | } |
| 1176 | } |
| 1177 | setTileEnabled(new ComponentName(packageName, |
| 1178 | BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin, pm); |
| 1179 | |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 1180 | } |
| 1181 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1182 | private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin, |
| 1183 | PackageManager pm) { |
Jason Monk | 5862c1e | 2016-06-07 14:02:33 -0400 | [diff] [blame] | 1184 | if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName()) |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1185 | && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) { |
| 1186 | enabled = false; |
| 1187 | } |
Jason Monk | 5862c1e | 2016-06-07 14:02:33 -0400 | [diff] [blame] | 1188 | setTileEnabled(component, enabled); |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 1189 | } |
| 1190 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1191 | private void getMetaData() { |
| 1192 | try { |
| 1193 | ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), |
| 1194 | PackageManager.GET_META_DATA); |
| 1195 | if (ai == null || ai.metaData == null) return; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1196 | mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); |
| 1197 | } catch (NameNotFoundException nnfe) { |
| 1198 | // No recovery |
| 1199 | Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString()); |
| 1200 | } |
| 1201 | } |
| 1202 | |
Fan Zhang | a96a2d8 | 2016-09-27 17:51:11 -0700 | [diff] [blame] | 1203 | @Override |
| 1204 | protected boolean isDashboardFeatureEnabled() { |
| 1205 | if (mDashboardFeatureProvider == null) { |
| 1206 | mDashboardFeatureProvider = |
| 1207 | FeatureFactory.getFactory(this).getDashboardFeatureProvider(this); |
| 1208 | } |
| 1209 | return mDashboardFeatureProvider.isEnabled(); |
| 1210 | } |
| 1211 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1212 | // give subclasses access to the Next button |
| 1213 | public boolean hasNextButton() { |
| 1214 | return mNextButton != null; |
| 1215 | } |
| 1216 | |
| 1217 | public Button getNextButton() { |
| 1218 | return mNextButton; |
| 1219 | } |
| 1220 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1221 | @Override |
| 1222 | public boolean shouldUpRecreateTask(Intent targetIntent) { |
| 1223 | return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class)); |
| 1224 | } |
| 1225 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1226 | @Override |
| 1227 | public boolean onQueryTextSubmit(String query) { |
| 1228 | switchToSearchResultsFragmentIfNeeded(); |
| 1229 | mSearchQuery = query; |
| 1230 | return mSearchResultsFragment.onQueryTextSubmit(query); |
| 1231 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1232 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1233 | @Override |
| 1234 | public boolean onQueryTextChange(String newText) { |
| 1235 | mSearchQuery = newText; |
Fabrice Di Meglio | 7e4855e | 2014-05-23 16:03:43 -0700 | [diff] [blame] | 1236 | if (mSearchResultsFragment == null) { |
Fabrice Di Meglio | a327076 | 2014-04-16 16:54:56 -0700 | [diff] [blame] | 1237 | return false; |
| 1238 | } |
| 1239 | return mSearchResultsFragment.onQueryTextChange(newText); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1240 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1241 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1242 | @Override |
| 1243 | public boolean onClose() { |
| 1244 | return false; |
| 1245 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1246 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1247 | @Override |
| 1248 | public boolean onMenuItemActionExpand(MenuItem item) { |
| 1249 | if (item.getItemId() == mSearchMenuItem.getItemId()) { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1250 | switchToSearchResultsFragmentIfNeeded(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1251 | } |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1252 | return true; |
| 1253 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1254 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1255 | @Override |
| 1256 | public boolean onMenuItemActionCollapse(MenuItem item) { |
| 1257 | if (item.getItemId() == mSearchMenuItem.getItemId()) { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1258 | if (mSearchMenuItemExpanded) { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1259 | revertToInitialFragment(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1260 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1261 | } |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1262 | return true; |
| 1263 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1264 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1265 | @Override |
Jason Monk | d4f03ec | 2016-01-07 16:25:34 -0500 | [diff] [blame] | 1266 | protected void onTileClicked(Tile tile) { |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1267 | if (mIsShowingDashboard) { |
| 1268 | // If on dashboard, don't finish so the back comes back to here. |
| 1269 | openTile(tile); |
| 1270 | } else { |
| 1271 | super.onTileClicked(tile); |
| 1272 | } |
| 1273 | } |
| 1274 | |
Jason Monk | af00109 | 2015-11-04 13:16:18 -0500 | [diff] [blame] | 1275 | @Override |
| 1276 | public void onProfileTileOpen() { |
| 1277 | if (!mIsShowingDashboard) { |
| 1278 | finish(); |
| 1279 | } |
| 1280 | } |
| 1281 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1282 | private void switchToSearchResultsFragmentIfNeeded() { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1283 | if (mSearchResultsFragment != null) { |
| 1284 | return; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1285 | } |
Anna Galusza | 6b1e9db | 2016-03-30 17:25:36 -0700 | [diff] [blame] | 1286 | Fragment current = getFragmentManager().findFragmentById(R.id.main_content); |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1287 | if (current != null && current instanceof SearchResultsSummary) { |
| 1288 | mSearchResultsFragment = (SearchResultsSummary) current; |
| 1289 | } else { |
Fan Zhang | 2869157 | 2016-03-23 15:31:08 -0700 | [diff] [blame] | 1290 | setContentHeaderView(null); |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1291 | mSearchResultsFragment = (SearchResultsSummary) switchToFragment( |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 1292 | SearchResultsSummary.class.getName(), null, false, true, |
| 1293 | R.string.search_results_title, null, true); |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1294 | } |
Fabrice Di Meglio | d297a58 | 2014-04-22 17:23:23 -0700 | [diff] [blame] | 1295 | mSearchResultsFragment.setSearchView(mSearchView); |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1296 | mSearchMenuItemExpanded = true; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 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 | public void needToRevertToInitialFragment() { |
| 1300 | mNeedToRevertToInitialFragment = true; |
| 1301 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1302 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1303 | private void revertToInitialFragment() { |
| 1304 | mNeedToRevertToInitialFragment = false; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1305 | mSearchResultsFragment = null; |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1306 | mSearchMenuItemExpanded = false; |
| 1307 | getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS, |
| 1308 | FragmentManager.POP_BACK_STACK_INCLUSIVE); |
Fabrice Di Meglio | 23ae00c | 2014-04-21 12:43:20 -0700 | [diff] [blame] | 1309 | if (mSearchMenuItem != null) { |
| 1310 | mSearchMenuItem.collapseActionView(); |
| 1311 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1312 | } |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 1313 | |
| 1314 | public Intent getResultIntentData() { |
| 1315 | return mResultIntentData; |
| 1316 | } |
| 1317 | |
| 1318 | public void setResultIntentData(Intent resultIntentData) { |
| 1319 | mResultIntentData = resultIntentData; |
| 1320 | } |
Jason Monk | d4f03ec | 2016-01-07 16:25:34 -0500 | [diff] [blame] | 1321 | |
| 1322 | public void startSuggestion(Intent intent) { |
| 1323 | mCurrentSuggestion = intent.getComponent(); |
| 1324 | startActivityForResult(intent, REQUEST_SUGGESTION); |
| 1325 | } |
| 1326 | |
| 1327 | @Override |
| 1328 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 1329 | if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null |
| 1330 | && resultCode != RESULT_CANCELED) { |
| 1331 | getPackageManager().setComponentEnabledSetting(mCurrentSuggestion, |
| 1332 | PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); |
| 1333 | } |
| 1334 | super.onActivityResult(requestCode, resultCode, data); |
| 1335 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1336 | } |