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 | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 19 | import android.content.Intent; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 20 | import android.content.pm.ActivityInfo; |
| 21 | import android.content.pm.PackageManager; |
| 22 | import android.content.pm.PackageManager.NameNotFoundException; |
Dianne Hackborn | f4eb85b | 2010-10-29 16:53:04 -0700 | [diff] [blame] | 23 | import android.os.Bundle; |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 24 | import android.preference.PreferenceActivity; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 25 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 26 | import java.util.HashMap; |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 27 | import java.util.List; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Top-level settings activity to handle single pane and double pane UI layout. |
| 31 | */ |
Daisuke Miyakawa | 25af150 | 2010-09-24 11:29:31 -0700 | [diff] [blame] | 32 | public class Settings extends PreferenceActivity { |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 33 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 34 | 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; |
| 41 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 42 | // TODO: Update Call Settings based on airplane mode state. |
Amith Yamasani | b61cf51 | 2010-09-12 08:17:50 -0700 | [diff] [blame] | 43 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 44 | protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>(); |
| 45 | |
| 46 | @Override |
| 47 | protected void onCreate(Bundle savedInstanceState) { |
| 48 | getMetaData(); |
| 49 | super.onCreate(savedInstanceState); |
| 50 | |
| 51 | // TODO: Do this only if 2-pane mode |
| 52 | highlightHeader(); |
| 53 | } |
| 54 | |
| 55 | private void highlightHeader() { |
| 56 | if (mTopLevelHeaderId != 0) { |
| 57 | Integer index = mHeaderIndexMap.get(mTopLevelHeaderId); |
| 58 | if (index != null) { |
| 59 | getListView().setItemChecked(index, true); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame] | 64 | @Override |
| 65 | public Intent getIntent() { |
| 66 | String startingFragment = getStartingFragmentClass(super.getIntent()); |
| 67 | if (startingFragment != null && !onIsMultiPane()) { |
| 68 | Intent modIntent = new Intent(super.getIntent()); |
| 69 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); |
Dianne Hackborn | f4eb85b | 2010-10-29 16:53:04 -0700 | [diff] [blame] | 70 | Bundle args = super.getIntent().getExtras(); |
| 71 | if (args != null) { |
| 72 | args = new Bundle(args); |
| 73 | } else { |
| 74 | args = new Bundle(); |
| 75 | } |
| 76 | args.putParcelable("intent", super.getIntent()); |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame] | 77 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, super.getIntent().getExtras()); |
| 78 | return modIntent; |
| 79 | } |
| 80 | return super.getIntent(); |
| 81 | } |
| 82 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 83 | /** |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 84 | * Checks if the component name in the intent is different from the Settings class and |
| 85 | * returns the class name to load as a fragment. |
| 86 | */ |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 87 | protected String getStartingFragmentClass(Intent intent) { |
| 88 | if (mFragmentClass != null) return mFragmentClass; |
| 89 | |
Dianne Hackborn | f4eb85b | 2010-10-29 16:53:04 -0700 | [diff] [blame] | 90 | String intentClass = intent.getComponent().getClassName(); |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 91 | if (intentClass.equals(getClass().getName())) return null; |
| 92 | |
Dianne Hackborn | ee29379 | 2010-11-01 12:32:33 -0700 | [diff] [blame] | 93 | if ("com.android.settings.ManageApplications".equals(intentClass) |
| 94 | || "com.android.settings.RunningServices".equals(intentClass) |
| 95 | || "com.android.settings.applications.StorageUse".equals(intentClass)) { |
Dianne Hackborn | f4eb85b | 2010-10-29 16:53:04 -0700 | [diff] [blame] | 96 | // Old name of manage apps. |
| 97 | intentClass = com.android.settings.applications.ManageApplications.class.getName(); |
| 98 | } |
| 99 | |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 100 | return intentClass; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Override initial header when an activity-alias is causing Settings to be launched |
| 105 | * for a specific fragment encoded in the android:name parameter. |
| 106 | */ |
| 107 | @Override |
| 108 | public Header onGetInitialHeader() { |
| 109 | String fragmentClass = getStartingFragmentClass(super.getIntent()); |
| 110 | if (fragmentClass != null) { |
| 111 | Header header = new Header(); |
| 112 | header.fragment = fragmentClass; |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame] | 113 | header.fragmentArguments = getIntent().getExtras(); |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 114 | return header; |
| 115 | } |
| 116 | return super.onGetInitialHeader(); |
| 117 | } |
| 118 | |
| 119 | /** |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 120 | * Populate the activity with the top-level headers. |
| 121 | */ |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 122 | @Override |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 123 | public void onBuildHeaders(List<Header> target) { |
| 124 | loadHeadersFromResource(R.xml.settings_headers, target); |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 125 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 126 | updateHeaderList(target); |
| 127 | } |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 128 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 129 | private void updateHeaderList(List<Header> target) { |
| 130 | int i = 0; |
| 131 | while (i < target.size()) { |
| 132 | Header header = target.get(i); |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 133 | // Ids are integers, so downcasting |
| 134 | int id = (int) header.id; |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 135 | if (id == R.id.dock_settings) { |
| 136 | if (!needsDockSettings()) |
| 137 | target.remove(header); |
| 138 | } else if (id == R.id.operator_settings || id == R.id.manufacturer_settings) { |
| 139 | Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header); |
| 140 | } else if (id == R.id.call_settings) { |
| 141 | if (!Utils.isVoiceCapable(this)) |
| 142 | target.remove(header); |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 143 | } |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 144 | // Increment if the current one wasn't removed by the Utils code. |
| 145 | if (target.get(i) == header) { |
| 146 | mHeaderIndexMap.put(id, i); |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 147 | i++; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 148 | } |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 152 | private boolean needsDockSettings() { |
| 153 | return getResources().getBoolean(R.bool.has_dock_settings); |
Amith Yamasani | b61cf51 | 2010-09-12 08:17:50 -0700 | [diff] [blame] | 154 | } |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 155 | |
| 156 | private void getMetaData() { |
| 157 | try { |
| 158 | ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), |
| 159 | PackageManager.GET_META_DATA); |
| 160 | if (ai == null || ai.metaData == null) return; |
| 161 | mTopLevelHeaderId = ai.metaData.getInt(META_DATA_KEY_HEADER_ID); |
| 162 | mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); |
| 163 | } catch (NameNotFoundException nnfe) { |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | /* |
| 168 | * Settings subclasses for launching independently. |
| 169 | */ |
| 170 | |
| 171 | public static class BluetoothSettingsActivity extends Settings { } |
| 172 | public static class WirelessSettingsActivity extends Settings { } |
| 173 | public static class TetherSettingsActivity extends Settings { } |
| 174 | public static class VpnSettingsActivity extends Settings { } |
| 175 | public static class DateTimeSettingsActivity extends Settings { } |
| 176 | public static class StorageSettingsActivity extends Settings { } |
| 177 | public static class WifiSettingsActivity extends Settings { } |
| 178 | public static class InputMethodAndLanguageSettingsActivity extends Settings { } |
| 179 | public static class InputMethodAndSubtypeEnablerActivity extends Settings { } |
| 180 | public static class LocalePickerActivity extends Settings { } |
| 181 | public static class UserDictionarySettingsActivity extends Settings { } |
| 182 | public static class SoundSettingsActivity extends Settings { } |
| 183 | public static class DisplaySettingsActivity extends Settings { } |
| 184 | public static class DeviceInfoSettingsActivity extends Settings { } |
| 185 | public static class ApplicationSettingsActivity extends Settings { } |
| 186 | public static class ManageApplicationsActivity extends Settings { } |
| 187 | public static class StorageUseActivity extends Settings { } |
| 188 | public static class DevelopmentSettingsActivity extends Settings { } |
| 189 | public static class AccessibilitySettingsActivity extends Settings { } |
| 190 | public static class SecuritySettingsActivity extends Settings { } |
| 191 | public static class PrivacySettingsActivity extends Settings { } |
| 192 | public static class DockSettingsActivity extends Settings { } |
| 193 | public static class RunningServicesActivity extends Settings { } |
| 194 | public static class VoiceInputOutputSettingsActivity extends Settings { } |
Amith Yamasani | ea07165 | 2010-11-08 14:28:05 -0800 | [diff] [blame] | 195 | public static class ManageAccountsSettingsActivity extends Settings { } |
Dianne Hackborn | 59a4860 | 2010-11-10 23:34:52 -0800 | [diff] [blame^] | 196 | public static class PowerUsageSummaryActivity extends Settings { } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 197 | } |