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