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