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