SettingsActivity.java revision e817a66e83191c0ae74acd53a538a0965eba2683
1263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio/* 2263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Copyright (C) 2014 The Android Open Source Project 3263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * 4263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Licensed under the Apache License, Version 2.0 (the "License"); 5263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * you may not use this file except in compliance with the License. 6263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * You may obtain a copy of the License at 7263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * 8263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * http://www.apache.org/licenses/LICENSE-2.0 9263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * 10263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Unless required by applicable law or agreed to in writing, software 11263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * distributed under the License is distributed on an "AS IS" BASIS, 12263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * See the License for the specific language governing permissions and 14263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * limitations under the License. 15263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 16263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 17263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Megliopackage com.android.settings; 18263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 19263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.ActionBar; 20263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Activity; 21263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Fragment; 22263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentManager; 23263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentTransaction; 24263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.BroadcastReceiver; 25d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.content.ComponentName; 26263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Context; 27263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Intent; 28263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.IntentFilter; 29263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.SharedPreferences; 30263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ActivityInfo; 31263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager; 32263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager.NameNotFoundException; 33263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ResolveInfo; 34263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.Configuration; 35263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.TypedArray; 36263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.XmlResourceParser; 37263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.nfc.NfcAdapter; 38263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Bundle; 39263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Handler; 40263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.INetworkManagementService; 41263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Message; 42263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.RemoteException; 43263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.ServiceManager; 44263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserHandle; 45263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserManager; 46263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.Preference; 47263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceFragment; 48263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceManager; 49263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceScreen; 50263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.text.TextUtils; 5159a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.transition.TransitionManager; 52263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.AttributeSet; 53263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Log; 54263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.TypedValue; 55263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Xml; 56d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.Menu; 57d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.MenuInflater; 58263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.MenuItem; 59263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View; 60263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View.OnClickListener; 6159a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.view.ViewGroup; 62263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.Button; 63d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.widget.SearchView; 64c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock 65263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.ArrayUtils; 66263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.XmlUtils; 67263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.AccessibilitySettings; 68263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.CaptionPropertiesFragment; 69263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.AccountSyncSettings; 70d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.applications.InstalledAppDetails; 71263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ManageApplications; 72263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ProcessStatsUi; 73263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.bluetooth.BluetoothSettings; 74c9dc66d6059a5bcc867ab2046c59f969a13c46d7PauloftheWestimport com.android.settings.bluetooth.MessageAccessSettings; 7563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglioimport com.android.settings.dashboard.DashboardCategory; 76263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.dashboard.DashboardSummary; 7763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglioimport com.android.settings.dashboard.DashboardTile; 78d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.NoHomeDialogFragment; 79d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.SearchResultsSummary; 80263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.deviceinfo.Memory; 81263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.deviceinfo.UsbSettings; 82c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlockimport com.android.settings.fuelgauge.BatterySaverSettings; 83263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.fuelgauge.PowerUsageSummary; 847a6bfd132cac4dcff72e3adcdd68a7ef777cee12Fabrice Di Meglioimport com.android.settings.search.DynamicIndexableContentMonitor; 85fa7dc240e978b1b77bb5c80a78cd1f8c77648301Fabrice Di Meglioimport com.android.settings.search.Index; 86263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.InputMethodAndLanguageSettings; 87263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.KeyboardLayoutPickerFragment; 88263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.SpellCheckersSettings; 89263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.UserDictionaryList; 90263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.location.LocationSettings; 91263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.AndroidBeam; 92263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.PaymentSettings; 93c9afadb04b00598f5988101681089290cf14f79cJohn Spurlockimport com.android.settings.notification.ConditionProviderSettings; 944a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationAccessSettings; 954a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationSettings; 964a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationStation; 974a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.ZenModeSettings; 98263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintJobSettingsFragment; 99263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintSettingsFragment; 100263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.tts.TextToSpeechSettings; 101263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.users.UserSettings; 102263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.vpn2.VpnSettings; 103263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wfd.WifiDisplaySettings; 10441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport com.android.settings.widget.SwitchBar; 105263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.AdvancedWifiSettings; 1067837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWestimport com.android.settings.wifi.SavedAccessPointsWifiSettings; 107263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.WifiSettings; 108263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.p2p.WifiP2pSettings; 109c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock 110263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParser; 111263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParserException; 112263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 113263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.io.IOException; 114263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.ArrayList; 115263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.List; 1160d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglioimport java.util.Set; 117263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 118e9326d276135b657738d851e0a56df447f09567aFabrice Di Meglioimport static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED; 119d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 120263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Megliopublic class SettingsActivity extends Activity 121263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio implements PreferenceManager.OnPreferenceTreeClickListener, 122263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PreferenceFragment.OnPreferenceStartFragmentCallback, 123cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina ButtonBarHandler, FragmentManager.OnBackStackChangedListener, 124d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio SearchView.OnQueryTextListener, SearchView.OnCloseListener, 125cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina MenuItem.OnActionExpandListener { 126263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 127263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String LOG_TAG = "Settings"; 128263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 129263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Constants for state save/restore 130769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private static final String SAVE_KEY_CATEGORIES = ":settings:categories"; 131d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded"; 132d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query"; 133b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up"; 1343d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search"; 135263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 136263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 137263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * When starting this activity, the invoking Intent can contain this extra 138263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * string to specify which fragment should be initially displayed. 139263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity 140263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * will call isValidFragment() to confirm that the fragment class name is valid for this 141263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * activity. 142263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 143263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment"; 144263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 145263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 146263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, 147263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * this extra can also be specified to supply a Bundle of arguments to pass 148263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * to that fragment when it is instantiated during the initial creation 149263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * of the activity. 150263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 151263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args"; 152263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 153263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 154c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS} 155c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio */ 156c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"; 157c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio 1586f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio public static final String BACK_STACK_PREFS = ":settings:prefs"; 1596f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio 160263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // extras that allow any preference activity to be launched as part of a wizard 161263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 162263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // show Back and Next buttons? takes boolean parameter 163263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Back will then return RESULT_CANCELED and Next RESULT_OK 164263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; 165263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 166263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // add a Skip button? 167263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip"; 168263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 169263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // specify custom text for the Back or Next buttons, or cause a button to not appear 170263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // at all by setting it to null 171263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text"; 172263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text"; 173263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 174263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 175263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, 176a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio * those extra can also be specify to supply the title or title res id to be shown for 177263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * that fragment. 178263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 179d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title"; 180a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = ":settings:show_fragment_title_resid"; 1810d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT = ":settings:show_fragment_as_shortcut"; 182263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 183263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String META_DATA_KEY_FRAGMENT_CLASS = 184263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio "com.android.settings.FRAGMENT_CLASS"; 185263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 186263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String EXTRA_UI_OPTIONS = "settings:ui_options"; 187263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 188d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio private static final String EMPTY_QUERY = ""; 189d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio 190263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static boolean sShowNoHomeNotice = false; 191263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 192263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private String mFragmentClass; 193263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1948eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio private CharSequence mInitialTitle; 195a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio private int mInitialTitleResId; 1968eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio 197263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Show only these settings for restricted users 198263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private int[] SETTINGS_FOR_RESTRICTED = { 199263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.wireless_section, 200263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.wifi_settings, 201263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.bluetooth_settings, 202263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.data_usage_settings, 203263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.wireless_settings, 204263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.device_section, 2054e4cdeffdb6087c953f44808f14f18554a749bdaJohn Spurlock R.id.notification_settings, 206263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.display_settings, 207263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.storage_settings, 208263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.application_settings, 209263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.battery_settings, 210263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.personal_section, 211263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.location_settings, 212263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.security_settings, 213263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.language_settings, 214263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.user_settings, 215263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.account_settings, 216263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.system_section, 217263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.date_time_settings, 218263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.about_settings, 219263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.accessibility_settings, 220263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.print_settings, 221263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.nfc_payment_settings, 2222858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio R.id.home_settings, 2232858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio R.id.dashboard 224263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 225263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 226263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String[] ENTRY_FRAGMENTS = { 227263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WirelessSettings.class.getName(), 228263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WifiSettings.class.getName(), 229263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AdvancedWifiSettings.class.getName(), 2307837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWest SavedAccessPointsWifiSettings.class.getName(), 231263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio BluetoothSettings.class.getName(), 232c9dc66d6059a5bcc867ab2046c59f969a13c46d7PauloftheWest MessageAccessSettings.class.getName(), 233263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TetherSettings.class.getName(), 234263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WifiP2pSettings.class.getName(), 235263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio VpnSettings.class.getName(), 236263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DateTimeSettings.class.getName(), 237263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio LocalePicker.class.getName(), 238263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio InputMethodAndLanguageSettings.class.getName(), 239263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio SpellCheckersSettings.class.getName(), 240263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UserDictionaryList.class.getName(), 241263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UserDictionarySettings.class.getName(), 2423033ce0723103b55b1b5a53145c05e143b5bbfd6Amith Yamasani HomeSettings.class.getName(), 243263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DisplaySettings.class.getName(), 244263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DeviceInfoSettings.class.getName(), 245263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ManageApplications.class.getName(), 246263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ProcessStatsUi.class.getName(), 247263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio NotificationStation.class.getName(), 248263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio LocationSettings.class.getName(), 249263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio SecuritySettings.class.getName(), 250263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PrivacySettings.class.getName(), 251263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DeviceAdminSettings.class.getName(), 252263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AccessibilitySettings.class.getName(), 253263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio CaptionPropertiesFragment.class.getName(), 254263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio com.android.settings.accessibility.ToggleInversionPreferenceFragment.class.getName(), 255263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(), 256263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TextToSpeechSettings.class.getName(), 257263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Memory.class.getName(), 258263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DevelopmentSettings.class.getName(), 259263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UsbSettings.class.getName(), 260263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AndroidBeam.class.getName(), 261263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WifiDisplaySettings.class.getName(), 262263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PowerUsageSummary.class.getName(), 263263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AccountSyncSettings.class.getName(), 264263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio CryptKeeperSettings.class.getName(), 265263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DataUsageSummary.class.getName(), 266263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DreamSettings.class.getName(), 267263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UserSettings.class.getName(), 268263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio NotificationAccessSettings.class.getName(), 269c9afadb04b00598f5988101681089290cf14f79cJohn Spurlock ConditionProviderSettings.class.getName(), 270263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PrintSettingsFragment.class.getName(), 271263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PrintJobSettingsFragment.class.getName(), 272263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TrustedCredentialsSettings.class.getName(), 273263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PaymentSettings.class.getName(), 274263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio KeyboardLayoutPickerFragment.class.getName(), 275d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio ZenModeSettings.class.getName(), 276d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio NotificationSettings.class.getName(), 277d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio ChooseLockPassword.ChooseLockPasswordFragment.class.getName(), 278d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio ChooseLockPattern.ChooseLockPatternFragment.class.getName(), 279c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock InstalledAppDetails.class.getName(), 280c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock BatterySaverSettings.class.getName(), 281263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 282263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 2835a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio 2845a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = { 2855a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio "android.settings.APPLICATION_DETAILS_SETTINGS" 2865a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio }; 2875a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio 288263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private SharedPreferences mDevelopmentPreferences; 289263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener; 290263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 291263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private boolean mBatteryPresent = true; 292263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() { 293263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 294263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 295263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onReceive(Context context, Intent intent) { 296263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String action = intent.getAction(); 297263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { 298263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio boolean batteryPresent = Utils.isBatteryPresent(intent); 299263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 300263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mBatteryPresent != batteryPresent) { 301263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mBatteryPresent = batteryPresent; 302769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio invalidateCategories(); 303263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 304263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 305263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 306263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 307263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 308990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor = 309990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav new DynamicIndexableContentMonitor(); 310853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav 311d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private ActionBar mActionBar; 31241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio private SwitchBar mSwitchBar; 31341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio 31441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio private Button mNextButton; 3153d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio 316b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio private boolean mDisplayHomeAsUpEnabled; 3173d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio private boolean mDisplaySearch; 318d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 31935062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio private boolean mIsShowingDashboard; 3200d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio private boolean mIsShortcut; 32135062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio 32259a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio private ViewGroup mContent; 32359a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio 324d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private SearchView mSearchView; 325d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private MenuItem mSearchMenuItem; 326d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private boolean mSearchMenuItemExpanded = false; 327d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private SearchResultsSummary mSearchResultsFragment; 328d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private String mSearchQuery; 329d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 330769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio // Categories 331769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>(); 332769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private boolean mNeedToRebuildCategories; 333263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 334769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private static final int MSG_BUILD_CATEGORIES = 1; 335263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private Handler mHandler = new Handler() { 336263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 337263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void handleMessage(Message msg) { 338263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio switch (msg.what) { 339769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio case MSG_BUILD_CATEGORIES: { 34042c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio if(mNeedToRebuildCategories) { 34142c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio buildDashboardCategories(mCategories); 34242c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio } 343263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } break; 344263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 345263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 346263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 347263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 348d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private boolean mNeedToRevertToInitialFragment = false; 349d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 35041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio public SwitchBar getSwitchBar() { 35141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio return mSwitchBar; 35241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio } 35341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio 354769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio public List<DashboardCategory> getDashboardCategories() { 35542c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio if (mNeedToRebuildCategories || mCategories.size() == 0) { 356769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio buildDashboardCategories(mCategories); 357769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio mNeedToRebuildCategories = false; 358769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio } 359769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio return mCategories; 360769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio } 361769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio 362263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 363263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { 364263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Override the fragment title for Wallpaper settings 365263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio int titleRes = pref.getTitleRes(); 366263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) { 367263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio titleRes = R.string.wallpaper_settings_fragment_title; 368263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName()) 369263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio && UserHandle.myUserId() != UserHandle.USER_OWNER) { 370263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (UserManager.get(this).isLinkedUser()) { 371263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio titleRes = R.string.profile_info_settings_title; 372263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 373263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio titleRes = R.string.user_info_settings_title; 374263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 375263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 376263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(), 377263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio null, 0); 378263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return true; 379263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 380263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 381263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 382263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { 383263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return false; 384263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 385263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 386769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private void invalidateCategories() { 387769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) { 388769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio mHandler.sendEmptyMessage(MSG_BUILD_CATEGORIES); 389263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 390263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 391263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 392263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 393263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onConfigurationChanged(Configuration newConfig) { 394263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onConfigurationChanged(newConfig); 3956f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio Index.getInstance(this).update(); 396263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 397263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 398263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 399d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio protected void onStart() { 400d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio super.onStart(); 401d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 402d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (mNeedToRevertToInitialFragment) { 403d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio revertToInitialFragment(); 404263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 405263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 406263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 407263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 408d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onCreateOptionsMenu(Menu menu) { 4093d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio if (!mDisplaySearch) { 4103d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio return false; 4113d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio } 4123d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio 413d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio MenuInflater inflater = getMenuInflater(); 414d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio inflater.inflate(R.menu.options_menu, menu); 415d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 416d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio // Cache the search query (can be overriden by the OnQueryTextListener) 417d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio final String query = mSearchQuery; 418d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 4199593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio mSearchMenuItem = menu.findItem(R.id.search); 4209593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio mSearchView = (SearchView) mSearchMenuItem.getActionView(); 421d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 42223ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio if (mSearchMenuItem == null || mSearchView == null) { 42323ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio return false; 42423ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio } 42523ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio 4268c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio if (mSearchResultsFragment != null) { 4278c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio mSearchResultsFragment.setSearchView(mSearchView); 4288c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio } 4298c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio 4309593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio mSearchMenuItem.setOnActionExpandListener(this); 431d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchView.setOnQueryTextListener(this); 432d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchView.setOnCloseListener(this); 433d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 434d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (mSearchMenuItemExpanded) { 435d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchMenuItem.expandActionView(); 436d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 437d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchView.setQuery(query, true /* submit */); 438d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 439d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return true; 440d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 441d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 4420d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio private static boolean isShortCutIntent(final Intent intent) { 4430d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio Set<String> categories = intent.getCategories(); 4440d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio return (categories != null) && categories.contains("com.android.settings.SHORTCUT"); 4450d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio } 4460d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio 4475b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio private static boolean isLikeShortCutIntent(final Intent intent) { 4485b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio String action = intent.getAction(); 4495a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio if (action == null) { 4505a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio return false; 4515a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio } 4525a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) { 4535a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true; 4545a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio } 4555a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio return false; 4565b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio } 4575b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio 458d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 459d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio protected void onCreate(Bundle savedState) { 4600d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio super.onCreate(savedState); 4610d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio 4620d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio // Should happen before any call to getIntent() 4630d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio getMetaData(); 4640d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio 4650d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio final Intent intent = getIntent(); 4660d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio if (intent.hasExtra(EXTRA_UI_OPTIONS)) { 4670d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0)); 468263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 469263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 470263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, 471263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Context.MODE_PRIVATE); 472263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 473da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio // Getting Intent properties can only be done after the super.onCreate(...) 4740d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); 4750d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio 4765b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || 4770d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false); 478da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio 479e817a66e83191c0ae74acd53a538a0965eba2683Fabrice Di Meglio final ComponentName cn = intent.getComponent(); 4805a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio final String className = cn.getClassName(); 481da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio 4825a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio mIsShowingDashboard = className.equals(Settings.class.getName()); 4835a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio final boolean isSubSettings = className.equals(SubSettings.class.getName()); 4845a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio 4855a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio // If this is a sub settings or not the main Dashboard and not a Shortcut and not initial 4865a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio // Fragment then apply the correct theme for the ActionBar content inset 4875a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio if (isSubSettings || 4885a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio (!mIsShowingDashboard && !mIsShortcut && (initialFragmentName == null))) { 489da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio setTheme(R.style.Theme_SubSettings); 490da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio } 491da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio 492263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setContentView(R.layout.settings_main); 493263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 49459a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio mContent = (ViewGroup) findViewById(R.id.prefs); 49559a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio 496263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio getFragmentManager().addOnBackStackChangedListener(this); 497263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 49835062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio if (mIsShowingDashboard) { 499dba577f8f017baac0086c185579340db1c9281d9Fabrice Di Meglio Index.getInstance(getApplicationContext()).update(); 5005cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio } 5015cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio 502d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (savedState != null) { 5031800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio // We are restarting from a previous saved state; used that to initialize, instead 5041800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio // of starting fresh. 505d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED); 506d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY); 507263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 5080d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio setTitleFromIntent(intent); 5095529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio 510769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio ArrayList<DashboardCategory> categories = 511769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); 512769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio if (categories != null) { 5135f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio mCategories.clear(); 514769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio mCategories.addAll(categories); 515b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio setTitleFromBackStack(); 516263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 517b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio 518b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); 5193d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH); 520263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 52135062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio if (!mIsShowingDashboard) { 5220d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio // Search is shown we are launched thru a Settings "shortcut". UP will be shown 5230d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio // only if it is a sub settings 5240d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio if (mIsShortcut) { 5250d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio mDisplayHomeAsUpEnabled = isSubSettings; 5263d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio mDisplaySearch = false; 5275a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio } else if (isSubSettings) { 5285a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio mDisplayHomeAsUpEnabled = true; 5295a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio mDisplaySearch = true; 530d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 5310d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio setTitleFromIntent(intent); 532c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio 5330d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); 534a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio switchToFragment(initialFragmentName, initialArguments, true, false, 535a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitleResId, mInitialTitle, false); 53610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } else { 5375a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio // No UP affordance if we are displaying the main Dashboard 538b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio mDisplayHomeAsUpEnabled = false; 5395a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio // Show Search affordance 5405a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio mDisplaySearch = true; 541a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitleResId = R.string.dashboard_title; 54242c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio switchToFragment(DashboardSummary.class.getName(), null, false, false, 543a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitleResId, mInitialTitle, false); 544263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 545263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 546263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 547d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mActionBar = getActionBar(); 548d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio if (mActionBar != null) { 549d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); 550d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); 551d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio } 55241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar); 55341937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio 554263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // see if we should show Back/Next buttons 555263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) { 556263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 557d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio View buttonBar = findViewById(R.id.button_bar); 558263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (buttonBar != null) { 559263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio buttonBar.setVisibility(View.VISIBLE); 560263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 561d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio Button backButton = (Button)findViewById(R.id.back_button); 562263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio backButton.setOnClickListener(new OnClickListener() { 563263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onClick(View v) { 564263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setResult(RESULT_CANCELED); 565263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio finish(); 566263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 567263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 568d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio Button skipButton = (Button)findViewById(R.id.skip_button); 569263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio skipButton.setOnClickListener(new OnClickListener() { 570263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onClick(View v) { 571263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setResult(RESULT_OK); 572263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio finish(); 573263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 574263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 575d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio mNextButton = (Button)findViewById(R.id.next_button); 576263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mNextButton.setOnClickListener(new OnClickListener() { 577263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onClick(View v) { 578263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setResult(RESULT_OK); 579263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio finish(); 580263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 581263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 582263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 583263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // set our various button parameters 584263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) { 585263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT); 586263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (TextUtils.isEmpty(buttonText)) { 587263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mNextButton.setVisibility(View.GONE); 588263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 589263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio else { 590263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mNextButton.setText(buttonText); 591263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 592263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 593263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) { 594263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT); 595263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (TextUtils.isEmpty(buttonText)) { 596263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio backButton.setVisibility(View.GONE); 597263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 598263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio else { 599263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio backButton.setText(buttonText); 600263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 601263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 602263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) { 603263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio skipButton.setVisibility(View.VISIBLE); 604263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 605263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 606263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 607c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio } 608c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio 609a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio private void setTitleFromIntent(Intent intent) { 610a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1); 611a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio if (initialTitleResId > 0) { 612a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitle = null; 613a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitleResId = initialTitleResId; 614a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio setTitle(mInitialTitleResId); 615a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } else { 616a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitleResId = -1; 617a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); 618a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitle = (initialTitle != null) ? initialTitle : getTitle(); 619a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio setTitle(mInitialTitle); 620a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } 621a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } 622a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio 623c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio @Override 624263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onBackStackChanged() { 625d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio setTitleFromBackStack(); 6268eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio } 6278eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio 628b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio private int setTitleFromBackStack() { 6298eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio final int count = getFragmentManager().getBackStackEntryCount(); 630b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio 6318eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (count == 0) { 632a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio if (mInitialTitleResId > 0) { 633a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio setTitle(mInitialTitleResId); 634a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } else { 635a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio setTitle(mInitialTitle); 636a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } 637b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio return 0; 638263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 639b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio 6408eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1); 6418eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio setTitleFromBackStackEntry(bse); 642b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio 643b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio return count; 644263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 645263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 6468eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) { 6475529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio final CharSequence title; 6488eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio final int titleRes = bse.getBreadCrumbTitleRes(); 6498eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (titleRes > 0) { 6508eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio title = getText(titleRes); 6515529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio } else { 6528eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio title = bse.getBreadCrumbTitle(); 6538eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio } 6548eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (title != null) { 6558eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio setTitle(title); 6565529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio } 6575529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio } 6585529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio 659263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 660263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected void onSaveInstanceState(Bundle outState) { 661263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onSaveInstanceState(outState); 662263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 663769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio if (mCategories.size() > 0) { 664769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories); 665263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 666d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio 667b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled); 6683d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch); 6693d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio 6703d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio if (mDisplaySearch) { 6713d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // The option menus are created if the ActionBar is visible and they are also created 6723d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // asynchronously. If you launch Settings with an Intent action like 6733d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked 6743d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search 6753d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // menu item and search view are null. 6763d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded(); 6773d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded); 6783d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio 6793d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY; 6803d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio outState.putString(SAVE_KEY_SEARCH_QUERY, query); 6813d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio } 682263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 683263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 684263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 685263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onResume() { 686263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onResume(); 687263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 688263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { 689263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 690263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { 691bb05178dba21509d5b26ae0bd718a471b8c6cd5eFabrice Di Meglio setNeedToRebuildCategories(true); 692769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio invalidateCategories(); 693263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 694263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 695263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferences.registerOnSharedPreferenceChangeListener( 696263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferencesListener); 697263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 698263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); 699853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav 700990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav mDynamicIndexableContentMonitor.register(this); 701a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio 7023d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) { 703a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio onQueryTextSubmit(mSearchQuery); 704a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio } 705263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 706263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 707263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 708263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onPause() { 709263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onPause(); 710263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 711263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio unregisterReceiver(mBatteryInfoReceiver); 712263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 713990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav mDynamicIndexableContentMonitor.unregister(); 714263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 715263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 716263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 717263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onDestroy() { 718263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onDestroy(); 719680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio 720680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener( 721680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio mDevelopmentPreferencesListener); 722680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio mDevelopmentPreferencesListener = null; 723263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 724263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 725263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected boolean isValidFragment(String fragmentName) { 726263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Almost all fragments are wrapped in this, 727263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // except for a few that have their own activities. 728263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) { 729263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true; 730263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 731263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return false; 732263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 733263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 734263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 735263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Intent getIntent() { 736263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Intent superIntent = super.getIntent(); 737263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String startingFragment = getStartingFragmentClass(superIntent); 738263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // This is called from super.onCreate, isMultiPane() is not yet reliable 739263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Do not use onIsHidingHeaders either, which relies itself on this method 740263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (startingFragment != null) { 741263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Intent modIntent = new Intent(superIntent); 742263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); 743263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Bundle args = superIntent.getExtras(); 744263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (args != null) { 745263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio args = new Bundle(args); 746263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 747263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio args = new Bundle(); 748263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 749263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio args.putParcelable("intent", superIntent); 750ac1e20ebfc233a4894fa04a29b5d86602ee188eeKenny Guy modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); 751263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return modIntent; 752263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 753263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return superIntent; 754263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 755263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 756263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 757263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Checks if the component name in the intent is different from the Settings class and 758263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * returns the class name to load as a fragment. 759263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 760263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private String getStartingFragmentClass(Intent intent) { 761263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mFragmentClass != null) return mFragmentClass; 762263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 763263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String intentClass = intent.getComponent().getClassName(); 764263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intentClass.equals(getClass().getName())) return null; 765263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 766263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if ("com.android.settings.ManageApplications".equals(intentClass) 767263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio || "com.android.settings.RunningServices".equals(intentClass) 768263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio || "com.android.settings.applications.StorageUse".equals(intentClass)) { 769263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Old names of manage apps. 770263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio intentClass = com.android.settings.applications.ManageApplications.class.getName(); 771263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 772263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 773263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return intentClass; 774263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 775263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 776263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 77710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * Start a new fragment containing a preference panel. If the preferences 77810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * are being displayed in multi-pane mode, the given fragment class will 77910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * be instantiated and placed in the appropriate pane. If running in 78010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * single-pane mode, a new activity will be launched in which to show the 78110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * fragment. 78210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * 78310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param fragmentClass Full name of the class implementing the fragment. 78410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param args Any desired arguments to supply to the fragment. 78510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param titleRes Optional resource identifier of the title of this 78610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * fragment. 78710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param titleText Optional text of the title of this fragment. 78810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param resultTo Optional fragment that result data should be sent to. 78910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * If non-null, resultTo.onActivityResult() will be called when this 79010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * preference panel is done. The launched panel must use 79110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * {@link #finishPreferencePanel(Fragment, int, Intent)} when done. 79210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param resultRequestCode If resultTo is non-null, this is the caller's 79358146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio * request code to be received with the result. 79410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio */ 79510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes, 796d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio CharSequence titleText, Fragment resultTo, int resultRequestCode) { 797a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio String title = null; 798a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio if (titleRes < 0) { 799a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio if (titleText != null) { 800a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio title = titleText.toString(); 801a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } else { 802a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio // There not much we can do in that case 803a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio title = ""; 804a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } 805911fb2ad907d47a882c023b871c6457db32359f8Fabrice Di Meglio } 806a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode, 8070d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio titleRes, title, mIsShortcut); 80810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 80910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio 81010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio /** 811263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Called by a preference panel fragment to finish itself. 812263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * 813263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param caller The fragment that is asking to be finished. 814263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param resultCode Optional result code to send back to the original 815263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * launching fragment. 816263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param resultData Optional result data to send back to the original 817263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * launching fragment. 818263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 819263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) { 820263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setResult(resultCode, resultData); 82158146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio finish(); 822263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 823263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 824263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 82510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * Start a new fragment. 82610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * 82710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param fragment The fragment to start 82810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param push If true, the current fragment will be pushed onto the back stack. If false, 82910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * the current fragment will be replaced. 83010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio */ 83110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio public void startPreferenceFragment(Fragment fragment, boolean push) { 83210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio FragmentTransaction transaction = getFragmentManager().beginTransaction(); 83310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.replace(R.id.prefs, fragment); 83410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio if (push) { 83510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 83610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.addToBackStack(BACK_STACK_PREFS); 83710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } else { 83810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 83910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 84010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.commitAllowingStateLoss(); 84110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 84210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio 84310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio /** 844d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio * Switch to a specific Fragment with taking care of validation, Title and BackStack 845d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio */ 846d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate, 847a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) { 848d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (validate && !isValidFragment(fragmentName)) { 849d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio throw new IllegalArgumentException("Invalid fragment for this activity: " 850d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio + fragmentName); 851d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 852d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio Fragment f = Fragment.instantiate(this, fragmentName, args); 853d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio FragmentTransaction transaction = getFragmentManager().beginTransaction(); 854d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio transaction.replace(R.id.prefs, f); 855d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (withTransition) { 85659a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio TransitionManager.beginDelayedTransition(mContent); 857d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 858d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (addToBackStack) { 859d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS); 860d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 861a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio if (titleResId > 0) { 862a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio transaction.setBreadCrumbTitle(titleResId); 863a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } else if (title != null) { 864d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio transaction.setBreadCrumbTitle(title); 865d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 866d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio transaction.commitAllowingStateLoss(); 86759a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio getFragmentManager().executePendingTransactions(); 868d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return f; 869d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 870d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 871769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio public void setNeedToRebuildCategories(boolean need) { 872769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio mNeedToRebuildCategories = need; 873263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 874263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 87563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio /** 876769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio * Called when the activity needs its list of categories/tiles built. 87763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * 87863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * @param categories The list in which to place the tiles categories. 87963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio */ 880769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private void buildDashboardCategories(List<DashboardCategory> categories) { 8815f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio categories.clear(); 88263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio loadCategoriesFromResource(R.xml.dashboard_categories, categories); 88363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio updateTilesList(categories); 88463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 88563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 88663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio /** 88763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * Parse the given XML file as a categories description, adding each 88863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * parsed categories and tiles into the target list. 88963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * 89063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * @param resid The XML resource to load and parse. 89163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * @param target The list in which the parsed categories and tiles should be placed. 89263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio */ 89363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) { 89463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlResourceParser parser = null; 89563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio try { 89663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio parser = getResources().getXml(resid); 89763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio AttributeSet attrs = Xml.asAttributeSet(parser); 89863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 89963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio int type; 90063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 90163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio && type != XmlPullParser.START_TAG) { 90263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Parse next until start tag is found 90363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 90463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 90563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio String nodeName = parser.getName(); 90663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!"dashboard-categories".equals(nodeName)) { 90763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio throw new RuntimeException( 90863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio "XML document must start with <preference-categories> tag; found" 90963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio + nodeName + " at " + parser.getPositionDescription()); 91063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 91163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 91263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio Bundle curBundle = null; 91363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 91463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final int outerDepth = parser.getDepth(); 91563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 91663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { 91763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 91863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio continue; 91963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 92063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 92163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio nodeName = parser.getName(); 92263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if ("dashboard-category".equals(nodeName)) { 92363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DashboardCategory category = new DashboardCategory(); 92463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 92563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio TypedArray sa = obtainStyledAttributes( 92663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio attrs, com.android.internal.R.styleable.PreferenceHeader); 92763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.id = sa.getResourceId( 92863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_id, 92963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio (int)DashboardCategory.CAT_ID_UNDEFINED); 93063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 93163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio TypedValue tv = sa.peekValue( 93263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_title); 93363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv != null && tv.type == TypedValue.TYPE_STRING) { 93463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv.resourceId != 0) { 93563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.titleRes = tv.resourceId; 93663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 93763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.title = tv.string; 93863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 93963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 94063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sa.recycle(); 94163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 94263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final int innerDepth = parser.getDepth(); 94363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 94463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { 94563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 94663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio continue; 94763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 94863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 94963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio String innerNodeName = parser.getName(); 95063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (innerNodeName.equals("dashboard-tile")) { 95163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DashboardTile tile = new DashboardTile(); 95263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 95363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sa = obtainStyledAttributes( 95463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio attrs, com.android.internal.R.styleable.PreferenceHeader); 95563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.id = sa.getResourceId( 95663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_id, 957e9326d276135b657738d851e0a56df447f09567aFabrice Di Meglio (int)TILE_ID_UNDEFINED); 95863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tv = sa.peekValue( 95963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_title); 96063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv != null && tv.type == TypedValue.TYPE_STRING) { 96163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv.resourceId != 0) { 96263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.titleRes = tv.resourceId; 96363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 96463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.title = tv.string; 96563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 96663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 96763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tv = sa.peekValue( 96863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_summary); 96963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv != null && tv.type == TypedValue.TYPE_STRING) { 97063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv.resourceId != 0) { 97163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.summaryRes = tv.resourceId; 97263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 97363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.summary = tv.string; 97463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 97563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 97663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.iconRes = sa.getResourceId( 97763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_icon, 0); 97863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.fragment = sa.getString( 97963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_fragment); 98063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sa.recycle(); 98163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 98263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (curBundle == null) { 98363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio curBundle = new Bundle(); 98463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 98563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 98663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final int innerDepth2 = parser.getDepth(); 98763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 98863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) { 98963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 99063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio continue; 99163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 99263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 99363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio String innerNodeName2 = parser.getName(); 99463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (innerNodeName2.equals("extra")) { 99563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio getResources().parseBundleExtra("extra", attrs, curBundle); 99663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlUtils.skipCurrentTag(parser); 99763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 99863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (innerNodeName2.equals("intent")) { 99963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.intent = Intent.parseIntent(getResources(), parser, attrs); 100063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 100163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 100263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlUtils.skipCurrentTag(parser); 100363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 100463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 100563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 100663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (curBundle.size() > 0) { 100763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.fragmentArguments = curBundle; 100863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio curBundle = null; 100963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 101063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 101163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.addTile(tile); 101263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 101363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 101463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlUtils.skipCurrentTag(parser); 101563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 101663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 101763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 101863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio target.add(category); 101963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 102063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlUtils.skipCurrentTag(parser); 102163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 102263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 102363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 102463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } catch (XmlPullParserException e) { 102563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio throw new RuntimeException("Error parsing categories", e); 102663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } catch (IOException e) { 102763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio throw new RuntimeException("Error parsing categories", e); 102863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } finally { 102963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (parser != null) parser.close(); 103063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 103163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 103263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 103363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio private void updateTilesList(List<DashboardCategory> target) { 103463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final boolean showDev = mDevelopmentPreferences.getBoolean( 103563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DevelopmentSettings.PREF_SHOW, 103663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio android.os.Build.TYPE.equals("eng")); 103763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 103863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); 103963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 104063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final int size = target.size(); 104163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio for (int i = 0; i < size; i++) { 104263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 104363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DashboardCategory category = target.get(i); 104463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 104563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Ids are integers, so downcasting is ok 104663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio int id = (int) category.id; 104763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio int n = category.getTilesCount() - 1; 104863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while (n >= 0) { 104963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 105063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DashboardTile tile = category.getTile(n); 105163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 105263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio id = (int) tile.id; 105363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (id == R.id.operator_settings || id == R.id.manufacturer_settings) { 105463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, category, tile); 105563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.wifi_settings) { 105663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Remove WiFi Settings if WiFi service is not available. 105763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) { 105863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 105963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 106063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.bluetooth_settings) { 106163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Remove Bluetooth Settings if Bluetooth service is not available. 106263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) { 106363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 106463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 106563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.data_usage_settings) { 106663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Remove data usage when kernel module not enabled 106763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final INetworkManagementService netManager = INetworkManagementService.Stub 106863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)); 106963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio try { 107063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!netManager.isBandwidthControlEnabled()) { 107163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 107263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 107363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } catch (RemoteException e) { 107463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // ignored 107563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 107663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.battery_settings) { 107763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Remove battery settings when battery is not available. (e.g. TV) 107863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 107963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!mBatteryPresent) { 108063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 108163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 108263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.home_settings) { 108363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!updateHomeSettingTiles(tile)) { 108463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 108563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 108663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.user_settings) { 10874093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani boolean hasMultipleUsers = 10884093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani ((UserManager) getSystemService(Context.USER_SERVICE)) 10894093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani .getUserCount() > 1; 109063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!UserHandle.MU_ENABLED 10914093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani || (!UserManager.supportsMultipleUsers() 10924093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani && !hasMultipleUsers) 109363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio || Utils.isMonkeyRunning()) { 109463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 109563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 109663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.nfc_payment_settings) { 109763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) { 109863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 109963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 110063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Only show if NFC is on and we have the HCE feature 110163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); 110263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!adapter.isEnabled() || !getPackageManager().hasSystemFeature( 110363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) { 110463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 110563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 110663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 1107488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio } else if (id == R.id.print_settings) { 1108488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio boolean hasPrintingSupport = getPackageManager().hasSystemFeature( 1109488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio PackageManager.FEATURE_PRINTING); 1110488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio if (!hasPrintingSupport) { 1111488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio category.removeTile(n); 1112488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio } 111363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.development_settings) { 11146c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds if (!showDev || um.hasUserRestriction( 11156c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds UserManager.DISALLOW_DEBUGGING_FEATURES)) { 111663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 111763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 111863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 111963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 112063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0 1121a97089d389338ca8e3d970b00dd13ffad732b5c1Amith Yamasani && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id) 1122a97089d389338ca8e3d970b00dd13ffad732b5c1Amith Yamasani && n < category.getTilesCount()) { 112363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 112463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 112563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 112663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio n--; 112763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 112863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 112963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 113063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 113163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio private boolean updateHomeSettingTiles(DashboardTile tile) { 113263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Once we decide to show Home settings, keep showing it forever 113363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE); 113463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) { 113563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio return true; 113663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 113763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 113863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio try { 113963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>(); 114063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio getPackageManager().getHomeActivities(homeApps); 114163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (homeApps.size() < 2) { 114263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // When there's only one available home app, omit this settings 114363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // category entirely at the top level UI. If the user just 114463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // uninstalled the penultimate home app candidiate, we also 114563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // now tell them about why they aren't seeing 'Home' in the list. 114663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (sShowNoHomeNotice) { 114763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sShowNoHomeNotice = false; 114863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio NoHomeDialogFragment.show(this); 114963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 115063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio return false; 115163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 115263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Okay, we're allowing the Home settings category. Tell it, when 115363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // invoked via this front door, that we'll need to be told about the 115463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // case when the user uninstalls all but one home app. 115563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tile.fragmentArguments == null) { 115663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.fragmentArguments = new Bundle(); 115763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 115863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true); 115963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 116063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } catch (Exception e) { 116163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Can't look up the home activity; bail on configuring the icon 116263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio Log.w(LOG_TAG, "Problem looking up home activity!", e); 116363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 116463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 116563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply(); 116663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio return true; 116763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 116863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 1169263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private void getMetaData() { 1170263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio try { 1171263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), 1172263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PackageManager.GET_META_DATA); 1173263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (ai == null || ai.metaData == null) return; 1174263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); 1175263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } catch (NameNotFoundException nnfe) { 1176263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // No recovery 1177263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString()); 1178263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1179263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1180263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1181263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // give subclasses access to the Next button 1182263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean hasNextButton() { 1183263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return mNextButton != null; 1184263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1185263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1186263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Button getNextButton() { 1187263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return mNextButton; 1188263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1189263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1190263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1191263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean shouldUpRecreateTask(Intent targetIntent) { 1192263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class)); 1193263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1194263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1195263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static void requestHomeNotice() { 1196263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio sShowNoHomeNotice = true; 1197263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1198263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1199d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1200d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onQueryTextSubmit(String query) { 1201d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio switchToSearchResultsFragmentIfNeeded(); 1202d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchQuery = query; 1203d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return mSearchResultsFragment.onQueryTextSubmit(query); 1204d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1205263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1206d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1207d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onQueryTextChange(String newText) { 1208d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchQuery = newText; 12097e4855e8f644bdecf68ec65b8c1b7c08624a4876Fabrice Di Meglio if (mSearchResultsFragment == null) { 1210a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio return false; 1211a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio } 1212a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio return mSearchResultsFragment.onQueryTextChange(newText); 1213d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1214263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1215d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1216d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onClose() { 1217d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return false; 1218d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1219263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1220d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1221d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onMenuItemActionExpand(MenuItem item) { 1222d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (item.getItemId() == mSearchMenuItem.getItemId()) { 1223bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio switchToSearchResultsFragmentIfNeeded(); 1224263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1225d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return true; 1226d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1227263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1228d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1229d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onMenuItemActionCollapse(MenuItem item) { 1230d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (item.getItemId() == mSearchMenuItem.getItemId()) { 1231bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio if (mSearchMenuItemExpanded) { 1232d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio revertToInitialFragment(); 1233263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1234263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1235d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return true; 1236d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1237263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1238d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private void switchToSearchResultsFragmentIfNeeded() { 1239bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio if (mSearchResultsFragment != null) { 1240bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio return; 1241263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1242bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio Fragment current = getFragmentManager().findFragmentById(R.id.prefs); 1243bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio if (current != null && current instanceof SearchResultsSummary) { 1244bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio mSearchResultsFragment = (SearchResultsSummary) current; 1245bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio } else { 1246bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio mSearchResultsFragment = (SearchResultsSummary) switchToFragment( 1247a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio SearchResultsSummary.class.getName(), null, false, true, 1248a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio R.string.search_results_title, null, true); 1249bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio } 1250d297a5840230b769a3c7ad8b85232968a7077f64Fabrice Di Meglio mSearchResultsFragment.setSearchView(mSearchView); 1251bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio mSearchMenuItemExpanded = true; 1252d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1253263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1254d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public void needToRevertToInitialFragment() { 1255d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mNeedToRevertToInitialFragment = true; 1256d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1257263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1258d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private void revertToInitialFragment() { 1259d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mNeedToRevertToInitialFragment = false; 1260d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchResultsFragment = null; 1261bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio mSearchMenuItemExpanded = false; 1262bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS, 1263bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio FragmentManager.POP_BACK_STACK_INCLUSIVE); 126423ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio if (mSearchMenuItem != null) { 126523ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio mSearchMenuItem.collapseActionView(); 126623ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio } 1267263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1268263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio} 1269