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