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

RingerVolumePreference

public class RingerVolumePreference extends android.preference.VolumePreference implements CheckBox.OnCheckedChangeListener
Special preference type that allows configuration of both the ring volume and notification volume.

Fields Summary
private static final String
TAG
private android.widget.CheckBox
mNotificationsUseRingVolumeCheckbox
private android.preference.VolumePreference.SeekBarVolumizer
mNotificationSeekBarVolumizer
private android.widget.TextView
mNotificationVolumeTitle
Constructors Summary
public RingerVolumePreference(android.content.Context context, android.util.AttributeSet attrs)

    
         
        super(context, attrs);

        // The always visible seekbar is for ring volume
        setStreamType(AudioManager.STREAM_RING);
        
        setDialogLayoutResource(R.layout.preference_dialog_ringervolume);
    
Methods Summary
private voidcleanup()

        if (mNotificationSeekBarVolumizer != null) {
            mNotificationSeekBarVolumizer.stop();
            mNotificationSeekBarVolumizer = null;
        }
    
public voidonActivityStop()

        super.onActivityStop();
        cleanup();
    
protected voidonBindDialogView(android.view.View view)

        super.onBindDialogView(view);
     
        mNotificationsUseRingVolumeCheckbox =
                (CheckBox) view.findViewById(R.id.same_notification_volume);
        mNotificationsUseRingVolumeCheckbox.setOnCheckedChangeListener(this);
        mNotificationsUseRingVolumeCheckbox.setChecked(Settings.System.getInt(
                getContext().getContentResolver(),
                Settings.System.NOTIFICATIONS_USE_RING_VOLUME, 1) == 1);
        
        final SeekBar seekBar = (SeekBar) view.findViewById(R.id.notification_volume_seekbar);
        mNotificationSeekBarVolumizer = new SeekBarVolumizer(getContext(), seekBar,
                AudioManager.STREAM_NOTIFICATION);
        
        mNotificationVolumeTitle = (TextView) view.findViewById(R.id.notification_volume_title);
        
        setNotificationVolumeVisibility(!mNotificationsUseRingVolumeCheckbox.isChecked());
    
public voidonCheckedChanged(android.widget.CompoundButton buttonView, boolean isChecked)

        setNotificationVolumeVisibility(!isChecked);
        
        Settings.System.putInt(getContext().getContentResolver(),
                Settings.System.NOTIFICATIONS_USE_RING_VOLUME, isChecked ? 1 : 0);
        
        if (isChecked) {
            // The user wants the notification to be same as ring, so do a
            // one-time sync right now
            AudioManager audioManager = (AudioManager) getContext()
                    .getSystemService(Context.AUDIO_SERVICE);
            audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION,
                    audioManager.getStreamVolume(AudioManager.STREAM_RING), 0);
        }
    
protected voidonDialogClosed(boolean positiveResult)

        super.onDialogClosed(positiveResult);
        
        if (!positiveResult && mNotificationSeekBarVolumizer != null) {
            mNotificationSeekBarVolumizer.revertVolume();
        }
        
        cleanup();
    
protected voidonSampleStarting(android.preference.VolumePreference.SeekBarVolumizer volumizer)

        super.onSampleStarting(volumizer);
        
        if (mNotificationSeekBarVolumizer != null && volumizer != mNotificationSeekBarVolumizer) {
            mNotificationSeekBarVolumizer.stopSample();
        }
    
private voidsetNotificationVolumeVisibility(boolean visible)

        if (mNotificationSeekBarVolumizer != null) {
            mNotificationSeekBarVolumizer.getSeekBar().setVisibility(
                    visible ? View.VISIBLE : View.GONE);
            mNotificationVolumeTitle.setVisibility(visible ? View.VISIBLE : View.GONE);
        }