SettingsActivity.java revision 3d35ec729256d4a1e1796be3e9d858eefedda23d
1263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio/* 2263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Copyright (C) 2014 The Android Open Source Project 3263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * 4263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Licensed under the Apache License, Version 2.0 (the "License"); 5263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * you may not use this file except in compliance with the License. 6263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * You may obtain a copy of the License at 7263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * 8263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * http://www.apache.org/licenses/LICENSE-2.0 9263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * 10263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Unless required by applicable law or agreed to in writing, software 11263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * distributed under the License is distributed on an "AS IS" BASIS, 12263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * See the License for the specific language governing permissions and 14263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * limitations under the License. 15263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 16263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 17263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Megliopackage com.android.settings; 18263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 19263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.accounts.Account; 20263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.accounts.AccountManager; 21263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.accounts.OnAccountsUpdateListener; 22263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.ActionBar; 23263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Activity; 24263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Fragment; 25263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentManager; 26263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.FragmentTransaction; 27263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.BroadcastReceiver; 28d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.content.ComponentName; 29263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Context; 30263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Intent; 31263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.IntentFilter; 32263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.SharedPreferences; 33263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ActivityInfo; 34263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager; 35263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager.NameNotFoundException; 36263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ResolveInfo; 37263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.Configuration; 38263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.TypedArray; 39263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.XmlResourceParser; 40263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.nfc.NfcAdapter; 41263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Bundle; 42263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Handler; 43263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.INetworkManagementService; 44263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Message; 45263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.RemoteException; 46263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.ServiceManager; 47263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserHandle; 48263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserManager; 49263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.Preference; 50263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceFragment; 51263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceManager; 52263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceScreen; 53263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.text.TextUtils; 5459a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.transition.TransitionManager; 55263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.AttributeSet; 56263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Log; 57263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.TypedValue; 58263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Xml; 59d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.Menu; 60d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.view.MenuInflater; 61263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.MenuItem; 62263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View; 63263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View.OnClickListener; 6459a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglioimport android.view.ViewGroup; 65263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.Button; 66263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 67d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglioimport android.widget.SearchView; 68263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.ArrayUtils; 69263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.XmlUtils; 70263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.AccessibilitySettings; 71263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.CaptionPropertiesFragment; 72263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.AccountSyncSettings; 73263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.AuthenticatorHelper; 74263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.ManageAccountsSettings; 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; 86263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.fuelgauge.PowerUsageSummary; 877a6bfd132cac4dcff72e3adcdd68a7ef777cee12Fabrice Di Meglioimport com.android.settings.search.DynamicIndexableContentMonitor; 88fa7dc240e978b1b77bb5c80a78cd1f8c77648301Fabrice Di Meglioimport com.android.settings.search.Index; 89263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.InputMethodAndLanguageSettings; 90263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.KeyboardLayoutPickerFragment; 91263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.SpellCheckersSettings; 92263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.UserDictionaryList; 93263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.location.LocationSettings; 94263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.AndroidBeam; 95263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.PaymentSettings; 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; 1004a35051565b0ce6d29313c3e4ffe19e1dde78db0John Spurlockimport com.android.settings.notification.ZenModeSettings; 101263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintJobSettingsFragment; 102263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintSettingsFragment; 103263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.tts.TextToSpeechSettings; 104263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.users.UserSettings; 105263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.vpn2.VpnSettings; 106263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wfd.WifiDisplaySettings; 10741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglioimport com.android.settings.widget.SwitchBar; 108263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.AdvancedWifiSettings; 109263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.WifiSettings; 110263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.p2p.WifiP2pSettings; 111263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParser; 112263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParserException; 113263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 114263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.io.IOException; 115263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.ArrayList; 116263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.Collections; 117263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.Comparator; 118263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.List; 119263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 120e9326d276135b657738d851e0a56df447f09567aFabrice Di Meglioimport static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED; 121d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 122263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Megliopublic class SettingsActivity extends Activity 123263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio implements PreferenceManager.OnPreferenceTreeClickListener, 124263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PreferenceFragment.OnPreferenceStartFragmentCallback, 125d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio ButtonBarHandler, OnAccountsUpdateListener, FragmentManager.OnBackStackChangedListener, 126d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio SearchView.OnQueryTextListener, SearchView.OnCloseListener, 127d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio MenuItem.OnActionExpandListener { 128263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 129263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String LOG_TAG = "Settings"; 130263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 131263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Constants for state save/restore 132769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private static final String SAVE_KEY_CATEGORIES = ":settings:categories"; 133d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded"; 134d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query"; 135b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up"; 1363d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search"; 137263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 138263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 139263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * When starting this activity, the invoking Intent can contain this extra 140263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * string to specify which fragment should be initially displayed. 141263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity 142263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * will call isValidFragment() to confirm that the fragment class name is valid for this 143263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * activity. 144263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 145263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment"; 146263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 147263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 148263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, 149263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * this extra can also be specified to supply a Bundle of arguments to pass 150263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * to that fragment when it is instantiated during the initial creation 151263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * of the activity. 152263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 153263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args"; 154263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 155263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 156c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS} 157c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio */ 158c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"; 159c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio 1606f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio public static final String BACK_STACK_PREFS = ":settings:prefs"; 1616f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio 162263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // extras that allow any preference activity to be launched as part of a wizard 163263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 164263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // show Back and Next buttons? takes boolean parameter 165263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Back will then return RESULT_CANCELED and Next RESULT_OK 166263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; 167263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 168263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // add a Skip button? 169263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip"; 170263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 171263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // specify custom text for the Back or Next buttons, or cause a button to not appear 172263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // at all by setting it to null 173263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text"; 174263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text"; 175263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 176263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 177263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, 178263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * this extra can also be specify to supply the title to be shown for 179263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * that fragment. 180263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 181d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title"; 182263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 183263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String META_DATA_KEY_FRAGMENT_CLASS = 184263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio "com.android.settings.FRAGMENT_CLASS"; 185263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 186263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String EXTRA_UI_OPTIONS = "settings:ui_options"; 187263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 188d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio private static final String EMPTY_QUERY = ""; 189d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio 190263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static boolean sShowNoHomeNotice = false; 191263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 192263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private String mFragmentClass; 193263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1948eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio private CharSequence mInitialTitle; 1958eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio 196263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Show only these settings for restricted users 197263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private int[] SETTINGS_FOR_RESTRICTED = { 198263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.wireless_section, 199263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.wifi_settings, 200263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.bluetooth_settings, 201263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.data_usage_settings, 202263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.wireless_settings, 203263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.device_section, 2044e4cdeffdb6087c953f44808f14f18554a749bdaJohn Spurlock R.id.notification_settings, 205263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.display_settings, 206263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.storage_settings, 207263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.application_settings, 208263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.battery_settings, 209263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.personal_section, 210263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.location_settings, 211263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.security_settings, 212263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.language_settings, 213263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.user_settings, 214263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.account_settings, 215263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.account_add, 216263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.system_section, 217263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.date_time_settings, 218263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.about_settings, 219263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.accessibility_settings, 220263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.print_settings, 221263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.nfc_payment_settings, 2222858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio R.id.home_settings, 2232858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio R.id.dashboard 224263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 225263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 226263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String[] ENTRY_FRAGMENTS = { 227263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WirelessSettings.class.getName(), 228263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WifiSettings.class.getName(), 229263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AdvancedWifiSettings.class.getName(), 230263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio BluetoothSettings.class.getName(), 231263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TetherSettings.class.getName(), 232263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WifiP2pSettings.class.getName(), 233263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio VpnSettings.class.getName(), 234263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DateTimeSettings.class.getName(), 235263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio LocalePicker.class.getName(), 236263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio InputMethodAndLanguageSettings.class.getName(), 237263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio SpellCheckersSettings.class.getName(), 238263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UserDictionaryList.class.getName(), 239263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UserDictionarySettings.class.getName(), 240263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DisplaySettings.class.getName(), 241263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DeviceInfoSettings.class.getName(), 242263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ManageApplications.class.getName(), 243263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ProcessStatsUi.class.getName(), 244263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio NotificationStation.class.getName(), 245263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio LocationSettings.class.getName(), 246263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio SecuritySettings.class.getName(), 247263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PrivacySettings.class.getName(), 248263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DeviceAdminSettings.class.getName(), 249263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AccessibilitySettings.class.getName(), 250263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio CaptionPropertiesFragment.class.getName(), 251263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio com.android.settings.accessibility.ToggleInversionPreferenceFragment.class.getName(), 252263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(), 253263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TextToSpeechSettings.class.getName(), 254263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Memory.class.getName(), 255263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DevelopmentSettings.class.getName(), 256263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UsbSettings.class.getName(), 257263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AndroidBeam.class.getName(), 258263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WifiDisplaySettings.class.getName(), 259263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PowerUsageSummary.class.getName(), 260263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AccountSyncSettings.class.getName(), 261263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio CryptKeeperSettings.class.getName(), 262263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DataUsageSummary.class.getName(), 263263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DreamSettings.class.getName(), 264263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UserSettings.class.getName(), 265263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio NotificationAccessSettings.class.getName(), 266c9afadb04b00598f5988101681089290cf14f79cJohn Spurlock ConditionProviderSettings.class.getName(), 267263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ManageAccountsSettings.class.getName(), 268263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PrintSettingsFragment.class.getName(), 269263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PrintJobSettingsFragment.class.getName(), 270263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TrustedCredentialsSettings.class.getName(), 271263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PaymentSettings.class.getName(), 272263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio KeyboardLayoutPickerFragment.class.getName(), 273d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio ZenModeSettings.class.getName(), 274d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio NotificationSettings.class.getName(), 275d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio ChooseLockPassword.ChooseLockPasswordFragment.class.getName(), 276d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio ChooseLockPattern.ChooseLockPatternFragment.class.getName(), 277d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio InstalledAppDetails.class.getName() 278263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 279263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 280263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private SharedPreferences mDevelopmentPreferences; 281263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener; 282263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 283263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private AuthenticatorHelper mAuthenticatorHelper; 284263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private boolean mListeningToAccountUpdates; 285263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 286263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private boolean mBatteryPresent = true; 287263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() { 288263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 289263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 290263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onReceive(Context context, Intent intent) { 291263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String action = intent.getAction(); 292263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { 293263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio boolean batteryPresent = Utils.isBatteryPresent(intent); 294263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 295263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mBatteryPresent != batteryPresent) { 296263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mBatteryPresent = batteryPresent; 297769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio invalidateCategories(); 298263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 299263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 300263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 301263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 302263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 303990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor = 304990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav new DynamicIndexableContentMonitor(); 305853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav 306d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private ActionBar mActionBar; 30741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio private SwitchBar mSwitchBar; 30841937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio 30941937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio private Button mNextButton; 3103d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio 311b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio private boolean mDisplayHomeAsUpEnabled; 3123d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio private boolean mDisplaySearch; 313d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 31435062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio private boolean mIsShowingDashboard; 31535062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio 31659a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio private ViewGroup mContent; 31759a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio 318d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private SearchView mSearchView; 319d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private MenuItem mSearchMenuItem; 320d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private boolean mSearchMenuItemExpanded = false; 321d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private SearchResultsSummary mSearchResultsFragment; 322d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private String mSearchQuery; 323d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 324769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio // Categories 325769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>(); 326769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private boolean mNeedToRebuildCategories; 327263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 328769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private static final int MSG_BUILD_CATEGORIES = 1; 329263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private Handler mHandler = new Handler() { 330263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 331263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void handleMessage(Message msg) { 332263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio switch (msg.what) { 333769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio case MSG_BUILD_CATEGORIES: { 33442c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio if(mNeedToRebuildCategories) { 33542c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio buildDashboardCategories(mCategories); 33642c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio } 337263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } break; 338263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 339263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 340263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 341263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 342d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private boolean mNeedToRevertToInitialFragment = false; 343d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 34441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio public SwitchBar getSwitchBar() { 34541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio return mSwitchBar; 34641937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio } 34741937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio 348769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio public AuthenticatorHelper getAuthenticatorHelper() { 349769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio return mAuthenticatorHelper; 350769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio } 351769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio 352769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio public List<DashboardCategory> getDashboardCategories() { 35342c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio if (mNeedToRebuildCategories || mCategories.size() == 0) { 354769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio buildDashboardCategories(mCategories); 355769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio mNeedToRebuildCategories = false; 356769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio } 357769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio return mCategories; 358769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio } 359769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio 360263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 361263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { 362263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Override the fragment title for Wallpaper settings 363263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio int titleRes = pref.getTitleRes(); 364263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) { 365263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio titleRes = R.string.wallpaper_settings_fragment_title; 366263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName()) 367263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio && UserHandle.myUserId() != UserHandle.USER_OWNER) { 368263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (UserManager.get(this).isLinkedUser()) { 369263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio titleRes = R.string.profile_info_settings_title; 370263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 371263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio titleRes = R.string.user_info_settings_title; 372263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 373263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 374263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(), 375263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio null, 0); 376263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return true; 377263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 378263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 379263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 380263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { 381263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return false; 382263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 383263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 384769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private void invalidateCategories() { 385769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio if (!mHandler.hasMessages(MSG_BUILD_CATEGORIES)) { 386769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio mHandler.sendEmptyMessage(MSG_BUILD_CATEGORIES); 387263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 388263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 389263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 390263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 391263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onConfigurationChanged(Configuration newConfig) { 392263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onConfigurationChanged(newConfig); 3936f0739a3d9a9eca1591ae6bada1dd4d1d92c0defFabrice Di Meglio Index.getInstance(this).update(); 394263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 395263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 396263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 397d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio protected void onStart() { 398d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio super.onStart(); 399d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 400d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (mNeedToRevertToInitialFragment) { 401d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio revertToInitialFragment(); 402263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 403263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 404263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 405263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 406d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onCreateOptionsMenu(Menu menu) { 4073d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio if (!mDisplaySearch) { 4083d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio return false; 4093d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio } 4103d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio 411d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio MenuInflater inflater = getMenuInflater(); 412d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio inflater.inflate(R.menu.options_menu, menu); 413d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 414d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio // Cache the search query (can be overriden by the OnQueryTextListener) 415d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio final String query = mSearchQuery; 416d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 4179593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio mSearchMenuItem = menu.findItem(R.id.search); 4189593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio mSearchView = (SearchView) mSearchMenuItem.getActionView(); 419d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 42023ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio if (mSearchMenuItem == null || mSearchView == null) { 42123ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio return false; 42223ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio } 42323ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio 4248c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio if (mSearchResultsFragment != null) { 4258c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio mSearchResultsFragment.setSearchView(mSearchView); 4268c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio } 4278c3b0ce7120da882082eed533462090c4feadff8Fabrice Di Meglio 4289593782d154f378a0c911cd015d410c18fe74a92Fabrice Di Meglio mSearchMenuItem.setOnActionExpandListener(this); 429d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchView.setOnQueryTextListener(this); 430d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchView.setOnCloseListener(this); 431d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 432d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (mSearchMenuItemExpanded) { 433d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchMenuItem.expandActionView(); 434d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 435d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchView.setQuery(query, true /* submit */); 436d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 437d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return true; 438d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 439d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 440d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 441d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio protected void onCreate(Bundle savedState) { 442263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) { 443263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio getWindow().setUiOptions(getIntent().getIntExtra(EXTRA_UI_OPTIONS, 0)); 444263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 4455ebabfcd35dd00a1d5beb9bcaca03574ae09b4e8Fabrice Di Meglio 446263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mAuthenticatorHelper = new AuthenticatorHelper(); 447263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mAuthenticatorHelper.updateAuthDescriptions(this); 448263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mAuthenticatorHelper.onAccountsUpdated(this, null); 449263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 450263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, 451263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Context.MODE_PRIVATE); 452263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 453263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio getMetaData(); 454263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 455d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio super.onCreate(savedState); 456263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 457263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setContentView(R.layout.settings_main); 458263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 45959a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio mContent = (ViewGroup) findViewById(R.id.prefs); 46059a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio 461263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio getFragmentManager().addOnBackStackChangedListener(this); 462263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 463b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio mDisplayHomeAsUpEnabled = true; 4643d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio mDisplaySearch = true; 465263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 4665cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio // Getting Intent properties can only be done after the super.onCreate(...) 4675cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio final String initialFragmentName = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT); 4685cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio 46935062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio mIsShowingDashboard = (initialFragmentName == null); 47035062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio 47135062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio if (mIsShowingDashboard) { 4725cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio Index.getInstance(this).update(); 4735cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio } 4745cda21b449a56de42f7868bdcdaa31bb6f587c03Fabrice Di Meglio 475d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (savedState != null) { 4761800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio // We are restarting from a previous saved state; used that to initialize, instead 4771800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio // of starting fresh. 478d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED); 479d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY); 480263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 4811800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio final String initialTitle = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); 4821800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio mInitialTitle = (initialTitle != null) ? initialTitle : getTitle(); 4831800a9f3e7027e8ab8ffcab51715d39b126bad43Fabrice Di Meglio setTitle(mInitialTitle); 4845529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio 485769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio ArrayList<DashboardCategory> categories = 486769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); 487769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio if (categories != null) { 4885f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio mCategories.clear(); 489769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio mCategories.addAll(categories); 490b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio setTitleFromBackStack(); 491263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 492b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio 493b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); 4943d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH); 495263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 49635062d6983e352f5cb6c4a6bbf3c1e4e214d44a9Fabrice Di Meglio if (!mIsShowingDashboard) { 497d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio final ComponentName cn = getIntent().getComponent(); 4983d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // No UP nor Search is shown we are launched thru a Settings "shortcut" 499d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (!cn.getClassName().equals(SubSettings.class.getName())) { 500b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio mDisplayHomeAsUpEnabled = false; 5013d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio mDisplaySearch = false; 502d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 503d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio final String initialTitle = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); 504d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mInitialTitle = (initialTitle != null) ? initialTitle : getTitle(); 505832e54618588fdd31397b1779411af06e58565d7Fabrice Di Meglio setTitle(mInitialTitle); 506c1457323d271309d5d1955743cd806417c84b9d6Fabrice Di Meglio 5075ebabfcd35dd00a1d5beb9bcaca03574ae09b4e8Fabrice Di Meglio Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); 508d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio switchToFragment( initialFragmentName, initialArguments, true, false, 509d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mInitialTitle, false); 51010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } else { 511e9326d276135b657738d851e0a56df447f09567aFabrice Di Meglio // No UP if we are displaying the main Dashboard 512b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio mDisplayHomeAsUpEnabled = false; 51342c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio mInitialTitle = getText(R.string.dashboard_title); 51442c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio switchToFragment(DashboardSummary.class.getName(), null, false, false, 51542c4b0abe5578a7812844ad5205ffc3b87cf3072Fabrice Di Meglio mInitialTitle, false); 516263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 517263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 518263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 519d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mActionBar = getActionBar(); 520d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio if (mActionBar != null) { 521d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); 522d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); 523d8aec08fa96c42a61bd6ead2aa9859b5b67a3f2cFabrice Di Meglio } 52441937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar); 52541937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio 526263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // see if we should show Back/Next buttons 527263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Intent intent = getIntent(); 528263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) { 529263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 530d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio View buttonBar = findViewById(R.id.button_bar); 531263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (buttonBar != null) { 532263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio buttonBar.setVisibility(View.VISIBLE); 533263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 534d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio Button backButton = (Button)findViewById(R.id.back_button); 535263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio backButton.setOnClickListener(new OnClickListener() { 536263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onClick(View v) { 537263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setResult(RESULT_CANCELED); 538263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio finish(); 539263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 540263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 541d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio Button skipButton = (Button)findViewById(R.id.skip_button); 542263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio skipButton.setOnClickListener(new OnClickListener() { 543263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onClick(View v) { 544263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setResult(RESULT_OK); 545263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio finish(); 546263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 547263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 548d2b64f339adb8f019e3c712e388e35830d8b68a9Fabrice Di Meglio mNextButton = (Button)findViewById(R.id.next_button); 549263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mNextButton.setOnClickListener(new OnClickListener() { 550263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onClick(View v) { 551263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setResult(RESULT_OK); 552263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio finish(); 553263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 554263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 555263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 556263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // set our various button parameters 557263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) { 558263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT); 559263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (TextUtils.isEmpty(buttonText)) { 560263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mNextButton.setVisibility(View.GONE); 561263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 562263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio else { 563263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mNextButton.setText(buttonText); 564263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 565263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 566263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) { 567263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT); 568263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (TextUtils.isEmpty(buttonText)) { 569263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio backButton.setVisibility(View.GONE); 570263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 571263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio else { 572263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio backButton.setText(buttonText); 573263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 574263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 575263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) { 576263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio skipButton.setVisibility(View.VISIBLE); 577263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 578263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 579263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 580c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio } 581c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio 582c95be4fbb3ec437517a2190d88fbda5068dba8dfFabrice Di Meglio @Override 583263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onBackStackChanged() { 584d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio setTitleFromBackStack(); 5858eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio } 5868eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio 587b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio private int setTitleFromBackStack() { 5888eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio final int count = getFragmentManager().getBackStackEntryCount(); 589b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio 5908eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (count == 0) { 5918eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio setTitle(mInitialTitle); 592b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio return 0; 593263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 594b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio 5958eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1); 5968eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio setTitleFromBackStackEntry(bse); 597b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio 598b643cbf6d60bb4cd43d3191106d68680fffe97b5Fabrice Di Meglio return count; 599263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 600263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 6018eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) { 6025529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio final CharSequence title; 6038eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio final int titleRes = bse.getBreadCrumbTitleRes(); 6048eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (titleRes > 0) { 6058eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio title = getText(titleRes); 6065529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio } else { 6078eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio title = bse.getBreadCrumbTitle(); 6088eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio } 6098eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (title != null) { 6108eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio setTitle(title); 6115529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio } 6125529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio } 6135529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio 614263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 615263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected void onSaveInstanceState(Bundle outState) { 616263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onSaveInstanceState(outState); 617263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 618769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio if (mCategories.size() > 0) { 619769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories); 620263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 621d6985df419549fbb7d420eced8e89f0429e49d71Fabrice Di Meglio 622b731dd0554744d91ca89d37ff7c82f8d6e5b502dFabrice Di Meglio outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled); 6233d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch); 6243d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio 6253d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio if (mDisplaySearch) { 6263d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // The option menus are created if the ActionBar is visible and they are also created 6273d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // asynchronously. If you launch Settings with an Intent action like 6283d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked 6293d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search 6303d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio // menu item and search view are null. 6313d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded(); 6323d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded); 6333d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio 6343d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY; 6353d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio outState.putString(SAVE_KEY_SEARCH_QUERY, query); 6363d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio } 637263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 638263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 639263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 640263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onResume() { 641263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onResume(); 642263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 643263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { 644263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 645263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { 646bb05178dba21509d5b26ae0bd718a471b8c6cd5eFabrice Di Meglio setNeedToRebuildCategories(true); 647769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio invalidateCategories(); 648263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 649263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 650263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferences.registerOnSharedPreferenceChangeListener( 651263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferencesListener); 652263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 653263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); 654853e47181dc116ba95e91463735dc79ad4bdc95aSvetoslav 655990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav mDynamicIndexableContentMonitor.register(this); 656a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio 6573d35ec729256d4a1e1796be3e9d858eefedda23dFabrice Di Meglio if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) { 658a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio onQueryTextSubmit(mSearchQuery); 659a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio } 660263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 661263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 662263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 663263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onPause() { 664263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onPause(); 665263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 666263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio unregisterReceiver(mBatteryInfoReceiver); 667263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 668990159abaad7f314fbe1f9eaf064a088806ffb19Svetoslav mDynamicIndexableContentMonitor.unregister(); 669263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 670263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 671263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 672263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onDestroy() { 673263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onDestroy(); 674680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio 675680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener( 676680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio mDevelopmentPreferencesListener); 677680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio mDevelopmentPreferencesListener = null; 678680b064b293888ea47a6211943b51bee3adfb70dFabrice Di Meglio 679263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mListeningToAccountUpdates) { 680263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AccountManager.get(this).removeOnAccountsUpdatedListener(this); 681263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 682263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 683263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 684263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected boolean isValidFragment(String fragmentName) { 685263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Almost all fragments are wrapped in this, 686263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // except for a few that have their own activities. 687263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) { 688263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true; 689263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 690263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return false; 691263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 692263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 693263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 694263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Intent getIntent() { 695263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Intent superIntent = super.getIntent(); 696263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String startingFragment = getStartingFragmentClass(superIntent); 697263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // This is called from super.onCreate, isMultiPane() is not yet reliable 698263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Do not use onIsHidingHeaders either, which relies itself on this method 699263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (startingFragment != null) { 700263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Intent modIntent = new Intent(superIntent); 701263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); 702263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Bundle args = superIntent.getExtras(); 703263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (args != null) { 704263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio args = new Bundle(args); 705263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 706263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio args = new Bundle(); 707263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 708263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio args.putParcelable("intent", superIntent); 709263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, superIntent.getExtras()); 710263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return modIntent; 711263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 712263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return superIntent; 713263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 714263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 715263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 716263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Checks if the component name in the intent is different from the Settings class and 717263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * returns the class name to load as a fragment. 718263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 719263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private String getStartingFragmentClass(Intent intent) { 720263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mFragmentClass != null) return mFragmentClass; 721263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 722263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String intentClass = intent.getComponent().getClassName(); 723263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intentClass.equals(getClass().getName())) return null; 724263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 725263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if ("com.android.settings.ManageApplications".equals(intentClass) 726263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio || "com.android.settings.RunningServices".equals(intentClass) 727263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio || "com.android.settings.applications.StorageUse".equals(intentClass)) { 728263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Old names of manage apps. 729263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio intentClass = com.android.settings.applications.ManageApplications.class.getName(); 730263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 731263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 732263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return intentClass; 733263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 734263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 735263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 73610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * Start a new fragment containing a preference panel. If the preferences 73710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * are being displayed in multi-pane mode, the given fragment class will 73810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * be instantiated and placed in the appropriate pane. If running in 73910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * single-pane mode, a new activity will be launched in which to show the 74010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * fragment. 74110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * 74210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param fragmentClass Full name of the class implementing the fragment. 74310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param args Any desired arguments to supply to the fragment. 74410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param titleRes Optional resource identifier of the title of this 74510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * fragment. 74610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param titleText Optional text of the title of this fragment. 74710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param resultTo Optional fragment that result data should be sent to. 74810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * If non-null, resultTo.onActivityResult() will be called when this 74910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * preference panel is done. The launched panel must use 75010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * {@link #finishPreferencePanel(Fragment, int, Intent)} when done. 75110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param resultRequestCode If resultTo is non-null, this is the caller's 75210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * request code to be received with the resut. 75310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio */ 75410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes, 755d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio CharSequence titleText, Fragment resultTo, int resultRequestCode) { 756911fb2ad907d47a882c023b871c6457db32359f8Fabrice Di Meglio String title; 757911fb2ad907d47a882c023b871c6457db32359f8Fabrice Di Meglio if (titleRes > 0) { 758911fb2ad907d47a882c023b871c6457db32359f8Fabrice Di Meglio title = getString(titleRes); 759821a0729ad4060b54a8311c957534117b84bc881Fabrice Di Meglio } else if (titleText != null) { 760911fb2ad907d47a882c023b871c6457db32359f8Fabrice Di Meglio title = titleText.toString(); 761821a0729ad4060b54a8311c957534117b84bc881Fabrice Di Meglio } else { 762821a0729ad4060b54a8311c957534117b84bc881Fabrice Di Meglio // There not much we can do in that case 763821a0729ad4060b54a8311c957534117b84bc881Fabrice Di Meglio title = ""; 764911fb2ad907d47a882c023b871c6457db32359f8Fabrice Di Meglio } 765769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode, title); 76610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 76710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio 76810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio /** 769263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Called by a preference panel fragment to finish itself. 770263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * 771263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param caller The fragment that is asking to be finished. 772263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param resultCode Optional result code to send back to the original 773263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * launching fragment. 774263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param resultData Optional result data to send back to the original 775263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * launching fragment. 776263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 777263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) { 778263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setResult(resultCode, resultData); 779263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 780263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 781263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 78210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * Start a new fragment. 78310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * 78410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param fragment The fragment to start 78510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param push If true, the current fragment will be pushed onto the back stack. If false, 78610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * the current fragment will be replaced. 78710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio */ 78810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio public void startPreferenceFragment(Fragment fragment, boolean push) { 78910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio FragmentTransaction transaction = getFragmentManager().beginTransaction(); 79010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.replace(R.id.prefs, fragment); 79110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio if (push) { 79210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 79310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.addToBackStack(BACK_STACK_PREFS); 79410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } else { 79510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 79610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 79710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.commitAllowingStateLoss(); 79810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 79910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio 80010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio /** 801d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio * Switch to a specific Fragment with taking care of validation, Title and BackStack 802d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio */ 803d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate, 804d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio boolean addToBackStack, CharSequence title, boolean withTransition) { 805d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (validate && !isValidFragment(fragmentName)) { 806d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio throw new IllegalArgumentException("Invalid fragment for this activity: " 807d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio + fragmentName); 808d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 809d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio Fragment f = Fragment.instantiate(this, fragmentName, args); 810d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio FragmentTransaction transaction = getFragmentManager().beginTransaction(); 811d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio transaction.replace(R.id.prefs, f); 812d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (withTransition) { 81359a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio TransitionManager.beginDelayedTransition(mContent); 814d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 815d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (addToBackStack) { 816d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS); 817d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 818d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (title != null) { 819d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio transaction.setBreadCrumbTitle(title); 820d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 821d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio transaction.commitAllowingStateLoss(); 82259a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio getFragmentManager().executePendingTransactions(); 823d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return f; 824d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 825d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio 826769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio public void setNeedToRebuildCategories(boolean need) { 827769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio mNeedToRebuildCategories = need; 828263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 829263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 83063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio /** 831769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio * Called when the activity needs its list of categories/tiles built. 83263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * 83363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * @param categories The list in which to place the tiles categories. 83463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio */ 835769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio private void buildDashboardCategories(List<DashboardCategory> categories) { 8365f995727cc2e4bd27d26a50f3a565fb677fdb294Fabrice Di Meglio categories.clear(); 83763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio loadCategoriesFromResource(R.xml.dashboard_categories, categories); 83863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio updateTilesList(categories); 83963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 84063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 84163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio /** 84263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * Parse the given XML file as a categories description, adding each 84363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * parsed categories and tiles into the target list. 84463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * 84563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * @param resid The XML resource to load and parse. 84663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio * @param target The list in which the parsed categories and tiles should be placed. 84763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio */ 84863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio private void loadCategoriesFromResource(int resid, List<DashboardCategory> target) { 84963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlResourceParser parser = null; 85063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio try { 85163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio parser = getResources().getXml(resid); 85263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio AttributeSet attrs = Xml.asAttributeSet(parser); 85363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 85463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio int type; 85563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 85663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio && type != XmlPullParser.START_TAG) { 85763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Parse next until start tag is found 85863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 85963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 86063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio String nodeName = parser.getName(); 86163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!"dashboard-categories".equals(nodeName)) { 86263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio throw new RuntimeException( 86363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio "XML document must start with <preference-categories> tag; found" 86463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio + nodeName + " at " + parser.getPositionDescription()); 86563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 86663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 86763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio Bundle curBundle = null; 86863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 86963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final int outerDepth = parser.getDepth(); 87063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 87163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { 87263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 87363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio continue; 87463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 87563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 87663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio nodeName = parser.getName(); 87763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if ("dashboard-category".equals(nodeName)) { 87863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DashboardCategory category = new DashboardCategory(); 87963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 88063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio TypedArray sa = obtainStyledAttributes( 88163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio attrs, com.android.internal.R.styleable.PreferenceHeader); 88263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.id = sa.getResourceId( 88363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_id, 88463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio (int)DashboardCategory.CAT_ID_UNDEFINED); 88563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 88663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio TypedValue tv = sa.peekValue( 88763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_title); 88863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv != null && tv.type == TypedValue.TYPE_STRING) { 88963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv.resourceId != 0) { 89063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.titleRes = tv.resourceId; 89163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 89263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.title = tv.string; 89363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 89463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 89563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sa.recycle(); 89663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 89763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final int innerDepth = parser.getDepth(); 89863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 89963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { 90063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 90163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio continue; 90263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 90363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 90463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio String innerNodeName = parser.getName(); 90563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (innerNodeName.equals("dashboard-tile")) { 90663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DashboardTile tile = new DashboardTile(); 90763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 90863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sa = obtainStyledAttributes( 90963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio attrs, com.android.internal.R.styleable.PreferenceHeader); 91063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.id = sa.getResourceId( 91163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_id, 912e9326d276135b657738d851e0a56df447f09567aFabrice Di Meglio (int)TILE_ID_UNDEFINED); 91363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tv = sa.peekValue( 91463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_title); 91563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv != null && tv.type == TypedValue.TYPE_STRING) { 91663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv.resourceId != 0) { 91763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.titleRes = tv.resourceId; 91863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 91963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.title = tv.string; 92063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 92163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 92263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tv = sa.peekValue( 92363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_summary); 92463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv != null && tv.type == TypedValue.TYPE_STRING) { 92563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tv.resourceId != 0) { 92663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.summaryRes = tv.resourceId; 92763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 92863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.summary = tv.string; 92963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 93063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 93163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.iconRes = sa.getResourceId( 93263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_icon, 0); 93363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.fragment = sa.getString( 93463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_fragment); 93563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sa.recycle(); 93663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 93763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (curBundle == null) { 93863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio curBundle = new Bundle(); 93963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 94063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 94163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final int innerDepth2 = parser.getDepth(); 94263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 94363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth2)) { 94463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 94563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio continue; 94663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 94763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 94863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio String innerNodeName2 = parser.getName(); 94963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (innerNodeName2.equals("extra")) { 95063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio getResources().parseBundleExtra("extra", attrs, curBundle); 95163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlUtils.skipCurrentTag(parser); 95263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 95363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (innerNodeName2.equals("intent")) { 95463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.intent = Intent.parseIntent(getResources(), parser, attrs); 95563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 95663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 95763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlUtils.skipCurrentTag(parser); 95863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 95963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 96063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 96163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (curBundle.size() > 0) { 96263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.fragmentArguments = curBundle; 96363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio curBundle = null; 96463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 96563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 96663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.addTile(tile); 96763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 96863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 96963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlUtils.skipCurrentTag(parser); 97063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 97163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 97263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 97363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio target.add(category); 97463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 97563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio XmlUtils.skipCurrentTag(parser); 97663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 97763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 97863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 97963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } catch (XmlPullParserException e) { 98063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio throw new RuntimeException("Error parsing categories", e); 98163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } catch (IOException e) { 98263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio throw new RuntimeException("Error parsing categories", e); 98363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } finally { 98463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (parser != null) parser.close(); 98563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 98663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 98763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 98863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio private void updateTilesList(List<DashboardCategory> target) { 98963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final boolean showDev = mDevelopmentPreferences.getBoolean( 99063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DevelopmentSettings.PREF_SHOW, 99163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio android.os.Build.TYPE.equals("eng")); 99263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 99363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); 99463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 99563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final int size = target.size(); 99663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio for (int i = 0; i < size; i++) { 99763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 99863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DashboardCategory category = target.get(i); 99963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 100063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Ids are integers, so downcasting is ok 100163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio int id = (int) category.id; 100263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (id == R.id.account_settings) { 100363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio insertAccountsTiles(category); 100463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio continue; 100563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 100663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio int n = category.getTilesCount() - 1; 100763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio while (n >= 0) { 100863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 100963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DashboardTile tile = category.getTile(n); 101063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 101163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio id = (int) tile.id; 101263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (id == R.id.operator_settings || id == R.id.manufacturer_settings) { 101363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio Utils.updateTileToSpecificActivityFromMetaDataOrRemove(this, category, tile); 101463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.wifi_settings) { 101563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Remove WiFi Settings if WiFi service is not available. 101663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) { 101763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 101863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 101963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.bluetooth_settings) { 102063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Remove Bluetooth Settings if Bluetooth service is not available. 102163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) { 102263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 102363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 102463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.data_usage_settings) { 102563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Remove data usage when kernel module not enabled 102663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final INetworkManagementService netManager = INetworkManagementService.Stub 102763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)); 102863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio try { 102963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!netManager.isBandwidthControlEnabled()) { 103063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 103163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 103263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } catch (RemoteException e) { 103363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // ignored 103463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 103563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.battery_settings) { 103663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Remove battery settings when battery is not available. (e.g. TV) 103763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 103863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!mBatteryPresent) { 103963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 104063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 104163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.home_settings) { 104263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!updateHomeSettingTiles(tile)) { 104363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 104463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 104563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.user_settings) { 104663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!UserHandle.MU_ENABLED 104763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio || !UserManager.supportsMultipleUsers() 104863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio || Utils.isMonkeyRunning()) { 104963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 105063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 105163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.nfc_payment_settings) { 105263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) { 105363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 105463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 105563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Only show if NFC is on and we have the HCE feature 105663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); 105763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!adapter.isEnabled() || !getPackageManager().hasSystemFeature( 105863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) { 105963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 106063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 106163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 1062488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio } else if (id == R.id.print_settings) { 1063488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio boolean hasPrintingSupport = getPackageManager().hasSystemFeature( 1064488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio PackageManager.FEATURE_PRINTING); 1065488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio if (!hasPrintingSupport) { 1066488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio category.removeTile(n); 1067488cae39dab2e8c298e8a1f1eec37bf0d96a83d2Fabrice Di Meglio } 106863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.development_settings) { 10696c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds if (!showDev || um.hasUserRestriction( 10706c088cb221bb43d47be065387231ffa7192ff211Julia Reynolds UserManager.DISALLOW_DEBUGGING_FEATURES)) { 107163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 107263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 107363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else if (id == R.id.account_add) { 107463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) { 107563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 107663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 107763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 107863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 107963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0 1080a97089d389338ca8e3d970b00dd13ffad732b5c1Amith Yamasani && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id) 1081a97089d389338ca8e3d970b00dd13ffad732b5c1Amith Yamasani && n < category.getTilesCount()) { 108263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio category.removeTile(n); 108363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 108463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 108563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio n--; 108663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 108763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 108863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 108963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 109063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio private boolean updateHomeSettingTiles(DashboardTile tile) { 109163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Once we decide to show Home settings, keep showing it forever 109263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE); 109363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) { 109463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio return true; 109563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 109663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 109763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio try { 109863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>(); 109963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio getPackageManager().getHomeActivities(homeApps); 110063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (homeApps.size() < 2) { 110163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // When there's only one available home app, omit this settings 110263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // category entirely at the top level UI. If the user just 110363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // uninstalled the penultimate home app candidiate, we also 110463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // now tell them about why they aren't seeing 'Home' in the list. 110563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (sShowNoHomeNotice) { 110663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sShowNoHomeNotice = false; 110763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio NoHomeDialogFragment.show(this); 110863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 110963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio return false; 111063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 111163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Okay, we're allowing the Home settings category. Tell it, when 111263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // invoked via this front door, that we'll need to be told about the 111363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // case when the user uninstalls all but one home app. 111463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (tile.fragmentArguments == null) { 111563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.fragmentArguments = new Bundle(); 111663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 111763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio tile.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true); 111863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 111963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } catch (Exception e) { 112063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Can't look up the home activity; bail on configuring the icon 112163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio Log.w(LOG_TAG, "Problem looking up home activity!", e); 112263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 112363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 112463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply(); 112563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio return true; 112663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 112763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 112863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio private void insertAccountsTiles(DashboardCategory target) { 112963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio String[] accountTypes = mAuthenticatorHelper.getEnabledAccountTypes(); 113063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio List<DashboardTile> dashboardTiles = new ArrayList<DashboardTile>(accountTypes.length); 113163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio for (String accountType : accountTypes) { 113263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio CharSequence label = mAuthenticatorHelper.getLabelForType(this, accountType); 113363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (label == null) { 113463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio continue; 113563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 113663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 113763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio Account[] accounts = AccountManager.get(this).getAccountsByType(accountType); 113863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio boolean skipToAccount = accounts.length == 1 113963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio && !mAuthenticatorHelper.hasAccountPreferences(accountType); 114063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio DashboardTile accountTile = new DashboardTile(); 114163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accountTile.title = label; 114263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (accountTile.extras == null) { 114363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accountTile.extras = new Bundle(); 114463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 114563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (skipToAccount) { 114663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accountTile.fragment = AccountSyncSettings.class.getName(); 114763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accountTile.fragmentArguments = new Bundle(); 114863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Need this for the icon 114963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accountTile.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); 115063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accountTile.extras.putParcelable(AccountSyncSettings.ACCOUNT_KEY, accounts[0]); 115163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accountTile.fragmentArguments.putParcelable(AccountSyncSettings.ACCOUNT_KEY, 115263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accounts[0]); 115363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } else { 115463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accountTile.fragment = ManageAccountsSettings.class.getName(); 115563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accountTile.fragmentArguments = new Bundle(); 115663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accountTile.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); 115763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accountTile.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, 115863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accountType); 115963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio accountTile.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL, 116063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio label.toString()); 116163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 116263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio dashboardTiles.add(accountTile); 116363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio mAuthenticatorHelper.preloadDrawableForType(this, accountType); 116463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 116563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 116663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio // Sort by label 116763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio Collections.sort(dashboardTiles, new Comparator<DashboardTile>() { 116863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio @Override 116963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio public int compare(DashboardTile t1, DashboardTile t2) { 117063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio return t1.title.toString().compareTo(t2.title.toString()); 117163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 117263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio }); 117363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio int index = 0; 117463bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio for (DashboardTile tile : dashboardTiles) { 117563bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio target.addTile(index, tile); 117663bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio index++; 117763bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 117863bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio if (!mListeningToAccountUpdates) { 117963bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true); 118063bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio mListeningToAccountUpdates = true; 118163bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 118263bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio } 118363bbb8e4fef5d0d0a5fa9c7656daa7ea160fd51bFabrice Di Meglio 1184263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private void getMetaData() { 1185263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio try { 1186263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), 1187263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PackageManager.GET_META_DATA); 1188263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (ai == null || ai.metaData == null) return; 1189263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); 1190263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } catch (NameNotFoundException nnfe) { 1191263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // No recovery 1192263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString()); 1193263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1194263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1195263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1196263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // give subclasses access to the Next button 1197263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean hasNextButton() { 1198263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return mNextButton != null; 1199263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1200263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1201263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Button getNextButton() { 1202263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return mNextButton; 1203263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1204263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1205263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1206263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean shouldUpRecreateTask(Intent targetIntent) { 1207263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class)); 1208263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1209263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1210263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1211263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onAccountsUpdated(Account[] accounts) { 1212263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // TODO: watch for package upgrades to invalidate cache; see 7206643 1213263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mAuthenticatorHelper.updateAuthDescriptions(this); 1214263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mAuthenticatorHelper.onAccountsUpdated(this, accounts); 1215769630c8956fa844545d964166da90cc802fabacFabrice Di Meglio invalidateCategories(); 1216263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1217263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1218263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static void requestHomeNotice() { 1219263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio sShowNoHomeNotice = true; 1220263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1221263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1222d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1223d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onQueryTextSubmit(String query) { 1224d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio switchToSearchResultsFragmentIfNeeded(); 1225d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchQuery = query; 1226d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return mSearchResultsFragment.onQueryTextSubmit(query); 1227d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1228263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1229d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1230d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onQueryTextChange(String newText) { 1231d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchQuery = newText; 12327e4855e8f644bdecf68ec65b8c1b7c08624a4876Fabrice Di Meglio if (mSearchResultsFragment == null) { 1233a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio return false; 1234a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio } 1235a32707664f85b77602d1fe45458e92fce1448ce2Fabrice Di Meglio return mSearchResultsFragment.onQueryTextChange(newText); 1236d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1237263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1238d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1239d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onClose() { 1240d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return false; 1241d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1242263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1243d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1244d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onMenuItemActionExpand(MenuItem item) { 1245d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (item.getItemId() == mSearchMenuItem.getItemId()) { 1246bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio switchToSearchResultsFragmentIfNeeded(); 1247263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1248d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return true; 1249d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1250263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1251d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio @Override 1252d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public boolean onMenuItemActionCollapse(MenuItem item) { 1253d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio if (item.getItemId() == mSearchMenuItem.getItemId()) { 1254bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio if (mSearchMenuItemExpanded) { 1255d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio revertToInitialFragment(); 1256263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1257263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1258d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio return true; 1259d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1260263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1261d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private void switchToSearchResultsFragmentIfNeeded() { 1262bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio if (mSearchResultsFragment != null) { 1263bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio return; 1264263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1265bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio Fragment current = getFragmentManager().findFragmentById(R.id.prefs); 1266bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio if (current != null && current instanceof SearchResultsSummary) { 1267bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio mSearchResultsFragment = (SearchResultsSummary) current; 1268bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio } else { 1269bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio String title = getString(R.string.search_results_title); 1270bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio mSearchResultsFragment = (SearchResultsSummary) switchToFragment( 127141937766981423c9252e12e3319b2e7532739627Fabrice Di Meglio SearchResultsSummary.class.getName(), null, false, true, title, 127259a4055cbb8f5a7b1b0c904bbc4ffc03d8a1239fFabrice Di Meglio true); 1273bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio } 1274d297a5840230b769a3c7ad8b85232968a7077f64Fabrice Di Meglio mSearchResultsFragment.setSearchView(mSearchView); 1275bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio mSearchMenuItemExpanded = true; 1276d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1277263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1278d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio public void needToRevertToInitialFragment() { 1279d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mNeedToRevertToInitialFragment = true; 1280d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio } 1281263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1282d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio private void revertToInitialFragment() { 1283d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mNeedToRevertToInitialFragment = false; 1284d25314d3305ed1a07b53991a978cd71219ef2a10Fabrice Di Meglio mSearchResultsFragment = null; 1285bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio mSearchMenuItemExpanded = false; 1286bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS, 1287bb16fd836a5347413e592acbffa189156b28bc53Fabrice Di Meglio FragmentManager.POP_BACK_STACK_INCLUSIVE); 128823ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio if (mSearchMenuItem != null) { 128923ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio mSearchMenuItem.collapseActionView(); 129023ae00c1d87d64578cd62da1894ee25da531ca11Fabrice Di Meglio } 1291263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1292263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio} 1293