Settings.java revision 25af150c9804cbca83461588fa5277908baa943d
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 17package com.android.settings; 18 19import android.app.Fragment; 20import android.content.Intent; 21import android.os.Bundle; 22import android.preference.PreferenceActivity; 23 24import java.util.List; 25 26/** 27 * Top-level settings activity to handle single pane and double pane UI layout. 28 */ 29public class Settings extends PreferenceActivity { 30 31 // TODO: Update Call Settings based on airplane mode state. 32 33 /** 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 /** 60 * Populate the activity with the top-level headers. 61 */ 62 @Override 63 public void onBuildHeaders(List<Header> target) { 64 loadHeadersFromResource(R.xml.settings_headers, target); 65 66 updateHeaderList(target); 67 } 68 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); 82 } 83 if (target.get(i) == header) 84 i++; 85 } 86 } 87 88 private boolean needsDockSettings() { 89 return getResources().getBoolean(R.bool.has_dock_settings); 90 } 91} 92