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 | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 20 | import android.preference.PreferenceActivity; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 21 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 22 | import java.util.List; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Top-level settings activity to handle single pane and double pane UI layout. |
| 26 | */ |
Daisuke Miyakawa | 25af150 | 2010-09-24 11:29:31 -0700 | [diff] [blame] | 27 | public class Settings extends PreferenceActivity { |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 28 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 29 | // TODO: Update Call Settings based on airplane mode state. |
Amith Yamasani | b61cf51 | 2010-09-12 08:17:50 -0700 | [diff] [blame] | 30 | |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame^] | 31 | @Override |
| 32 | public Intent getIntent() { |
| 33 | String startingFragment = getStartingFragmentClass(super.getIntent()); |
| 34 | if (startingFragment != null && !onIsMultiPane()) { |
| 35 | Intent modIntent = new Intent(super.getIntent()); |
| 36 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); |
| 37 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, super.getIntent().getExtras()); |
| 38 | return modIntent; |
| 39 | } |
| 40 | return super.getIntent(); |
| 41 | } |
| 42 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 43 | /** |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 44 | * Checks if the component name in the intent is different from the Settings class and |
| 45 | * returns the class name to load as a fragment. |
| 46 | */ |
| 47 | private String getStartingFragmentClass(Intent intent) { |
| 48 | final String intentClass = intent.getComponent().getClassName(); |
| 49 | if (intentClass.equals(getClass().getName())) return null; |
| 50 | |
| 51 | return intentClass; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Override initial header when an activity-alias is causing Settings to be launched |
| 56 | * for a specific fragment encoded in the android:name parameter. |
| 57 | */ |
| 58 | @Override |
| 59 | public Header onGetInitialHeader() { |
| 60 | String fragmentClass = getStartingFragmentClass(super.getIntent()); |
| 61 | if (fragmentClass != null) { |
| 62 | Header header = new Header(); |
| 63 | header.fragment = fragmentClass; |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame^] | 64 | header.fragmentArguments = getIntent().getExtras(); |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 65 | return header; |
| 66 | } |
| 67 | return super.onGetInitialHeader(); |
| 68 | } |
| 69 | |
| 70 | /** |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 71 | * Populate the activity with the top-level headers. |
| 72 | */ |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 73 | @Override |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 74 | public void onBuildHeaders(List<Header> target) { |
| 75 | loadHeadersFromResource(R.xml.settings_headers, target); |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 76 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 77 | updateHeaderList(target); |
| 78 | } |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 79 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 80 | private void updateHeaderList(List<Header> target) { |
| 81 | int i = 0; |
| 82 | while (i < target.size()) { |
| 83 | Header header = target.get(i); |
| 84 | long id = header.id; |
| 85 | if (id == R.id.dock_settings) { |
| 86 | if (!needsDockSettings()) |
| 87 | target.remove(header); |
| 88 | } else if (id == R.id.operator_settings || id == R.id.manufacturer_settings) { |
| 89 | Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header); |
| 90 | } else if (id == R.id.call_settings) { |
| 91 | if (!Utils.isVoiceCapable(this)) |
| 92 | target.remove(header); |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 93 | } |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 94 | if (target.get(i) == header) |
| 95 | i++; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 99 | private boolean needsDockSettings() { |
| 100 | return getResources().getBoolean(R.bool.has_dock_settings); |
Amith Yamasani | b61cf51 | 2010-09-12 08:17:50 -0700 | [diff] [blame] | 101 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 102 | } |