Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame^] | 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 | |
| 17 | package com.android.phone; |
| 18 | |
| 19 | import android.preference.CheckBoxPreference; |
| 20 | import android.preference.Preference; |
| 21 | import android.preference.PreferenceActivity; |
| 22 | import android.preference.PreferenceScreen; |
| 23 | import android.content.res.Resources; |
| 24 | |
| 25 | import com.android.internal.telephony.Phone; |
| 26 | import com.android.internal.telephony.PhoneConstants; |
| 27 | import com.android.internal.telephony.PhoneFactory; |
| 28 | |
| 29 | /** |
| 30 | * List of Network-specific settings screens. |
| 31 | */ |
| 32 | public class GsmUmtsOptions { |
| 33 | private static final String LOG_TAG = "GsmUmtsOptions"; |
| 34 | |
| 35 | private PreferenceScreen mButtonAPNExpand; |
| 36 | private PreferenceScreen mButtonOperatorSelectionExpand; |
| 37 | private CheckBoxPreference mButtonPrefer2g; |
| 38 | |
| 39 | private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key"; |
| 40 | private static final String BUTTON_OPERATOR_SELECTION_EXPAND_KEY = "button_carrier_sel_key"; |
| 41 | private static final String BUTTON_PREFER_2G_KEY = "button_prefer_2g_key"; |
| 42 | private PreferenceActivity mPrefActivity; |
| 43 | private PreferenceScreen mPrefScreen; |
| 44 | |
| 45 | public GsmUmtsOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen) { |
| 46 | mPrefActivity = prefActivity; |
| 47 | mPrefScreen = prefScreen; |
| 48 | create(); |
| 49 | } |
| 50 | |
| 51 | protected void create() { |
| 52 | mPrefActivity.addPreferencesFromResource(R.xml.gsm_umts_options); |
| 53 | mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY); |
| 54 | mButtonOperatorSelectionExpand = |
| 55 | (PreferenceScreen) mPrefScreen.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY); |
| 56 | mButtonPrefer2g = (CheckBoxPreference) mPrefScreen.findPreference(BUTTON_PREFER_2G_KEY); |
| 57 | if (PhoneFactory.getDefaultPhone().getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) { |
| 58 | log("Not a GSM phone"); |
| 59 | mButtonAPNExpand.setEnabled(false); |
| 60 | mButtonOperatorSelectionExpand.setEnabled(false); |
| 61 | mButtonPrefer2g.setEnabled(false); |
| 62 | } else { |
| 63 | log("Not a CDMA phone"); |
| 64 | Resources res = mPrefActivity.getResources(); |
| 65 | |
| 66 | // Determine which options to display, for GSM these are defaulted |
| 67 | // are defaulted to true in Phone/res/values/config.xml. But for |
| 68 | // some operators like verizon they maybe overriden in operator |
| 69 | // specific resources or device specifc overlays. |
| 70 | if (!res.getBoolean(R.bool.config_apn_expand)) { |
| 71 | mPrefScreen.removePreference(mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY)); |
| 72 | } |
| 73 | if (!res.getBoolean(R.bool.config_operator_selection_expand)) { |
| 74 | mPrefScreen.removePreference(mPrefScreen |
| 75 | .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY)); |
| 76 | } |
| 77 | if (!res.getBoolean(R.bool.config_prefer_2g)) { |
| 78 | mPrefScreen.removePreference(mPrefScreen.findPreference(BUTTON_PREFER_2G_KEY)); |
| 79 | } |
| 80 | |
| 81 | if (res.getBoolean(R.bool.csp_enabled)) { |
| 82 | if (PhoneFactory.getDefaultPhone().isCspPlmnEnabled()) { |
| 83 | log("[CSP] Enabling Operator Selection menu."); |
| 84 | mButtonOperatorSelectionExpand.setEnabled(true); |
| 85 | } else { |
| 86 | log("[CSP] Disabling Operator Selection menu."); |
| 87 | mPrefScreen.removePreference(mPrefScreen |
| 88 | .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY)); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | public boolean preferenceTreeClick(Preference preference) { |
| 95 | if (preference.getKey().equals(BUTTON_PREFER_2G_KEY)) { |
| 96 | log("preferenceTreeClick: return true"); |
| 97 | return true; |
| 98 | } |
| 99 | log("preferenceTreeClick: return false"); |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | protected void log(String s) { |
| 104 | android.util.Log.d(LOG_TAG, s); |
| 105 | } |
| 106 | } |