blob: 09584ad99ca80a861c6ba05537b957e4cc05306f [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;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070020import android.content.pm.ActivityInfo;
21import android.content.pm.PackageManager;
22import android.content.pm.PackageManager.NameNotFoundException;
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -070023import android.os.Bundle;
Amith Yamasani02cf71a2010-09-21 15:48:52 -070024import android.preference.PreferenceActivity;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080025
Amith Yamasani5203bdf2010-11-04 09:59:44 -070026import java.util.HashMap;
Amith Yamasani02cf71a2010-09-21 15:48:52 -070027import java.util.List;
Amith Yamasanid7993472010-08-18 13:59:28 -070028
29/**
30 * Top-level settings activity to handle single pane and double pane UI layout.
31 */
Daisuke Miyakawa25af1502010-09-24 11:29:31 -070032public class Settings extends PreferenceActivity {
Amith Yamasanid7993472010-08-18 13:59:28 -070033
Amith Yamasani5203bdf2010-11-04 09:59:44 -070034 private static final String META_DATA_KEY_HEADER_ID =
35 "com.android.settings.TOP_LEVEL_HEADER_ID";
36 private static final String META_DATA_KEY_FRAGMENT_CLASS =
37 "com.android.settings.FRAGMENT_CLASS";
38
39 private String mFragmentClass;
40 private int mTopLevelHeaderId;
Amith Yamasani3965ae62010-11-15 14:45:19 -080041 private Header mFirstHeader;
Amith Yamasani5203bdf2010-11-04 09:59:44 -070042
Amith Yamasani02cf71a2010-09-21 15:48:52 -070043 // TODO: Update Call Settings based on airplane mode state.
Amith Yamasanib61cf512010-09-12 08:17:50 -070044
Amith Yamasani5203bdf2010-11-04 09:59:44 -070045 protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>();
46
47 @Override
48 protected void onCreate(Bundle savedInstanceState) {
49 getMetaData();
50 super.onCreate(savedInstanceState);
51
Amith Yamasani72aa19d2010-12-09 06:07:12 -080052 if (!onIsHidingHeaders() && onIsMultiPane()) {
53 highlightHeader();
54 // Force the title so that it doesn't get overridden by a direct launch of
55 // a specific settings screen.
56 setTitle(R.string.settings_label);
57 }
Amith Yamasani5203bdf2010-11-04 09:59:44 -070058 }
59
Amith Yamasani3965ae62010-11-15 14:45:19 -080060 @Override
61 public void onNewIntent(Intent intent) {
62 super.onNewIntent(intent);
63
64 // If it is not launched from history, then reset to top-level
65 if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0
66 && mFirstHeader != null) {
67 switchToHeader(mFirstHeader);
68 }
69 }
70
Amith Yamasani5203bdf2010-11-04 09:59:44 -070071 private void highlightHeader() {
72 if (mTopLevelHeaderId != 0) {
73 Integer index = mHeaderIndexMap.get(mTopLevelHeaderId);
74 if (index != null) {
75 getListView().setItemChecked(index, true);
76 }
77 }
78 }
79
Amith Yamasanie0e4fc22010-10-05 11:49:51 -070080 @Override
81 public Intent getIntent() {
82 String startingFragment = getStartingFragmentClass(super.getIntent());
83 if (startingFragment != null && !onIsMultiPane()) {
84 Intent modIntent = new Intent(super.getIntent());
85 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -070086 Bundle args = super.getIntent().getExtras();
87 if (args != null) {
88 args = new Bundle(args);
89 } else {
90 args = new Bundle();
91 }
92 args.putParcelable("intent", super.getIntent());
Amith Yamasanie0e4fc22010-10-05 11:49:51 -070093 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, super.getIntent().getExtras());
94 return modIntent;
95 }
96 return super.getIntent();
97 }
98
Amith Yamasani02cf71a2010-09-21 15:48:52 -070099 /**
Amith Yamasani379d9b02010-09-27 12:03:59 -0700100 * Checks if the component name in the intent is different from the Settings class and
101 * returns the class name to load as a fragment.
102 */
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700103 protected String getStartingFragmentClass(Intent intent) {
104 if (mFragmentClass != null) return mFragmentClass;
105
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -0700106 String intentClass = intent.getComponent().getClassName();
Amith Yamasani379d9b02010-09-27 12:03:59 -0700107 if (intentClass.equals(getClass().getName())) return null;
108
Dianne Hackbornee293792010-11-01 12:32:33 -0700109 if ("com.android.settings.ManageApplications".equals(intentClass)
110 || "com.android.settings.RunningServices".equals(intentClass)
111 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -0700112 // Old name of manage apps.
113 intentClass = com.android.settings.applications.ManageApplications.class.getName();
114 }
115
Amith Yamasani379d9b02010-09-27 12:03:59 -0700116 return intentClass;
117 }
118
119 /**
120 * Override initial header when an activity-alias is causing Settings to be launched
121 * for a specific fragment encoded in the android:name parameter.
122 */
123 @Override
124 public Header onGetInitialHeader() {
125 String fragmentClass = getStartingFragmentClass(super.getIntent());
126 if (fragmentClass != null) {
127 Header header = new Header();
128 header.fragment = fragmentClass;
Amith Yamasanie0e4fc22010-10-05 11:49:51 -0700129 header.fragmentArguments = getIntent().getExtras();
Amith Yamasani379d9b02010-09-27 12:03:59 -0700130 return header;
131 }
132 return super.onGetInitialHeader();
133 }
134
135 /**
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700136 * Populate the activity with the top-level headers.
137 */
Amith Yamasanid7993472010-08-18 13:59:28 -0700138 @Override
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700139 public void onBuildHeaders(List<Header> target) {
140 loadHeadersFromResource(R.xml.settings_headers, target);
Amith Yamasanid7993472010-08-18 13:59:28 -0700141
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700142 updateHeaderList(target);
143 }
Amith Yamasanid7993472010-08-18 13:59:28 -0700144
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700145 private void updateHeaderList(List<Header> target) {
146 int i = 0;
147 while (i < target.size()) {
148 Header header = target.get(i);
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700149 // Ids are integers, so downcasting
150 int id = (int) header.id;
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700151 if (id == R.id.dock_settings) {
152 if (!needsDockSettings())
153 target.remove(header);
154 } else if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
155 Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header);
156 } else if (id == R.id.call_settings) {
157 if (!Utils.isVoiceCapable(this))
158 target.remove(header);
Amith Yamasanid7993472010-08-18 13:59:28 -0700159 }
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700160 // Increment if the current one wasn't removed by the Utils code.
161 if (target.get(i) == header) {
Amith Yamasani3965ae62010-11-15 14:45:19 -0800162 // Hold on to the first header, when we need to reset to the top-level
163 if (i == 0) mFirstHeader = header;
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700164 mHeaderIndexMap.put(id, i);
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700165 i++;
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700166 }
Amith Yamasanid7993472010-08-18 13:59:28 -0700167 }
168 }
169
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700170 private boolean needsDockSettings() {
171 return getResources().getBoolean(R.bool.has_dock_settings);
Amith Yamasanib61cf512010-09-12 08:17:50 -0700172 }
Amith Yamasani5203bdf2010-11-04 09:59:44 -0700173
174 private void getMetaData() {
175 try {
176 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
177 PackageManager.GET_META_DATA);
178 if (ai == null || ai.metaData == null) return;
179 mTopLevelHeaderId = ai.metaData.getInt(META_DATA_KEY_HEADER_ID);
180 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
181 } catch (NameNotFoundException nnfe) {
182 }
183 }
184
185 /*
186 * Settings subclasses for launching independently.
187 */
188
189 public static class BluetoothSettingsActivity extends Settings { }
190 public static class WirelessSettingsActivity extends Settings { }
191 public static class TetherSettingsActivity extends Settings { }
192 public static class VpnSettingsActivity extends Settings { }
193 public static class DateTimeSettingsActivity extends Settings { }
194 public static class StorageSettingsActivity extends Settings { }
195 public static class WifiSettingsActivity extends Settings { }
196 public static class InputMethodAndLanguageSettingsActivity extends Settings { }
197 public static class InputMethodAndSubtypeEnablerActivity extends Settings { }
198 public static class LocalePickerActivity extends Settings { }
199 public static class UserDictionarySettingsActivity extends Settings { }
200 public static class SoundSettingsActivity extends Settings { }
201 public static class DisplaySettingsActivity extends Settings { }
202 public static class DeviceInfoSettingsActivity extends Settings { }
203 public static class ApplicationSettingsActivity extends Settings { }
204 public static class ManageApplicationsActivity extends Settings { }
205 public static class StorageUseActivity extends Settings { }
206 public static class DevelopmentSettingsActivity extends Settings { }
207 public static class AccessibilitySettingsActivity extends Settings { }
208 public static class SecuritySettingsActivity extends Settings { }
209 public static class PrivacySettingsActivity extends Settings { }
210 public static class DockSettingsActivity extends Settings { }
211 public static class RunningServicesActivity extends Settings { }
212 public static class VoiceInputOutputSettingsActivity extends Settings { }
Amith Yamasaniea071652010-11-08 14:28:05 -0800213 public static class ManageAccountsSettingsActivity extends Settings { }
Dianne Hackborn59a48602010-11-10 23:34:52 -0800214 public static class PowerUsageSummaryActivity extends Settings { }
Amith Yamasani43c69782010-12-01 09:04:36 -0800215 public static class AccountSyncSettingsActivity extends Settings { }
216 public static class AccountSyncSettingsInAddAccountActivity extends Settings { }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800217}