SettingsActivity.java revision d033285ca7789b464f15cde149bef7df3ad2e1a3
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 192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED; 202ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk 21263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.ActionBar; 22263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Activity; 23263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Fragment; 24263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentManager; 25263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentTransaction; 26263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.BroadcastReceiver; 27d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.content.ComponentName; 28263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Context; 29263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Intent; 30263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.IntentFilter; 31263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.SharedPreferences; 32263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ActivityInfo; 33263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager; 34263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager.NameNotFoundException; 35263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ResolveInfo; 36263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.Configuration; 37263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.TypedArray; 38263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.XmlResourceParser; 39263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.nfc.NfcAdapter; 40263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Bundle; 41263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Handler; 42263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.INetworkManagementService; 43263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Message; 44263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.RemoteException; 45263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.ServiceManager; 46263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserHandle; 47263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserManager; 48263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.Preference; 49263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceFragment; 50263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceManager; 51263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceScreen; 52263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.text.TextUtils; 5359a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.transition.TransitionManager; 542ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport android.util.ArrayMap; 55263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.AttributeSet; 56263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Log; 572ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport android.util.Pair; 58263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.TypedValue; 59263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Xml; 60d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.Menu; 61d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.MenuInflater; 62263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.MenuItem; 63263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View; 64263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View.OnClickListener; 6559a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.view.ViewGroup; 66263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.Button; 67d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.widget.SearchView; 68c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock 69263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.ArrayUtils; 70263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.XmlUtils; 71263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.AccessibilitySettings; 72263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.CaptionPropertiesFragment; 736d839875b74f1570e8807005c586298beb677413Alexandra Gherghinaimport com.android.settings.accounts.AccountSettings; 74263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.AccountSyncSettings; 75d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.applications.InstalledAppDetails; 76263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ManageApplications; 77263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ProcessStatsUi; 78263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.bluetooth.BluetoothSettings; 7963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglioimport com.android.settings.dashboard.DashboardCategory; 80263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.dashboard.DashboardSummary; 8163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglioimport com.android.settings.dashboard.DashboardTile; 82d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.NoHomeDialogFragment; 83d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport com.android.settings.dashboard.SearchResultsSummary; 84263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.deviceinfo.Memory; 85263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.deviceinfo.UsbSettings; 86c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlockimport com.android.settings.fuelgauge.BatterySaverSettings; 87263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.fuelgauge.PowerUsageSummary; 88263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.InputMethodAndLanguageSettings; 89263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.KeyboardLayoutPickerFragment; 90263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.SpellCheckersSettings; 91263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.UserDictionaryList; 92263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.location.LocationSettings; 93263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.AndroidBeam; 94263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.PaymentSettings; 95802ddf99f57e316d0fd87c2cfeed5dc3a0cfa8feJohn Spurlockimport com.android.settings.notification.AppNotificationSettings; 96c9afadb04b00598f5988101681089290cf14f79cJohn Spurlockimport com.android.settings.notification.ConditionProviderSettings; 974a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationAccessSettings; 984a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationSettings; 994a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.NotificationStation; 1002ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.notification.OtherSoundSettings; 1014a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.ZenModeSettings; 102263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintJobSettingsFragment; 103263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintSettingsFragment; 1042ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.search.DynamicIndexableContentMonitor; 1052ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport com.android.settings.search.Index; 1063815561997eced7fd773062ce32eaa50bece072cPauloftheWestimport com.android.settings.sim.SimSettings; 107263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.tts.TextToSpeechSettings; 108263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.users.UserSettings; 109b51253cfed0796b20e03a104aaca4d8d3e2d3024Dianne Hackbornimport com.android.settings.voice.VoiceInputSettings; 110263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.vpn2.VpnSettings; 111263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wfd.WifiDisplaySettings; 11241937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport com.android.settings.widget.SwitchBar; 113263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.AdvancedWifiSettings; 1147837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWestimport com.android.settings.wifi.SavedAccessPointsWifiSettings; 115263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.WifiSettings; 116263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.p2p.WifiP2pSettings; 1172ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk 118263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParser; 119263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParserException; 120263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 121263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.io.IOException; 122263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.ArrayList; 123263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.List; 1242ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monkimport java.util.Map; 1250d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglioimport java.util.Set; 126263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 127263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Megliopublic class SettingsActivity extends Activity 128263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio implements PreferenceManager.OnPreferenceTreeClickListener, 129263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PreferenceFragment.OnPreferenceStartFragmentCallback, 130cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina ButtonBarHandler, FragmentManager.OnBackStackChangedListener, 131d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio SearchView.OnQueryTextListener, SearchView.OnCloseListener, 132cfc7f9d9600f7b4514ce9608314874bf1023eb21Alexandra Gherghina MenuItem.OnActionExpandListener { 133263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 134263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String LOG_TAG = "Settings"; 135263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 136263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Constants for state save/restore 137769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private static final String SAVE_KEY_CATEGORIES = ":settings:categories"; 138d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded"; 139d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query"; 140b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up"; 1413d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search"; 142ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count"; 143263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 144263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 145263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * When starting this activity, the invoking Intent can contain this extra 146263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * string to specify which fragment should be initially displayed. 147263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity 148263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * will call isValidFragment() to confirm that the fragment class name is valid for this 149263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * activity. 150263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 151263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment"; 152263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 153263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 154263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, 155263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * this extra can also be specified to supply a Bundle of arguments to pass 156263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * to that fragment when it is instantiated during the initial creation 157263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * of the activity. 158263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 159263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args"; 160263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 161263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 162c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS} 163c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio */ 164c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"; 165c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio 1666f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio public static final String BACK_STACK_PREFS = ":settings:prefs"; 1676f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio 168263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // extras that allow any preference activity to be launched as part of a wizard 169263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 170263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // show Back and Next buttons? takes boolean parameter 171263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Back will then return RESULT_CANCELED and Next RESULT_OK 172263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; 173263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 174263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // add a Skip button? 175263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip"; 176263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 177263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // specify custom text for the Back or Next buttons, or cause a button to not appear 178263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // at all by setting it to null 179263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text"; 180263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text"; 181263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 182263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 183263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, 184a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio * those extra can also be specify to supply the title or title res id to be shown for 185263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * that fragment. 186263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 187d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title"; 18862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina /** 18962464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina * The package name used to resolve the title resource id. 19062464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina */ 19162464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME = 19262464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina ":settings:show_fragment_title_res_package_name"; 19361a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = 19461a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio ":settings:show_fragment_title_resid"; 19561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT = 19661a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio ":settings:show_fragment_as_shortcut"; 19761a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio 19861a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING = 19961a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio ":settings:show_fragment_as_subsetting"; 200263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 201263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String META_DATA_KEY_FRAGMENT_CLASS = 202263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio "com.android.settings.FRAGMENT_CLASS"; 203263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 204263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String EXTRA_UI_OPTIONS = "settings:ui_options"; 205263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 206d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio private static final String EMPTY_QUERY = ""; 207d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio 2082ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk /** 2092ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * Settings will search for system activities of this action and add them as a top level 2102ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * settings tile using the following parameters. 2112ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * 2122ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * <p>A category must be specified in the meta-data for the activity named 2132ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * {@link #EXTRA_CATEGORY_KEY} 2142ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * 2152ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * <p>The title may be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_TITLE} 2162ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * otherwise the label for the activity will be used. 2172ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * 2182ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * <p>The icon may be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_ICON} 2192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * otherwise the icon for the activity will be used. 2202ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * 2212ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * <p>A summary my be defined by meta-data named {@link Utils#META_DATA_PREFERENCE_SUMMARY} 2222ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk */ 2232ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk private static final String EXTRA_SETTINGS_ACTION = 2242ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk "com.android.settings.action.EXTRA_SETTINGS"; 2252ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk 2262ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk /** 2272ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * The key used to get the category from metadata of activities of action 2282ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * {@link #EXTRA_SETTINGS_ACTION} 2292ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * The value must be one of: 2302ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * <li>com.android.settings.category.wireless</li> 2312ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * <li>com.android.settings.category.device</li> 2322ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * <li>com.android.settings.category.personal</li> 2332ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk * <li>com.android.settings.category.system</li> 2342ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk */ 2352ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk private static final String EXTRA_CATEGORY_KEY = "com.android.settings.category"; 2362ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk 237263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static boolean sShowNoHomeNotice = false; 238263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 239263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private String mFragmentClass; 240263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 2418eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio private CharSequence mInitialTitle; 242a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio private int mInitialTitleResId; 2438eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio 244263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Show only these settings for restricted users 245263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private int[] SETTINGS_FOR_RESTRICTED = { 246263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.wireless_section, 247263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.wifi_settings, 248263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.bluetooth_settings, 249263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.data_usage_settings, 2503815561997eced7fd773062ce32eaa50bece072cPauloftheWest R.id.sim_settings, 251263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.wireless_settings, 252263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.device_section, 2534e4cdeffdb6087c953f44808f14f18554a749bdaJohn Spurlock R.id.notification_settings, 254263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.display_settings, 255263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.storage_settings, 256263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.application_settings, 257263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.battery_settings, 258263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.personal_section, 259263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.location_settings, 260263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.security_settings, 261263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.language_settings, 262263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.user_settings, 263263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.account_settings, 264263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.system_section, 265263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.date_time_settings, 266263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.about_settings, 267263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.accessibility_settings, 268263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.print_settings, 269263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.nfc_payment_settings, 2702858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio R.id.home_settings, 2712858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio R.id.dashboard 272263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 273263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 274263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String[] ENTRY_FRAGMENTS = { 275263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WirelessSettings.class.getName(), 276263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WifiSettings.class.getName(), 277263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AdvancedWifiSettings.class.getName(), 2787837b999862cf341b0f124be7ace1dfc64d0a5a8PauloftheWest SavedAccessPointsWifiSettings.class.getName(), 279263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio BluetoothSettings.class.getName(), 2803815561997eced7fd773062ce32eaa50bece072cPauloftheWest SimSettings.class.getName(), 281263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TetherSettings.class.getName(), 282263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WifiP2pSettings.class.getName(), 283263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio VpnSettings.class.getName(), 284263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DateTimeSettings.class.getName(), 285263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio LocalePicker.class.getName(), 286263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio InputMethodAndLanguageSettings.class.getName(), 287b51253cfed0796b20e03a104aaca4d8d3e2d3024Dianne Hackborn VoiceInputSettings.class.getName(), 288263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio SpellCheckersSettings.class.getName(), 289263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UserDictionaryList.class.getName(), 290263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UserDictionarySettings.class.getName(), 2913033ce0723103b55b1b5a53145c05e143b5bbfd6Amith Yamasani HomeSettings.class.getName(), 292263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DisplaySettings.class.getName(), 293263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DeviceInfoSettings.class.getName(), 294263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ManageApplications.class.getName(), 295263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ProcessStatsUi.class.getName(), 296263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio NotificationStation.class.getName(), 297263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio LocationSettings.class.getName(), 298263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio SecuritySettings.class.getName(), 299b51253cfed0796b20e03a104aaca4d8d3e2d3024Dianne Hackborn UsageAccessSettings.class.getName(), 300263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PrivacySettings.class.getName(), 301263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DeviceAdminSettings.class.getName(), 302263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AccessibilitySettings.class.getName(), 303263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio CaptionPropertiesFragment.class.getName(), 304263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(), 305263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TextToSpeechSettings.class.getName(), 306263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Memory.class.getName(), 307263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DevelopmentSettings.class.getName(), 308263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UsbSettings.class.getName(), 309263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AndroidBeam.class.getName(), 310263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WifiDisplaySettings.class.getName(), 311263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PowerUsageSummary.class.getName(), 312263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AccountSyncSettings.class.getName(), 3136d839875b74f1570e8807005c586298beb677413Alexandra Gherghina AccountSettings.class.getName(), 314263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio CryptKeeperSettings.class.getName(), 315263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DataUsageSummary.class.getName(), 316263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DreamSettings.class.getName(), 317263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UserSettings.class.getName(), 318263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio NotificationAccessSettings.class.getName(), 319c9afadb04b00598f5988101681089290cf14f79cJohn Spurlock ConditionProviderSettings.class.getName(), 320263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PrintSettingsFragment.class.getName(), 321263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PrintJobSettingsFragment.class.getName(), 322263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TrustedCredentialsSettings.class.getName(), 323263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PaymentSettings.class.getName(), 324263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio KeyboardLayoutPickerFragment.class.getName(), 325d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio ZenModeSettings.class.getName(), 326d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio NotificationSettings.class.getName(), 327d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio ChooseLockPassword.ChooseLockPasswordFragment.class.getName(), 328d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio ChooseLockPattern.ChooseLockPatternFragment.class.getName(), 329c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock InstalledAppDetails.class.getName(), 330c7f8e8ce69e80ea495472aade5f8569c6583c5e8John Spurlock BatterySaverSettings.class.getName(), 331dcf59dd82ca5a5b211461f1c2825623325c3811cFabrice Di Meglio AppNotificationSettings.class.getName(), 332e3ff4d8e92a19473c622c1d46b30c63bf2d001d0Fabrice Di Meglio OtherSoundSettings.class.getName(), 33333acb15e032ac65d743b708731004b9a5f7813d5Narayan Kamath ApnSettings.class.getName(), 3344ab32563f1cd7d018ee7cdaec8d5a527964a05b9Pavel Zhamaitsiak WifiCallingSettings.class.getName() 335263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 336263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 3375a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio 3385a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = { 3395a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio "android.settings.APPLICATION_DETAILS_SETTINGS" 3405a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio }; 3415a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio 342263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private SharedPreferences mDevelopmentPreferences; 343263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener; 344263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 345263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private boolean mBatteryPresent = true; 346263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() { 347263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 348263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onReceive(Context context, Intent intent) { 349263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String action = intent.getAction(); 350263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { 351263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio boolean batteryPresent = Utils.isBatteryPresent(intent); 352263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 353263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mBatteryPresent != batteryPresent) { 354263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mBatteryPresent = batteryPresent; 355b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio invalidateCategories(true); 356263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 357263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 358263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 359263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 360263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 361990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor = 362990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav new DynamicIndexableContentMonitor(); 363853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav 364d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private ActionBar mActionBar; 36541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio private SwitchBar mSwitchBar; 36641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio 36741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio private Button mNextButton; 3683d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio 369b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio private boolean mDisplayHomeAsUpEnabled; 3703d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio private boolean mDisplaySearch; 371d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 37235062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio private boolean mIsShowingDashboard; 3730d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio private boolean mIsShortcut; 37435062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio 37559a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio private ViewGroup mContent; 37659a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio 377d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private SearchView mSearchView; 378d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private MenuItem mSearchMenuItem; 379d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private boolean mSearchMenuItemExpanded = false; 380d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private SearchResultsSummary mSearchResultsFragment; 381d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private String mSearchQuery; 382d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 383769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio // Categories 384769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>(); 385263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 386b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh"; 387769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private static final int MSG_BUILD_CATEGORIES = 1; 388263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private Handler mHandler = new Handler() { 389263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 390263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void handleMessage(Message msg) { 391263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio switch (msg.what) { 392769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio case MSG_BUILD_CATEGORIES: { 393b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio final boolean forceRefresh = msg.getData().getBoolean(MSG_DATA_FORCE_REFRESH); 394b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio if (forceRefresh) { 39542c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio buildDashboardCategories(mCategories); 39642c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio } 397263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } break; 398263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 399263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 400263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 401263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 402d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private boolean mNeedToRevertToInitialFragment = false; 403ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio private int mHomeActivitiesCount = 1; 404d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 4050698a216311acd9ab52224602d1a75c08bf89f04Jim Miller private Intent mResultIntentData; 4060698a216311acd9ab52224602d1a75c08bf89f04Jim Miller 40741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio public SwitchBar getSwitchBar() { 40841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio return mSwitchBar; 40941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio } 41041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio 411b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio public List<DashboardCategory> getDashboardCategories(boolean forceRefresh) { 412b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio if (forceRefresh || mCategories.size() == 0) { 413769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio buildDashboardCategories(mCategories); 414769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio } 415769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio return mCategories; 416769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio } 417769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio 418263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 419263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { 420263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Override the fragment title for Wallpaper settings 421263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio int titleRes = pref.getTitleRes(); 422263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) { 423263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio titleRes = R.string.wallpaper_settings_fragment_title; 424263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName()) 425263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio && UserHandle.myUserId() != UserHandle.USER_OWNER) { 426263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (UserManager.get(this).isLinkedUser()) { 427263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio titleRes = R.string.profile_info_settings_title; 428263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 429263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio titleRes = R.string.user_info_settings_title; 430263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 431263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 432263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(), 433263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio null, 0); 434263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return true; 435263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 436263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 437263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 438263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { 439263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return false; 440263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 441263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 442b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio private void invalidateCategories(boolean forceRefresh) { 443769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) { 444b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio Message msg = new Message(); 445b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio msg.what = MSG_BUILD_CATEGORIES; 446b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio msg.getData().putBoolean(MSG_DATA_FORCE_REFRESH, forceRefresh); 447263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 448263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 449263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 450263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 451263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onConfigurationChanged(Configuration newConfig) { 452263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onConfigurationChanged(newConfig); 4536f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio Index.getInstance(this).update(); 454263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 455263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 456263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 457d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio protected void onStart() { 458d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio super.onStart(); 459d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 460d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (mNeedToRevertToInitialFragment) { 461d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio revertToInitialFragment(); 462263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 463263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 464263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 465263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 466d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onCreateOptionsMenu(Menu menu) { 4673d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio if (!mDisplaySearch) { 4683d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio return false; 4693d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio } 4703d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio 471d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio MenuInflater inflater = getMenuInflater(); 472d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio inflater.inflate(R.menu.options_menu, menu); 473d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 474d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio // Cache the search query (can be overriden by the OnQueryTextListener) 475d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio final String query = mSearchQuery; 476d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 4779593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio mSearchMenuItem = menu.findItem(R.id.search); 4789593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio mSearchView = (SearchView) mSearchMenuItem.getActionView(); 479d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 48023ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio if (mSearchMenuItem == null || mSearchView == null) { 48123ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio return false; 48223ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio } 48323ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio 4848c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio if (mSearchResultsFragment != null) { 4858c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio mSearchResultsFragment.setSearchView(mSearchView); 4868c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio } 4878c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio 4889593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio mSearchMenuItem.setOnActionExpandListener(this); 489d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchView.setOnQueryTextListener(this); 490d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchView.setOnCloseListener(this); 491d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 492d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (mSearchMenuItemExpanded) { 493d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchMenuItem.expandActionView(); 494d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 495d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchView.setQuery(query, true /* submit */); 496d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 497d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return true; 498d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 499d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 5000d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio private static boolean isShortCutIntent(final Intent intent) { 5010d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio Set<String> categories = intent.getCategories(); 5020d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio return (categories != null) && categories.contains("com.android.settings.SHORTCUT"); 5030d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio } 5040d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio 5055b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio private static boolean isLikeShortCutIntent(final Intent intent) { 5065b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio String action = intent.getAction(); 5075a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio if (action == null) { 5085a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio return false; 5095a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio } 5105a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) { 5115a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true; 5125a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio } 5135a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio return false; 5145b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio } 5155b7a100dbd9135b6b87ae4cc9ff3a5ece123bcf6Fabrice Di Meglio 516d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 517d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio protected void onCreate(Bundle savedState) { 5180d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio super.onCreate(savedState); 5190d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio 5200d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio // Should happen before any call to getIntent() 5210d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio getMetaData(); 5220d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio 5230d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio final Intent intent = getIntent(); 5240d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio if (intent.hasExtra(EXTRA_UI_OPTIONS)) { 5250d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0)); 526263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 527263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 528263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, 529263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Context.MODE_PRIVATE); 530263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 531da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio // Getting Intent properties can only be done after the super.onCreate(...) 5320d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); 5330d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio 5345b3c3c00b0a280e29f3767878913f80274bd4993Fabrice Di Meglio mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || 5350d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false); 536da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio 537e817a66e83191c0ae74acd53a538a0965eba2683Fabrice Di Meglio final ComponentName cn = intent.getComponent(); 5385a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio final String className = cn.getClassName(); 539da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio 5405a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio mIsShowingDashboard = className.equals(Settings.class.getName()); 5415a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio 54261a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio // This is a "Sub Settings" when: 54361a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio // - this is a real SubSettings 54461a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio // - or :settings:show_fragment_as_subsetting is passed to the Intent 54561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio final boolean isSubSettings = className.equals(SubSettings.class.getName()) || 54661a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false); 54761a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio 54861a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets 54961a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio if (isSubSettings) { 550712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio // Check also that we are not a Theme Dialog as we don't want to override them 551712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio final int themeResId = getThemeResId(); 552712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio if (themeResId != R.style.Theme_DialogWhenLarge && 553712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio themeResId != R.style.Theme_SubSettingsDialogWhenLarge) { 554712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio setTheme(R.style.Theme_SubSettings); 555712df6cb7050a87985ab30b8d1bad909a6bc09aaFabrice Di Meglio } 556da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio } 557da8babaedf45caf55eb77320f0c3ea873d195c4dFabrice Di Meglio 558d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio setContentView(mIsShowingDashboard ? 559d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio R.layout.settings_main_dashboard : R.layout.settings_main_prefs); 560263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 561d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio mContent = (ViewGroup) findViewById(R.id.main_content); 56259a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio 563263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio getFragmentManager().addOnBackStackChangedListener(this); 564263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 56535062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio if (mIsShowingDashboard) { 566dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio // Run the Index update only if we have some space 567dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio if (!Utils.isLowStorage(this)) { 568dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio Index.getInstance(getApplicationContext()).update(); 569dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio } else { 570dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!"); 571dff3faaf30bd6d695e4d9f632af53dbc73cf6506Fabrice Di Meglio } 5725cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio } 5735cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio 574d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (savedState != null) { 5751800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio // We are restarting from a previous saved state; used that to initialize, instead 5761800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio // of starting fresh. 577d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED); 578d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY); 579263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 5800d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio setTitleFromIntent(intent); 5815529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio 582769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio ArrayList<DashboardCategory> categories = 583769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); 584769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio if (categories != null) { 5855f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio mCategories.clear(); 586769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio mCategories.addAll(categories); 587b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio setTitleFromBackStack(); 588263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 589b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio 590b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); 5913d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH); 592ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, 593ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio 1 /* one home activity by default */); 594263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 59535062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio if (!mIsShowingDashboard) { 5960d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio // Search is shown we are launched thru a Settings "shortcut". UP will be shown 5970d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio // only if it is a sub settings 5980d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio if (mIsShortcut) { 5990d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio mDisplayHomeAsUpEnabled = isSubSettings; 6003d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio mDisplaySearch = false; 6015a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio } else if (isSubSettings) { 6025a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio mDisplayHomeAsUpEnabled = true; 6035a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio mDisplaySearch = true; 60461a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio } else { 60561a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio mDisplayHomeAsUpEnabled = false; 60661a1fec49fbfbe8bdd0137ddb06e5eacf4f8ec54Fabrice Di Meglio mDisplaySearch = false; 607d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 6080d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio setTitleFromIntent(intent); 609c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio 6100d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); 611a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio switchToFragment(initialFragmentName, initialArguments, true, false, 612a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitleResId, mInitialTitle, false); 61310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } else { 6145a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio // No UP affordance if we are displaying the main Dashboard 615b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio mDisplayHomeAsUpEnabled = false; 6165a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio // Show Search affordance 6175a62d94a2b1b5a93911e1f2cc9f3190e2f22622cFabrice Di Meglio mDisplaySearch = true; 618a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitleResId = R.string.dashboard_title; 61942c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio switchToFragment(DashboardSummary.class.getName(), null, false, false, 620a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitleResId, mInitialTitle, false); 621263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 622263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 623263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 624d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mActionBar = getActionBar(); 625d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio if (mActionBar != null) { 626d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); 627d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); 628d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio } 62941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar); 63041937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio 631263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // see if we should show Back/Next buttons 632263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) { 633263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 634d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio View buttonBar = findViewById(R.id.button_bar); 635263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (buttonBar != null) { 636263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio buttonBar.setVisibility(View.VISIBLE); 637263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 638d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio Button backButton = (Button)findViewById(R.id.back_button); 639263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio backButton.setOnClickListener(new OnClickListener() { 640263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onClick(View v) { 6410698a216311acd9ab52224602d1a75c08bf89f04Jim Miller setResult(RESULT_CANCELED, getResultIntentData()); 642263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio finish(); 643263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 644263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 645d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio Button skipButton = (Button)findViewById(R.id.skip_button); 646263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio skipButton.setOnClickListener(new OnClickListener() { 647263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onClick(View v) { 6480698a216311acd9ab52224602d1a75c08bf89f04Jim Miller setResult(RESULT_OK, getResultIntentData()); 649263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio finish(); 650263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 651263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 652d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio mNextButton = (Button)findViewById(R.id.next_button); 653263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mNextButton.setOnClickListener(new OnClickListener() { 654263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onClick(View v) { 6550698a216311acd9ab52224602d1a75c08bf89f04Jim Miller setResult(RESULT_OK, getResultIntentData()); 656263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio finish(); 657263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 658263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 659263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 660263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // set our various button parameters 661263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) { 662263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT); 663263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (TextUtils.isEmpty(buttonText)) { 664263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mNextButton.setVisibility(View.GONE); 665263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 666263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio else { 667263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mNextButton.setText(buttonText); 668263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 669263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 670263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) { 671263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT); 672263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (TextUtils.isEmpty(buttonText)) { 673263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio backButton.setVisibility(View.GONE); 674263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 675263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio else { 676263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio backButton.setText(buttonText); 677263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 678263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 679263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) { 680263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio skipButton.setVisibility(View.VISIBLE); 681263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 682263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 683263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 684ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio 685ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio mHomeActivitiesCount = getHomeActivitiesCount(); 686ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio } 687ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio 688ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio private int getHomeActivitiesCount() { 689ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>(); 690ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio getPackageManager().getHomeActivities(homeApps); 691ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio return homeApps.size(); 692c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio } 693c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio 694a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio private void setTitleFromIntent(Intent intent) { 695a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1); 696a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio if (initialTitleResId > 0) { 697a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitle = null; 698a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitleResId = initialTitleResId; 69962464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina 70062464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina final String initialTitleResPackageName = intent.getStringExtra( 70162464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME); 70262464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina if (initialTitleResPackageName != null) { 70362464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina try { 70462464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina Context authContext = createPackageContextAsUser(initialTitleResPackageName, 70562464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina 0 /* flags */, new UserHandle(UserHandle.myUserId())); 70662464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina mInitialTitle = authContext.getResources().getText(mInitialTitleResId); 70762464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina setTitle(mInitialTitle); 70862464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina mInitialTitleResId = -1; 70962464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina return; 71062464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina } catch (NameNotFoundException e) { 71162464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName); 71262464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina } 71362464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina } else { 71462464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina setTitle(mInitialTitleResId); 71562464b819e185ce4a1642442fcf4cc18a4932a78Alexandra Gherghina } 716a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } else { 717a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitleResId = -1; 718a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); 719a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio mInitialTitle = (initialTitle != null) ? initialTitle : getTitle(); 720a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio setTitle(mInitialTitle); 721a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } 722a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } 723a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio 724c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio @Override 725263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onBackStackChanged() { 726d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio setTitleFromBackStack(); 7278eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio } 7288eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio 729b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio private int setTitleFromBackStack() { 7308eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio final int count = getFragmentManager().getBackStackEntryCount(); 731b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio 7328eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (count == 0) { 733a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio if (mInitialTitleResId > 0) { 734a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio setTitle(mInitialTitleResId); 735a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } else { 736a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio setTitle(mInitialTitle); 737a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } 738b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio return 0; 739263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 740b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio 7418eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1); 7428eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio setTitleFromBackStackEntry(bse); 743b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio 744b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio return count; 745263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 746263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 7478eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) { 7485529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio final CharSequence title; 7498eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio final int titleRes = bse.getBreadCrumbTitleRes(); 7508eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (titleRes > 0) { 7518eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio title = getText(titleRes); 7525529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio } else { 7538eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio title = bse.getBreadCrumbTitle(); 7548eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio } 7558eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (title != null) { 7568eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio setTitle(title); 7575529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio } 7585529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio } 7595529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio 760263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 761263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected void onSaveInstanceState(Bundle outState) { 762263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onSaveInstanceState(outState); 763263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 764769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio if (mCategories.size() > 0) { 765769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories); 766263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 767d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio 768b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled); 7693d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch); 7703d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio 7713d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio if (mDisplaySearch) { 7723d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // The option menus are created if the ActionBar is visible and they are also created 7733d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // asynchronously. If you launch Settings with an Intent action like 7743d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked 7753d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search 7763d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // menu item and search view are null. 7773d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded(); 7783d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded); 7793d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio 7803d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY; 7813d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio outState.putString(SAVE_KEY_SEARCH_QUERY, query); 7823d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio } 783ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio 784ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount); 785263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 786263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 787263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 788263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onResume() { 789263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onResume(); 790263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 791ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio final int newHomeActivityCount = getHomeActivitiesCount(); 792ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio if (newHomeActivityCount != mHomeActivitiesCount) { 793ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio mHomeActivitiesCount = newHomeActivityCount; 794b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio invalidateCategories(true); 795ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio } 796ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio 797263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { 798263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 799263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { 800b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio invalidateCategories(true); 801263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 802263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 803263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferences.registerOnSharedPreferenceChangeListener( 804263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferencesListener); 805263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 806263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); 807853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav 808990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav mDynamicIndexableContentMonitor.register(this); 809a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio 8103d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) { 811a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio onQueryTextSubmit(mSearchQuery); 812a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio } 813263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 814263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 815263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 816263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onPause() { 817263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onPause(); 818263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 819263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio unregisterReceiver(mBatteryInfoReceiver); 820990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav mDynamicIndexableContentMonitor.unregister(); 821263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 822263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 823263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 824263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onDestroy() { 825263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onDestroy(); 826680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio 827680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener( 828680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio mDevelopmentPreferencesListener); 829680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio mDevelopmentPreferencesListener = null; 830263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 831263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 832263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected boolean isValidFragment(String fragmentName) { 833263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Almost all fragments are wrapped in this, 834263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // except for a few that have their own activities. 835263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) { 836263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true; 837263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 838263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return false; 839263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 840263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 841263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 842263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Intent getIntent() { 843263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Intent superIntent = super.getIntent(); 844263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String startingFragment = getStartingFragmentClass(superIntent); 845263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // This is called from super.onCreate, isMultiPane() is not yet reliable 846263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Do not use onIsHidingHeaders either, which relies itself on this method 847263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (startingFragment != null) { 848263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Intent modIntent = new Intent(superIntent); 849263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); 850263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Bundle args = superIntent.getExtras(); 851263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (args != null) { 852263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio args = new Bundle(args); 853263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 854263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio args = new Bundle(); 855263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 856263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio args.putParcelable("intent", superIntent); 857ac1e20ebfc233a4894fa04a29b5d86602ee188eeKenny Guy modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); 858263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return modIntent; 859263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 860263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return superIntent; 861263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 862263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 863263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 864263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Checks if the component name in the intent is different from the Settings class and 865263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * returns the class name to load as a fragment. 866263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 867263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private String getStartingFragmentClass(Intent intent) { 868263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mFragmentClass != null) return mFragmentClass; 869263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 870263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String intentClass = intent.getComponent().getClassName(); 871263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intentClass.equals(getClass().getName())) return null; 872263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 873263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if ("com.android.settings.ManageApplications".equals(intentClass) 874263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio || "com.android.settings.RunningServices".equals(intentClass) 875263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio || "com.android.settings.applications.StorageUse".equals(intentClass)) { 876263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Old names of manage apps. 877263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio intentClass = com.android.settings.applications.ManageApplications.class.getName(); 878263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 879263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 880263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return intentClass; 881263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 882263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 883263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 88410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * Start a new fragment containing a preference panel. If the preferences 88510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * are being displayed in multi-pane mode, the given fragment class will 88610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * be instantiated and placed in the appropriate pane. If running in 88710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * single-pane mode, a new activity will be launched in which to show the 88810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * fragment. 88910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * 89010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param fragmentClass Full name of the class implementing the fragment. 89110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param args Any desired arguments to supply to the fragment. 89210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param titleRes Optional resource identifier of the title of this 89310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * fragment. 89410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param titleText Optional text of the title of this fragment. 89510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param resultTo Optional fragment that result data should be sent to. 89610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * If non-null, resultTo.onActivityResult() will be called when this 89710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * preference panel is done. The launched panel must use 89810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * {@link #finishPreferencePanel(Fragment, int, Intent)} when done. 89910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param resultRequestCode If resultTo is non-null, this is the caller's 90058146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio * request code to be received with the result. 90110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio */ 90210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes, 903d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio CharSequence titleText, Fragment resultTo, int resultRequestCode) { 904a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio String title = null; 905a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio if (titleRes < 0) { 906a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio if (titleText != null) { 907a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio title = titleText.toString(); 908a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } else { 909a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio // There not much we can do in that case 910a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio title = ""; 911a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } 912911fb2ad907d47a882c023b871c6457db32359f8Fabrice Di Meglio } 913a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode, 9140d643fd182d37d2e8ee5d547b80d80423a5ed98dFabrice Di Meglio titleRes, title, mIsShortcut); 91510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 91610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio 91710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio /** 9187a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban * Start a new fragment in a new activity containing a preference panel for a given user. If the 9197a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban * preferences are being displayed in multi-pane mode, the given fragment class will be 9207a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban * instantiated and placed in the appropriate pane. If running in single-pane mode, a new 9217a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban * activity will be launched in which to show the fragment. 9227a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban * 9237a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban * @param fragmentClass Full name of the class implementing the fragment. 9247a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban * @param args Any desired arguments to supply to the fragment. 9257a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban * @param titleRes Optional resource identifier of the title of this fragment. 9267a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban * @param titleText Optional text of the title of this fragment. 9277a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban * @param userHandle The user for which the panel has to be started. 9287a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban */ 9297a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes, 9307a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban CharSequence titleText, UserHandle userHandle) { 931d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang // This is a workaround. 932d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang // 933d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent 934d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang // starting the fragment could cause a native stack corruption. See b/17523189. However, 935d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang // adding that flag and start the preference panel with the same UserHandler will make it 936d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang // impossible to use back button to return to the previous screen. See b/20042570. 937d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang // 938d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing 939d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang // another check here to call startPreferencePanel() instead of startWithFragmentAsUser() 940d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang // when we're calling it as the same user. 941d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang if (userHandle.getIdentifier() == UserHandle.myUserId()) { 942d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0); 943d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang } else { 944d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang String title = null; 945d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang if (titleRes < 0) { 946d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang if (titleText != null) { 947d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang title = titleText.toString(); 948d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang } else { 949d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang // There not much we can do in that case 950d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang title = ""; 951d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang } 9527a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban } 953d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang Utils.startWithFragmentAsUser(this, fragmentClass, args, 954d033285ca7789b464f15cde149bef7df3ad2e1a3Lifu Tang titleRes, title, mIsShortcut, userHandle); 9557a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban } 9567a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban } 9577a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban 9587a2ccf201e839e8755b2184402072113498eef1fZoltan Szatmary-Ban /** 959263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Called by a preference panel fragment to finish itself. 960263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * 961263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param caller The fragment that is asking to be finished. 962263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param resultCode Optional result code to send back to the original 963263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * launching fragment. 964263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param resultData Optional result data to send back to the original 965263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * launching fragment. 966263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 967263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) { 968263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setResult(resultCode, resultData); 96958146c2b2fa24d774840a07cf697ad315baf4de0Fabrice Di Meglio finish(); 970263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 971263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 972263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 97310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * Start a new fragment. 97410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * 97510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param fragment The fragment to start 97610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param push If true, the current fragment will be pushed onto the back stack. If false, 97710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * the current fragment will be replaced. 97810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio */ 97910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio public void startPreferenceFragment(Fragment fragment, boolean push) { 98010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio FragmentTransaction transaction = getFragmentManager().beginTransaction(); 981d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio transaction.replace(R.id.main_content, fragment); 98210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio if (push) { 98310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 98410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.addToBackStack(BACK_STACK_PREFS); 98510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } else { 98610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 98710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 98810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.commitAllowingStateLoss(); 98910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 99010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio 99110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio /** 992d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio * Switch to a specific Fragment with taking care of validation, Title and BackStack 993d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio */ 994d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate, 995a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) { 996d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (validate && !isValidFragment(fragmentName)) { 997d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio throw new IllegalArgumentException("Invalid fragment for this activity: " 998d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio + fragmentName); 999d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1000d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio Fragment f = Fragment.instantiate(this, fragmentName, args); 1001d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio FragmentTransaction transaction = getFragmentManager().beginTransaction(); 1002d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio transaction.replace(R.id.main_content, f); 1003d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (withTransition) { 100459a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio TransitionManager.beginDelayedTransition(mContent); 1005d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1006d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (addToBackStack) { 1007d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS); 1008d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1009a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio if (titleResId > 0) { 1010a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio transaction.setBreadCrumbTitle(titleResId); 1011a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio } else if (title != null) { 1012d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio transaction.setBreadCrumbTitle(title); 1013d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1014d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio transaction.commitAllowingStateLoss(); 101559a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio getFragmentManager().executePendingTransactions(); 1016d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return f; 1017d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1018d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 101963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio /** 1020769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio * Called when the activity needs its list of categories/tiles built. 102163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * 102263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * @param categories The list in which to place the tiles categories. 102363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio */ 1024769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private void buildDashboardCategories(List<DashboardCategory> categories) { 10255f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio categories.clear(); 102663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio loadCategoriesFromResource(R.xml.dashboard_categories, categories); 102763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio updateTilesList(categories); 102863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 102963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 103063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio /** 103163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * Parse the given XML file as a categories description, adding each 103263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * parsed categories and tiles into the target list. 103363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * 103463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * @param resid The XML resource to load and parse. 103563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * @param target The list in which the parsed categories and tiles should be placed. 103663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio */ 103763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) { 103863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlResourceParser parser = null; 103963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio try { 104063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio parser = getResources().getXml(resid); 104163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio AttributeSet attrs = Xml.asAttributeSet(parser); 104263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 104363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio int type; 104463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 104563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio && type != XmlPullParser.START_TAG) { 104663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Parse next until start tag is found 104763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 104863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 104963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio String nodeName = parser.getName(); 105063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!"dashboard-categories".equals(nodeName)) { 105163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio throw new RuntimeException( 105263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio "XML document must start with <preference-categories> tag; found" 105363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio + nodeName + " at " + parser.getPositionDescription()); 105463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 105563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 105663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio Bundle curBundle = null; 105763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 105863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final int outerDepth = parser.getDepth(); 105963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 106063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { 106163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 106263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio continue; 106363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 106463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 106563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio nodeName = parser.getName(); 106663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if ("dashboard-category".equals(nodeName)) { 106763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DashboardCategory category = new DashboardCategory(); 106863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 106963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio TypedArray sa = obtainStyledAttributes( 107063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio attrs, com.android.internal.R.styleable.PreferenceHeader); 107163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.id = sa.getResourceId( 107263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_id, 107363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio (int)DashboardCategory.CAT_ID_UNDEFINED); 107463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 107563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio TypedValue tv = sa.peekValue( 107663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_title); 107763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv != null && tv.type == TypedValue.TYPE_STRING) { 107863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv.resourceId != 0) { 107963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.titleRes = tv.resourceId; 108063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 108163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.title = tv.string; 108263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 108363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 108463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sa.recycle(); 10852ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk sa = obtainStyledAttributes(attrs, com.android.internal.R.styleable.Preference); 10862ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk tv = sa.peekValue( 10872ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk com.android.internal.R.styleable.Preference_key); 10882ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk if (tv != null && tv.type == TypedValue.TYPE_STRING) { 10892ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk if (tv.resourceId != 0) { 10902ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk category.key = getString(tv.resourceId); 10912ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } else { 10922ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk category.key = tv.string.toString(); 10932ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 10942ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 10952ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk sa.recycle(); 109663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 109763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final int innerDepth = parser.getDepth(); 109863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 109963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { 110063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 110163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio continue; 110263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 110363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 110463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio String innerNodeName = parser.getName(); 110563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (innerNodeName.equals("dashboard-tile")) { 110663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DashboardTile tile = new DashboardTile(); 110763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 110863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sa = obtainStyledAttributes( 110963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio attrs, com.android.internal.R.styleable.PreferenceHeader); 111063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.id = sa.getResourceId( 111163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_id, 1112e9326d276135b657738d851e0a56df447f09567aFabrice Di Meglio (int)TILE_ID_UNDEFINED); 111363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tv = sa.peekValue( 111463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_title); 111563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv != null && tv.type == TypedValue.TYPE_STRING) { 111663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv.resourceId != 0) { 111763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.titleRes = tv.resourceId; 111863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 111963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.title = tv.string; 112063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 112163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 112263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tv = sa.peekValue( 112363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_summary); 112463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv != null && tv.type == TypedValue.TYPE_STRING) { 112563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv.resourceId != 0) { 112663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.summaryRes = tv.resourceId; 112763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 112863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.summary = tv.string; 112963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 113063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 113163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.iconRes = sa.getResourceId( 113263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_icon, 0); 113363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.fragment = sa.getString( 113463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_fragment); 113563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sa.recycle(); 113663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 113763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (curBundle == null) { 113863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio curBundle = new Bundle(); 113963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 114063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 114163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final int innerDepth2 = parser.getDepth(); 114263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 114363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) { 114463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 114563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio continue; 114663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 114763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 114863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio String innerNodeName2 = parser.getName(); 114963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (innerNodeName2.equals("extra")) { 115063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio getResources().parseBundleExtra("extra", attrs, curBundle); 115163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlUtils.skipCurrentTag(parser); 115263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 115363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (innerNodeName2.equals("intent")) { 115463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.intent = Intent.parseIntent(getResources(), parser, attrs); 115563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 115663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 115763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlUtils.skipCurrentTag(parser); 115863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 115963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 116063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 116163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (curBundle.size() > 0) { 116263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.fragmentArguments = curBundle; 116363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio curBundle = null; 116463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 116563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 11663815561997eced7fd773062ce32eaa50bece072cPauloftheWest // Show the SIM Cards setting if there are more than 2 SIMs installed. 116722a2a49b445b8721c8194eedf3608ea81c62ccefFabrice Di Meglio if(tile.id != R.id.sim_settings || Utils.showSimCardTile(this)){ 11683815561997eced7fd773062ce32eaa50bece072cPauloftheWest category.addTile(tile); 11693815561997eced7fd773062ce32eaa50bece072cPauloftheWest } 117063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 11712ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } else if (innerNodeName.equals("external-tiles")) { 11722ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk category.externalIndex = category.getTilesCount(); 117363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 117463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlUtils.skipCurrentTag(parser); 117563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 117663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 117763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 117863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio target.add(category); 117963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 118063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlUtils.skipCurrentTag(parser); 118163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 118263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 118363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 118463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } catch (XmlPullParserException e) { 118563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio throw new RuntimeException("Error parsing categories", e); 118663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } catch (IOException e) { 118763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio throw new RuntimeException("Error parsing categories", e); 118863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } finally { 118963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (parser != null) parser.close(); 119063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 119163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 119263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 119363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio private void updateTilesList(List<DashboardCategory> target) { 119463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final boolean showDev = mDevelopmentPreferences.getBoolean( 119563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DevelopmentSettings.PREF_SHOW, 119663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio android.os.Build.TYPE.equals("eng")); 119763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 119863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); 119963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 120063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final int size = target.size(); 120163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio for (int i = 0; i < size; i++) { 120263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 120363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DashboardCategory category = target.get(i); 120463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 120563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Ids are integers, so downcasting is ok 120663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio int id = (int) category.id; 120763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio int n = category.getTilesCount() - 1; 120863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while (n >= 0) { 120963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 121063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DashboardTile tile = category.getTile(n); 121157fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani boolean removeTile = false; 121263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio id = (int) tile.id; 121363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (id == R.id.operator_settings || id == R.id.manufacturer_settings) { 121457fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani if (!Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile)) { 121557fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani removeTile = true; 121657fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani } 121763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.wifi_settings) { 121863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Remove WiFi Settings if WiFi service is not available. 121963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) { 122057fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani removeTile = true; 122163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 122263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.bluetooth_settings) { 122363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Remove Bluetooth Settings if Bluetooth service is not available. 122463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) { 122557fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani removeTile = true; 122663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 122763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.data_usage_settings) { 122863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Remove data usage when kernel module not enabled 122963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final INetworkManagementService netManager = INetworkManagementService.Stub 123063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)); 123163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio try { 123263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!netManager.isBandwidthControlEnabled()) { 123357fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani removeTile = true; 123463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 123563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } catch (RemoteException e) { 123663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // ignored 123763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 123863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.battery_settings) { 123963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Remove battery settings when battery is not available. (e.g. TV) 124063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 124163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!mBatteryPresent) { 124257fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani removeTile = true; 124363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 124463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.home_settings) { 124563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!updateHomeSettingTiles(tile)) { 124657fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani removeTile = true; 124763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 124863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.user_settings) { 12494093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani boolean hasMultipleUsers = 12504093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani ((UserManager) getSystemService(Context.USER_SERVICE)) 12514093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani .getUserCount() > 1; 125263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!UserHandle.MU_ENABLED 12534093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani || (!UserManager.supportsMultipleUsers() 12544093e40e18f2e8d395ca467f54aef6e763c394f6Amith Yamasani && !hasMultipleUsers) 125563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio || Utils.isMonkeyRunning()) { 125657fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani removeTile = true; 125763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 125863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.nfc_payment_settings) { 125963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) { 126057fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani removeTile = true; 126163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 126263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Only show if NFC is on and we have the HCE feature 126363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); 1264b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio if (adapter == null || !adapter.isEnabled() || 1265b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio !getPackageManager().hasSystemFeature( 1266b3c7a179b10040945c055bed30731d7f27c2dcc2Fabrice Di Meglio PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) { 126757fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani removeTile = true; 126863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 126963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 1270488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio } else if (id == R.id.print_settings) { 1271488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio boolean hasPrintingSupport = getPackageManager().hasSystemFeature( 1272488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio PackageManager.FEATURE_PRINTING); 1273488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio if (!hasPrintingSupport) { 127457fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani removeTile = true; 1275488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio } 127663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.development_settings) { 12776c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds if (!showDev || um.hasUserRestriction( 12786c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds UserManager.DISALLOW_DEBUGGING_FEATURES)) { 127957fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani removeTile = true; 128063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 128163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 128263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 128363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0 128457fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) { 128557fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani removeTile = true; 128663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 128763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 128857fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani if (removeTile && n < category.getTilesCount()) { 128957fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani category.removeTile(n); 129057fd5fd84be2497845f6c03905500d2a36668b6cAmith Yamasani } 129163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio n--; 129263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 129363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 12942ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk addExternalTiles(target); 12952ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 12962ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk 12972ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk private void addExternalTiles(List<DashboardCategory> target) { 12982ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk Map<Pair<String, String>, DashboardTile> addedCache = 12992ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk new ArrayMap<Pair<String, String>, DashboardTile>(); 13002ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk UserManager userManager = UserManager.get(this); 13012ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk for (UserHandle user : userManager.getUserProfiles()) { 13022ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk addExternalTiles(target, user, addedCache); 13032ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 13042ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 13052ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk 13062ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk private void addExternalTiles(List<DashboardCategory> target, UserHandle user, 13072ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk Map<Pair<String, String>, DashboardTile> addedCache) { 13082ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk PackageManager pm = getPackageManager(); 13092ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk Intent intent = new Intent(EXTRA_SETTINGS_ACTION); 13102ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk List<ResolveInfo> results = pm.queryIntentActivitiesAsUser(intent, 13112ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk PackageManager.GET_META_DATA, user.getIdentifier()); 13122ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk for (ResolveInfo resolved : results) { 13132ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk if (!resolved.system) { 13142ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk // Do not allow any app to add to settings, only system ones. 13152ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk continue; 13162ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 13172ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk ActivityInfo activityInfo = resolved.activityInfo; 13182ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk Bundle metaData = activityInfo.metaData; 13192ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk if ((metaData == null) || !metaData.containsKey(EXTRA_CATEGORY_KEY)) { 13202ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk Log.w(LOG_TAG, "Found " + resolved.activityInfo.name + " for action " 13212ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk + EXTRA_SETTINGS_ACTION + " missing metadata " + 13222ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk (metaData == null ? "" : EXTRA_CATEGORY_KEY)); 13232ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk continue; 13242ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 13252ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk String categoryKey = metaData.getString(EXTRA_CATEGORY_KEY); 13262ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk DashboardCategory category = getCategory(target, categoryKey); 13272ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk if (category == null) { 13282ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk Log.w(LOG_TAG, "Activity " + resolved.activityInfo.name + " has unknown " 13292ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk + "category key " + categoryKey); 13302ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk continue; 13312ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 13322ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk Pair<String, String> key = new Pair<String, String>(activityInfo.packageName, 13332ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk activityInfo.name); 13342ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk DashboardTile tile = addedCache.get(key); 13352ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk if (tile == null) { 13362ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk tile = new DashboardTile(); 13372ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk tile.intent = new Intent().setClassName( 13382ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk activityInfo.packageName, activityInfo.name); 13392ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, tile); 13402ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk 13412ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk if (category.externalIndex == -1) { 13422ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk // If no location for external tiles has been specified for this category, 13432ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk // then just put them at the end. 13442ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk category.addTile(tile); 13452ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } else { 13462ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk category.addTile(category.externalIndex, tile); 13472ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 13482ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk addedCache.put(key, tile); 13492ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 13502ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk tile.userHandle.add(user); 13512ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 13522ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 13532ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk 13542ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk private DashboardCategory getCategory(List<DashboardCategory> target, String categoryKey) { 13552ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk for (DashboardCategory category : target) { 13562ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk if (categoryKey.equals(category.key)) { 13572ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk return category; 13582ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 13592ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk } 13602ebc8a01696c4e7dd29863b92a15ae0bbbbb254dJason Monk return null; 136163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 136263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 136363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio private boolean updateHomeSettingTiles(DashboardTile tile) { 136463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Once we decide to show Home settings, keep showing it forever 136563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE); 136663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) { 136763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio return true; 136863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 136963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 137063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio try { 1371b0a464fd2cbbe00821d483d28e76a04ac17996eaFabrice Di Meglio mHomeActivitiesCount = getHomeActivitiesCount(); 1372ceb335f88fc0df88dafc8063733842afe35c5da1Fabrice Di Meglio if (mHomeActivitiesCount < 2) { 137363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // When there's only one available home app, omit this settings 137463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // category entirely at the top level UI. If the user just 137563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // uninstalled the penultimate home app candidiate, we also 137663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // now tell them about why they aren't seeing 'Home' in the list. 137763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (sShowNoHomeNotice) { 137863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sShowNoHomeNotice = false; 137963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio NoHomeDialogFragment.show(this); 138063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 138163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio return false; 138263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 138363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Okay, we're allowing the Home settings category. Tell it, when 138463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // invoked via this front door, that we'll need to be told about the 138563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // case when the user uninstalls all but one home app. 138663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tile.fragmentArguments == null) { 138763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.fragmentArguments = new Bundle(); 138863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 138963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true); 139063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 139163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } catch (Exception e) { 139263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Can't look up the home activity; bail on configuring the icon 139363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio Log.w(LOG_TAG, "Problem looking up home activity!", e); 139463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 139563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 139663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply(); 139763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio return true; 139863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 139963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 1400263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private void getMetaData() { 1401263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio try { 1402263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), 1403263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PackageManager.GET_META_DATA); 1404263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (ai == null || ai.metaData == null) return; 1405263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); 1406263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } catch (NameNotFoundException nnfe) { 1407263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // No recovery 1408263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString()); 1409263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1410263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1411263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1412263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // give subclasses access to the Next button 1413263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean hasNextButton() { 1414263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return mNextButton != null; 1415263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1416263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1417263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Button getNextButton() { 1418263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return mNextButton; 1419263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1420263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1421263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1422263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean shouldUpRecreateTask(Intent targetIntent) { 1423263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class)); 1424263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1425263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1426263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static void requestHomeNotice() { 1427263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio sShowNoHomeNotice = true; 1428263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1429263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1430d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1431d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onQueryTextSubmit(String query) { 1432d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio switchToSearchResultsFragmentIfNeeded(); 1433d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchQuery = query; 1434d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return mSearchResultsFragment.onQueryTextSubmit(query); 1435d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1436263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1437d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1438d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onQueryTextChange(String newText) { 1439d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchQuery = newText; 14407e4855e8f644bdecf68ec65b8c1b7c08624a4876Fabrice Di Meglio if (mSearchResultsFragment == null) { 1441a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio return false; 1442a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio } 1443a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio return mSearchResultsFragment.onQueryTextChange(newText); 1444d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1445263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1446d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1447d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onClose() { 1448d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return false; 1449d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1450263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1451d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1452d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onMenuItemActionExpand(MenuItem item) { 1453d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (item.getItemId() == mSearchMenuItem.getItemId()) { 1454bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio switchToSearchResultsFragmentIfNeeded(); 1455263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1456d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return true; 1457d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1458263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1459d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1460d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onMenuItemActionCollapse(MenuItem item) { 1461d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (item.getItemId() == mSearchMenuItem.getItemId()) { 1462bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio if (mSearchMenuItemExpanded) { 1463d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio revertToInitialFragment(); 1464263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1465263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1466d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return true; 1467d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1468263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1469d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private void switchToSearchResultsFragmentIfNeeded() { 1470bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio if (mSearchResultsFragment != null) { 1471bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio return; 1472263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1473d40dd45c18a55d574d65b3a0ac16b59d76027049Fabrice Di Meglio Fragment current = getFragmentManager().findFragmentById(R.id.main_content); 1474bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio if (current != null && current instanceof SearchResultsSummary) { 1475bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio mSearchResultsFragment = (SearchResultsSummary) current; 1476bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio } else { 1477bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio mSearchResultsFragment = (SearchResultsSummary) switchToFragment( 1478a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio SearchResultsSummary.class.getName(), null, false, true, 1479a9e77993d1f82a230ff381134d4a22eff4a907cdFabrice Di Meglio R.string.search_results_title, null, true); 1480bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio } 1481d297a5840230b769a3c7ad8b85232968a7077f64Fabrice Di Meglio mSearchResultsFragment.setSearchView(mSearchView); 1482bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio mSearchMenuItemExpanded = true; 1483d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1484263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1485d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public void needToRevertToInitialFragment() { 1486d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mNeedToRevertToInitialFragment = true; 1487d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1488263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1489d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private void revertToInitialFragment() { 1490d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mNeedToRevertToInitialFragment = false; 1491d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchResultsFragment = null; 1492bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio mSearchMenuItemExpanded = false; 1493bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS, 1494bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio FragmentManager.POP_BACK_STACK_INCLUSIVE); 149523ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio if (mSearchMenuItem != null) { 149623ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio mSearchMenuItem.collapseActionView(); 149723ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio } 1498263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 14990698a216311acd9ab52224602d1a75c08bf89f04Jim Miller 15000698a216311acd9ab52224602d1a75c08bf89f04Jim Miller public Intent getResultIntentData() { 15010698a216311acd9ab52224602d1a75c08bf89f04Jim Miller return mResultIntentData; 15020698a216311acd9ab52224602d1a75c08bf89f04Jim Miller } 15030698a216311acd9ab52224602d1a75c08bf89f04Jim Miller 15040698a216311acd9ab52224602d1a75c08bf89f04Jim Miller public void setResultIntentData(Intent resultIntentData) { 15050698a216311acd9ab52224602d1a75c08bf89f04Jim Miller mResultIntentData = resultIntentData; 15060698a216311acd9ab52224602d1a75c08bf89f04Jim Miller } 1507263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio} 1508