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