blob: 3a6e6d844fdfb17aa2e9269467d50f9db4d6383e [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;
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -070020import android.os.Bundle;
Amith Yamasani02cf71a2010-09-21 15:48:52 -070021import android.preference.PreferenceActivity;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080022
Amith Yamasani02cf71a2010-09-21 15:48:52 -070023import java.util.List;
Amith Yamasanid7993472010-08-18 13:59:28 -070024
25/**
26 * Top-level settings activity to handle single pane and double pane UI layout.
27 */
Daisuke Miyakawa25af1502010-09-24 11:29:31 -070028public class Settings extends PreferenceActivity {
Amith Yamasanid7993472010-08-18 13:59:28 -070029
Amith Yamasani02cf71a2010-09-21 15:48:52 -070030 // TODO: Update Call Settings based on airplane mode state.
Amith Yamasanib61cf512010-09-12 08:17:50 -070031
Amith Yamasanie0e4fc22010-10-05 11:49:51 -070032 @Override
33 public Intent getIntent() {
34 String startingFragment = getStartingFragmentClass(super.getIntent());
35 if (startingFragment != null && !onIsMultiPane()) {
36 Intent modIntent = new Intent(super.getIntent());
37 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -070038 Bundle args = super.getIntent().getExtras();
39 if (args != null) {
40 args = new Bundle(args);
41 } else {
42 args = new Bundle();
43 }
44 args.putParcelable("intent", super.getIntent());
Amith Yamasanie0e4fc22010-10-05 11:49:51 -070045 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, super.getIntent().getExtras());
46 return modIntent;
47 }
48 return super.getIntent();
49 }
50
Amith Yamasani02cf71a2010-09-21 15:48:52 -070051 /**
Amith Yamasani379d9b02010-09-27 12:03:59 -070052 * Checks if the component name in the intent is different from the Settings class and
53 * returns the class name to load as a fragment.
54 */
55 private String getStartingFragmentClass(Intent intent) {
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -070056 String intentClass = intent.getComponent().getClassName();
Amith Yamasani379d9b02010-09-27 12:03:59 -070057 if (intentClass.equals(getClass().getName())) return null;
58
Dianne Hackbornee293792010-11-01 12:32:33 -070059 if ("com.android.settings.ManageApplications".equals(intentClass)
60 || "com.android.settings.RunningServices".equals(intentClass)
61 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
Dianne Hackbornf4eb85b2010-10-29 16:53:04 -070062 // Old name of manage apps.
63 intentClass = com.android.settings.applications.ManageApplications.class.getName();
64 }
65
Amith Yamasani379d9b02010-09-27 12:03:59 -070066 return intentClass;
67 }
68
69 /**
70 * Override initial header when an activity-alias is causing Settings to be launched
71 * for a specific fragment encoded in the android:name parameter.
72 */
73 @Override
74 public Header onGetInitialHeader() {
75 String fragmentClass = getStartingFragmentClass(super.getIntent());
76 if (fragmentClass != null) {
77 Header header = new Header();
78 header.fragment = fragmentClass;
Amith Yamasanie0e4fc22010-10-05 11:49:51 -070079 header.fragmentArguments = getIntent().getExtras();
Amith Yamasani379d9b02010-09-27 12:03:59 -070080 return header;
81 }
82 return super.onGetInitialHeader();
83 }
84
85 /**
Amith Yamasani02cf71a2010-09-21 15:48:52 -070086 * Populate the activity with the top-level headers.
87 */
Amith Yamasanid7993472010-08-18 13:59:28 -070088 @Override
Amith Yamasani02cf71a2010-09-21 15:48:52 -070089 public void onBuildHeaders(List<Header> target) {
90 loadHeadersFromResource(R.xml.settings_headers, target);
Amith Yamasanid7993472010-08-18 13:59:28 -070091
Amith Yamasani02cf71a2010-09-21 15:48:52 -070092 updateHeaderList(target);
93 }
Amith Yamasanid7993472010-08-18 13:59:28 -070094
Amith Yamasani02cf71a2010-09-21 15:48:52 -070095 private void updateHeaderList(List<Header> target) {
96 int i = 0;
97 while (i < target.size()) {
98 Header header = target.get(i);
99 long id = header.id;
100 if (id == R.id.dock_settings) {
101 if (!needsDockSettings())
102 target.remove(header);
103 } else if (id == R.id.operator_settings || id == R.id.manufacturer_settings) {
104 Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header);
105 } else if (id == R.id.call_settings) {
106 if (!Utils.isVoiceCapable(this))
107 target.remove(header);
Amith Yamasanid7993472010-08-18 13:59:28 -0700108 }
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700109 if (target.get(i) == header)
110 i++;
Amith Yamasanid7993472010-08-18 13:59:28 -0700111 }
112 }
113
Amith Yamasani02cf71a2010-09-21 15:48:52 -0700114 private boolean needsDockSettings() {
115 return getResources().getBoolean(R.bool.has_dock_settings);
Amith Yamasanib61cf512010-09-12 08:17:50 -0700116 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800117}