FileDocCategorySizeDatePackage
AirplaneModeEnabler.javaAPI DocAndroid 1.5 API4117Wed May 06 22:42:48 BST 2009com.android.settings

AirplaneModeEnabler

public class AirplaneModeEnabler extends Object implements Preference.OnPreferenceChangeListener

Fields Summary
private final android.content.Context
mContext
private com.android.internal.telephony.PhoneStateIntentReceiver
mPhoneStateReceiver
private final android.preference.CheckBoxPreference
mCheckBoxPref
private static final int
EVENT_SERVICE_STATE_CHANGED
private android.os.Handler
mHandler
Constructors Summary
public AirplaneModeEnabler(android.content.Context context, android.preference.CheckBoxPreference airplaneModeCheckBoxPreference)


         
        
        mContext = context;
        mCheckBoxPref = airplaneModeCheckBoxPreference;
        
        airplaneModeCheckBoxPreference.setPersistent(false);
    
        mPhoneStateReceiver = new PhoneStateIntentReceiver(mContext, mHandler);
        mPhoneStateReceiver.notifyServiceState(EVENT_SERVICE_STATE_CHANGED);
    
Methods Summary
static booleanisAirplaneModeOn(android.content.Context context)

        return Settings.System.getInt(context.getContentResolver(),
                Settings.System.AIRPLANE_MODE_ON, 0) != 0;
    
private voidonAirplaneModeChanged()
Called when we've received confirmation that the airplane mode was set.

        ServiceState serviceState = mPhoneStateReceiver.getServiceState();
        boolean airplaneModeEnabled = serviceState.getState() == ServiceState.STATE_POWER_OFF;
        mCheckBoxPref.setChecked(airplaneModeEnabled);
        mCheckBoxPref.setSummary(airplaneModeEnabled ? null : 
                mContext.getString(R.string.airplane_mode_summary));            
        mCheckBoxPref.setEnabled(true);
    
public booleanonPreferenceChange(android.preference.Preference preference, java.lang.Object newValue)
Called when someone clicks on the checkbox preference.

        setAirplaneModeOn((Boolean) newValue);
        return true;
    
public voidpause()

        mPhoneStateReceiver.unregisterIntent();
        mCheckBoxPref.setOnPreferenceChangeListener(null);
    
public voidresume()

        
        // This is the widget enabled state, not the preference toggled state
        mCheckBoxPref.setEnabled(true);
        mCheckBoxPref.setChecked(isAirplaneModeOn(mContext));

        mPhoneStateReceiver.registerIntent();
        mCheckBoxPref.setOnPreferenceChangeListener(this);
    
private voidsetAirplaneModeOn(boolean enabling)

        
        mCheckBoxPref.setEnabled(false);
        mCheckBoxPref.setSummary(enabling ? R.string.airplane_mode_turning_on
                : R.string.airplane_mode_turning_off);
        
        // Change the system setting
        Settings.System.putInt(mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 
                                enabling ? 1 : 0);
        
        // Post the intent
        Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        intent.putExtra("state", enabling);
        mContext.sendBroadcast(intent);