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