The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settings; |
| 18 | |
Amith Yamasani | 56821db | 2012-06-05 13:20:45 -0700 | [diff] [blame] | 19 | import android.accounts.Account; |
| 20 | import android.accounts.AccountManager; |
| 21 | import android.accounts.OnAccountsUpdateListener; |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 22 | import android.content.ComponentName; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 23 | import android.content.Context; |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 24 | import android.content.Intent; |
Amith Yamasani | 233592b | 2013-03-01 17:05:23 -0800 | [diff] [blame] | 25 | import android.content.RestrictionEntry; |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 26 | import android.content.SharedPreferences; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 27 | import android.content.pm.ActivityInfo; |
| 28 | import android.content.pm.PackageManager; |
| 29 | import android.content.pm.PackageManager.NameNotFoundException; |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 30 | import android.graphics.drawable.Drawable; |
Dianne Hackborn | f4eb85b | 2010-10-29 16:53:04 -0700 | [diff] [blame] | 31 | import android.os.Bundle; |
Jeff Sharkey | 34e964d | 2012-04-21 15:41:48 -0700 | [diff] [blame] | 32 | import android.os.INetworkManagementService; |
| 33 | import android.os.RemoteException; |
| 34 | import android.os.ServiceManager; |
Dianne Hackborn | bb06a42 | 2012-08-16 11:01:57 -0700 | [diff] [blame] | 35 | import android.os.UserHandle; |
Jeff Sharkey | 4420246 | 2012-09-19 13:13:45 -0700 | [diff] [blame] | 36 | import android.os.UserManager; |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 37 | import android.preference.Preference; |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 38 | import android.preference.PreferenceActivity; |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 39 | import android.preference.PreferenceFragment; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 40 | import android.text.TextUtils; |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 41 | import android.util.Log; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 42 | import android.view.LayoutInflater; |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 43 | import android.view.View; |
| 44 | import android.view.View.OnClickListener; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 45 | import android.view.ViewGroup; |
| 46 | import android.widget.ArrayAdapter; |
Amith Yamasani | 9e3a470 | 2011-01-11 09:09:26 -0800 | [diff] [blame] | 47 | import android.widget.Button; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 48 | import android.widget.ImageView; |
| 49 | import android.widget.ListAdapter; |
| 50 | import android.widget.Switch; |
| 51 | import android.widget.TextView; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 52 | |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 53 | import com.android.internal.util.ArrayUtils; |
| 54 | import com.android.settings.AccessibilitySettings.ToggleAccessibilityServicePreferenceFragment; |
| 55 | import com.android.settings.accounts.AccountSyncSettings; |
| 56 | import com.android.settings.accounts.AuthenticatorHelper; |
| 57 | import com.android.settings.accounts.ManageAccountsSettings; |
| 58 | import com.android.settings.bluetooth.BluetoothEnabler; |
| 59 | import com.android.settings.bluetooth.BluetoothSettings; |
Jeff Sharkey | 0c3634c | 2013-02-20 12:35:16 -0800 | [diff] [blame] | 60 | import com.android.settings.wfd.WifiDisplaySettings; |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 61 | import com.android.settings.wifi.WifiEnabler; |
| 62 | import com.android.settings.wifi.WifiSettings; |
| 63 | import com.android.settings.wifi.p2p.WifiP2pSettings; |
| 64 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 65 | import java.util.ArrayList; |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 66 | import java.util.Collections; |
| 67 | import java.util.Comparator; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 68 | import java.util.HashMap; |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 69 | import java.util.List; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Top-level settings activity to handle single pane and double pane UI layout. |
| 73 | */ |
Amith Yamasani | 56821db | 2012-06-05 13:20:45 -0700 | [diff] [blame] | 74 | public class Settings extends PreferenceActivity |
| 75 | implements ButtonBarHandler, OnAccountsUpdateListener { |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 76 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 77 | private static final String LOG_TAG = "Settings"; |
Amith Yamasani | ea7b28c | 2012-06-20 13:51:40 -0700 | [diff] [blame] | 78 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 79 | private static final String META_DATA_KEY_HEADER_ID = |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 80 | "com.android.settings.TOP_LEVEL_HEADER_ID"; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 81 | private static final String META_DATA_KEY_FRAGMENT_CLASS = |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 82 | "com.android.settings.FRAGMENT_CLASS"; |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 83 | private static final String META_DATA_KEY_PARENT_TITLE = |
| 84 | "com.android.settings.PARENT_FRAGMENT_TITLE"; |
| 85 | private static final String META_DATA_KEY_PARENT_FRAGMENT_CLASS = |
| 86 | "com.android.settings.PARENT_FRAGMENT_CLASS"; |
| 87 | |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 88 | private static final String EXTRA_UI_OPTIONS = "settings:ui_options"; |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 89 | |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 90 | private static final String SAVE_KEY_CURRENT_HEADER = "com.android.settings.CURRENT_HEADER"; |
| 91 | private static final String SAVE_KEY_PARENT_HEADER = "com.android.settings.PARENT_HEADER"; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 92 | |
| 93 | private String mFragmentClass; |
| 94 | private int mTopLevelHeaderId; |
Amith Yamasani | 3965ae6 | 2010-11-15 14:45:19 -0800 | [diff] [blame] | 95 | private Header mFirstHeader; |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 96 | private Header mCurrentHeader; |
| 97 | private Header mParentHeader; |
| 98 | private boolean mInLocalHeaderSwitch; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 99 | |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 100 | // Show only these settings for restricted users |
| 101 | private int[] SETTINGS_FOR_RESTRICTED = { |
Amith Yamasani | 3263039 | 2012-08-10 19:31:39 -0700 | [diff] [blame] | 102 | R.id.wireless_section, |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 103 | R.id.wifi_settings, |
| 104 | R.id.bluetooth_settings, |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 105 | R.id.data_usage_settings, |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 106 | R.id.wireless_settings, |
Amith Yamasani | 3263039 | 2012-08-10 19:31:39 -0700 | [diff] [blame] | 107 | R.id.device_section, |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 108 | R.id.sound_settings, |
| 109 | R.id.display_settings, |
Jeff Sharkey | 90c8b20 | 2012-08-30 15:20:10 -0700 | [diff] [blame] | 110 | R.id.storage_settings, |
Dianne Hackborn | 271c8b0 | 2012-08-20 17:24:39 -0700 | [diff] [blame] | 111 | R.id.application_settings, |
Dianne Hackborn | 52e56a2 | 2012-09-12 17:02:23 -0700 | [diff] [blame] | 112 | R.id.battery_settings, |
Amith Yamasani | 3263039 | 2012-08-10 19:31:39 -0700 | [diff] [blame] | 113 | R.id.personal_section, |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 114 | R.id.location_settings, |
Amith Yamasani | 3deeeb7 | 2012-04-05 14:44:48 -0700 | [diff] [blame] | 115 | R.id.security_settings, |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 116 | R.id.language_settings, |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 117 | R.id.user_settings, |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 118 | R.id.account_settings, |
Amith Yamasani | 3263039 | 2012-08-10 19:31:39 -0700 | [diff] [blame] | 119 | R.id.account_add, |
| 120 | R.id.system_section, |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 121 | R.id.date_time_settings, |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame] | 122 | R.id.about_settings, |
Svetoslav Ganov | 46045d8 | 2012-09-20 15:04:55 -0700 | [diff] [blame] | 123 | R.id.accessibility_settings |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 126 | private SharedPreferences mDevelopmentPreferences; |
| 127 | private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener; |
| 128 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 129 | // TODO: Update Call Settings based on airplane mode state. |
Amith Yamasani | b61cf51 | 2010-09-12 08:17:50 -0700 | [diff] [blame] | 130 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 131 | protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>(); |
| 132 | |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 133 | private AuthenticatorHelper mAuthenticatorHelper; |
| 134 | private Header mLastHeader; |
Amith Yamasani | 86708a8 | 2012-06-06 20:23:08 -0700 | [diff] [blame] | 135 | private boolean mListeningToAccountUpdates; |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 136 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 137 | @Override |
| 138 | protected void onCreate(Bundle savedInstanceState) { |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 139 | if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) { |
| 140 | getWindow().setUiOptions(getIntent().getIntExtra(EXTRA_UI_OPTIONS, 0)); |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 141 | } |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 142 | |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 143 | mAuthenticatorHelper = new AuthenticatorHelper(); |
| 144 | mAuthenticatorHelper.updateAuthDescriptions(this); |
| 145 | mAuthenticatorHelper.onAccountsUpdated(this, null); |
| 146 | |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 147 | mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, |
| 148 | Context.MODE_PRIVATE); |
| 149 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 150 | getMetaData(); |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 151 | mInLocalHeaderSwitch = true; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 152 | super.onCreate(savedInstanceState); |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 153 | mInLocalHeaderSwitch = false; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 154 | |
Gilles Debunne | 3661b62 | 2011-06-27 11:19:16 -0700 | [diff] [blame] | 155 | if (!onIsHidingHeaders() && onIsMultiPane()) { |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 156 | highlightHeader(mTopLevelHeaderId); |
Amith Yamasani | 72aa19d | 2010-12-09 06:07:12 -0800 | [diff] [blame] | 157 | // Force the title so that it doesn't get overridden by a direct launch of |
| 158 | // a specific settings screen. |
| 159 | setTitle(R.string.settings_label); |
| 160 | } |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 161 | |
| 162 | // Retrieve any saved state |
| 163 | if (savedInstanceState != null) { |
| 164 | mCurrentHeader = savedInstanceState.getParcelable(SAVE_KEY_CURRENT_HEADER); |
| 165 | mParentHeader = savedInstanceState.getParcelable(SAVE_KEY_PARENT_HEADER); |
| 166 | } |
| 167 | |
| 168 | // If the current header was saved, switch to it |
| 169 | if (savedInstanceState != null && mCurrentHeader != null) { |
| 170 | //switchToHeaderLocal(mCurrentHeader); |
| 171 | showBreadCrumbs(mCurrentHeader.title, null); |
| 172 | } |
| 173 | |
| 174 | if (mParentHeader != null) { |
| 175 | setParentTitle(mParentHeader.title, null, new OnClickListener() { |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 176 | @Override |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 177 | public void onClick(View v) { |
| 178 | switchToParent(mParentHeader.fragment); |
| 179 | } |
| 180 | }); |
| 181 | } |
Gilles Debunne | dc7101f | 2011-06-27 12:00:49 -0700 | [diff] [blame] | 182 | |
Amith Yamasani | 3d384f4 | 2012-05-11 15:22:04 -0700 | [diff] [blame] | 183 | // Override up navigation for multi-pane, since we handle it in the fragment breadcrumbs |
| 184 | if (onIsMultiPane()) { |
| 185 | getActionBar().setDisplayHomeAsUpEnabled(false); |
| 186 | getActionBar().setHomeButtonEnabled(false); |
| 187 | } |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | @Override |
| 191 | protected void onSaveInstanceState(Bundle outState) { |
| 192 | super.onSaveInstanceState(outState); |
| 193 | |
| 194 | // Save the current fragment, if it is the same as originally launched |
| 195 | if (mCurrentHeader != null) { |
| 196 | outState.putParcelable(SAVE_KEY_CURRENT_HEADER, mCurrentHeader); |
| 197 | } |
| 198 | if (mParentHeader != null) { |
| 199 | outState.putParcelable(SAVE_KEY_PARENT_HEADER, mParentHeader); |
| 200 | } |
| 201 | } |
| 202 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 203 | @Override |
| 204 | public void onResume() { |
| 205 | super.onResume(); |
| 206 | |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 207 | mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { |
| 208 | @Override |
| 209 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { |
| 210 | invalidateHeaders(); |
| 211 | } |
| 212 | }; |
| 213 | mDevelopmentPreferences.registerOnSharedPreferenceChangeListener( |
| 214 | mDevelopmentPreferencesListener); |
| 215 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 216 | ListAdapter listAdapter = getListAdapter(); |
| 217 | if (listAdapter instanceof HeaderAdapter) { |
| 218 | ((HeaderAdapter) listAdapter).resume(); |
| 219 | } |
Amith Yamasani | ea7b28c | 2012-06-20 13:51:40 -0700 | [diff] [blame] | 220 | invalidateHeaders(); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public void onPause() { |
| 225 | super.onPause(); |
| 226 | |
| 227 | ListAdapter listAdapter = getListAdapter(); |
| 228 | if (listAdapter instanceof HeaderAdapter) { |
| 229 | ((HeaderAdapter) listAdapter).pause(); |
Amith Yamasani | 86708a8 | 2012-06-06 20:23:08 -0700 | [diff] [blame] | 230 | } |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 231 | |
| 232 | mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener( |
| 233 | mDevelopmentPreferencesListener); |
| 234 | mDevelopmentPreferencesListener = null; |
Amith Yamasani | 86708a8 | 2012-06-06 20:23:08 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | @Override |
| 238 | public void onDestroy() { |
| 239 | super.onDestroy(); |
| 240 | if (mListeningToAccountUpdates) { |
Amith Yamasani | 56821db | 2012-06-05 13:20:45 -0700 | [diff] [blame] | 241 | AccountManager.get(this).removeOnAccountsUpdatedListener(this); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 245 | private void switchToHeaderLocal(Header header) { |
| 246 | mInLocalHeaderSwitch = true; |
| 247 | switchToHeader(header); |
| 248 | mInLocalHeaderSwitch = false; |
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public void switchToHeader(Header header) { |
| 253 | if (!mInLocalHeaderSwitch) { |
| 254 | mCurrentHeader = null; |
| 255 | mParentHeader = null; |
| 256 | } |
| 257 | super.switchToHeader(header); |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Switch to parent fragment and store the grand parent's info |
Jake Hamby | 2748fc2 | 2011-01-12 15:06:28 -0800 | [diff] [blame] | 262 | * @param className name of the activity wrapper for the parent fragment. |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 263 | */ |
| 264 | private void switchToParent(String className) { |
| 265 | final ComponentName cn = new ComponentName(this, className); |
| 266 | try { |
| 267 | final PackageManager pm = getPackageManager(); |
| 268 | final ActivityInfo parentInfo = pm.getActivityInfo(cn, PackageManager.GET_META_DATA); |
| 269 | |
| 270 | if (parentInfo != null && parentInfo.metaData != null) { |
| 271 | String fragmentClass = parentInfo.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); |
| 272 | CharSequence fragmentTitle = parentInfo.loadLabel(pm); |
| 273 | Header parentHeader = new Header(); |
| 274 | parentHeader.fragment = fragmentClass; |
| 275 | parentHeader.title = fragmentTitle; |
| 276 | mCurrentHeader = parentHeader; |
| 277 | |
| 278 | switchToHeaderLocal(parentHeader); |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 279 | highlightHeader(mTopLevelHeaderId); |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 280 | |
| 281 | mParentHeader = new Header(); |
| 282 | mParentHeader.fragment |
| 283 | = parentInfo.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS); |
| 284 | mParentHeader.title = parentInfo.metaData.getString(META_DATA_KEY_PARENT_TITLE); |
| 285 | } |
| 286 | } catch (NameNotFoundException nnfe) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 287 | Log.w(LOG_TAG, "Could not find parent activity : " + className); |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 288 | } |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Amith Yamasani | 3965ae6 | 2010-11-15 14:45:19 -0800 | [diff] [blame] | 291 | @Override |
| 292 | public void onNewIntent(Intent intent) { |
| 293 | super.onNewIntent(intent); |
| 294 | |
| 295 | // If it is not launched from history, then reset to top-level |
Amith Yamasani | ef61723 | 2012-10-09 16:57:25 -0700 | [diff] [blame] | 296 | if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) { |
| 297 | if (mFirstHeader != null && !onIsHidingHeaders() && onIsMultiPane()) { |
| 298 | switchToHeaderLocal(mFirstHeader); |
| 299 | } |
| 300 | getListView().setSelectionFromTop(0, 0); |
Amith Yamasani | 3965ae6 | 2010-11-15 14:45:19 -0800 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 304 | private void highlightHeader(int id) { |
| 305 | if (id != 0) { |
| 306 | Integer index = mHeaderIndexMap.get(id); |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 307 | if (index != null) { |
| 308 | getListView().setItemChecked(index, true); |
Amith Yamasani | ef61723 | 2012-10-09 16:57:25 -0700 | [diff] [blame] | 309 | if (isMultiPane()) { |
| 310 | getListView().smoothScrollToPosition(index); |
| 311 | } |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame] | 316 | @Override |
| 317 | public Intent getIntent() { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 318 | Intent superIntent = super.getIntent(); |
| 319 | String startingFragment = getStartingFragmentClass(superIntent); |
Gilles Debunne | 3661b62 | 2011-06-27 11:19:16 -0700 | [diff] [blame] | 320 | // This is called from super.onCreate, isMultiPane() is not yet reliable |
| 321 | // Do not use onIsHidingHeaders either, which relies itself on this method |
| 322 | if (startingFragment != null && !onIsMultiPane()) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 323 | Intent modIntent = new Intent(superIntent); |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame] | 324 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 325 | Bundle args = superIntent.getExtras(); |
Dianne Hackborn | f4eb85b | 2010-10-29 16:53:04 -0700 | [diff] [blame] | 326 | if (args != null) { |
| 327 | args = new Bundle(args); |
| 328 | } else { |
| 329 | args = new Bundle(); |
| 330 | } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 331 | args.putParcelable("intent", superIntent); |
| 332 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, superIntent.getExtras()); |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame] | 333 | return modIntent; |
| 334 | } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 335 | return superIntent; |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 338 | /** |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 339 | * Checks if the component name in the intent is different from the Settings class and |
| 340 | * returns the class name to load as a fragment. |
| 341 | */ |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 342 | protected String getStartingFragmentClass(Intent intent) { |
| 343 | if (mFragmentClass != null) return mFragmentClass; |
| 344 | |
Dianne Hackborn | f4eb85b | 2010-10-29 16:53:04 -0700 | [diff] [blame] | 345 | String intentClass = intent.getComponent().getClassName(); |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 346 | if (intentClass.equals(getClass().getName())) return null; |
| 347 | |
Dianne Hackborn | ee29379 | 2010-11-01 12:32:33 -0700 | [diff] [blame] | 348 | if ("com.android.settings.ManageApplications".equals(intentClass) |
| 349 | || "com.android.settings.RunningServices".equals(intentClass) |
| 350 | || "com.android.settings.applications.StorageUse".equals(intentClass)) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 351 | // Old names of manage apps. |
Dianne Hackborn | f4eb85b | 2010-10-29 16:53:04 -0700 | [diff] [blame] | 352 | intentClass = com.android.settings.applications.ManageApplications.class.getName(); |
| 353 | } |
| 354 | |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 355 | return intentClass; |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Override initial header when an activity-alias is causing Settings to be launched |
| 360 | * for a specific fragment encoded in the android:name parameter. |
| 361 | */ |
| 362 | @Override |
| 363 | public Header onGetInitialHeader() { |
| 364 | String fragmentClass = getStartingFragmentClass(super.getIntent()); |
| 365 | if (fragmentClass != null) { |
| 366 | Header header = new Header(); |
| 367 | header.fragment = fragmentClass; |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 368 | header.title = getTitle(); |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame] | 369 | header.fragmentArguments = getIntent().getExtras(); |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 370 | mCurrentHeader = header; |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 371 | return header; |
| 372 | } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 373 | |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 374 | return mFirstHeader; |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Dianne Hackborn | b725818 | 2011-03-15 16:23:55 -0700 | [diff] [blame] | 377 | @Override |
Dianne Hackborn | 48147dc | 2011-03-18 12:29:41 -0700 | [diff] [blame] | 378 | public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args, |
| 379 | int titleRes, int shortTitleRes) { |
| 380 | Intent intent = super.onBuildStartFragmentIntent(fragmentName, args, |
| 381 | titleRes, shortTitleRes); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 382 | |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 383 | // Some fragments want split ActionBar; these should stay in sync with |
| 384 | // uiOptions for fragments also defined as activities in manifest. |
| 385 | if (WifiSettings.class.getName().equals(fragmentName) || |
| 386 | WifiP2pSettings.class.getName().equals(fragmentName) || |
Jeff Sharkey | 0c3634c | 2013-02-20 12:35:16 -0800 | [diff] [blame] | 387 | WifiDisplaySettings.class.getName().equals(fragmentName) || |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 388 | BluetoothSettings.class.getName().equals(fragmentName) || |
| 389 | DreamSettings.class.getName().equals(fragmentName) || |
| 390 | ToggleAccessibilityServicePreferenceFragment.class.getName().equals(fragmentName)) { |
| 391 | intent.putExtra(EXTRA_UI_OPTIONS, ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Dianne Hackborn | b725818 | 2011-03-15 16:23:55 -0700 | [diff] [blame] | 394 | intent.setClass(this, SubSettings.class); |
| 395 | return intent; |
| 396 | } |
Amith Yamasani | ea7b28c | 2012-06-20 13:51:40 -0700 | [diff] [blame] | 397 | |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 398 | /** |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 399 | * Populate the activity with the top-level headers. |
| 400 | */ |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 401 | @Override |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 402 | public void onBuildHeaders(List<Header> headers) { |
| 403 | loadHeadersFromResource(R.xml.settings_headers, headers); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 404 | updateHeaderList(headers); |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 405 | } |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 406 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 407 | private void updateHeaderList(List<Header> target) { |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 408 | final boolean showDev = mDevelopmentPreferences.getBoolean( |
| 409 | DevelopmentSettings.PREF_SHOW, |
| 410 | android.os.Build.TYPE.equals("eng")); |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 411 | int i = 0; |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 412 | |
| 413 | final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 414 | mHeaderIndexMap.clear(); |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 415 | while (i < target.size()) { |
| 416 | Header header = target.get(i); |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 417 | // Ids are integers, so downcasting |
| 418 | int id = (int) header.id; |
Chris Wren | 2bc32ae | 2012-09-24 14:23:46 -0400 | [diff] [blame] | 419 | if (id == R.id.operator_settings || id == R.id.manufacturer_settings) { |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 420 | Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header); |
Gilles Debunne | 2454f49 | 2011-06-21 16:16:06 -0700 | [diff] [blame] | 421 | } else if (id == R.id.wifi_settings) { |
| 422 | // Remove WiFi Settings if WiFi service is not available. |
| 423 | if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) { |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 424 | target.remove(i); |
Gilles Debunne | 2454f49 | 2011-06-21 16:16:06 -0700 | [diff] [blame] | 425 | } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 426 | } else if (id == R.id.bluetooth_settings) { |
| 427 | // Remove Bluetooth Settings if Bluetooth service is not available. |
Gilles Debunne | 2454f49 | 2011-06-21 16:16:06 -0700 | [diff] [blame] | 428 | if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) { |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 429 | target.remove(i); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 430 | } |
Jeff Sharkey | 34e964d | 2012-04-21 15:41:48 -0700 | [diff] [blame] | 431 | } else if (id == R.id.data_usage_settings) { |
| 432 | // Remove data usage when kernel module not enabled |
| 433 | final INetworkManagementService netManager = INetworkManagementService.Stub |
| 434 | .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)); |
| 435 | try { |
| 436 | if (!netManager.isBandwidthControlEnabled()) { |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 437 | target.remove(i); |
Jeff Sharkey | 34e964d | 2012-04-21 15:41:48 -0700 | [diff] [blame] | 438 | } |
| 439 | } catch (RemoteException e) { |
| 440 | // ignored |
| 441 | } |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 442 | } else if (id == R.id.account_settings) { |
| 443 | int headerIndex = i + 1; |
| 444 | i = insertAccountsHeaders(target, headerIndex); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 445 | } else if (id == R.id.user_settings) { |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 446 | if (!UserHandle.MU_ENABLED |
Jeff Sharkey | 4420246 | 2012-09-19 13:13:45 -0700 | [diff] [blame] | 447 | || !UserManager.supportsMultipleUsers() |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 448 | || Utils.isMonkeyRunning()) { |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 449 | target.remove(i); |
| 450 | } |
| 451 | } else if (id == R.id.development_settings) { |
| 452 | if (!showDev) { |
| 453 | target.remove(i); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 454 | } |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 455 | } else if (id == R.id.account_add) { |
| 456 | if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) { |
| 457 | target.remove(i); |
| 458 | } |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 459 | } |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 460 | |
Jaewan Kim | bb0e621 | 2013-02-04 15:36:17 +0900 | [diff] [blame] | 461 | if (i < target.size() && target.get(i) == header |
Amith Yamasani | b99f864 | 2012-10-10 21:41:12 -0700 | [diff] [blame] | 462 | && UserHandle.MU_ENABLED && UserHandle.myUserId() != 0 |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 463 | && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) { |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 464 | target.remove(i); |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 465 | } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 466 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 467 | // Increment if the current one wasn't removed by the Utils code. |
Jaewan Kim | bb0e621 | 2013-02-04 15:36:17 +0900 | [diff] [blame] | 468 | if (i < target.size() && target.get(i) == header) { |
Amith Yamasani | 3965ae6 | 2010-11-15 14:45:19 -0800 | [diff] [blame] | 469 | // Hold on to the first header, when we need to reset to the top-level |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 470 | if (mFirstHeader == null && |
| 471 | HeaderAdapter.getHeaderType(header) != HeaderAdapter.HEADER_TYPE_CATEGORY) { |
| 472 | mFirstHeader = header; |
| 473 | } |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 474 | mHeaderIndexMap.put(id, i); |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 475 | i++; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 476 | } |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 480 | private int insertAccountsHeaders(List<Header> target, int headerIndex) { |
| 481 | String[] accountTypes = mAuthenticatorHelper.getEnabledAccountTypes(); |
| 482 | List<Header> accountHeaders = new ArrayList<Header>(accountTypes.length); |
| 483 | for (String accountType : accountTypes) { |
| 484 | CharSequence label = mAuthenticatorHelper.getLabelForType(this, accountType); |
Brian Muramatsu | c28af52 | 2012-06-28 14:25:14 -0700 | [diff] [blame] | 485 | if (label == null) { |
| 486 | continue; |
| 487 | } |
| 488 | |
Amith Yamasani | 3882c2e | 2012-06-07 17:03:20 -0700 | [diff] [blame] | 489 | Account[] accounts = AccountManager.get(this).getAccountsByType(accountType); |
| 490 | boolean skipToAccount = accounts.length == 1 |
| 491 | && !mAuthenticatorHelper.hasAccountPreferences(accountType); |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 492 | Header accHeader = new Header(); |
| 493 | accHeader.title = label; |
| 494 | if (accHeader.extras == null) { |
| 495 | accHeader.extras = new Bundle(); |
| 496 | } |
Amith Yamasani | 3882c2e | 2012-06-07 17:03:20 -0700 | [diff] [blame] | 497 | if (skipToAccount) { |
| 498 | accHeader.breadCrumbTitleRes = R.string.account_sync_settings_title; |
| 499 | accHeader.breadCrumbShortTitleRes = R.string.account_sync_settings_title; |
| 500 | accHeader.fragment = AccountSyncSettings.class.getName(); |
| 501 | accHeader.fragmentArguments = new Bundle(); |
| 502 | // Need this for the icon |
| 503 | accHeader.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); |
| 504 | accHeader.extras.putParcelable(AccountSyncSettings.ACCOUNT_KEY, accounts[0]); |
| 505 | accHeader.fragmentArguments.putParcelable(AccountSyncSettings.ACCOUNT_KEY, |
| 506 | accounts[0]); |
| 507 | } else { |
| 508 | accHeader.breadCrumbTitle = label; |
| 509 | accHeader.breadCrumbShortTitle = label; |
| 510 | accHeader.fragment = ManageAccountsSettings.class.getName(); |
| 511 | accHeader.fragmentArguments = new Bundle(); |
| 512 | accHeader.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); |
| 513 | accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, |
| 514 | accountType); |
| 515 | if (!isMultiPane()) { |
| 516 | accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL, |
| 517 | label.toString()); |
| 518 | } |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 519 | } |
| 520 | accountHeaders.add(accHeader); |
| 521 | } |
| 522 | |
| 523 | // Sort by label |
| 524 | Collections.sort(accountHeaders, new Comparator<Header>() { |
| 525 | @Override |
| 526 | public int compare(Header h1, Header h2) { |
| 527 | return h1.title.toString().compareTo(h2.title.toString()); |
| 528 | } |
| 529 | }); |
| 530 | |
| 531 | for (Header header : accountHeaders) { |
| 532 | target.add(headerIndex++, header); |
| 533 | } |
Amith Yamasani | 86708a8 | 2012-06-06 20:23:08 -0700 | [diff] [blame] | 534 | if (!mListeningToAccountUpdates) { |
| 535 | AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true); |
| 536 | mListeningToAccountUpdates = true; |
| 537 | } |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 538 | return headerIndex; |
| 539 | } |
| 540 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 541 | private void getMetaData() { |
| 542 | try { |
| 543 | ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), |
| 544 | PackageManager.GET_META_DATA); |
| 545 | if (ai == null || ai.metaData == null) return; |
| 546 | mTopLevelHeaderId = ai.metaData.getInt(META_DATA_KEY_HEADER_ID); |
| 547 | mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 548 | |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 549 | // Check if it has a parent specified and create a Header object |
| 550 | final int parentHeaderTitleRes = ai.metaData.getInt(META_DATA_KEY_PARENT_TITLE); |
| 551 | String parentFragmentClass = ai.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS); |
| 552 | if (parentFragmentClass != null) { |
| 553 | mParentHeader = new Header(); |
| 554 | mParentHeader.fragment = parentFragmentClass; |
| 555 | if (parentHeaderTitleRes != 0) { |
| 556 | mParentHeader.title = getResources().getString(parentHeaderTitleRes); |
| 557 | } |
| 558 | } |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 559 | } catch (NameNotFoundException nnfe) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 560 | // No recovery |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
Amith Yamasani | 9e3a470 | 2011-01-11 09:09:26 -0800 | [diff] [blame] | 564 | @Override |
| 565 | public boolean hasNextButton() { |
| 566 | return super.hasNextButton(); |
| 567 | } |
| 568 | |
| 569 | @Override |
| 570 | public Button getNextButton() { |
| 571 | return super.getNextButton(); |
| 572 | } |
| 573 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 574 | private static class HeaderAdapter extends ArrayAdapter<Header> { |
| 575 | static final int HEADER_TYPE_CATEGORY = 0; |
| 576 | static final int HEADER_TYPE_NORMAL = 1; |
| 577 | static final int HEADER_TYPE_SWITCH = 2; |
| 578 | private static final int HEADER_TYPE_COUNT = HEADER_TYPE_SWITCH + 1; |
| 579 | |
| 580 | private final WifiEnabler mWifiEnabler; |
| 581 | private final BluetoothEnabler mBluetoothEnabler; |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 582 | private AuthenticatorHelper mAuthHelper; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 583 | |
| 584 | private static class HeaderViewHolder { |
| 585 | ImageView icon; |
| 586 | TextView title; |
| 587 | TextView summary; |
| 588 | Switch switch_; |
| 589 | } |
| 590 | |
| 591 | private LayoutInflater mInflater; |
| 592 | |
| 593 | static int getHeaderType(Header header) { |
| 594 | if (header.fragment == null && header.intent == null) { |
| 595 | return HEADER_TYPE_CATEGORY; |
| 596 | } else if (header.id == R.id.wifi_settings || header.id == R.id.bluetooth_settings) { |
| 597 | return HEADER_TYPE_SWITCH; |
| 598 | } else { |
| 599 | return HEADER_TYPE_NORMAL; |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | @Override |
| 604 | public int getItemViewType(int position) { |
| 605 | Header header = getItem(position); |
| 606 | return getHeaderType(header); |
| 607 | } |
| 608 | |
| 609 | @Override |
| 610 | public boolean areAllItemsEnabled() { |
| 611 | return false; // because of categories |
| 612 | } |
| 613 | |
| 614 | @Override |
| 615 | public boolean isEnabled(int position) { |
| 616 | return getItemViewType(position) != HEADER_TYPE_CATEGORY; |
| 617 | } |
| 618 | |
| 619 | @Override |
| 620 | public int getViewTypeCount() { |
| 621 | return HEADER_TYPE_COUNT; |
| 622 | } |
| 623 | |
| 624 | @Override |
| 625 | public boolean hasStableIds() { |
| 626 | return true; |
| 627 | } |
| 628 | |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 629 | public HeaderAdapter(Context context, List<Header> objects, |
| 630 | AuthenticatorHelper authenticatorHelper) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 631 | super(context, 0, objects); |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 632 | |
| 633 | mAuthHelper = authenticatorHelper; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 634 | mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 635 | |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 636 | // Temp Switches provided as placeholder until the adapter replaces these with actual |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 637 | // Switches inflated from their layouts. Must be done before adapter is set in super |
| 638 | mWifiEnabler = new WifiEnabler(context, new Switch(context)); |
| 639 | mBluetoothEnabler = new BluetoothEnabler(context, new Switch(context)); |
| 640 | } |
| 641 | |
| 642 | @Override |
| 643 | public View getView(int position, View convertView, ViewGroup parent) { |
| 644 | HeaderViewHolder holder; |
| 645 | Header header = getItem(position); |
| 646 | int headerType = getHeaderType(header); |
| 647 | View view = null; |
| 648 | |
| 649 | if (convertView == null) { |
| 650 | holder = new HeaderViewHolder(); |
| 651 | switch (headerType) { |
| 652 | case HEADER_TYPE_CATEGORY: |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 653 | view = new TextView(getContext(), null, |
| 654 | android.R.attr.listSeparatorTextViewStyle); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 655 | holder.title = (TextView) view; |
| 656 | break; |
| 657 | |
| 658 | case HEADER_TYPE_SWITCH: |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 659 | view = mInflater.inflate(R.layout.preference_header_switch_item, parent, |
| 660 | false); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 661 | holder.icon = (ImageView) view.findViewById(R.id.icon); |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 662 | holder.title = (TextView) |
| 663 | view.findViewById(com.android.internal.R.id.title); |
| 664 | holder.summary = (TextView) |
| 665 | view.findViewById(com.android.internal.R.id.summary); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 666 | holder.switch_ = (Switch) view.findViewById(R.id.switchWidget); |
| 667 | break; |
| 668 | |
| 669 | case HEADER_TYPE_NORMAL: |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 670 | view = mInflater.inflate( |
Amith Yamasani | c8a9317 | 2012-06-08 13:35:47 -0700 | [diff] [blame] | 671 | R.layout.preference_header_item, parent, |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 672 | false); |
Amith Yamasani | c8a9317 | 2012-06-08 13:35:47 -0700 | [diff] [blame] | 673 | holder.icon = (ImageView) view.findViewById(R.id.icon); |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 674 | holder.title = (TextView) |
| 675 | view.findViewById(com.android.internal.R.id.title); |
| 676 | holder.summary = (TextView) |
| 677 | view.findViewById(com.android.internal.R.id.summary); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 678 | break; |
| 679 | } |
| 680 | view.setTag(holder); |
| 681 | } else { |
| 682 | view = convertView; |
| 683 | holder = (HeaderViewHolder) view.getTag(); |
| 684 | } |
| 685 | |
| 686 | // All view fields must be updated every time, because the view may be recycled |
| 687 | switch (headerType) { |
| 688 | case HEADER_TYPE_CATEGORY: |
| 689 | holder.title.setText(header.getTitle(getContext().getResources())); |
| 690 | break; |
| 691 | |
| 692 | case HEADER_TYPE_SWITCH: |
| 693 | // Would need a different treatment if the main menu had more switches |
| 694 | if (header.id == R.id.wifi_settings) { |
| 695 | mWifiEnabler.setSwitch(holder.switch_); |
| 696 | } else { |
| 697 | mBluetoothEnabler.setSwitch(holder.switch_); |
| 698 | } |
| 699 | // No break, fall through on purpose to update common fields |
| 700 | |
| 701 | //$FALL-THROUGH$ |
| 702 | case HEADER_TYPE_NORMAL: |
Amith Yamasani | 3882c2e | 2012-06-07 17:03:20 -0700 | [diff] [blame] | 703 | if (header.extras != null |
| 704 | && header.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) { |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 705 | String accType = header.extras.getString( |
| 706 | ManageAccountsSettings.KEY_ACCOUNT_TYPE); |
| 707 | ViewGroup.LayoutParams lp = holder.icon.getLayoutParams(); |
| 708 | lp.width = getContext().getResources().getDimensionPixelSize( |
| 709 | R.dimen.header_icon_width); |
| 710 | lp.height = lp.width; |
| 711 | holder.icon.setLayoutParams(lp); |
| 712 | Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType); |
| 713 | holder.icon.setImageDrawable(icon); |
| 714 | } else { |
| 715 | holder.icon.setImageResource(header.iconRes); |
| 716 | } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 717 | holder.title.setText(header.getTitle(getContext().getResources())); |
| 718 | CharSequence summary = header.getSummary(getContext().getResources()); |
| 719 | if (!TextUtils.isEmpty(summary)) { |
| 720 | holder.summary.setVisibility(View.VISIBLE); |
| 721 | holder.summary.setText(summary); |
| 722 | } else { |
| 723 | holder.summary.setVisibility(View.GONE); |
| 724 | } |
| 725 | break; |
| 726 | } |
| 727 | |
| 728 | return view; |
| 729 | } |
| 730 | |
| 731 | public void resume() { |
| 732 | mWifiEnabler.resume(); |
| 733 | mBluetoothEnabler.resume(); |
| 734 | } |
Brian Muramatsu | c28af52 | 2012-06-28 14:25:14 -0700 | [diff] [blame] | 735 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 736 | public void pause() { |
| 737 | mWifiEnabler.pause(); |
| 738 | mBluetoothEnabler.pause(); |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | @Override |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 743 | public void onHeaderClick(Header header, int position) { |
| 744 | boolean revert = false; |
| 745 | if (header.id == R.id.account_add) { |
| 746 | revert = true; |
| 747 | } |
| 748 | |
| 749 | super.onHeaderClick(header, position); |
| 750 | |
| 751 | if (revert && mLastHeader != null) { |
| 752 | highlightHeader((int) mLastHeader.id); |
| 753 | } else { |
| 754 | mLastHeader = header; |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | @Override |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 759 | public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { |
| 760 | // Override the fragment title for Wallpaper settings |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 761 | int titleRes = pref.getTitleRes(); |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 762 | if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) { |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 763 | titleRes = R.string.wallpaper_settings_fragment_title; |
Amith Yamasani | 8666b9e | 2012-09-27 14:50:13 -0700 | [diff] [blame] | 764 | } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName()) |
| 765 | && UserHandle.myUserId() != UserHandle.USER_OWNER) { |
Amith Yamasani | b017171 | 2013-04-28 22:13:22 -0700 | [diff] [blame^] | 766 | if (UserManager.get(this).isLinkedUser()) { |
| 767 | titleRes = R.string.profile_info_settings_title; |
| 768 | } else { |
| 769 | titleRes = R.string.user_info_settings_title; |
| 770 | } |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 771 | } |
Jean Chalard | 7dabe45 | 2012-05-10 18:08:07 +0900 | [diff] [blame] | 772 | startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(), |
| 773 | null, 0); |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 774 | return true; |
| 775 | } |
| 776 | |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 777 | @Override |
Amith Yamasani | 3d384f4 | 2012-05-11 15:22:04 -0700 | [diff] [blame] | 778 | public boolean shouldUpRecreateTask(Intent targetIntent) { |
| 779 | return super.shouldUpRecreateTask(new Intent(this, Settings.class)); |
| 780 | } |
| 781 | |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 782 | @Override |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 783 | public void setListAdapter(ListAdapter adapter) { |
Amith Yamasani | ea7b28c | 2012-06-20 13:51:40 -0700 | [diff] [blame] | 784 | if (adapter == null) { |
| 785 | super.setListAdapter(null); |
| 786 | } else { |
| 787 | super.setListAdapter(new HeaderAdapter(this, getHeaders(), mAuthenticatorHelper)); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 788 | } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Amith Yamasani | 56821db | 2012-06-05 13:20:45 -0700 | [diff] [blame] | 791 | @Override |
| 792 | public void onAccountsUpdated(Account[] accounts) { |
Jeff Sharkey | 9ff79c1 | 2012-10-03 16:48:17 -0700 | [diff] [blame] | 793 | // TODO: watch for package upgrades to invalidate cache; see 7206643 |
| 794 | mAuthenticatorHelper.updateAuthDescriptions(this); |
Amith Yamasani | 56821db | 2012-06-05 13:20:45 -0700 | [diff] [blame] | 795 | mAuthenticatorHelper.onAccountsUpdated(this, accounts); |
| 796 | invalidateHeaders(); |
| 797 | } |
| 798 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 799 | /* |
| 800 | * Settings subclasses for launching independently. |
| 801 | */ |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 802 | public static class BluetoothSettingsActivity extends Settings { /* empty */ } |
| 803 | public static class WirelessSettingsActivity extends Settings { /* empty */ } |
| 804 | public static class TetherSettingsActivity extends Settings { /* empty */ } |
| 805 | public static class VpnSettingsActivity extends Settings { /* empty */ } |
| 806 | public static class DateTimeSettingsActivity extends Settings { /* empty */ } |
| 807 | public static class StorageSettingsActivity extends Settings { /* empty */ } |
| 808 | public static class WifiSettingsActivity extends Settings { /* empty */ } |
repo sync | b98463f | 2011-06-30 10:58:43 -0700 | [diff] [blame] | 809 | public static class WifiP2pSettingsActivity extends Settings { /* empty */ } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 810 | public static class InputMethodAndLanguageSettingsActivity extends Settings { /* empty */ } |
Jeff Brown | e46c5f3 | 2012-04-05 11:42:18 -0700 | [diff] [blame] | 811 | public static class KeyboardLayoutPickerActivity extends Settings { /* empty */ } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 812 | public static class InputMethodAndSubtypeEnablerActivity extends Settings { /* empty */ } |
satok | e077d2b | 2011-07-25 09:38:11 +0900 | [diff] [blame] | 813 | public static class SpellCheckersSettingsActivity extends Settings { /* empty */ } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 814 | public static class LocalePickerActivity extends Settings { /* empty */ } |
| 815 | public static class UserDictionarySettingsActivity extends Settings { /* empty */ } |
| 816 | public static class SoundSettingsActivity extends Settings { /* empty */ } |
| 817 | public static class DisplaySettingsActivity extends Settings { /* empty */ } |
| 818 | public static class DeviceInfoSettingsActivity extends Settings { /* empty */ } |
| 819 | public static class ApplicationSettingsActivity extends Settings { /* empty */ } |
| 820 | public static class ManageApplicationsActivity extends Settings { /* empty */ } |
Dianne Hackborn | a522a8e | 2013-01-15 19:02:05 -0800 | [diff] [blame] | 821 | public static class AppOpsSummaryActivity extends Settings { /* empty */ } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 822 | public static class StorageUseActivity extends Settings { /* empty */ } |
| 823 | public static class DevelopmentSettingsActivity extends Settings { /* empty */ } |
| 824 | public static class AccessibilitySettingsActivity extends Settings { /* empty */ } |
| 825 | public static class SecuritySettingsActivity extends Settings { /* empty */ } |
Gilles Debunne | a6a8a14 | 2011-06-09 11:56:17 -0700 | [diff] [blame] | 826 | public static class LocationSettingsActivity extends Settings { /* empty */ } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 827 | public static class PrivacySettingsActivity extends Settings { /* empty */ } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 828 | public static class RunningServicesActivity extends Settings { /* empty */ } |
| 829 | public static class ManageAccountsSettingsActivity extends Settings { /* empty */ } |
| 830 | public static class PowerUsageSummaryActivity extends Settings { /* empty */ } |
| 831 | public static class AccountSyncSettingsActivity extends Settings { /* empty */ } |
| 832 | public static class AccountSyncSettingsInAddAccountActivity extends Settings { /* empty */ } |
| 833 | public static class CryptKeeperSettingsActivity extends Settings { /* empty */ } |
| 834 | public static class DeviceAdminSettingsActivity extends Settings { /* empty */ } |
| 835 | public static class DataUsageSummaryActivity extends Settings { /* empty */ } |
Gilles Debunne | ab189bd | 2011-07-06 13:10:16 -0700 | [diff] [blame] | 836 | public static class AdvancedWifiSettingsActivity extends Settings { /* empty */ } |
Gilles Debunne | ab189bd | 2011-07-06 13:10:16 -0700 | [diff] [blame] | 837 | public static class TextToSpeechSettingsActivity extends Settings { /* empty */ } |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 838 | public static class AndroidBeamSettingsActivity extends Settings { /* empty */ } |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame] | 839 | public static class WifiDisplaySettingsActivity extends Settings { /* empty */ } |
Daniel Sandler | 7dee75c | 2012-11-27 22:41:30 -0500 | [diff] [blame] | 840 | public static class DreamSettingsActivity extends Settings { /* empty */ } |
Daniel Sandler | 328e2d2 | 2013-01-17 13:14:02 -0500 | [diff] [blame] | 841 | public static class NotificationStationActivity extends Settings { /* empty */ } |
Amith Yamasani | 233592b | 2013-03-01 17:05:23 -0800 | [diff] [blame] | 842 | public static class UserSettingsActivity extends Settings { /* empty */ } |
Daniel Sandler | 79b9bfe | 2013-04-04 14:30:04 -0400 | [diff] [blame] | 843 | public static class NotificationAccessSettingsActivity extends Settings { /* empty */ } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 844 | } |