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