Code example for CheckBox

Methods: setEnabled, setChecked

0
    PushPreferences prefs = PushManager.shared().getPreferences();
 
     
    private void pushSettingsActive(boolean b) {
    	soundEnabled.setEnabled(b);
    	vibrateEnabled.setEnabled(b);
    } 
     
    private void quietTimeSettingsActive(boolean b) {
    	startTime.setEnabled(b);
    	endTime.setEnabled(b);
    } 
     
    @Override 
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
 
        Window w = getWindow();
        w.requestFeature(Window.FEATURE_LEFT_ICON);
        setContentView(R.layout.push_preferences_dialog); 
         
        pushEnabled = (CheckBox) findViewById(R.id.push_enabled);
        soundEnabled = (CheckBox) findViewById(R.id.sound_enabled);
        vibrateEnabled = (CheckBox) findViewById(R.id.vibrate_enabled);
        quietTimeEnabled = (CheckBox) findViewById(R.id.quiet_time_enabled);
         
        startTime = (TimePicker) findViewById(R.id.start_time);
        endTime = (TimePicker) findViewById(R.id.end_time);
 
        startTime.setIs24HourView(DateFormat.is24HourFormat(this));
        endTime.setIs24HourView(DateFormat.is24HourFormat(this));
         
        pushEnabled.setOnClickListener(new OnClickListener() {
 
			@Override 
			public void onClick(View v) {
				pushSettingsActive(((CheckBox)v).isChecked());
			} 
        	 
        }); 
         
        quietTimeEnabled.setOnClickListener(new OnClickListener(){
 
			@Override 
			public void onClick(View v) {
				quietTimeSettingsActive(((CheckBox)v).isChecked());
			} 
        }); 
         
    } 
 
    // When the activity starts, we need to fetch and display the user's current 
    // Push preferences in the view, if applicable. 
    @Override 
    public void onStart() { 
        super.onStart(); 
         
        boolean isPushEnabled = prefs.isPushEnabled();
        pushEnabled.setChecked(isPushEnabled);
        soundEnabled.setChecked(prefs.isSoundEnabled());
        vibrateEnabled.setChecked(prefs.isVibrateEnabled());
        pushSettingsActive(isPushEnabled);
         
        boolean isQuietTimeEnabled = prefs.isQuietTimeEnabled();
        quietTimeEnabled.setChecked(isQuietTimeEnabled);
        quietTimeSettingsActive(isQuietTimeEnabled);