blob: bca5e46c1b3ef88c24fa050eed7cac51b193fd68 [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
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080019import android.content.ComponentName;
Gilles Debunnee78c1872011-06-20 15:00:07 -070020import android.content.Context;
Amith Yamasani379d9b02010-09-27 12:03:59 -070021import android.content.Intent;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070022import android.content.pm.ActivityInfo;
23import android.content.pm.PackageManager;
24import android.content.pm.PackageManager.NameNotFoundException;
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -070025import android.os.Bundle;
Amith Yamasani02cf71a2010-09-21 15:48:52 -070026import android.preference.PreferenceActivity;
Gilles Debunnee78c1872011-06-20 15:00:07 -070027import android.text.TextUtils;
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080028import android.util.Log;
Gilles Debunnee78c1872011-06-20 15:00:07 -070029import android.view.LayoutInflater;
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080030import android.view.View;
31import android.view.View.OnClickListener;
Gilles Debunnee78c1872011-06-20 15:00:07 -070032import android.view.ViewGroup;
33import android.widget.ArrayAdapter;
Amith Yamasani9e3a4702011-01-11 09:09:26 -080034import android.widget.Button;
Gilles Debunnee78c1872011-06-20 15:00:07 -070035import android.widget.ImageView;
36import android.widget.ListAdapter;
37import android.widget.Switch;
38import android.widget.TextView;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080039
Gilles Debunnee78c1872011-06-20 15:00:07 -070040import com.android.settings.bluetooth.BluetoothEnabler;
41import com.android.settings.wifi.WifiEnabler;
42
43import java.util.ArrayList;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070044import java.util.HashMap;
Amith Yamasani02cf71a2010-09-21 15:48:52 -070045import java.util.List;
Amith Yamasanid7993472010-08-18 13:59:28 -070046
47/**
48 * Top-level settings activity to handle single pane and double pane UI layout.
49 */
Daisuke Miyakawa79c5fd92011-01-15 14:58:00 -080050public class Settings extends PreferenceActivity implements ButtonBarHandler {
Amith Yamasanid7993472010-08-18 13:59:28 -070051
Gilles Debunnee78c1872011-06-20 15:00:07 -070052 private static final String LOG_TAG = "Settings";
Amith Yamasani5203bdf2010-11-04 09:59:44 -070053 private static final String META_DATA_KEY_HEADER_ID =
Gilles Debunnee78c1872011-06-20 15:00:07 -070054 "com.android.settings.TOP_LEVEL_HEADER_ID";
Amith Yamasani5203bdf2010-11-04 09:59:44 -070055 private static final String META_DATA_KEY_FRAGMENT_CLASS =
Gilles Debunnee78c1872011-06-20 15:00:07 -070056 "com.android.settings.FRAGMENT_CLASS";
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080057 private static final String META_DATA_KEY_PARENT_TITLE =
58 "com.android.settings.PARENT_FRAGMENT_TITLE";
59 private static final String META_DATA_KEY_PARENT_FRAGMENT_CLASS =
60 "com.android.settings.PARENT_FRAGMENT_CLASS";
61
62 private static final String SAVE_KEY_CURRENT_HEADER = "com.android.settings.CURRENT_HEADER";
63 private static final String SAVE_KEY_PARENT_HEADER = "com.android.settings.PARENT_HEADER";
Amith Yamasani5203bdf2010-11-04 09:59:44 -070064
65 private String mFragmentClass;
66 private int mTopLevelHeaderId;
Amith Yamasani3965ae62010-11-15 14:45:19 -080067 private Header mFirstHeader;
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080068 private Header mCurrentHeader;
69 private Header mParentHeader;
70 private boolean mInLocalHeaderSwitch;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070071
Amith Yamasani02cf71a2010-09-21 15:48:52 -070072 // TODO: Update Call Settings based on airplane mode state.
Amith Yamasanib61cf512010-09-12 08:17:50 -070073
Amith Yamasani5203bdf2010-11-04 09:59:44 -070074 protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>();
Gilles Debunnee78c1872011-06-20 15:00:07 -070075 private List<Header> mHeaders;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070076
77 @Override
78 protected void onCreate(Bundle savedInstanceState) {
79 getMetaData();
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080080 mInLocalHeaderSwitch = true;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070081 super.onCreate(savedInstanceState);
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080082 mInLocalHeaderSwitch = false;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070083
Gilles Debunne3661b622011-06-27 11:19:16 -070084 if (!onIsHidingHeaders() && onIsMultiPane()) {
Amith Yamasani72aa19d2010-12-09 06:07:12 -080085 highlightHeader();
86 // Force the title so that it doesn't get overridden by a direct launch of
87 // a specific settings screen.
88 setTitle(R.string.settings_label);
89 }
Amith Yamasanic9fdfa82010-12-14 14:38:16 -080090
91 // Retrieve any saved state
92 if (savedInstanceState != null) {
93 mCurrentHeader = savedInstanceState.getParcelable(SAVE_KEY_CURRENT_HEADER);
94 mParentHeader = savedInstanceState.getParcelable(SAVE_KEY_PARENT_HEADER);
95 }
96
97 // If the current header was saved, switch to it
98 if (savedInstanceState != null && mCurrentHeader != null) {
99 //switchToHeaderLocal(mCurrentHeader);
100 showBreadCrumbs(mCurrentHeader.title, null);
101 }
102
103 if (mParentHeader != null) {
104 setParentTitle(mParentHeader.title, null, new OnClickListener() {
105 public void onClick(View v) {
106 switchToParent(mParentHeader.fragment);
107 }
108 });
109 }
110 }
111
112 @Override
113 protected void onSaveInstanceState(Bundle outState) {
114 super.onSaveInstanceState(outState);
115
116 // Save the current fragment, if it is the same as originally launched
117 if (mCurrentHeader != null) {
118 outState.putParcelable(SAVE_KEY_CURRENT_HEADER, mCurrentHeader);
119 }
120 if (mParentHeader != null) {
121 outState.putParcelable(SAVE_KEY_PARENT_HEADER, mParentHeader);
122 }
123 }
124
Gilles Debunnee78c1872011-06-20 15:00:07 -0700125 @Override
126 public void onResume() {
127 super.onResume();
128
129 ListAdapter listAdapter = getListAdapter();
130 if (listAdapter instanceof HeaderAdapter) {
131 ((HeaderAdapter) listAdapter).resume();
132 }
133 }
134
135 @Override
136 public void onPause() {
137 super.onPause();
138
139 ListAdapter listAdapter = getListAdapter();
140 if (listAdapter instanceof HeaderAdapter) {
141 ((HeaderAdapter) listAdapter).pause();
142 }
143 }
144
Amith Yamasanic9fdfa82010-12-14 14:38:16 -0800145 private void switchToHeaderLocal(Header header) {
146 mInLocalHeaderSwitch = true;
147 switchToHeader(header);
148 mInLocalHeaderSwitch = false;
149 }
150
151 @Override
152 public void switchToHeader(Header header) {
153 if (!mInLocalHeaderSwitch) {
154 mCurrentHeader = null;
155 mParentHeader = null;
156 }
157 super.switchToHeader(header);
158 }
159
160 /**
161 * Switch to parent fragment and store the grand parent's info
Jake Hamby2748fc22011-01-12 15:06:28 -0800162 * @param className name of the activity wrapper for the parent fragment.
Amith Yamasanic9fdfa82010-12-14 14:38:16 -0800163 */
164 private void switchToParent(String className) {
165 final ComponentName cn = new ComponentName(this, className);
166 try {
167 final PackageManager pm = getPackageManager();
168 final ActivityInfo parentInfo = pm.getActivityInfo(cn, PackageManager.GET_META_DATA);
169
170 if (parentInfo != null && parentInfo.metaData != null) {
171 String fragmentClass = parentInfo.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
172 CharSequence fragmentTitle = parentInfo.loadLabel(pm);
173 Header parentHeader = new Header();
174 parentHeader.fragment = fragmentClass;
175 parentHeader.title = fragmentTitle;
176 mCurrentHeader = parentHeader;
177
178 switchToHeaderLocal(parentHeader);
179
180 mParentHeader = new Header();
181 mParentHeader.fragment
182 = parentInfo.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS);
183 mParentHeader.title = parentInfo.metaData.getString(META_DATA_KEY_PARENT_TITLE);
184 }
185 } catch (NameNotFoundException nnfe) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700186 Log.w(LOG_TAG, "Could not find parent activity : " + className);
Amith Yamasanic9fdfa82010-12-14 14:38:16 -0800187 }
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700188 }
189
Amith Yamasani3965ae62010-11-15 14:45:19 -0800190 @Override
191 public void onNewIntent(Intent intent) {
192 super.onNewIntent(intent);
193
194 // If it is not launched from history, then reset to top-level
195 if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0
Gilles Debunne3661b622011-06-27 11:19:16 -0700196 && mFirstHeader != null && !onIsHidingHeaders() && onIsMultiPane()) {
Amith Yamasanic9fdfa82010-12-14 14:38:16 -0800197 switchToHeaderLocal(mFirstHeader);
Amith Yamasani3965ae62010-11-15 14:45:19 -0800198 }
199 }
200
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700201 private void highlightHeader() {
202 if (mTopLevelHeaderId != 0) {
203 Integer index = mHeaderIndexMap.get(mTopLevelHeaderId);
204 if (index != null) {
205 getListView().setItemChecked(index, true);
206 }
207 }
208 }
209
Amith Yamasanie0e4fc22010-10-05 11:49:51 -0700210 @Override
211 public Intent getIntent() {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700212 Intent superIntent = super.getIntent();
213 String startingFragment = getStartingFragmentClass(superIntent);
Gilles Debunne3661b622011-06-27 11:19:16 -0700214 // This is called from super.onCreate, isMultiPane() is not yet reliable
215 // Do not use onIsHidingHeaders either, which relies itself on this method
216 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
Gilles Debunneb396c9b2011-06-22 16:07:29 -0700268 return mFirstHeader;
Amith Yamasani379d9b02010-09-27 12:03:59 -0700269 }
270
Dianne Hackbornb7258182011-03-15 16:23:55 -0700271 @Override
Dianne Hackborn48147dc2011-03-18 12:29:41 -0700272 public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args,
273 int titleRes, int shortTitleRes) {
274 Intent intent = super.onBuildStartFragmentIntent(fragmentName, args,
275 titleRes, shortTitleRes);
Dianne Hackbornb7258182011-03-15 16:23:55 -0700276 intent.setClass(this, SubSettings.class);
277 return intent;
278 }
279
Amith Yamasani379d9b02010-09-27 12:03:59 -0700280 /**
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700281 * Populate the activity with the top-level headers.
282 */
Amith Yamasanid7993472010-08-18 13:59:28 -0700283 @Override
Gilles Debunnee78c1872011-06-20 15:00:07 -0700284 public void onBuildHeaders(List<Header> headers) {
285 loadHeadersFromResource(R.xml.settings_headers, headers);
Amith Yamasanid7993472010-08-18 13:59:28 -0700286
Gilles Debunnee78c1872011-06-20 15:00:07 -0700287 updateHeaderList(headers);
288
289 mHeaders = headers;
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700290 }
Amith Yamasanid7993472010-08-18 13:59:28 -0700291
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700292 private void updateHeaderList(List<Header> target) {
293 int i = 0;
294 while (i < target.size()) {
295 Header header = target.get(i);
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700296 // Ids are integers, so downcasting
297 int id = (int) header.id;
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700298 if (id == R.id.dock_settings) {
299 if (!needsDockSettings())
300 target.remove(header);
301 } else if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
302 Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header);
303 } else if (id == R.id.call_settings) {
304 if (!Utils.isVoiceCapable(this))
305 target.remove(header);
Gilles Debunne2454f492011-06-21 16:16:06 -0700306 } else if (id == R.id.wifi_settings) {
307 // Remove WiFi Settings if WiFi service is not available.
308 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) {
309 target.remove(header);
310 }
Gilles Debunnee78c1872011-06-20 15:00:07 -0700311 } else if (id == R.id.bluetooth_settings) {
312 // Remove Bluetooth Settings if Bluetooth service is not available.
Gilles Debunne2454f492011-06-21 16:16:06 -0700313 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700314 target.remove(header);
315 }
Amith Yamasanid7993472010-08-18 13:59:28 -0700316 }
Gilles Debunnee78c1872011-06-20 15:00:07 -0700317
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700318 // Increment if the current one wasn't removed by the Utils code.
319 if (target.get(i) == header) {
Amith Yamasani3965ae62010-11-15 14:45:19 -0800320 // Hold on to the first header, when we need to reset to the top-level
Gilles Debunneb396c9b2011-06-22 16:07:29 -0700321 if (mFirstHeader == null &&
322 HeaderAdapter.getHeaderType(header) != HeaderAdapter.HEADER_TYPE_CATEGORY) {
323 mFirstHeader = header;
324 }
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700325 mHeaderIndexMap.put(id, i);
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700326 i++;
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700327 }
Amith Yamasanid7993472010-08-18 13:59:28 -0700328 }
329 }
330
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700331 private boolean needsDockSettings() {
332 return getResources().getBoolean(R.bool.has_dock_settings);
Amith Yamasanib61cf512010-09-12 08:17:50 -0700333 }
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700334
335 private void getMetaData() {
336 try {
337 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
338 PackageManager.GET_META_DATA);
339 if (ai == null || ai.metaData == null) return;
340 mTopLevelHeaderId = ai.metaData.getInt(META_DATA_KEY_HEADER_ID);
341 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
Amith Yamasanic9fdfa82010-12-14 14:38:16 -0800342
343 // Check if it has a parent specified and create a Header object
344 final int parentHeaderTitleRes = ai.metaData.getInt(META_DATA_KEY_PARENT_TITLE);
345 String parentFragmentClass = ai.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS);
346 if (parentFragmentClass != null) {
347 mParentHeader = new Header();
348 mParentHeader.fragment = parentFragmentClass;
349 if (parentHeaderTitleRes != 0) {
350 mParentHeader.title = getResources().getString(parentHeaderTitleRes);
351 }
352 }
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700353 } catch (NameNotFoundException nnfe) {
Gilles Debunnee78c1872011-06-20 15:00:07 -0700354 // No recovery
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700355 }
356 }
357
Amith Yamasani9e3a4702011-01-11 09:09:26 -0800358 @Override
359 public boolean hasNextButton() {
360 return super.hasNextButton();
361 }
362
363 @Override
364 public Button getNextButton() {
365 return super.getNextButton();
366 }
367
Gilles Debunnee78c1872011-06-20 15:00:07 -0700368 private static class HeaderAdapter extends ArrayAdapter<Header> {
369 static final int HEADER_TYPE_CATEGORY = 0;
370 static final int HEADER_TYPE_NORMAL = 1;
371 static final int HEADER_TYPE_SWITCH = 2;
372 private static final int HEADER_TYPE_COUNT = HEADER_TYPE_SWITCH + 1;
373
374 private final WifiEnabler mWifiEnabler;
375 private final BluetoothEnabler mBluetoothEnabler;
376
377 private static class HeaderViewHolder {
378 ImageView icon;
379 TextView title;
380 TextView summary;
381 Switch switch_;
382 }
383
384 private LayoutInflater mInflater;
385
386 static int getHeaderType(Header header) {
387 if (header.fragment == null && header.intent == null) {
388 return HEADER_TYPE_CATEGORY;
389 } else if (header.id == R.id.wifi_settings || header.id == R.id.bluetooth_settings) {
390 return HEADER_TYPE_SWITCH;
391 } else {
392 return HEADER_TYPE_NORMAL;
393 }
394 }
395
396 @Override
397 public int getItemViewType(int position) {
398 Header header = getItem(position);
399 return getHeaderType(header);
400 }
401
402 @Override
403 public boolean areAllItemsEnabled() {
404 return false; // because of categories
405 }
406
407 @Override
408 public boolean isEnabled(int position) {
409 return getItemViewType(position) != HEADER_TYPE_CATEGORY;
410 }
411
412 @Override
413 public int getViewTypeCount() {
414 return HEADER_TYPE_COUNT;
415 }
416
417 @Override
418 public boolean hasStableIds() {
419 return true;
420 }
421
422 public HeaderAdapter(Context context, List<Header> objects) {
423 super(context, 0, objects);
424 mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
425
Gilles Debunneb396c9b2011-06-22 16:07:29 -0700426 // Temp Switches provided as placeholder until the adapter replaces these with actual
Gilles Debunnee78c1872011-06-20 15:00:07 -0700427 // Switches inflated from their layouts. Must be done before adapter is set in super
428 mWifiEnabler = new WifiEnabler(context, new Switch(context));
429 mBluetoothEnabler = new BluetoothEnabler(context, new Switch(context));
430 }
431
432 @Override
433 public View getView(int position, View convertView, ViewGroup parent) {
434 HeaderViewHolder holder;
435 Header header = getItem(position);
436 int headerType = getHeaderType(header);
437 View view = null;
438
439 if (convertView == null) {
440 holder = new HeaderViewHolder();
441 switch (headerType) {
442 case HEADER_TYPE_CATEGORY:
Gilles Debunneb396c9b2011-06-22 16:07:29 -0700443 view = new TextView(getContext(), null,
444 android.R.attr.listSeparatorTextViewStyle);
Gilles Debunnee78c1872011-06-20 15:00:07 -0700445 holder.title = (TextView) view;
446 break;
447
448 case HEADER_TYPE_SWITCH:
Gilles Debunneb396c9b2011-06-22 16:07:29 -0700449 view = mInflater.inflate(R.layout.preference_header_switch_item, parent,
450 false);
Gilles Debunnee78c1872011-06-20 15:00:07 -0700451 holder.icon = (ImageView) view.findViewById(R.id.icon);
Gilles Debunneb396c9b2011-06-22 16:07:29 -0700452 holder.title = (TextView)
453 view.findViewById(com.android.internal.R.id.title);
454 holder.summary = (TextView)
455 view.findViewById(com.android.internal.R.id.summary);
Gilles Debunnee78c1872011-06-20 15:00:07 -0700456 holder.switch_ = (Switch) view.findViewById(R.id.switchWidget);
457 break;
458
459 case HEADER_TYPE_NORMAL:
Gilles Debunneb396c9b2011-06-22 16:07:29 -0700460 view = mInflater.inflate(
461 com.android.internal.R.layout.preference_header_item, parent,
462 false);
Gilles Debunnee78c1872011-06-20 15:00:07 -0700463 holder.icon = (ImageView) view.findViewById(com.android.internal.R.id.icon);
Gilles Debunneb396c9b2011-06-22 16:07:29 -0700464 holder.title = (TextView)
465 view.findViewById(com.android.internal.R.id.title);
466 holder.summary = (TextView)
467 view.findViewById(com.android.internal.R.id.summary);
Gilles Debunnee78c1872011-06-20 15:00:07 -0700468 break;
469 }
470 view.setTag(holder);
471 } else {
472 view = convertView;
473 holder = (HeaderViewHolder) view.getTag();
474 }
475
476 // All view fields must be updated every time, because the view may be recycled
477 switch (headerType) {
478 case HEADER_TYPE_CATEGORY:
479 holder.title.setText(header.getTitle(getContext().getResources()));
480 break;
481
482 case HEADER_TYPE_SWITCH:
483 // Would need a different treatment if the main menu had more switches
484 if (header.id == R.id.wifi_settings) {
485 mWifiEnabler.setSwitch(holder.switch_);
486 } else {
487 mBluetoothEnabler.setSwitch(holder.switch_);
488 }
489 // No break, fall through on purpose to update common fields
490
491 //$FALL-THROUGH$
492 case HEADER_TYPE_NORMAL:
493 holder.icon.setImageResource(header.iconRes);
494 holder.title.setText(header.getTitle(getContext().getResources()));
495 CharSequence summary = header.getSummary(getContext().getResources());
496 if (!TextUtils.isEmpty(summary)) {
497 holder.summary.setVisibility(View.VISIBLE);
498 holder.summary.setText(summary);
499 } else {
500 holder.summary.setVisibility(View.GONE);
501 }
502 break;
503 }
504
505 return view;
506 }
507
508 public void resume() {
509 mWifiEnabler.resume();
510 mBluetoothEnabler.resume();
511 }
512
513 public void pause() {
514 mWifiEnabler.pause();
515 mBluetoothEnabler.pause();
516 }
517 }
518
519 @Override
520 public void setListAdapter(ListAdapter adapter) {
521 if (mHeaders == null) {
522 mHeaders = new ArrayList<Header>();
523 // When the saved state provides the list of headers, onBuildHeaders is not called
524 // Copy the list of Headers from the adapter, preserving their order
525 for (int i = 0; i < adapter.getCount(); i++) {
526 mHeaders.add((Header) adapter.getItem(i));
527 }
528 }
529
530 // Ignore the adapter provided by PreferenceActivity and substitute ours instead
531 super.setListAdapter(new HeaderAdapter(this, mHeaders));
532 }
533
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700534 /*
535 * Settings subclasses for launching independently.
536 */
Gilles Debunnee78c1872011-06-20 15:00:07 -0700537 public static class BluetoothSettingsActivity extends Settings { /* empty */ }
538 public static class WirelessSettingsActivity extends Settings { /* empty */ }
539 public static class TetherSettingsActivity extends Settings { /* empty */ }
540 public static class VpnSettingsActivity extends Settings { /* empty */ }
541 public static class DateTimeSettingsActivity extends Settings { /* empty */ }
542 public static class StorageSettingsActivity extends Settings { /* empty */ }
543 public static class WifiSettingsActivity extends Settings { /* empty */ }
544 public static class InputMethodAndLanguageSettingsActivity extends Settings { /* empty */ }
545 public static class InputMethodConfigActivity extends Settings { /* empty */ }
546 public static class InputMethodAndSubtypeEnablerActivity extends Settings { /* empty */ }
547 public static class LocalePickerActivity extends Settings { /* empty */ }
548 public static class UserDictionarySettingsActivity extends Settings { /* empty */ }
549 public static class SoundSettingsActivity extends Settings { /* empty */ }
550 public static class DisplaySettingsActivity extends Settings { /* empty */ }
551 public static class DeviceInfoSettingsActivity extends Settings { /* empty */ }
552 public static class ApplicationSettingsActivity extends Settings { /* empty */ }
553 public static class ManageApplicationsActivity extends Settings { /* empty */ }
554 public static class StorageUseActivity extends Settings { /* empty */ }
555 public static class DevelopmentSettingsActivity extends Settings { /* empty */ }
556 public static class AccessibilitySettingsActivity extends Settings { /* empty */ }
557 public static class SecuritySettingsActivity extends Settings { /* empty */ }
Gilles Debunnea6a8a142011-06-09 11:56:17 -0700558 public static class LocationSettingsActivity extends Settings { /* empty */ }
Gilles Debunnee78c1872011-06-20 15:00:07 -0700559 public static class PrivacySettingsActivity extends Settings { /* empty */ }
560 public static class DockSettingsActivity extends Settings { /* empty */ }
561 public static class RunningServicesActivity extends Settings { /* empty */ }
562 public static class ManageAccountsSettingsActivity extends Settings { /* empty */ }
563 public static class PowerUsageSummaryActivity extends Settings { /* empty */ }
564 public static class AccountSyncSettingsActivity extends Settings { /* empty */ }
565 public static class AccountSyncSettingsInAddAccountActivity extends Settings { /* empty */ }
566 public static class CryptKeeperSettingsActivity extends Settings { /* empty */ }
567 public static class DeviceAdminSettingsActivity extends Settings { /* empty */ }
568 public static class DataUsageSummaryActivity extends Settings { /* empty */ }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800569}