blob: 102dd7faa6a57fb0abab429e5f35f8efaaa78614 [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
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
17package com.android.settings;
18
Gilles Debunnee78c1872011-06-20 15:00:07 -070019import android.bluetooth.BluetoothAdapter;
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080020import android.content.ComponentName;
Gilles Debunnee78c1872011-06-20 15:00:07 -070021import android.content.Context;
Amith Yamasani379d9b02010-09-27 12:03:59 -070022import android.content.Intent;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070023import android.content.pm.ActivityInfo;
24import android.content.pm.PackageManager;
25import android.content.pm.PackageManager.NameNotFoundException;
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -070026import android.os.Bundle;
Gilles Debunnee78c1872011-06-20 15:00:07 -070027import android.os.ServiceManager;
Amith Yamasani02cf71a2010-09-21 15:48:52 -070028import android.preference.PreferenceActivity;
Gilles Debunnee78c1872011-06-20 15:00:07 -070029import android.text.TextUtils;
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080030import android.util.Log;
Gilles Debunnee78c1872011-06-20 15:00:07 -070031import android.view.LayoutInflater;
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080032import android.view.View;
33import android.view.View.OnClickListener;
Gilles Debunnee78c1872011-06-20 15:00:07 -070034import android.view.ViewGroup;
35import android.widget.ArrayAdapter;
Amith Yamasani9e3a4702011-01-11 09:09:26 -080036import android.widget.Button;
Gilles Debunnee78c1872011-06-20 15:00:07 -070037import android.widget.ImageView;
38import android.widget.ListAdapter;
39import android.widget.Switch;
40import android.widget.TextView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080041
Gilles Debunnee78c1872011-06-20 15:00:07 -070042import com.android.settings.bluetooth.BluetoothEnabler;
43import com.android.settings.wifi.WifiEnabler;
44
45import java.util.ArrayList;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070046import java.util.HashMap;
Amith Yamasani02cf71a2010-09-21 15:48:52 -070047import java.util.List;
Amith Yamasanid7993472010-08-18 13:59:28 -070048
49/**
50 * Top-level settings activity to handle single pane and double pane UI layout.
51 */
Daisuke Miyakawa79c5fd92011-01-15 14:58:00 -080052public class Settings extends PreferenceActivity implements ButtonBarHandler {
Amith Yamasanid7993472010-08-18 13:59:28 -070053
Gilles Debunnee78c1872011-06-20 15:00:07 -070054 private static final String LOG_TAG = "Settings";
Amith Yamasani5203bdf2010-11-04 09:59:44 -070055 private static final String META_DATA_KEY_HEADER_ID =
Gilles Debunnee78c1872011-06-20 15:00:07 -070056 "com.android.settings.TOP_LEVEL_HEADER_ID";
Amith Yamasani5203bdf2010-11-04 09:59:44 -070057 private static final String META_DATA_KEY_FRAGMENT_CLASS =
Gilles Debunnee78c1872011-06-20 15:00:07 -070058 "com.android.settings.FRAGMENT_CLASS";
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080059 private static final String META_DATA_KEY_PARENT_TITLE =
60 "com.android.settings.PARENT_FRAGMENT_TITLE";
61 private static final String META_DATA_KEY_PARENT_FRAGMENT_CLASS =
62 "com.android.settings.PARENT_FRAGMENT_CLASS";
63
64 private static final String SAVE_KEY_CURRENT_HEADER = "com.android.settings.CURRENT_HEADER";
65 private static final String SAVE_KEY_PARENT_HEADER = "com.android.settings.PARENT_HEADER";
Amith Yamasani5203bdf2010-11-04 09:59:44 -070066
67 private String mFragmentClass;
68 private int mTopLevelHeaderId;
Amith Yamasani3965ae62010-11-15 14:45:19 -080069 private Header mFirstHeader;
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080070 private Header mCurrentHeader;
71 private Header mParentHeader;
72 private boolean mInLocalHeaderSwitch;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070073
Amith Yamasani02cf71a2010-09-21 15:48:52 -070074 // TODO: Update Call Settings based on airplane mode state.
Amith Yamasanib61cf512010-09-12 08:17:50 -070075
Amith Yamasani5203bdf2010-11-04 09:59:44 -070076 protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>();
Gilles Debunnee78c1872011-06-20 15:00:07 -070077 private List<Header> mHeaders;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070078
79 @Override
80 protected void onCreate(Bundle savedInstanceState) {
81 getMetaData();
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080082 mInLocalHeaderSwitch = true;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070083 super.onCreate(savedInstanceState);
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080084 mInLocalHeaderSwitch = false;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070085
Amith Yamasani72aa19d2010-12-09 06:07:12 -080086 if (!onIsHidingHeaders() && onIsMultiPane()) {
87 highlightHeader();
88 // Force the title so that it doesn't get overridden by a direct launch of
89 // a specific settings screen.
90 setTitle(R.string.settings_label);
91 }
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080092
93 // Retrieve any saved state
94 if (savedInstanceState != null) {
95 mCurrentHeader = savedInstanceState.getParcelable(SAVE_KEY_CURRENT_HEADER);
96 mParentHeader = savedInstanceState.getParcelable(SAVE_KEY_PARENT_HEADER);
97 }
98
99 // If the current header was saved, switch to it
100 if (savedInstanceState != null && mCurrentHeader != null) {
101 //switchToHeaderLocal(mCurrentHeader);
102 showBreadCrumbs(mCurrentHeader.title, null);
103 }
104
105 if (mParentHeader != null) {
106 setParentTitle(mParentHeader.title, null, new OnClickListener() {
107 public void onClick(View v) {
108 switchToParent(mParentHeader.fragment);
109 }
110 });
111 }
112 }
113
114 @Override
115 protected void onSaveInstanceState(Bundle outState) {
116 super.onSaveInstanceState(outState);
117
118 // Save the current fragment, if it is the same as originally launched
119 if (mCurrentHeader != null) {
120 outState.putParcelable(SAVE_KEY_CURRENT_HEADER, mCurrentHeader);
121 }
122 if (mParentHeader != null) {
123 outState.putParcelable(SAVE_KEY_PARENT_HEADER, mParentHeader);
124 }
125 }
126
Gilles Debunnee78c1872011-06-20 15:00:07 -0700127 @Override
128 public void onResume() {
129 super.onResume();
130
131 ListAdapter listAdapter = getListAdapter();
132 if (listAdapter instanceof HeaderAdapter) {
133 ((HeaderAdapter) listAdapter).resume();
134 }
135 }
136
137 @Override
138 public void onPause() {
139 super.onPause();
140
141 ListAdapter listAdapter = getListAdapter();
142 if (listAdapter instanceof HeaderAdapter) {
143 ((HeaderAdapter) listAdapter).pause();
144 }
145 }
146
Amith Yamasanic9fdfa82010-12-14 14:38:16 -0800147 private void switchToHeaderLocal(Header header) {
148 mInLocalHeaderSwitch = true;
149 switchToHeader(header);
150 mInLocalHeaderSwitch = false;
151 }
152
153 @Override
154 public void switchToHeader(Header header) {
155 if (!mInLocalHeaderSwitch) {
156 mCurrentHeader = null;
157 mParentHeader = null;
158 }
159 super.switchToHeader(header);
160 }
161
162 /**
163 * Switch to parent fragment and store the grand parent's info
Jake Hamby2748fc22011-01-12 15:06:28 -0800164 * @param className name of the activity wrapper for the parent fragment.
Amith Yamasanic9fdfa82010-12-14 14:38:16 -0800165 */
166 private void switchToParent(String className) {
167 final ComponentName cn = new ComponentName(this, className);
168 try {
169 final PackageManager pm = getPackageManager();
170 final ActivityInfo parentInfo = pm.getActivityInfo(cn, PackageManager.GET_META_DATA);
171
172 if (parentInfo != null && parentInfo.metaData != null) {
173 String fragmentClass = parentInfo.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
174 CharSequence fragmentTitle = parentInfo.loadLabel(pm);
175 Header parentHeader = new Header();
176 parentHeader.fragment = fragmentClass;
177 parentHeader.title = fragmentTitle;
178 mCurrentHeader = parentHeader;
179
180 switchToHeaderLocal(parentHeader);
181
182 mParentHeader = new Header();
183 mParentHeader.fragment
184 = parentInfo.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS);
185 mParentHeader.title = parentInfo.metaData.getString(META_DATA_KEY_PARENT_TITLE);
186 }
187 } catch (NameNotFoundException nnfe) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700188 Log.w(LOG_TAG, "Could not find parent activity : " + className);
Amith Yamasanic9fdfa82010-12-14 14:38:16 -0800189 }
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700190 }
191
Amith Yamasani3965ae62010-11-15 14:45:19 -0800192 @Override
193 public void onNewIntent(Intent intent) {
194 super.onNewIntent(intent);
195
196 // If it is not launched from history, then reset to top-level
197 if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0
198 && mFirstHeader != null) {
Amith Yamasanic9fdfa82010-12-14 14:38:16 -0800199 switchToHeaderLocal(mFirstHeader);
Amith Yamasani3965ae62010-11-15 14:45:19 -0800200 }
201 }
202
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700203 private void highlightHeader() {
204 if (mTopLevelHeaderId != 0) {
205 Integer index = mHeaderIndexMap.get(mTopLevelHeaderId);
206 if (index != null) {
207 getListView().setItemChecked(index, true);
208 }
209 }
210 }
211
Amith Yamasanie0e4fc22010-10-05 11:49:51 -0700212 @Override
213 public Intent getIntent() {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700214 Intent superIntent = super.getIntent();
215 String startingFragment = getStartingFragmentClass(superIntent);
Amith Yamasanie0e4fc22010-10-05 11:49:51 -0700216 if (startingFragment != null && !onIsMultiPane()) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700217 Intent modIntent = new Intent(superIntent);
Amith Yamasanie0e4fc22010-10-05 11:49:51 -0700218 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
Gilles Debunnee78c1872011-06-20 15:00:07 -0700219 Bundle args = superIntent.getExtras();
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -0700220 if (args != null) {
221 args = new Bundle(args);
222 } else {
223 args = new Bundle();
224 }
Gilles Debunnee78c1872011-06-20 15:00:07 -0700225 args.putParcelable("intent", superIntent);
226 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, superIntent.getExtras());
Amith Yamasanie0e4fc22010-10-05 11:49:51 -0700227 return modIntent;
228 }
Gilles Debunnee78c1872011-06-20 15:00:07 -0700229 return superIntent;
Amith Yamasanie0e4fc22010-10-05 11:49:51 -0700230 }
231
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700232 /**
Amith Yamasani379d9b02010-09-27 12:03:59 -0700233 * Checks if the component name in the intent is different from the Settings class and
234 * returns the class name to load as a fragment.
235 */
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700236 protected String getStartingFragmentClass(Intent intent) {
237 if (mFragmentClass != null) return mFragmentClass;
238
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -0700239 String intentClass = intent.getComponent().getClassName();
Amith Yamasani379d9b02010-09-27 12:03:59 -0700240 if (intentClass.equals(getClass().getName())) return null;
241
Dianne Hackbornee293792010-11-01 12:32:33 -0700242 if ("com.android.settings.ManageApplications".equals(intentClass)
243 || "com.android.settings.RunningServices".equals(intentClass)
244 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700245 // Old names of manage apps.
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -0700246 intentClass = com.android.settings.applications.ManageApplications.class.getName();
247 }
248
Amith Yamasani379d9b02010-09-27 12:03:59 -0700249 return intentClass;
250 }
251
252 /**
253 * Override initial header when an activity-alias is causing Settings to be launched
254 * for a specific fragment encoded in the android:name parameter.
255 */
256 @Override
257 public Header onGetInitialHeader() {
258 String fragmentClass = getStartingFragmentClass(super.getIntent());
259 if (fragmentClass != null) {
260 Header header = new Header();
261 header.fragment = fragmentClass;
Amith Yamasanic9fdfa82010-12-14 14:38:16 -0800262 header.title = getTitle();
Amith Yamasanie0e4fc22010-10-05 11:49:51 -0700263 header.fragmentArguments = getIntent().getExtras();
Amith Yamasanic9fdfa82010-12-14 14:38:16 -0800264 mCurrentHeader = header;
Amith Yamasani379d9b02010-09-27 12:03:59 -0700265 return header;
266 }
Gilles Debunnee78c1872011-06-20 15:00:07 -0700267
268 // Find first non-category header
269 int position = 0;
270 while (position < mHeaders.size()) {
271 Header header = mHeaders.get(position);
272 if (HeaderAdapter.getHeaderType(header) != HeaderAdapter.HEADER_TYPE_CATEGORY)
273 return header;
274 position++;
275 }
276
277 Log.e(LOG_TAG, "Unable to find a non-category header");
278 return null;
Amith Yamasani379d9b02010-09-27 12:03:59 -0700279 }
280
Dianne Hackbornb7258182011-03-15 16:23:55 -0700281 @Override
Dianne Hackborn48147dc2011-03-18 12:29:41 -0700282 public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args,
283 int titleRes, int shortTitleRes) {
284 Intent intent = super.onBuildStartFragmentIntent(fragmentName, args,
285 titleRes, shortTitleRes);
Dianne Hackbornb7258182011-03-15 16:23:55 -0700286 intent.setClass(this, SubSettings.class);
287 return intent;
288 }
289
Amith Yamasani379d9b02010-09-27 12:03:59 -0700290 /**
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700291 * Populate the activity with the top-level headers.
292 */
Amith Yamasanid7993472010-08-18 13:59:28 -0700293 @Override
Gilles Debunnee78c1872011-06-20 15:00:07 -0700294 public void onBuildHeaders(List<Header> headers) {
295 loadHeadersFromResource(R.xml.settings_headers, headers);
Amith Yamasanid7993472010-08-18 13:59:28 -0700296
Gilles Debunnee78c1872011-06-20 15:00:07 -0700297 updateHeaderList(headers);
298
299 mHeaders = headers;
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700300 }
Amith Yamasanid7993472010-08-18 13:59:28 -0700301
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700302 private void updateHeaderList(List<Header> target) {
303 int i = 0;
304 while (i < target.size()) {
305 Header header = target.get(i);
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700306 // Ids are integers, so downcasting
307 int id = (int) header.id;
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700308 if (id == R.id.dock_settings) {
309 if (!needsDockSettings())
310 target.remove(header);
311 } else if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
312 Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header);
313 } else if (id == R.id.call_settings) {
314 if (!Utils.isVoiceCapable(this))
315 target.remove(header);
Gilles Debunnee78c1872011-06-20 15:00:07 -0700316 } else if (id == R.id.bluetooth_settings) {
317 // Remove Bluetooth Settings if Bluetooth service is not available.
318 if (ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE) == null) {
319 target.remove(header);
320 }
Amith Yamasanid7993472010-08-18 13:59:28 -0700321 }
Gilles Debunnee78c1872011-06-20 15:00:07 -0700322
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700323 // Increment if the current one wasn't removed by the Utils code.
324 if (target.get(i) == header) {
Amith Yamasani3965ae62010-11-15 14:45:19 -0800325 // Hold on to the first header, when we need to reset to the top-level
326 if (i == 0) mFirstHeader = header;
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700327 mHeaderIndexMap.put(id, i);
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700328 i++;
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700329 }
Amith Yamasanid7993472010-08-18 13:59:28 -0700330 }
331 }
332
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700333 private boolean needsDockSettings() {
334 return getResources().getBoolean(R.bool.has_dock_settings);
Amith Yamasanib61cf512010-09-12 08:17:50 -0700335 }
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700336
337 private void getMetaData() {
338 try {
339 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
340 PackageManager.GET_META_DATA);
341 if (ai == null || ai.metaData == null) return;
342 mTopLevelHeaderId = ai.metaData.getInt(META_DATA_KEY_HEADER_ID);
343 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
Amith Yamasanic9fdfa82010-12-14 14:38:16 -0800344
345 // Check if it has a parent specified and create a Header object
346 final int parentHeaderTitleRes = ai.metaData.getInt(META_DATA_KEY_PARENT_TITLE);
347 String parentFragmentClass = ai.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS);
348 if (parentFragmentClass != null) {
349 mParentHeader = new Header();
350 mParentHeader.fragment = parentFragmentClass;
351 if (parentHeaderTitleRes != 0) {
352 mParentHeader.title = getResources().getString(parentHeaderTitleRes);
353 }
354 }
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700355 } catch (NameNotFoundException nnfe) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700356 // No recovery
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700357 }
358 }
359
Amith Yamasani9e3a4702011-01-11 09:09:26 -0800360 @Override
361 public boolean hasNextButton() {
362 return super.hasNextButton();
363 }
364
365 @Override
366 public Button getNextButton() {
367 return super.getNextButton();
368 }
369
Gilles Debunnee78c1872011-06-20 15:00:07 -0700370 private static class HeaderAdapter extends ArrayAdapter<Header> {
371 static final int HEADER_TYPE_CATEGORY = 0;
372 static final int HEADER_TYPE_NORMAL = 1;
373 static final int HEADER_TYPE_SWITCH = 2;
374 private static final int HEADER_TYPE_COUNT = HEADER_TYPE_SWITCH + 1;
375
376 private final WifiEnabler mWifiEnabler;
377 private final BluetoothEnabler mBluetoothEnabler;
378
379 private static class HeaderViewHolder {
380 ImageView icon;
381 TextView title;
382 TextView summary;
383 Switch switch_;
384 }
385
386 private LayoutInflater mInflater;
387
388 static int getHeaderType(Header header) {
389 if (header.fragment == null && header.intent == null) {
390 return HEADER_TYPE_CATEGORY;
391 } else if (header.id == R.id.wifi_settings || header.id == R.id.bluetooth_settings) {
392 return HEADER_TYPE_SWITCH;
393 } else {
394 return HEADER_TYPE_NORMAL;
395 }
396 }
397
398 @Override
399 public int getItemViewType(int position) {
400 Header header = getItem(position);
401 return getHeaderType(header);
402 }
403
404 @Override
405 public boolean areAllItemsEnabled() {
406 return false; // because of categories
407 }
408
409 @Override
410 public boolean isEnabled(int position) {
411 return getItemViewType(position) != HEADER_TYPE_CATEGORY;
412 }
413
414 @Override
415 public int getViewTypeCount() {
416 return HEADER_TYPE_COUNT;
417 }
418
419 @Override
420 public boolean hasStableIds() {
421 return true;
422 }
423
424 public HeaderAdapter(Context context, List<Header> objects) {
425 super(context, 0, objects);
426 mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
427
428 // These Switches are provided as placeholder until the adapter replaces these with actual
429 // Switches inflated from their layouts. Must be done before adapter is set in super
430 mWifiEnabler = new WifiEnabler(context, new Switch(context));
431 mBluetoothEnabler = new BluetoothEnabler(context, new Switch(context));
432 }
433
434 @Override
435 public View getView(int position, View convertView, ViewGroup parent) {
436 HeaderViewHolder holder;
437 Header header = getItem(position);
438 int headerType = getHeaderType(header);
439 View view = null;
440
441 if (convertView == null) {
442 holder = new HeaderViewHolder();
443 switch (headerType) {
444 case HEADER_TYPE_CATEGORY:
445 view = new TextView(getContext(), null, android.R.attr.listSeparatorTextViewStyle);
446 holder.title = (TextView) view;
447 break;
448
449 case HEADER_TYPE_SWITCH:
450 view = mInflater.inflate(R.layout.preference_header_switch_item, parent, false);
451 holder.icon = (ImageView) view.findViewById(R.id.icon);
452 holder.title = (TextView) view.findViewById(com.android.internal.R.id.title);
453 holder.summary = (TextView) view.findViewById(com.android.internal.R.id.summary);
454 holder.switch_ = (Switch) view.findViewById(R.id.switchWidget);
455 break;
456
457 case HEADER_TYPE_NORMAL:
458 view = mInflater.inflate(com.android.internal.R.layout.preference_header_item, parent, false);
459 holder.icon = (ImageView) view.findViewById(com.android.internal.R.id.icon);
460 holder.title = (TextView) view.findViewById(com.android.internal.R.id.title);
461 holder.summary = (TextView) view.findViewById(com.android.internal.R.id.summary);
462 break;
463 }
464 view.setTag(holder);
465 } else {
466 view = convertView;
467 holder = (HeaderViewHolder) view.getTag();
468 }
469
470 // All view fields must be updated every time, because the view may be recycled
471 switch (headerType) {
472 case HEADER_TYPE_CATEGORY:
473 holder.title.setText(header.getTitle(getContext().getResources()));
474 break;
475
476 case HEADER_TYPE_SWITCH:
477 // Would need a different treatment if the main menu had more switches
478 if (header.id == R.id.wifi_settings) {
479 mWifiEnabler.setSwitch(holder.switch_);
480 } else {
481 mBluetoothEnabler.setSwitch(holder.switch_);
482 }
483 // No break, fall through on purpose to update common fields
484
485 //$FALL-THROUGH$
486 case HEADER_TYPE_NORMAL:
487 holder.icon.setImageResource(header.iconRes);
488 holder.title.setText(header.getTitle(getContext().getResources()));
489 CharSequence summary = header.getSummary(getContext().getResources());
490 if (!TextUtils.isEmpty(summary)) {
491 holder.summary.setVisibility(View.VISIBLE);
492 holder.summary.setText(summary);
493 } else {
494 holder.summary.setVisibility(View.GONE);
495 }
496 break;
497 }
498
499 return view;
500 }
501
502 public void resume() {
503 mWifiEnabler.resume();
504 mBluetoothEnabler.resume();
505 }
506
507 public void pause() {
508 mWifiEnabler.pause();
509 mBluetoothEnabler.pause();
510 }
511 }
512
513 @Override
514 public void setListAdapter(ListAdapter adapter) {
515 if (mHeaders == null) {
516 mHeaders = new ArrayList<Header>();
517 // When the saved state provides the list of headers, onBuildHeaders is not called
518 // Copy the list of Headers from the adapter, preserving their order
519 for (int i = 0; i < adapter.getCount(); i++) {
520 mHeaders.add((Header) adapter.getItem(i));
521 }
522 }
523
524 // Ignore the adapter provided by PreferenceActivity and substitute ours instead
525 super.setListAdapter(new HeaderAdapter(this, mHeaders));
526 }
527
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700528 /*
529 * Settings subclasses for launching independently.
530 */
Gilles Debunnee78c1872011-06-20 15:00:07 -0700531 public static class BluetoothSettingsActivity extends Settings { /* empty */ }
532 public static class WirelessSettingsActivity extends Settings { /* empty */ }
533 public static class TetherSettingsActivity extends Settings { /* empty */ }
534 public static class VpnSettingsActivity extends Settings { /* empty */ }
535 public static class DateTimeSettingsActivity extends Settings { /* empty */ }
536 public static class StorageSettingsActivity extends Settings { /* empty */ }
537 public static class WifiSettingsActivity extends Settings { /* empty */ }
538 public static class InputMethodAndLanguageSettingsActivity extends Settings { /* empty */ }
539 public static class InputMethodConfigActivity extends Settings { /* empty */ }
540 public static class InputMethodAndSubtypeEnablerActivity extends Settings { /* empty */ }
541 public static class LocalePickerActivity extends Settings { /* empty */ }
542 public static class UserDictionarySettingsActivity extends Settings { /* empty */ }
543 public static class SoundSettingsActivity extends Settings { /* empty */ }
544 public static class DisplaySettingsActivity extends Settings { /* empty */ }
545 public static class DeviceInfoSettingsActivity extends Settings { /* empty */ }
546 public static class ApplicationSettingsActivity extends Settings { /* empty */ }
547 public static class ManageApplicationsActivity extends Settings { /* empty */ }
548 public static class StorageUseActivity extends Settings { /* empty */ }
549 public static class DevelopmentSettingsActivity extends Settings { /* empty */ }
550 public static class AccessibilitySettingsActivity extends Settings { /* empty */ }
551 public static class SecuritySettingsActivity extends Settings { /* empty */ }
Gilles Debunnea6a8a142011-06-09 11:56:17 -0700552 public static class LocationSettingsActivity extends Settings { /* empty */ }
Gilles Debunnee78c1872011-06-20 15:00:07 -0700553 public static class PrivacySettingsActivity extends Settings { /* empty */ }
554 public static class DockSettingsActivity extends Settings { /* empty */ }
555 public static class RunningServicesActivity extends Settings { /* empty */ }
556 public static class ManageAccountsSettingsActivity extends Settings { /* empty */ }
557 public static class PowerUsageSummaryActivity extends Settings { /* empty */ }
558 public static class AccountSyncSettingsActivity extends Settings { /* empty */ }
559 public static class AccountSyncSettingsInAddAccountActivity extends Settings { /* empty */ }
560 public static class CryptKeeperSettingsActivity extends Settings { /* empty */ }
561 public static class DeviceAdminSettingsActivity extends Settings { /* empty */ }
562 public static class DataUsageSummaryActivity extends Settings { /* empty */ }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800563}