FileDocCategorySizeDatePackage
Settings.javaAPI DocAndroid 1.5 API7171Wed May 06 22:42:46 BST 2009com.android.phone

Settings

public class Settings extends android.preference.PreferenceActivity implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener
List of Phone-specific settings screens.

Fields Summary
private static final String
BUTTON_ROAMING_KEY
private static final String
BUTTON_PREFER_2G_KEY
private android.preference.CheckBoxPreference
mButtonDataRoam
private android.preference.CheckBoxPreference
mButtonPrefer2g
private com.android.internal.telephony.Phone
mPhone
private boolean
mOkClicked
private MyHandler
mHandler
Constructors Summary
Methods Summary
public voidonClick(android.content.DialogInterface dialog, int which)

    
    //This is a method implemented for DialogInterface.OnClickListener.
    //  Used to dismiss the dialogs when they come up.
          
        if (which == DialogInterface.BUTTON1) {
            mPhone.setDataRoamingEnabled(true);
            mOkClicked = true;
        } else {
            // Reset the toggle
            mButtonDataRoam.setChecked(false);
        }
    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);

        addPreferencesFromResource(R.xml.network_setting);
        
        mPhone = PhoneFactory.getDefaultPhone();
        mHandler = new MyHandler();

        //get UI object references
        PreferenceScreen prefSet = getPreferenceScreen();

        mButtonDataRoam = (CheckBoxPreference) prefSet.findPreference(BUTTON_ROAMING_KEY);
        mButtonPrefer2g = (CheckBoxPreference) prefSet.findPreference(BUTTON_PREFER_2G_KEY);
        
        // The intent code that resided here in the past has been moved into the
        // more conventional location in network_setting.xml
    
public voidonDismiss(android.content.DialogInterface dialog)

        // Assuming that onClick gets called first
        if (!mOkClicked) {
            mButtonDataRoam.setChecked(false);
        }
    
public booleanonPreferenceTreeClick(android.preference.PreferenceScreen preferenceScreen, android.preference.Preference preference)
Invoked on each preference click in this hierarchy, overrides PreferenceActivity's implementation. Used to make sure we track the preference click events.

        if (preference == mButtonDataRoam) {
            //normally called on the toggle click
            if (mButtonDataRoam.isChecked()) {
                // First confirm with a warning dialog about charges
                mOkClicked = false;
                new AlertDialog.Builder(this).setMessage(
                        getResources().getString(R.string.roaming_warning))
                        .setTitle(android.R.string.dialog_alert_title)
                        .setIcon(android.R.drawable.ic_dialog_alert)
                        .setPositiveButton(android.R.string.yes, this)
                        .setNegativeButton(android.R.string.no, this)
                        .show()
                        .setOnDismissListener(this);
            } else {
                mPhone.setDataRoamingEnabled(false);
            }
            return true;
        } else if (preference == mButtonPrefer2g) {
            int networkType = mButtonPrefer2g.isChecked() ? Phone.NT_GSM_TYPE : Phone.NT_AUTO_TYPE;
            mPhone.setPreferredNetworkType(networkType, mHandler
                    .obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE));
            return true;
        } else {
            // if the button is anything but the simple toggle preference,
            // we'll need to disable all preferences to reject all click
            // events until the sub-activity's UI comes up.
            preferenceScreen.setEnabled(false);
            // Let the intents be launched by the Preference manager
            return false;
        }
    
protected voidonResume()

        super.onResume();
        // upon resumption from the sub-activity, make sure we re-enable the
        // preferences.
        getPreferenceScreen().setEnabled(true);
        
        // Set UI state in onResume because a user could go home, launch some
        // app to change this setting's backend, and re-launch this settings app
        // and the UI state would be inconsistent with actual state
        mButtonDataRoam.setChecked(mPhone.getDataRoamingEnabled());

        // Get the state for 'prefer 2g' setting
        mPhone.getPreferredNetworkType(mHandler.obtainMessage(MyHandler.MESSAGE_GET_PREFERRED_NETWORK_TYPE));