blob: 1f57f6c4e5c2ce48ca608a081a7018cdc3dfa8c3 [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 Yamasanid7993472010-08-18 13:59:28 -070019import android.app.Fragment;
Amith Yamasani379d9b02010-09-27 12:03:59 -070020import android.content.Intent;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080021import android.os.Bundle;
Amith Yamasani02cf71a2010-09-21 15:48:52 -070022import android.preference.PreferenceActivity;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080023
Amith Yamasani02cf71a2010-09-21 15:48:52 -070024import java.util.List;
Amith Yamasanid7993472010-08-18 13:59:28 -070025
26/**
27 * Top-level settings activity to handle single pane and double pane UI layout.
28 */
Daisuke Miyakawa25af1502010-09-24 11:29:31 -070029public class Settings extends PreferenceActivity {
Amith Yamasanid7993472010-08-18 13:59:28 -070030
Amith Yamasani02cf71a2010-09-21 15:48:52 -070031 // TODO: Update Call Settings based on airplane mode state.
Amith Yamasanib61cf512010-09-12 08:17:50 -070032
Amith Yamasani02cf71a2010-09-21 15:48:52 -070033 /**
Amith Yamasani379d9b02010-09-27 12:03:59 -070034 * 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 Yamasani02cf71a2010-09-21 15:48:52 -070060 * Populate the activity with the top-level headers.
61 */
Amith Yamasanid7993472010-08-18 13:59:28 -070062 @Override
Amith Yamasani02cf71a2010-09-21 15:48:52 -070063 public void onBuildHeaders(List<Header> target) {
64 loadHeadersFromResource(R.xml.settings_headers, target);
Amith Yamasanid7993472010-08-18 13:59:28 -070065
Amith Yamasani02cf71a2010-09-21 15:48:52 -070066 updateHeaderList(target);
67 }
Amith Yamasanid7993472010-08-18 13:59:28 -070068
Amith Yamasani02cf71a2010-09-21 15:48:52 -070069 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 Yamasanid7993472010-08-18 13:59:28 -070082 }
Amith Yamasani02cf71a2010-09-21 15:48:52 -070083 if (target.get(i) == header)
84 i++;
Amith Yamasanid7993472010-08-18 13:59:28 -070085 }
86 }
87
Amith Yamasani02cf71a2010-09-21 15:48:52 -070088 private boolean needsDockSettings() {
89 return getResources().getBoolean(R.bool.has_dock_settings);
Amith Yamasanib61cf512010-09-12 08:17:50 -070090 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080091}