Home | History | Annotate | Download | only in phone
      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 
     24 import com.android.internal.telephony.Phone;
     25 import com.android.internal.telephony.PhoneFactory;
     26 
     27 /**
     28  * List of Network-specific settings screens.
     29  */
     30 public class GsmUmtsOptions {
     31     private static final String LOG_TAG = "GsmUmtsOptions";
     32 
     33     private PreferenceScreen mButtonAPNExpand;
     34     private PreferenceScreen mButtonOperatorSelectionExpand;
     35     private CheckBoxPreference mButtonPrefer2g;
     36 
     37     private static final String BUTTON_APN_EXPAND_KEY = "button_apn_key";
     38     private static final String BUTTON_OPERATOR_SELECTION_EXPAND_KEY = "button_carrier_sel_key";
     39     private static final String BUTTON_PREFER_2G_KEY = "button_prefer_2g_key";
     40     private PreferenceActivity mPrefActivity;
     41     private PreferenceScreen mPrefScreen;
     42 
     43     public GsmUmtsOptions(PreferenceActivity prefActivity, PreferenceScreen prefScreen) {
     44         mPrefActivity = prefActivity;
     45         mPrefScreen = prefScreen;
     46         create();
     47     }
     48 
     49     protected void create() {
     50         mPrefActivity.addPreferencesFromResource(R.xml.gsm_umts_options);
     51         mButtonAPNExpand = (PreferenceScreen) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
     52         mButtonOperatorSelectionExpand =
     53                 (PreferenceScreen) mPrefScreen.findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY);
     54         mButtonPrefer2g = (CheckBoxPreference) mPrefScreen.findPreference(BUTTON_PREFER_2G_KEY);
     55         if (PhoneFactory.getDefaultPhone().getPhoneType() != Phone.PHONE_TYPE_GSM) {
     56             log("Not a GSM phone");
     57             mButtonAPNExpand.setEnabled(false);
     58             mButtonOperatorSelectionExpand.setEnabled(false);
     59             mButtonPrefer2g.setEnabled(false);
     60         } else if (mPrefActivity.getResources().getBoolean(R.bool.csp_enabled)) {
     61             if (PhoneFactory.getDefaultPhone().isCspPlmnEnabled()) {
     62                 log("[CSP] Enabling Operator Selection menu.");
     63                 mButtonOperatorSelectionExpand.setEnabled(true);
     64             } else {
     65                 log("[CSP] Disabling Operator Selection menu.");
     66                 mPrefScreen.removePreference(mPrefScreen
     67                       .findPreference(BUTTON_OPERATOR_SELECTION_EXPAND_KEY));
     68             }
     69         }
     70     }
     71 
     72     public boolean preferenceTreeClick(Preference preference) {
     73         if (preference.getKey().equals(BUTTON_PREFER_2G_KEY)) {
     74             log("preferenceTreeClick: return true");
     75             return true;
     76         }
     77         log("preferenceTreeClick: return false");
     78         return false;
     79     }
     80 
     81     protected void log(String s) {
     82         android.util.Log.d(LOG_TAG, s);
     83     }
     84 }
     85