blob: b428928e3d1b78cd984828fe81a1e827a52979e6 [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 Yamasani379d9b02010-09-27 12:03:59 -070019import android.content.Intent;
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -070020import android.os.Bundle;
Amith Yamasani02cf71a2010-09-21 15:48:52 -070021import android.preference.PreferenceActivity;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080022
Amith Yamasani02cf71a2010-09-21 15:48:52 -070023import java.util.List;
Amith Yamasanid7993472010-08-18 13:59:28 -070024
25/**
26 * Top-level settings activity to handle single pane and double pane UI layout.
27 */
Daisuke Miyakawa25af1502010-09-24 11:29:31 -070028public class Settings extends PreferenceActivity {
Amith Yamasanid7993472010-08-18 13:59:28 -070029
Amith Yamasani02cf71a2010-09-21 15:48:52 -070030 // TODO: Update Call Settings based on airplane mode state.
Amith Yamasanib61cf512010-09-12 08:17:50 -070031
Amith Yamasanie0e4fc22010-10-05 11:49:51 -070032 @Override
33 public Intent getIntent() {
34 String startingFragment = getStartingFragmentClass(super.getIntent());
35 if (startingFragment != null && !onIsMultiPane()) {
36 Intent modIntent = new Intent(super.getIntent());
37 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -070038 Bundle args = super.getIntent().getExtras();
39 if (args != null) {
40 args = new Bundle(args);
41 } else {
42 args = new Bundle();
43 }
44 args.putParcelable("intent", super.getIntent());
Amith Yamasanie0e4fc22010-10-05 11:49:51 -070045 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, super.getIntent().getExtras());
46 return modIntent;
47 }
48 return super.getIntent();
49 }
50
Amith Yamasani02cf71a2010-09-21 15:48:52 -070051 /**
Amith Yamasani379d9b02010-09-27 12:03:59 -070052 * Checks if the component name in the intent is different from the Settings class and
53 * returns the class name to load as a fragment.
54 */
55 private String getStartingFragmentClass(Intent intent) {
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -070056 String intentClass = intent.getComponent().getClassName();
Amith Yamasani379d9b02010-09-27 12:03:59 -070057 if (intentClass.equals(getClass().getName())) return null;
58
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -070059 if ("com.android.settings.ManageApplications".equals(intentClass)) {
60 // Old name of manage apps.
61 intentClass = com.android.settings.applications.ManageApplications.class.getName();
62 }
63
Amith Yamasani379d9b02010-09-27 12:03:59 -070064 return intentClass;
65 }
66
67 /**
68 * Override initial header when an activity-alias is causing Settings to be launched
69 * for a specific fragment encoded in the android:name parameter.
70 */
71 @Override
72 public Header onGetInitialHeader() {
73 String fragmentClass = getStartingFragmentClass(super.getIntent());
74 if (fragmentClass != null) {
75 Header header = new Header();
76 header.fragment = fragmentClass;
Amith Yamasanie0e4fc22010-10-05 11:49:51 -070077 header.fragmentArguments = getIntent().getExtras();
Amith Yamasani379d9b02010-09-27 12:03:59 -070078 return header;
79 }
80 return super.onGetInitialHeader();
81 }
82
83 /**
Amith Yamasani02cf71a2010-09-21 15:48:52 -070084 * Populate the activity with the top-level headers.
85 */
Amith Yamasanid7993472010-08-18 13:59:28 -070086 @Override
Amith Yamasani02cf71a2010-09-21 15:48:52 -070087 public void onBuildHeaders(List<Header> target) {
88 loadHeadersFromResource(R.xml.settings_headers, target);
Amith Yamasanid7993472010-08-18 13:59:28 -070089
Amith Yamasani02cf71a2010-09-21 15:48:52 -070090 updateHeaderList(target);
91 }
Amith Yamasanid7993472010-08-18 13:59:28 -070092
Amith Yamasani02cf71a2010-09-21 15:48:52 -070093 private void updateHeaderList(List<Header> target) {
94 int i = 0;
95 while (i < target.size()) {
96 Header header = target.get(i);
97 long id = header.id;
98 if (id == R.id.dock_settings) {
99 if (!needsDockSettings())
100 target.remove(header);
101 } else if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
102 Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header);
103 } else if (id == R.id.call_settings) {
104 if (!Utils.isVoiceCapable(this))
105 target.remove(header);
Amith Yamasanid7993472010-08-18 13:59:28 -0700106 }
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700107 if (target.get(i) == header)
108 i++;
Amith Yamasanid7993472010-08-18 13:59:28 -0700109 }
110 }
111
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700112 private boolean needsDockSettings() {
113 return getResources().getBoolean(R.bool.has_dock_settings);
Amith Yamasanib61cf512010-09-12 08:17:50 -0700114 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800115}