SettingsActivity.java revision 6d534a1da52667c6c41b723d4c203fe0d59a2676
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.app.AlertDialog; 28263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.Dialog; 29263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.DialogFragment; 30263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.app.admin.DevicePolicyManager; 31263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.BroadcastReceiver; 32263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Context; 33263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.Intent; 34263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.IntentFilter; 35263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.SharedPreferences; 36263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ActivityInfo; 37263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager; 38263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.PackageManager.NameNotFoundException; 39263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.pm.ResolveInfo; 40263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.Configuration; 41263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.Resources; 42263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.TypedArray; 43263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.content.res.XmlResourceParser; 44263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.graphics.drawable.Drawable; 45263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.nfc.NfcAdapter; 46263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Bundle; 47263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Handler; 48263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.INetworkManagementService; 49263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Message; 50263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Parcel; 51263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.Parcelable; 52263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.RemoteException; 53263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.ServiceManager; 54263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserHandle; 55263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.os.UserManager; 56263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.Preference; 57263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceFragment; 58263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceManager; 59263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.preference.PreferenceScreen; 60263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.support.v4.app.ActionBarDrawerToggle; 61263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.support.v4.widget.DrawerLayout; 62263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.text.TextUtils; 63263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.AttributeSet; 64263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Log; 65263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.TypedValue; 66263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.util.Xml; 67263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.LayoutInflater; 68263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.MenuItem; 69263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View; 70263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.View.OnClickListener; 71263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.view.ViewGroup; 7210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglioimport android.widget.AbsListView; 73263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.AdapterView; 74263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.ArrayAdapter; 75263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.Button; 76263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.ImageButton; 77263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.ImageView; 78263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.ListView; 79263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.Switch; 80263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport android.widget.TextView; 81263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 82263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.ArrayUtils; 83263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.internal.util.XmlUtils; 84263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.AccessibilitySettings; 85263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accessibility.CaptionPropertiesFragment; 86263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.AccountSyncSettings; 87263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.AuthenticatorHelper; 88263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.accounts.ManageAccountsSettings; 89263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ManageApplications; 90263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.applications.ProcessStatsUi; 91263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.bluetooth.BluetoothEnabler; 92263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.bluetooth.BluetoothSettings; 93263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.dashboard.DashboardSummary; 94263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.deviceinfo.Memory; 95263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.deviceinfo.UsbSettings; 96263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.fuelgauge.PowerUsageSummary; 97263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.InputMethodAndLanguageSettings; 98263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.KeyboardLayoutPickerFragment; 99263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.SpellCheckersSettings; 100263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.inputmethod.UserDictionaryList; 101263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.location.LocationSettings; 102263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.AndroidBeam; 103263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.nfc.PaymentSettings; 104263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintJobSettingsFragment; 105263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.print.PrintSettingsFragment; 106263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.tts.TextToSpeechSettings; 107263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.users.UserSettings; 108263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.vpn2.VpnSettings; 109263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wfd.WifiDisplaySettings; 110263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.AdvancedWifiSettings; 111263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.WifiEnabler; 112263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.WifiSettings; 113263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport com.android.settings.wifi.p2p.WifiP2pSettings; 114263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParser; 115263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport org.xmlpull.v1.XmlPullParserException; 116263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 117263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.io.IOException; 118263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.ArrayList; 119263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.Collections; 120263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.Comparator; 121263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.HashMap; 122263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglioimport java.util.List; 123263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 124263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Megliopublic class SettingsActivity extends Activity 125263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio implements PreferenceManager.OnPreferenceTreeClickListener, 126263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PreferenceFragment.OnPreferenceStartFragmentCallback, 127263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ButtonBarHandler, OnAccountsUpdateListener, FragmentManager.OnBackStackChangedListener { 128263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 129263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String LOG_TAG = "Settings"; 130263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 131263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Constants for state save/restore 1326502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio private static final String SAVE_KEY_HEADERS_TAG = ":settings:headers"; 1336502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio private static final String SAVE_KEY_CURRENT_HEADER_TAG = ":settings:cur_header"; 1345529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio private static final String SAVE_KEY_TITLES_TAG = ":settings:titles"; 135263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 136263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 137263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * When starting this activity, the invoking Intent can contain this extra 138263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * string to specify which fragment should be initially displayed. 139263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity 140263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * will call isValidFragment() to confirm that the fragment class name is valid for this 141263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * activity. 142263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 143263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment"; 144263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 145263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 146263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, 147263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * this extra can also be specified to supply a Bundle of arguments to pass 148263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * to that fragment when it is instantiated during the initial creation 149263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * of the activity. 150263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 151263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args"; 152263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 153263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 154263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * When starting this activity, the invoking Intent can contain this extra 155263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * boolean that the header list should not be displayed. This is most often 156263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * used in conjunction with {@link #EXTRA_SHOW_FRAGMENT} to launch 157263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * the activity to display a specific fragment that the user has navigated 158263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * to. 159263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 160263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static final String EXTRA_NO_HEADERS = ":settings:no_headers"; 161263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice 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 */ 181263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title"; 182263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 183263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String BACK_STACK_PREFS = ":settings:prefs"; 184263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 185263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String META_DATA_KEY_HEADER_ID = 186263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio "com.android.settings.TOP_LEVEL_HEADER_ID"; 187263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 188263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String META_DATA_KEY_FRAGMENT_CLASS = 189263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio "com.android.settings.FRAGMENT_CLASS"; 190263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 191263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String EXTRA_UI_OPTIONS = "settings:ui_options"; 192263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 193263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static boolean sShowNoHomeNotice = false; 194263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 195263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private String mFragmentClass; 196263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private int mTopLevelHeaderId; 197263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private Header mFirstHeader; 1986502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio private Header mSelectedHeader; 199263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private Header mCurrentHeader; 200263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 2018eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio private CharSequence mInitialTitle; 2026d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio private Header mInitialHeader; 2038eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio 204263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Show only these settings for restricted users 205263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private int[] SETTINGS_FOR_RESTRICTED = { 206263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.wireless_section, 207263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.wifi_settings, 208263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.bluetooth_settings, 209263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.data_usage_settings, 210263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.wireless_settings, 211263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.device_section, 212263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.sound_settings, 213263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.display_settings, 214263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.storage_settings, 215263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.application_settings, 216263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.battery_settings, 217263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.personal_section, 218263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.location_settings, 219263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.security_settings, 220263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.language_settings, 221263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.user_settings, 222263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.account_settings, 223263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.account_add, 224263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.system_section, 225263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.date_time_settings, 226263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.about_settings, 227263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.accessibility_settings, 228263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.print_settings, 229263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.id.nfc_payment_settings, 2302858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio R.id.home_settings, 2312858b790ad92bb39e26150d696432f0b717bcddcFabrice Di Meglio R.id.dashboard 232263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 233263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 234263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final String[] ENTRY_FRAGMENTS = { 235263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WirelessSettings.class.getName(), 236263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WifiSettings.class.getName(), 237263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AdvancedWifiSettings.class.getName(), 238263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio BluetoothSettings.class.getName(), 239263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TetherSettings.class.getName(), 240263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WifiP2pSettings.class.getName(), 241263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio VpnSettings.class.getName(), 242263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DateTimeSettings.class.getName(), 243263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio LocalePicker.class.getName(), 244263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio InputMethodAndLanguageSettings.class.getName(), 245263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio SpellCheckersSettings.class.getName(), 246263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UserDictionaryList.class.getName(), 247263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UserDictionarySettings.class.getName(), 248263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio SoundSettings.class.getName(), 249263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DisplaySettings.class.getName(), 250263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DeviceInfoSettings.class.getName(), 251263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ManageApplications.class.getName(), 252263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ProcessStatsUi.class.getName(), 253263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio NotificationStation.class.getName(), 254263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio LocationSettings.class.getName(), 255263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio SecuritySettings.class.getName(), 256263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PrivacySettings.class.getName(), 257263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DeviceAdminSettings.class.getName(), 258263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AccessibilitySettings.class.getName(), 259263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio CaptionPropertiesFragment.class.getName(), 260263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio com.android.settings.accessibility.ToggleInversionPreferenceFragment.class.getName(), 261263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio com.android.settings.accessibility.ToggleContrastPreferenceFragment.class.getName(), 262263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(), 263263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TextToSpeechSettings.class.getName(), 264263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Memory.class.getName(), 265263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DevelopmentSettings.class.getName(), 266263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UsbSettings.class.getName(), 267263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AndroidBeam.class.getName(), 268263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio WifiDisplaySettings.class.getName(), 269263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PowerUsageSummary.class.getName(), 270263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AccountSyncSettings.class.getName(), 271263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio CryptKeeperSettings.class.getName(), 272263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DataUsageSummary.class.getName(), 273263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DreamSettings.class.getName(), 274263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio UserSettings.class.getName(), 275263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio NotificationAccessSettings.class.getName(), 276263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ManageAccountsSettings.class.getName(), 277263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PrintSettingsFragment.class.getName(), 278263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PrintJobSettingsFragment.class.getName(), 279263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TrustedCredentialsSettings.class.getName(), 280263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PaymentSettings.class.getName(), 281263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio KeyboardLayoutPickerFragment.class.getName(), 28272438063453d2141218cf7fa4d8c1da6de6cbf4cJohn Spurlock DashboardSummary.class.getName(), 28372438063453d2141218cf7fa4d8c1da6de6cbf4cJohn Spurlock ZenModeSettings.class.getName() 284263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 285263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 286263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private SharedPreferences mDevelopmentPreferences; 287263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener; 288263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 289263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // TODO: Update Call Settings based on airplane mode state. 290263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 291263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>(); 292263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 293263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private AuthenticatorHelper mAuthenticatorHelper; 294263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private boolean mListeningToAccountUpdates; 295263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 296263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private Button mNextButton; 297263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 298263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private boolean mBatteryPresent = true; 299263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() { 300263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 301263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 302263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onReceive(Context context, Intent intent) { 303263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String action = intent.getAction(); 304263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { 305263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio boolean batteryPresent = Utils.isBatteryPresent(intent); 306263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 307263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mBatteryPresent != batteryPresent) { 308263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mBatteryPresent = batteryPresent; 309263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio invalidateHeaders(); 310263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 311263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 312263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 313263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 314263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 315263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private final ArrayList<Header> mHeaders = new ArrayList<Header>(); 316263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private HeaderAdapter mHeaderAdapter; 317263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 318263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private DrawerLayout mDrawerLayout; 319263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private ListView mDrawer; 320263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private ActionBarDrawerToggle mDrawerToggle; 321263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private ActionBar mActionBar; 322263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 323263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final int MSG_BUILD_HEADERS = 1; 324263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private Handler mHandler = new Handler() { 325263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 326263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void handleMessage(Message msg) { 327263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio switch (msg.what) { 328263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio case MSG_BUILD_HEADERS: { 329263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mHeaders.clear(); 330263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio onBuildHeaders(mHeaders); 331263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mHeaderAdapter.notifyDataSetChanged(); 3326502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio if (mCurrentHeader != null) { 3336502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio Header mappedHeader = findBestMatchingHeader(mCurrentHeader, mHeaders); 334263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mappedHeader != null) { 335263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setSelectedHeader(mappedHeader); 336263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 337263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 338263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } break; 339263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 340263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 341263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 342263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 343263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 344263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { 345263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Override the fragment title for Wallpaper settings 346263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio int titleRes = pref.getTitleRes(); 347263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) { 348263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio titleRes = R.string.wallpaper_settings_fragment_title; 349263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName()) 350263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio && UserHandle.myUserId() != UserHandle.USER_OWNER) { 351263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (UserManager.get(this).isLinkedUser()) { 352263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio titleRes = R.string.profile_info_settings_title; 353263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 354263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio titleRes = R.string.user_info_settings_title; 355263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 356263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 357263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(), 358263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio null, 0); 359263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return true; 360263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 361263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 362263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 363263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { 364263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return false; 365263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 366263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 367263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private class DrawerListener implements DrawerLayout.DrawerListener { 368263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 369263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onDrawerOpened(View drawerView) { 370263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDrawerToggle.onDrawerOpened(drawerView); 371263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 372263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 373263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 374263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onDrawerClosed(View drawerView) { 375263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDrawerToggle.onDrawerClosed(drawerView); 3767ce7c40dac0fa8d27b28b82084d3c3fe7f2f524fFabrice Di Meglio // Cannot process clicks when the App is finishing 377a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio if (isFinishing() || mSelectedHeader == null) { 378a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio return; 379a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio } 3808eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio switchToHeader(mSelectedHeader, false, false); 381a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio mSelectedHeader = null; 382263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 383263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 384263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 385263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onDrawerSlide(View drawerView, float slideOffset) { 386263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDrawerToggle.onDrawerSlide(drawerView, slideOffset); 387263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 388263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 389263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 390263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onDrawerStateChanged(int newState) { 391263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDrawerToggle.onDrawerStateChanged(newState); 392263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 393263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 394263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 395263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private class DrawerItemClickListener implements ListView.OnItemClickListener { 396263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 397263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 398263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDrawerLayout.closeDrawer(mDrawer); 39910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio onListItemClick((ListView)parent, view, position, id); 400263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 401263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 402263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 4036502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio private Header findBestMatchingHeader(Header current, ArrayList<Header> from) { 404263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ArrayList<Header> matches = new ArrayList<Header>(); 405263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio for (int j=0; j<from.size(); j++) { 406263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Header oh = from.get(j); 4076502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio if (current == oh || (current.id != HEADER_ID_UNDEFINED && current.id == oh.id)) { 408263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Must be this one. 409263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio matches.clear(); 410263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio matches.add(oh); 411263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio break; 412263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 4136502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio if (current.fragment != null) { 4146502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio if (current.fragment.equals(oh.fragment)) { 415263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio matches.add(oh); 416263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 4176502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio } else if (current.intent != null) { 4186502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio if (current.intent.equals(oh.intent)) { 419263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio matches.add(oh); 420263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 4216502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio } else if (current.title != null) { 4226502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio if (current.title.equals(oh.title)) { 423263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio matches.add(oh); 424263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 425263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 426263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 427263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio final int NM = matches.size(); 428263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (NM == 1) { 429263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return matches.get(0); 430263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (NM > 1) { 431263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio for (int j=0; j<NM; j++) { 432263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Header oh = matches.get(j); 4336502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio if (current.fragmentArguments != null && 4346502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio current.fragmentArguments.equals(oh.fragmentArguments)) { 435263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return oh; 436263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 4376502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio if (current.extras != null && current.extras.equals(oh.extras)) { 438263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return oh; 439263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 4406502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio if (current.title != null && current.title.equals(oh.title)) { 441263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return oh; 442263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 443263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 444263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 445263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return null; 446263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 447263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 448263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private void invalidateHeaders() { 449263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!mHandler.hasMessages(MSG_BUILD_HEADERS)) { 450263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mHandler.sendEmptyMessage(MSG_BUILD_HEADERS); 451263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 452263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 453263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 454263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 455263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected void onPostCreate(Bundle savedInstanceState) { 456263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onPostCreate(savedInstanceState); 457263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 458263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Sync the toggle state after onRestoreInstanceState has occurred. 4596d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mDrawerToggle.syncState(); 460263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 461263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 462263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 463263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onConfigurationChanged(Configuration newConfig) { 464263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onConfigurationChanged(newConfig); 4656d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mDrawerToggle.onConfigurationChanged(newConfig); 466263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 467263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 468263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 469263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean onOptionsItemSelected(MenuItem item) { 4706d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio if (mDrawerToggle.onOptionsItemSelected(item)) { 471263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return true; 472263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 473263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return super.onOptionsItemSelected(item); 474263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 475263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 476263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 477263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected void onCreate(Bundle savedInstanceState) { 478263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) { 479263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio getWindow().setUiOptions(getIntent().getIntExtra(EXTRA_UI_OPTIONS, 0)); 480263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 481263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 482263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mAuthenticatorHelper = new AuthenticatorHelper(); 483263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mAuthenticatorHelper.updateAuthDescriptions(this); 484263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mAuthenticatorHelper.onAccountsUpdated(this, null); 485263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 486263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DevicePolicyManager dpm = 487263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); 488dca2806a23d202384eb9b37a5026325f8fb08476Fabrice Di Meglio 4896d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mHeaderAdapter= new HeaderAdapter(this, mHeaders, mAuthenticatorHelper, dpm); 490263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 491263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, 492263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Context.MODE_PRIVATE); 493263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 494263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio getMetaData(); 495263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 496263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onCreate(savedInstanceState); 497263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 498263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setContentView(R.layout.settings_main); 499263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 500263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio getFragmentManager().addOnBackStackChangedListener(this); 501263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 502263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mActionBar = getActionBar(); 5036d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mActionBar.setDisplayHomeAsUpEnabled(true); 5046d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mActionBar.setHomeButtonEnabled(true); 505263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 5066d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mDrawer = (ListView) findViewById(R.id.headers_drawer); 5076d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mDrawer.setAdapter(mHeaderAdapter); 5086d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mDrawer.setOnItemClickListener(new DrawerItemClickListener()); 5096d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mDrawer.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); 510263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 5116d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 5126d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, 5136d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close); 514263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 515263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (savedInstanceState != null) { 516263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // We are restarting from a previous saved state; used that to 517263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // initialize, instead of starting fresh. 5188eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio mInitialTitle = getTitle(); 5198eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio setTitleFromBackStack(); 5205529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio 5216502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio ArrayList<Header> headers = 5226502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio savedInstanceState.getParcelableArrayList(SAVE_KEY_HEADERS_TAG); 523263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (headers != null) { 524263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mHeaders.addAll(headers); 5256502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio int curHeader = savedInstanceState.getInt(SAVE_KEY_CURRENT_HEADER_TAG, 526263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio (int) HEADER_ID_UNDEFINED); 527263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (curHeader >= 0 && curHeader < mHeaders.size()) { 528263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setSelectedHeader(mHeaders.get(curHeader)); 5296d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mInitialHeader = mCurrentHeader; 530263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 531263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 532263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 5336d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio String initialFragment = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT); 5346d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); 5356d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio 5366d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio // We need to build the Headers in all cases 5376d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio onBuildHeaders(mHeaders); 5386d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio 539263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (initialFragment != null) { 54010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio // If we are just showing a fragment, we want to run in 54110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio // new fragment mode, but don't need to compute and show 54210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio // the headers. 5438eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio final int initialTitleResId = getIntent().getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE, 0); 5448eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio mInitialTitle = (initialTitleResId > 0) ? getText(initialTitleResId) : getTitle(); 54510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio 5468eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio switchToHeader(initialFragment, initialArguments, true, mInitialTitle); 5476d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio setSelectedHeaderByFragmentName(initialFragment); 5486d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mInitialHeader = mCurrentHeader; 54910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } else { 55010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio // If there are headers, then at this point we need to show 55110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio // them and, depending on the screen, we may also show in-line 55210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio // the currently selected preference fragment. 55310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio if (mHeaders.size() > 0) { 5546d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mInitialHeader = onGetInitialHeader(); 5556d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mInitialTitle = getHeaderTitle(mInitialHeader); 5566d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio switchToHeader(mInitialHeader, false, true); 55710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 558263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 559263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 560263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 561263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // see if we should show Back/Next buttons 562263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Intent intent = getIntent(); 563263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) { 564263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 565263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio View buttonBar = findViewById(com.android.internal.R.id.button_bar); 566263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (buttonBar != null) { 567263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio buttonBar.setVisibility(View.VISIBLE); 568263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 569263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Button backButton = (Button)findViewById(com.android.internal.R.id.back_button); 570263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio backButton.setOnClickListener(new OnClickListener() { 571263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onClick(View v) { 572263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setResult(RESULT_CANCELED); 573263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio finish(); 574263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 575263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 576263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Button skipButton = (Button)findViewById(com.android.internal.R.id.skip_button); 577263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio skipButton.setOnClickListener(new OnClickListener() { 578263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onClick(View v) { 579263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setResult(RESULT_OK); 580263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio finish(); 581263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 582263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 583263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mNextButton = (Button)findViewById(com.android.internal.R.id.next_button); 584263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mNextButton.setOnClickListener(new OnClickListener() { 585263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onClick(View v) { 586263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setResult(RESULT_OK); 587263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio finish(); 588263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 589263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 590263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 591263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // set our various button parameters 592263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) { 593263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT); 594263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (TextUtils.isEmpty(buttonText)) { 595263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mNextButton.setVisibility(View.GONE); 596263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 597263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio else { 598263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mNextButton.setText(buttonText); 599263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 600263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 601263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) { 602263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT); 603263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (TextUtils.isEmpty(buttonText)) { 604263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio backButton.setVisibility(View.GONE); 605263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 606263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio else { 607263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio backButton.setText(buttonText); 608263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 609263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 610263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) { 611263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio skipButton.setVisibility(View.VISIBLE); 612263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 613263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 614263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 615263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 616263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!onIsHidingHeaders()) { 617263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio highlightHeader(mTopLevelHeaderId); 618263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 619263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 620263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 6216d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio public Header onGetInitialHeader() { 6226d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio String fragmentClass = getStartingFragmentClass(super.getIntent()); 6236d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio if (fragmentClass != null) { 6246d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio Header header = new Header(); 6256d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio header.fragment = fragmentClass; 6266d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio header.title = getTitle(); 6276d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio header.fragmentArguments = getIntent().getExtras(); 6286d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio return header; 6296d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio } 6306d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio 6316d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio return mFirstHeader; 6326d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio } 6336d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio 634263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 635263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onBackStackChanged() { 6368eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio setTitleFromBackStack(); 6378eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio } 6388eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio 6398eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio private void setTitleFromBackStack() { 6408eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio final int count = getFragmentManager().getBackStackEntryCount(); 6418eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (count == 0) { 6428eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio setTitle(mInitialTitle); 6438eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio return; 644263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 6458eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1); 6468eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio setTitleFromBackStackEntry(bse); 647263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 648263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 6498eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) { 6505529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio final CharSequence title; 6518eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio final int titleRes = bse.getBreadCrumbTitleRes(); 6528eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (titleRes > 0) { 6538eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio title = getText(titleRes); 6545529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio } else { 6558eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio title = bse.getBreadCrumbTitle(); 6568eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio } 6578eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (title != null) { 6588eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio setTitle(title); 6595529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio } 6605529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio } 6615529d29f6c22e9f28444ca1c0aa9ea2534264220Fabrice Di Meglio 662263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 663263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected void onSaveInstanceState(Bundle outState) { 664263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onSaveInstanceState(outState); 665263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 666263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mHeaders.size() > 0) { 6676502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio outState.putParcelableArrayList(SAVE_KEY_HEADERS_TAG, mHeaders); 6686502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio if (mCurrentHeader != null) { 6696502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio int index = mHeaders.indexOf(mCurrentHeader); 670263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (index >= 0) { 6716502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio outState.putInt(SAVE_KEY_CURRENT_HEADER_TAG, index); 672263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 673263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 674263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 675263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 676263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 677263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 678263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onResume() { 679263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onResume(); 680263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 681263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { 682263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 683263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { 684263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio invalidateHeaders(); 685263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 686263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 687263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferences.registerOnSharedPreferenceChangeListener( 688263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferencesListener); 689263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 690a504c4dcdf18be1be9f67cf83b506638f19077b8Matthew Xie mHeaderAdapter.resume(this); 691263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio invalidateHeaders(); 692263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 693263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); 6947ce7c40dac0fa8d27b28b82084d3c3fe7f2f524fFabrice Di Meglio 6957ce7c40dac0fa8d27b28b82084d3c3fe7f2f524fFabrice Di Meglio mDrawerLayout.setDrawerListener(new DrawerListener()); 696263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 697263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 698263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 699263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onPause() { 700263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onPause(); 701263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 7027ce7c40dac0fa8d27b28b82084d3c3fe7f2f524fFabrice Di Meglio mDrawerLayout.setDrawerListener(null); 7037ce7c40dac0fa8d27b28b82084d3c3fe7f2f524fFabrice Di Meglio 704263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio unregisterReceiver(mBatteryInfoReceiver); 705263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 706263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mHeaderAdapter.pause(); 707263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 708263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener( 709263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferencesListener); 710263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 711263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevelopmentPreferencesListener = null; 712263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 713263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 714263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 715263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onDestroy() { 716263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onDestroy(); 717263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mListeningToAccountUpdates) { 718263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AccountManager.get(this).removeOnAccountsUpdatedListener(this); 719263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 720263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 721263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 722263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio protected boolean isValidFragment(String fragmentName) { 723263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Almost all fragments are wrapped in this, 724263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // except for a few that have their own activities. 725263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) { 726263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true; 727263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 728263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return false; 729263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 730263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 731a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio private CharSequence getHeaderTitle(Header header) { 732a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio final CharSequence title; 733a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio if (header.fragment.equals(DashboardSummary.class.getName())) { 734a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio title = getResources().getString(R.string.settings_label); 735a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio } else { 736a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio title = header.getTitle(getResources()); 737a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio } 738a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio return title; 739a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio } 740a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio 7416d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio 7426d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio private void setSelectedHeaderByFragmentName(String fragmentName) { 7436d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio final int count = mHeaders.size(); 7446d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio for (int n = 0; n < count; n++) { 7456d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio Header h = mHeaders.get(n); 7466d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio if (h.fragment != null && h.fragment.equals(fragmentName)) { 7476d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio setSelectedHeader(h); 7486d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio return; 7496d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio } 7506d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio } 7516d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio } 7526d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio 753263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private void setSelectedHeader(Header header) { 754a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio if (header == null) { 755a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio mCurrentHeader = null; 756a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio return; 757a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio } 758a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio // Update selected Header into Drawer only if it is not "Add Account" 759a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio if (header.id == R.id.account_add) { 760a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio mDrawer.clearChoices(); 761a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio return; 762a7ad619af46baf78f7d6b65a0482aa387f4a6784Fabrice Di Meglio } 7636502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio mCurrentHeader = header; 764263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio int index = mHeaders.indexOf(header); 7656d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio if (index >= 0) { 7666d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mDrawer.setItemChecked(index, true); 7676d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio } else { 7686d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio mDrawer.clearChoices(); 769263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 770263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 771263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 7726d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio /** 7736d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio * When in two-pane mode, switch to the fragment pane to show the given 7746d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio * preference fragment. 7756d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio * 7766d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio * @param header The new header to display. 7776d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio * @param validate true means that the fragment's Header needs to be validated. 7786d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio * @param initial true means that it is the initial Header. 7796d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio */ 7806d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio private void switchToHeader(Header header, boolean validate, boolean initial) { 7816d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio if (header == null) { 7826d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio return; 7836d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio } 7846d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio // For switching to another Header it should be a different one 7856d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio if (mCurrentHeader == null || header.id != mCurrentHeader.id) { 7866d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio if (header.fragment != null) { 7876d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio boolean addToBackStack = !initial && header.id != mInitialHeader.id; 7886d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio switchToHeaderInner(header.fragment, header.fragmentArguments, validate, 7896d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio addToBackStack, getHeaderTitle(header)); 7906d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio setSelectedHeader(header); 7916d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio } else if (header.intent != null) { 7926d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio setSelectedHeader(header); 7936d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio startActivity(header.intent); 7946d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio } else { 7956d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio throw new IllegalStateException( 7966d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio "Can't switch to header that has no Fragment nor Intent"); 7976d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio } 798263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 7994cc95a53c2d9080095c4e1e06f815b8bc7a2cdfeFabrice Di Meglio } 8004cc95a53c2d9080095c4e1e06f815b8bc7a2cdfeFabrice Di Meglio 8014cc95a53c2d9080095c4e1e06f815b8bc7a2cdfeFabrice Di Meglio /** 8028eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio * Switch the fragment pane to show the given preference fragment. 8034cc95a53c2d9080095c4e1e06f815b8bc7a2cdfeFabrice Di Meglio * 8046d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio * (used for initial fragment) 8056d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio * 8064cc95a53c2d9080095c4e1e06f815b8bc7a2cdfeFabrice Di Meglio * @param fragmentName The name of the fragment to display. 8074cc95a53c2d9080095c4e1e06f815b8bc7a2cdfeFabrice Di Meglio * @param args Optional arguments to supply to the fragment. 8086d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio * @param validate true means that the fragment's Header needs to be validated. 8096d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio * @param title The title of the fragment to display. 8104cc95a53c2d9080095c4e1e06f815b8bc7a2cdfeFabrice Di Meglio */ 8118eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio private void switchToHeader(String fragmentName, Bundle args, boolean validate, 8128eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio CharSequence title) { 81310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio setSelectedHeader(null); 8148eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio switchToHeaderInner(fragmentName, args, validate, false, title); 8154cc95a53c2d9080095c4e1e06f815b8bc7a2cdfeFabrice Di Meglio } 8164cc95a53c2d9080095c4e1e06f815b8bc7a2cdfeFabrice Di Meglio 8176d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio /** 8186d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio * Switch to a specific Header with taking care of validation, Title and BackStack 8196d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio */ 8208eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio private void switchToHeaderInner(String fragmentName, Bundle args, boolean validate, 8218eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio boolean addToBackStack, CharSequence title) { 82210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio getFragmentManager().popBackStack(BACK_STACK_PREFS, 82310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio FragmentManager.POP_BACK_STACK_INCLUSIVE); 82410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio if (validate && !isValidFragment(fragmentName)) { 82510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio throw new IllegalArgumentException("Invalid fragment for this activity: " 82610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio + fragmentName); 8274cc95a53c2d9080095c4e1e06f815b8bc7a2cdfeFabrice Di Meglio } 82810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio Fragment f = Fragment.instantiate(this, fragmentName, args); 82910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio FragmentTransaction transaction = getFragmentManager().beginTransaction(); 83010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.replace(R.id.prefs, f); 8318eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 8328eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (addToBackStack) { 8338eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio transaction.addToBackStack(BACK_STACK_PREFS); 8348eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio } 8358eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (title != null) { 8368eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio transaction.setBreadCrumbTitle(title); 8378eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio } 838263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio transaction.commitAllowingStateLoss(); 839263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 840263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 841263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 842263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onNewIntent(Intent intent) { 843263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super.onNewIntent(intent); 844263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 845263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // If it is not launched from history, then reset to top-level 846263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) { 847263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mDrawer != null) { 848263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDrawer.setSelectionFromTop(0, 0); 849263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 850263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 851263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 852263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 853263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 854263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Called to determine whether the header list should be hidden. 855263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * The default implementation returns the 856263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * value given in {@link #EXTRA_NO_HEADERS} or false if it is not supplied. 857263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * This is set to false, for example, when the activity is being re-launched 858263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * to show a particular preference activity. 859263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 860263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean onIsHidingHeaders() { 861263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return getIntent().getBooleanExtra(EXTRA_NO_HEADERS, false); 862263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 863263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 864263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private void highlightHeader(int id) { 865263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (id != 0) { 866263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Integer index = mHeaderIndexMap.get(id); 867263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (index != null && mDrawer != null) { 868263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDrawer.setItemChecked(index, true); 869263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mDrawer.getVisibility() == View.VISIBLE) { 870263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDrawer.smoothScrollToPosition(index); 871263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 872263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 873263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 874263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 875263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 876263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 877263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Intent getIntent() { 878263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Intent superIntent = super.getIntent(); 879263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String startingFragment = getStartingFragmentClass(superIntent); 880263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // This is called from super.onCreate, isMultiPane() is not yet reliable 881263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Do not use onIsHidingHeaders either, which relies itself on this method 882263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (startingFragment != null) { 883263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Intent modIntent = new Intent(superIntent); 884263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); 885263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Bundle args = superIntent.getExtras(); 886263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (args != null) { 887263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio args = new Bundle(args); 888263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 889263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio args = new Bundle(); 890263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 891263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio args.putParcelable("intent", superIntent); 892263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, superIntent.getExtras()); 893263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return modIntent; 894263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 895263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return superIntent; 896263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 897263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 898263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 899263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Checks if the component name in the intent is different from the Settings class and 900263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * returns the class name to load as a fragment. 901263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 902263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private String getStartingFragmentClass(Intent intent) { 903263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mFragmentClass != null) return mFragmentClass; 904263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 905263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String intentClass = intent.getComponent().getClassName(); 906263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intentClass.equals(getClass().getName())) return null; 907263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 908263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if ("com.android.settings.ManageApplications".equals(intentClass) 909263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio || "com.android.settings.RunningServices".equals(intentClass) 910263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio || "com.android.settings.applications.StorageUse".equals(intentClass)) { 911263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Old names of manage apps. 912263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio intentClass = com.android.settings.applications.ManageApplications.class.getName(); 913263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 914263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 915263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return intentClass; 916263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 917263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 918263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 91910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * Start a new fragment containing a preference panel. If the preferences 92010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * are being displayed in multi-pane mode, the given fragment class will 92110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * be instantiated and placed in the appropriate pane. If running in 92210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * single-pane mode, a new activity will be launched in which to show the 92310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * fragment. 92410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * 92510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param fragmentClass Full name of the class implementing the fragment. 92610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param args Any desired arguments to supply to the fragment. 92710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param titleRes Optional resource identifier of the title of this 92810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * fragment. 92910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param titleText Optional text of the title of this fragment. 93010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param resultTo Optional fragment that result data should be sent to. 93110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * If non-null, resultTo.onActivityResult() will be called when this 93210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * preference panel is done. The launched panel must use 93310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * {@link #finishPreferencePanel(Fragment, int, Intent)} when done. 93410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param resultRequestCode If resultTo is non-null, this is the caller's 93510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * request code to be received with the resut. 93610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio */ 93710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes, 93810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio CharSequence titleText, Fragment resultTo, 93910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio int resultRequestCode) { 94010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio startWithFragment(fragmentClass, args, resultTo, resultRequestCode, titleRes, titleText); 94110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 94210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio 94310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio /** 944263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Called by a preference panel fragment to finish itself. 945263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * 946263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param caller The fragment that is asking to be finished. 947263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param resultCode Optional result code to send back to the original 948263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * launching fragment. 949263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param resultData Optional result data to send back to the original 950263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * launching fragment. 951263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 952263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) { 953263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setResult(resultCode, resultData); 954263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 955263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 956263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 95710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * Start a new fragment. 95810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * 95910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param fragment The fragment to start 96010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param push If true, the current fragment will be pushed onto the back stack. If false, 96110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * the current fragment will be replaced. 96210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio */ 96310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio public void startPreferenceFragment(Fragment fragment, boolean push) { 96410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio FragmentTransaction transaction = getFragmentManager().beginTransaction(); 96510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.replace(R.id.prefs, fragment); 96610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio if (push) { 96710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 96810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.addToBackStack(BACK_STACK_PREFS); 96910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } else { 97010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 97110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 97210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.commitAllowingStateLoss(); 97310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 97410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio 97510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio /** 97610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * Start a new fragment. 97710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * 97810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param fragmentName The name of the fragment to display. 97910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param args Optional arguments to supply to the fragment. 98010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param resultTo Option fragment that should receive the result of 98110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * the activity launch. 98210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param resultRequestCode If resultTo is non-null, this is the request code in which to 98310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * report the result. 98410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param titleRes Resource ID of string to display for the title of. If the Resource ID is a 98510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * valid one then it will be used to get the title. Otherwise the titleText 98610afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * argument will be used as the title. 98710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio * @param titleText string to display for the title of. 98810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio */ 98910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio private void startWithFragment(String fragmentName, Bundle args, Fragment resultTo, 99010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio int resultRequestCode, int titleRes, CharSequence titleText) { 9918eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio final CharSequence cs; 9928eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio if (titleRes != 0) { 9938eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio cs = getText(titleRes); 9948eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio } else { 9958eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio cs = titleText; 9968eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio } 9978eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio 99810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio Fragment f = Fragment.instantiate(this, fragmentName, args); 99910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio if (resultTo != null) { 100010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio f.setTargetFragment(resultTo, resultRequestCode); 100110afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 100210afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio FragmentTransaction transaction = getFragmentManager().beginTransaction(); 100310afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.replace(R.id.prefs, f); 100410afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 100510afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.addToBackStack(BACK_STACK_PREFS); 10068eb3f0fbf2ced7291167755fe74ce50164eb3a9eFabrice Di Meglio transaction.setBreadCrumbTitle(cs); 100710afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio transaction.commitAllowingStateLoss(); 100810afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio } 100910afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio 101010afdb82aca7c6345d2aace30c7b66238e6bfb3cFabrice Di Meglio /** 10116d534a1da52667c6c41b723d4c203fe0d59a2676Fabrice Di Meglio * Called when the activity needs its list of headers build. 1012263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * 1013263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param headers The list in which to place the headers. 1014263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1015263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private void onBuildHeaders(List<Header> headers) { 1016263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio loadHeadersFromResource(R.xml.settings_headers, headers); 1017263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio updateHeaderList(headers); 1018263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1019263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1020263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1021263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Parse the given XML file as a header description, adding each 1022263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * parsed Header into the target list. 1023263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * 1024263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param resid The XML resource to load and parse. 1025263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @param target The list in which the parsed headers should be placed. 1026263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1027263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private void loadHeadersFromResource(int resid, List<Header> target) { 1028263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio XmlResourceParser parser = null; 1029263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio try { 1030263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio parser = getResources().getXml(resid); 1031263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AttributeSet attrs = Xml.asAttributeSet(parser); 1032263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1033263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio int type; 1034263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 1035263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio && type != XmlPullParser.START_TAG) { 1036263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Parse next until start tag is found 1037263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1038263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1039263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String nodeName = parser.getName(); 1040263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!"preference-headers".equals(nodeName)) { 1041263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio throw new RuntimeException( 1042263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio "XML document must start with <preference-headers> tag; found" 1043263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio + nodeName + " at " + parser.getPositionDescription()); 1044263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1045263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1046263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Bundle curBundle = null; 1047263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1048263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio final int outerDepth = parser.getDepth(); 1049263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 1050263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { 1051263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 1052263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio continue; 1053263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1054263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1055263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio nodeName = parser.getName(); 1056263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if ("header".equals(nodeName)) { 1057263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Header header = new Header(); 1058263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1059263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TypedArray sa = obtainStyledAttributes( 1060263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio attrs, com.android.internal.R.styleable.PreferenceHeader); 1061263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio header.id = sa.getResourceId( 1062263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_id, 1063263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio (int)HEADER_ID_UNDEFINED); 1064263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TypedValue tv = sa.peekValue( 1065263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_title); 1066263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (tv != null && tv.type == TypedValue.TYPE_STRING) { 1067263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (tv.resourceId != 0) { 1068263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio header.titleRes = tv.resourceId; 1069263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1070263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio header.title = tv.string; 1071263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1072263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1073263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio tv = sa.peekValue( 1074263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_summary); 1075263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (tv != null && tv.type == TypedValue.TYPE_STRING) { 1076263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (tv.resourceId != 0) { 1077263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio header.summaryRes = tv.resourceId; 1078263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1079263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio header.summary = tv.string; 1080263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1081263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1082263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio header.iconRes = sa.getResourceId( 1083263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_icon, 0); 1084263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio header.fragment = sa.getString( 1085263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio com.android.internal.R.styleable.PreferenceHeader_fragment); 1086263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio sa.recycle(); 1087263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1088263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (curBundle == null) { 1089263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio curBundle = new Bundle(); 1090263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1091263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1092263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio final int innerDepth = parser.getDepth(); 1093263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 1094263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { 1095263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { 1096263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio continue; 1097263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1098263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1099263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String innerNodeName = parser.getName(); 1100263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (innerNodeName.equals("extra")) { 1101263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio getResources().parseBundleExtra("extra", attrs, curBundle); 1102263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio XmlUtils.skipCurrentTag(parser); 1103263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1104263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (innerNodeName.equals("intent")) { 1105263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio header.intent = Intent.parseIntent(getResources(), parser, attrs); 1106263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1107263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1108263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio XmlUtils.skipCurrentTag(parser); 1109263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1110263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1111263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1112263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (curBundle.size() > 0) { 1113263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio header.fragmentArguments = curBundle; 1114263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio curBundle = null; 1115263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1116263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1117263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio target.add(header); 1118263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1119263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio XmlUtils.skipCurrentTag(parser); 1120263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1121263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1122263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1123263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } catch (XmlPullParserException e) { 1124263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio throw new RuntimeException("Error parsing headers", e); 1125263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } catch (IOException e) { 1126263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio throw new RuntimeException("Error parsing headers", e); 1127263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } finally { 1128263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (parser != null) parser.close(); 1129263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1130263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1131263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1132263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private void updateHeaderList(List<Header> target) { 1133263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio final boolean showDev = mDevelopmentPreferences.getBoolean( 1134263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio DevelopmentSettings.PREF_SHOW, 1135263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio android.os.Build.TYPE.equals("eng")); 1136263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio int i = 0; 1137263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1138263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); 1139263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mHeaderIndexMap.clear(); 1140263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio while (i < target.size()) { 1141263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Header header = target.get(i); 1142263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Ids are integers, so downcasting 1143263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio int id = (int) header.id; 1144263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (id == R.id.operator_settings || id == R.id.manufacturer_settings) { 1145263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header); 1146263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (id == R.id.wifi_settings) { 1147263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Remove WiFi Settings if WiFi service is not available. 1148263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) { 1149263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio target.remove(i); 1150263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1151263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (id == R.id.bluetooth_settings) { 1152263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Remove Bluetooth Settings if Bluetooth service is not available. 1153263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) { 1154263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio target.remove(i); 1155263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1156263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (id == R.id.data_usage_settings) { 1157263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Remove data usage when kernel module not enabled 1158263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio final INetworkManagementService netManager = INetworkManagementService.Stub 1159263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)); 1160263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio try { 1161263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!netManager.isBandwidthControlEnabled()) { 1162263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio target.remove(i); 1163263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1164263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } catch (RemoteException e) { 1165263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // ignored 1166263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1167263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (id == R.id.battery_settings) { 1168263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Remove battery settings when battery is not available. (e.g. TV) 1169263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1170263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!mBatteryPresent) { 1171263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio target.remove(i); 1172263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1173263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (id == R.id.account_settings) { 1174263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio int headerIndex = i + 1; 1175263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio i = insertAccountsHeaders(target, headerIndex); 1176263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (id == R.id.home_settings) { 1177263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!updateHomeSettingHeaders(header)) { 1178263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio target.remove(i); 1179263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1180263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (id == R.id.user_settings) { 1181263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!UserHandle.MU_ENABLED 1182263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio || !UserManager.supportsMultipleUsers() 1183263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio || Utils.isMonkeyRunning()) { 1184263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio target.remove(i); 1185263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1186263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (id == R.id.nfc_payment_settings) { 1187263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) { 1188263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio target.remove(i); 1189263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1190263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Only show if NFC is on and we have the HCE feature 1191263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); 1192263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!adapter.isEnabled() || !getPackageManager().hasSystemFeature( 1193263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) { 1194263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio target.remove(i); 1195263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1196263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1197263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (id == R.id.development_settings) { 1198263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!showDev) { 1199263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio target.remove(i); 1200263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1201263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (id == R.id.account_add) { 1202263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) { 1203263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio target.remove(i); 1204263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1205263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1206263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1207263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (i < target.size() && target.get(i) == header 1208263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio && UserHandle.MU_ENABLED && UserHandle.myUserId() != 0 1209263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) { 1210263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio target.remove(i); 1211263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1212263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1213263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Increment if the current one wasn't removed by the Utils code. 1214263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (i < target.size() && target.get(i) == header) { 1215263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Hold on to the first header, when we need to reset to the top-level 1216263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (mFirstHeader == null && 1217263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio HeaderAdapter.getHeaderType(header) != HeaderAdapter.HEADER_TYPE_CATEGORY) { 1218263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mFirstHeader = header; 1219263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1220263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mHeaderIndexMap.put(id, i); 1221263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio i++; 1222263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1223263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1224263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1225263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1226263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private int insertAccountsHeaders(List<Header> target, int headerIndex) { 1227263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String[] accountTypes = mAuthenticatorHelper.getEnabledAccountTypes(); 1228263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio List<Header> accountHeaders = new ArrayList<Header>(accountTypes.length); 1229263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio for (String accountType : accountTypes) { 1230263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio CharSequence label = mAuthenticatorHelper.getLabelForType(this, accountType); 1231263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (label == null) { 1232263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio continue; 1233263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1234263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1235263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Account[] accounts = AccountManager.get(this).getAccountsByType(accountType); 1236263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio boolean skipToAccount = accounts.length == 1 1237263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio && !mAuthenticatorHelper.hasAccountPreferences(accountType); 1238263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Header accHeader = new Header(); 1239263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accHeader.title = label; 1240263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (accHeader.extras == null) { 1241263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accHeader.extras = new Bundle(); 1242263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1243263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (skipToAccount) { 1244263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accHeader.fragment = AccountSyncSettings.class.getName(); 1245263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accHeader.fragmentArguments = new Bundle(); 1246263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Need this for the icon 1247263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accHeader.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); 1248263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accHeader.extras.putParcelable(AccountSyncSettings.ACCOUNT_KEY, accounts[0]); 1249263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accHeader.fragmentArguments.putParcelable(AccountSyncSettings.ACCOUNT_KEY, 1250263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accounts[0]); 1251263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1252263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accHeader.fragment = ManageAccountsSettings.class.getName(); 1253263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accHeader.fragmentArguments = new Bundle(); 1254263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accHeader.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); 1255263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, 1256263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accountType); 1257263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL, 1258263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio label.toString()); 1259263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1260263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio accountHeaders.add(accHeader); 1261263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mAuthenticatorHelper.preloadDrawableForType(this, accountType); 1262263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1263263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1264263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Sort by label 1265263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Collections.sort(accountHeaders, new Comparator<Header>() { 1266263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1267263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public int compare(Header h1, Header h2) { 1268263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return h1.title.toString().compareTo(h2.title.toString()); 1269263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1270263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 1271263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1272263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio for (Header header : accountHeaders) { 1273263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio target.add(headerIndex++, header); 1274263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1275263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!mListeningToAccountUpdates) { 1276263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true); 1277263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mListeningToAccountUpdates = true; 1278263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1279263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return headerIndex; 1280263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1281263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1282263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private boolean updateHomeSettingHeaders(Header header) { 1283263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Once we decide to show Home settings, keep showing it forever 1284263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE); 1285263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) { 1286263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return true; 1287263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1288263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1289263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio try { 1290263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>(); 1291263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio getPackageManager().getHomeActivities(homeApps); 1292263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (homeApps.size() < 2) { 1293263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // When there's only one available home app, omit this settings 1294263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // category entirely at the top level UI. If the user just 1295263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // uninstalled the penultimate home app candidiate, we also 1296263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // now tell them about why they aren't seeing 'Home' in the list. 1297263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (sShowNoHomeNotice) { 1298263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio sShowNoHomeNotice = false; 1299263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio NoHomeDialogFragment.show(this); 1300263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1301263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return false; 1302263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1303263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Okay, we're allowing the Home settings category. Tell it, when 1304263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // invoked via this front door, that we'll need to be told about the 1305263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // case when the user uninstalls all but one home app. 1306263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (header.fragmentArguments == null) { 1307263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio header.fragmentArguments = new Bundle(); 1308263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1309263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio header.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true); 1310263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1311263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } catch (Exception e) { 1312263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Can't look up the home activity; bail on configuring the icon 1313263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Log.w(LOG_TAG, "Problem looking up home activity!", e); 1314263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1315263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1316263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply(); 1317263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return true; 1318263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1319263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1320263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private void getMetaData() { 1321263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio try { 1322263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), 1323263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio PackageManager.GET_META_DATA); 1324263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (ai == null || ai.metaData == null) return; 1325263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mTopLevelHeaderId = ai.metaData.getInt(META_DATA_KEY_HEADER_ID); 1326263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); 1327263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } catch (NameNotFoundException nnfe) { 1328263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // No recovery 1329263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString()); 1330263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1331263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1332263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1333263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // give subclasses access to the Next button 1334263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean hasNextButton() { 1335263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return mNextButton != null; 1336263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1337263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1338263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Button getNextButton() { 1339263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return mNextButton; 1340263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1341263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1342263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static class NoHomeDialogFragment extends DialogFragment { 1343263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static void show(Activity parent) { 1344263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio final NoHomeDialogFragment dialog = new NoHomeDialogFragment(); 1345263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio dialog.show(parent.getFragmentManager(), null); 1346263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1347263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1348263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1349263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Dialog onCreateDialog(Bundle savedInstanceState) { 1350263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return new AlertDialog.Builder(getActivity()) 1351263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio .setMessage(R.string.only_one_home_message) 1352263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio .setPositiveButton(android.R.string.ok, null) 1353263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio .create(); 1354263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1355263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1356263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1357263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static class HeaderAdapter extends ArrayAdapter<Header> { 1358263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio static final int HEADER_TYPE_CATEGORY = 0; 1359263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio static final int HEADER_TYPE_NORMAL = 1; 1360263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio static final int HEADER_TYPE_SWITCH = 2; 1361263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio static final int HEADER_TYPE_BUTTON = 3; 1362263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final int HEADER_TYPE_COUNT = HEADER_TYPE_BUTTON + 1; 1363263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1364263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private final WifiEnabler mWifiEnabler; 1365263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private final BluetoothEnabler mBluetoothEnabler; 1366263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private AuthenticatorHelper mAuthHelper; 1367263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private DevicePolicyManager mDevicePolicyManager; 1368263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1369263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static class HeaderViewHolder { 1370263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ImageView mIcon; 1371263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TextView mTitle; 1372263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TextView mSummary; 1373263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Switch mSwitch; 1374263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ImageButton mButton; 1375263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio View mDivider; 1376263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1377263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1378263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private LayoutInflater mInflater; 1379263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1380263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio static int getHeaderType(Header header) { 1381263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (header.fragment == null && header.intent == null) { 1382263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return HEADER_TYPE_CATEGORY; 1383263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else if (header.id == R.id.security_settings) { 1384263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return HEADER_TYPE_BUTTON; 1385263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1386263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return HEADER_TYPE_NORMAL; 1387263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1388263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1389263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1390263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1391263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public int getItemViewType(int position) { 1392263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Header header = getItem(position); 1393263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return getHeaderType(header); 1394263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1395263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1396263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1397263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean areAllItemsEnabled() { 1398263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return false; // because of categories 1399263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1400263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1401263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1402263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean isEnabled(int position) { 1403263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return getItemViewType(position) != HEADER_TYPE_CATEGORY; 1404263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1405263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1406263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1407263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public int getViewTypeCount() { 1408263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return HEADER_TYPE_COUNT; 1409263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1410263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1411263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1412263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean hasStableIds() { 1413263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return true; 1414263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1415263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1416263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public HeaderAdapter(Context context, List<Header> objects, 1417263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio AuthenticatorHelper authenticatorHelper, DevicePolicyManager dpm) { 1418263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio super(context, 0, objects); 1419263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1420263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mAuthHelper = authenticatorHelper; 1421263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 1422263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1423263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Temp Switches provided as placeholder until the adapter replaces these with actual 1424263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Switches inflated from their layouts. Must be done before adapter is set in super 1425263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mWifiEnabler = new WifiEnabler(context, new Switch(context)); 1426263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mBluetoothEnabler = new BluetoothEnabler(context, new Switch(context)); 1427263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mDevicePolicyManager = dpm; 1428263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1429263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1430263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1431263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public View getView(int position, View convertView, ViewGroup parent) { 1432263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio HeaderViewHolder holder; 1433263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Header header = getItem(position); 1434263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio int headerType = getHeaderType(header); 1435263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio View view = null; 1436263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1437263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (convertView == null) { 1438263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder = new HeaderViewHolder(); 1439263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio switch (headerType) { 1440263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio case HEADER_TYPE_CATEGORY: 1441263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio view = new TextView(getContext(), null, 1442263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio android.R.attr.listSeparatorTextViewStyle); 1443263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mTitle = (TextView) view; 1444263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio break; 1445263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1446263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio case HEADER_TYPE_SWITCH: 1447263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio view = mInflater.inflate(R.layout.preference_header_switch_item, parent, 1448263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio false); 1449263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mIcon = (ImageView) view.findViewById(R.id.icon); 1450263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mTitle = (TextView) 1451263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio view.findViewById(com.android.internal.R.id.title); 1452263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mSummary = (TextView) 1453263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio view.findViewById(com.android.internal.R.id.summary); 1454263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mSwitch = (Switch) view.findViewById(R.id.switchWidget); 1455263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio break; 1456263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1457263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio case HEADER_TYPE_BUTTON: 1458263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio view = mInflater.inflate(R.layout.preference_header_button_item, parent, 1459263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio false); 1460263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mIcon = (ImageView) view.findViewById(R.id.icon); 1461263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mTitle = (TextView) 1462263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio view.findViewById(com.android.internal.R.id.title); 1463263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mSummary = (TextView) 1464263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio view.findViewById(com.android.internal.R.id.summary); 1465263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mButton = (ImageButton) view.findViewById(R.id.buttonWidget); 1466263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mDivider = view.findViewById(R.id.divider); 1467263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio break; 1468263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1469263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio case HEADER_TYPE_NORMAL: 1470263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio view = mInflater.inflate( 1471263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.layout.preference_header_item, parent, 1472263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio false); 1473263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mIcon = (ImageView) view.findViewById(R.id.icon); 1474263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mTitle = (TextView) 1475263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio view.findViewById(com.android.internal.R.id.title); 1476263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mSummary = (TextView) 1477263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio view.findViewById(com.android.internal.R.id.summary); 1478263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio break; 1479263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 14800e2f949c90cc3057243020b51f1bdada02fd87fdFabrice Di Meglio if (holder.mIcon != null) { 14810e2f949c90cc3057243020b51f1bdada02fd87fdFabrice Di Meglio holder.mIcon.setBackgroundResource(R.color.background_drawer_icon); 14820e2f949c90cc3057243020b51f1bdada02fd87fdFabrice Di Meglio } 1483263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio view.setTag(holder); 1484263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1485263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio view = convertView; 1486263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder = (HeaderViewHolder) view.getTag(); 1487263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1488263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1489263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // All view fields must be updated every time, because the view may be recycled 1490263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio switch (headerType) { 1491263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio case HEADER_TYPE_CATEGORY: 1492263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mTitle.setText(header.getTitle(getContext().getResources())); 1493263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio break; 1494263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1495263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio case HEADER_TYPE_SWITCH: 1496263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Would need a different treatment if the main menu had more switches 1497263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (header.id == R.id.wifi_settings) { 1498263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mWifiEnabler.setSwitch(holder.mSwitch); 1499263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1500263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mBluetoothEnabler.setSwitch(holder.mSwitch); 1501263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1502263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio updateCommonHeaderView(header, holder); 1503263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio break; 1504263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1505263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio case HEADER_TYPE_BUTTON: 1506263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (header.id == R.id.security_settings) { 1507263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio boolean hasCert = DevicePolicyManager.hasAnyCaCertsInstalled(); 1508263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (hasCert) { 1509263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mButton.setVisibility(View.VISIBLE); 1510263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mDivider.setVisibility(View.VISIBLE); 1511263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio boolean isManaged = mDevicePolicyManager.getDeviceOwner() != null; 1512263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (isManaged) { 1513263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mButton.setImageResource(R.drawable.ic_settings_about); 1514263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1515263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mButton.setImageResource( 1516263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio android.R.drawable.stat_notify_error); 1517263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1518263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mButton.setOnClickListener(new OnClickListener() { 1519263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1520263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onClick(View v) { 1521263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Intent intent = new Intent( 1522263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio android.provider.Settings.ACTION_MONITORING_CERT_INFO); 1523263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio getContext().startActivity(intent); 1524263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1525263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }); 1526263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1527263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mButton.setVisibility(View.GONE); 1528263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mDivider.setVisibility(View.GONE); 1529263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1530263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1531263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio updateCommonHeaderView(header, holder); 1532263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio break; 1533263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1534263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio case HEADER_TYPE_NORMAL: 1535263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio updateCommonHeaderView(header, holder); 1536263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio break; 1537263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1538263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1539263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return view; 1540263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1541263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1542263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private void updateCommonHeaderView(Header header, HeaderViewHolder holder) { 1543263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (header.extras != null 1544263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio && header.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) { 1545263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio String accType = header.extras.getString( 1546263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ManageAccountsSettings.KEY_ACCOUNT_TYPE); 1547263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType); 1548263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio setHeaderIcon(holder, icon); 1549263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1550263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mIcon.setImageResource(header.iconRes); 1551263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1552263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mTitle.setText(header.getTitle(getContext().getResources())); 1553263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio CharSequence summary = header.getSummary(getContext().getResources()); 1554263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!TextUtils.isEmpty(summary)) { 1555263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mSummary.setVisibility(View.VISIBLE); 1556263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mSummary.setText(summary); 1557263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1558263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mSummary.setVisibility(View.GONE); 1559263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1560263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1561263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1562263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private void setHeaderIcon(HeaderViewHolder holder, Drawable icon) { 1563263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio ViewGroup.LayoutParams lp = holder.mIcon.getLayoutParams(); 1564263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio lp.width = getContext().getResources().getDimensionPixelSize( 1565263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio R.dimen.header_icon_width); 1566263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio lp.height = lp.width; 1567263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mIcon.setLayoutParams(lp); 1568263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio holder.mIcon.setImageDrawable(icon); 1569263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1570263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1571a504c4dcdf18be1be9f67cf83b506638f19077b8Matthew Xie public void resume(Context context) { 1572263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mWifiEnabler.resume(); 1573a504c4dcdf18be1be9f67cf83b506638f19077b8Matthew Xie mBluetoothEnabler.resume(context); 1574263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1575263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1576263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void pause() { 1577263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mWifiEnabler.pause(); 1578263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mBluetoothEnabler.pause(); 1579263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1580263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1581263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1582263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private void onListItemClick(ListView l, View v, int position, long id) { 1583263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (!isResumed()) { 1584263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return; 1585263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1586263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Object item = mHeaderAdapter.getItem(position); 1587263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (item instanceof Header) { 15886502720566595543b1fbb79370319a0dd700036fFabrice Di Meglio mSelectedHeader = (Header) item; 1589263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1590263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1591263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1592263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1593263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public boolean shouldUpRecreateTask(Intent targetIntent) { 1594263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class)); 1595263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1596263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1597263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1598263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void onAccountsUpdated(Account[] accounts) { 1599263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // TODO: watch for package upgrades to invalidate cache; see 7206643 1600263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mAuthenticatorHelper.updateAuthDescriptions(this); 1601263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio mAuthenticatorHelper.onAccountsUpdated(this, accounts); 1602263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio invalidateHeaders(); 1603263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1604263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1605263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static void requestHomeNotice() { 1606263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio sShowNoHomeNotice = true; 1607263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1608263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1609263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1610263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Default value for {@link Header#id Header.id} indicating that no 1611263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * identifier value is set. All other values (including those below -1) 1612263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * are valid. 1613263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1614263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio private static final long HEADER_ID_UNDEFINED = -1; 1615263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1616263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1617263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Description of a single Header item that the user can select. 1618263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1619263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio static final class Header implements Parcelable { 1620263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1621263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Identifier for this header, to correlate with a new list when 1622263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * it is updated. The default value is 1623263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * {@link SettingsActivity#HEADER_ID_UNDEFINED}, meaning no id. 1624263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @attr ref android.R.styleable#PreferenceHeader_id 1625263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1626263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public long id = HEADER_ID_UNDEFINED; 1627263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1628263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1629263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Resource ID of title of the header that is shown to the user. 1630263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @attr ref android.R.styleable#PreferenceHeader_title 1631263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1632263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public int titleRes; 1633263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1634263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1635263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Title of the header that is shown to the user. 1636263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @attr ref android.R.styleable#PreferenceHeader_title 1637263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1638263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public CharSequence title; 1639263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1640263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1641263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Resource ID of optional summary describing what this header controls. 1642263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @attr ref android.R.styleable#PreferenceHeader_summary 1643263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1644263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public int summaryRes; 1645263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1646263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1647263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Optional summary describing what this header controls. 1648263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @attr ref android.R.styleable#PreferenceHeader_summary 1649263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1650263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public CharSequence summary; 1651263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1652263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1653263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Optional icon resource to show for this header. 1654263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @attr ref android.R.styleable#PreferenceHeader_icon 1655263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1656263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public int iconRes; 1657263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1658263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1659263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Full class name of the fragment to display when this header is 1660263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * selected. 1661263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * @attr ref android.R.styleable#PreferenceHeader_fragment 1662263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1663263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public String fragment; 1664263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1665263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1666263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Optional arguments to supply to the fragment when it is 1667263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * instantiated. 1668263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1669263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Bundle fragmentArguments; 1670263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1671263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1672263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Intent to launch when the preference is selected. 1673263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1674263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Intent intent; 1675263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1676263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1677263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Optional additional data for use by subclasses of the activity 1678263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1679263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Bundle extras; 1680263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1681263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Header() { 1682263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio // Empty 1683263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1684263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1685263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1686263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Return the currently set title. If {@link #titleRes} is set, 1687263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * this resource is loaded from <var>res</var> and returned. Otherwise 1688263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * {@link #title} is returned. 1689263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1690263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public CharSequence getTitle(Resources res) { 1691263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (titleRes != 0) { 1692263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return res.getText(titleRes); 1693263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1694263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return title; 1695263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1696263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1697263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio /** 1698263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * Return the currently set summary. If {@link #summaryRes} is set, 1699263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * this resource is loaded from <var>res</var> and returned. Otherwise 1700263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio * {@link #summary} is returned. 1701263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio */ 1702263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public CharSequence getSummary(Resources res) { 1703263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (summaryRes != 0) { 1704263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return res.getText(summaryRes); 1705263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1706263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return summary; 1707263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1708263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1709263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1710263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public int describeContents() { 1711263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return 0; 1712263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1713263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1714263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio @Override 1715263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void writeToParcel(Parcel dest, int flags) { 1716263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio dest.writeLong(id); 1717263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio dest.writeInt(titleRes); 1718263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TextUtils.writeToParcel(title, dest, flags); 1719263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio dest.writeInt(summaryRes); 1720263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio TextUtils.writeToParcel(summary, dest, flags); 1721263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio dest.writeInt(iconRes); 1722263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio dest.writeString(fragment); 1723263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio dest.writeBundle(fragmentArguments); 1724263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (intent != null) { 1725263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio dest.writeInt(1); 1726263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio intent.writeToParcel(dest, flags); 1727263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } else { 1728263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio dest.writeInt(0); 1729263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1730263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio dest.writeBundle(extras); 1731263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1732263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1733263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public void readFromParcel(Parcel in) { 1734263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio id = in.readLong(); 1735263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio titleRes = in.readInt(); 1736263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); 1737263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio summaryRes = in.readInt(); 1738263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); 1739263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio iconRes = in.readInt(); 1740263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio fragment = in.readString(); 1741263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio fragmentArguments = in.readBundle(); 1742263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio if (in.readInt() != 0) { 1743263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio intent = Intent.CREATOR.createFromParcel(in); 1744263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1745263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio extras = in.readBundle(); 1746263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1747263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1748263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio Header(Parcel in) { 1749263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio readFromParcel(in); 1750263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1751263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio 1752263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public static final Creator<Header> CREATOR = new Creator<Header>() { 1753263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Header createFromParcel(Parcel source) { 1754263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return new Header(source); 1755263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1756263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio public Header[] newArray(int size) { 1757263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio return new Header[size]; 1758263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1759263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio }; 1760263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio } 1761263bcc8b732dbb47d3ce63904e0e05191fabbad6Fabrice Di Meglio} 1762