blob: 6cc641ed8e6335f665d4964b7b027c01f310bdbc [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 Yamasani02cf71a2010-09-21 15:48:52 -070020import android.preference.PreferenceActivity;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080021
Amith Yamasani02cf71a2010-09-21 15:48:52 -070022import java.util.List;
Amith Yamasanid7993472010-08-18 13:59:28 -070023
24/**
25 * Top-level settings activity to handle single pane and double pane UI layout.
26 */
Daisuke Miyakawa25af1502010-09-24 11:29:31 -070027public class Settings extends PreferenceActivity {
Amith Yamasanid7993472010-08-18 13:59:28 -070028
Amith Yamasani02cf71a2010-09-21 15:48:52 -070029 // TODO: Update Call Settings based on airplane mode state.
Amith Yamasanib61cf512010-09-12 08:17:50 -070030
Amith Yamasanie0e4fc22010-10-05 11:49:51 -070031 @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 Yamasani02cf71a2010-09-21 15:48:52 -070043 /**
Amith Yamasani379d9b02010-09-27 12:03:59 -070044 * 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 Yamasanie0e4fc22010-10-05 11:49:51 -070064 header.fragmentArguments = getIntent().getExtras();
Amith Yamasani379d9b02010-09-27 12:03:59 -070065 return header;
66 }
67 return super.onGetInitialHeader();
68 }
69
70 /**
Amith Yamasani02cf71a2010-09-21 15:48:52 -070071 * Populate the activity with the top-level headers.
72 */
Amith Yamasanid7993472010-08-18 13:59:28 -070073 @Override
Amith Yamasani02cf71a2010-09-21 15:48:52 -070074 public void onBuildHeaders(List<Header> target) {
75 loadHeadersFromResource(R.xml.settings_headers, target);
Amith Yamasanid7993472010-08-18 13:59:28 -070076
Amith Yamasani02cf71a2010-09-21 15:48:52 -070077 updateHeaderList(target);
78 }
Amith Yamasanid7993472010-08-18 13:59:28 -070079
Amith Yamasani02cf71a2010-09-21 15:48:52 -070080 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 Yamasanid7993472010-08-18 13:59:28 -070093 }
Amith Yamasani02cf71a2010-09-21 15:48:52 -070094 if (target.get(i) == header)
95 i++;
Amith Yamasanid7993472010-08-18 13:59:28 -070096 }
97 }
98
Amith Yamasani02cf71a2010-09-21 15:48:52 -070099 private boolean needsDockSettings() {
100 return getResources().getBoolean(R.bool.has_dock_settings);
Amith Yamasanib61cf512010-09-12 08:17:50 -0700101 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800102}