Example usage for android.media AudioManager ADJUST_TOGGLE_MUTE

List of usage examples for android.media AudioManager ADJUST_TOGGLE_MUTE

Introduction

In this page you can find the example usage for android.media AudioManager ADJUST_TOGGLE_MUTE.

Prototype

int ADJUST_TOGGLE_MUTE

To view the source code for android.media AudioManager ADJUST_TOGGLE_MUTE.

Click Source Link

Document

Toggle the mute state.

Usage

From source file:net.hyx.app.volumenotification.NotificationFactory.java

void setVolume(int position) {
    int selection = settings.getButtonSelection(position);
    int direction = AudioManager.ADJUST_SAME;
    int type = STREAM_TYPES[selection];

    if (type == AudioManager.STREAM_MUSIC && settings.getToggleMute()) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            direction = AudioManager.ADJUST_TOGGLE_MUTE;
        } else {// w  ww  . j  a  va 2 s. c o m
            _mute = !_mute;
            audio.setStreamMute(type, _mute);
        }
    } else if (type == AudioManager.STREAM_RING && settings.getToggleSilent()) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            direction = AudioManager.ADJUST_TOGGLE_MUTE;
        } else {
            _silent = !_silent;
            audio.setStreamMute(type, _silent);
        }
    }
    audio.adjustStreamVolume(type, direction, AudioManager.FLAG_SHOW_UI);
}

From source file:net.hyx.app.volumenotification.factory.NotificationFactory.java

private int getStreamFlag(int type) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if ((type == AudioManager.STREAM_MUSIC && settings.getToggleMute())
                || (type == AudioManager.STREAM_RING && settings.getToggleSilent())) {
            return AudioManager.ADJUST_TOGGLE_MUTE;
        }//from w  w  w  . j a  va 2  s.  co  m
    }
    return AudioManager.ADJUST_SAME;
}