blob: de1a63c0279e3eafb33c1368d4204b7ad0b5a655 [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 */
Amith Yamasani02cf71a2010-09-21 15:48:52 -070029public class Settings extends PreferenceActivity implements
Daisuke Miyakawab5647c52010-09-10 18:04:02 -070030 SettingsPreferenceFragment.FragmentStarter {
Amith Yamasanid7993472010-08-18 13:59:28 -070031
Amith Yamasani02cf71a2010-09-21 15:48:52 -070032 // TODO: Update Call Settings based on airplane mode state.
Amith Yamasanib61cf512010-09-12 08:17:50 -070033
Amith Yamasani02cf71a2010-09-21 15:48:52 -070034 /**
Amith Yamasani379d9b02010-09-27 12:03:59 -070035 * Checks if the component name in the intent is different from the Settings class and
36 * returns the class name to load as a fragment.
37 */
38 private String getStartingFragmentClass(Intent intent) {
39 final String intentClass = intent.getComponent().getClassName();
40 if (intentClass.equals(getClass().getName())) return null;
41
42 return intentClass;
43 }
44
45 /**
46 * Override initial header when an activity-alias is causing Settings to be launched
47 * for a specific fragment encoded in the android:name parameter.
48 */
49 @Override
50 public Header onGetInitialHeader() {
51 String fragmentClass = getStartingFragmentClass(super.getIntent());
52 if (fragmentClass != null) {
53 Header header = new Header();
54 header.fragment = fragmentClass;
55 return header;
56 }
57 return super.onGetInitialHeader();
58 }
59
60 /**
Amith Yamasani02cf71a2010-09-21 15:48:52 -070061 * Populate the activity with the top-level headers.
62 */
Amith Yamasanid7993472010-08-18 13:59:28 -070063 @Override
Amith Yamasani02cf71a2010-09-21 15:48:52 -070064 public void onBuildHeaders(List<Header> target) {
65 loadHeadersFromResource(R.xml.settings_headers, target);
Amith Yamasanid7993472010-08-18 13:59:28 -070066
Amith Yamasani02cf71a2010-09-21 15:48:52 -070067 updateHeaderList(target);
68 }
Amith Yamasanid7993472010-08-18 13:59:28 -070069
Amith Yamasani02cf71a2010-09-21 15:48:52 -070070 private void updateHeaderList(List<Header> target) {
71 int i = 0;
72 while (i < target.size()) {
73 Header header = target.get(i);
74 long id = header.id;
75 if (id == R.id.dock_settings) {
76 if (!needsDockSettings())
77 target.remove(header);
78 } else if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
79 Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header);
80 } else if (id == R.id.call_settings) {
81 if (!Utils.isVoiceCapable(this))
82 target.remove(header);
Amith Yamasanid7993472010-08-18 13:59:28 -070083 }
Amith Yamasani02cf71a2010-09-21 15:48:52 -070084 if (target.get(i) == header)
85 i++;
Amith Yamasanid7993472010-08-18 13:59:28 -070086 }
87 }
88
Amith Yamasani02cf71a2010-09-21 15:48:52 -070089 private boolean needsDockSettings() {
90 return getResources().getBoolean(R.bool.has_dock_settings);
Amith Yamasanib61cf512010-09-12 08:17:50 -070091 }
92
Amith Yamasani02cf71a2010-09-21 15:48:52 -070093 public boolean startFragment(Fragment caller, String fragmentClass, int requestCode,
94 Bundle extras) {
Daisuke Miyakawab5647c52010-09-10 18:04:02 -070095 Fragment f = Fragment.instantiate(this, fragmentClass, extras);
96 caller.setTargetFragment(f, requestCode);
Amith Yamasanid7993472010-08-18 13:59:28 -070097 if (f instanceof SettingsPreferenceFragment) {
Daisuke Miyakawab5647c52010-09-10 18:04:02 -070098 SettingsPreferenceFragment spf = (SettingsPreferenceFragment) f;
Daisuke Miyakawab5647c52010-09-10 18:04:02 -070099 spf.setFragmentStarter(this);
Amith Yamasanid7993472010-08-18 13:59:28 -0700100 }
Amith Yamasanid7993472010-08-18 13:59:28 -0700101 return true;
102 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800103}