Example usage for android.view KeyEvent KEYCODE_VOLUME_DOWN

List of usage examples for android.view KeyEvent KEYCODE_VOLUME_DOWN

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_VOLUME_DOWN.

Prototype

int KEYCODE_VOLUME_DOWN

To view the source code for android.view KeyEvent KEYCODE_VOLUME_DOWN.

Click Source Link

Document

Key code constant: Volume Down key.

Usage

From source file:net.reichholf.dreamdroid.fragment.helper.HttpFragmentHelper.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (getAppCompatActivity() == null) //not attached to activity
        return false;
    if (PreferenceManager.getDefaultSharedPreferences(getAppCompatActivity()).getBoolean("volume_control",
            false)) {/*w w  w  .  j a v a2s  .  c  o  m*/
        switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            onVolumeButtonClicked(Volume.CMD_UP);
            return true;

        case KeyEvent.KEYCODE_VOLUME_DOWN:
            onVolumeButtonClicked(Volume.CMD_DOWN);
            return true;
        }
    }
    return false;
}

From source file:com.glanznig.beepme.view.MainActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (action == KeyEvent.ACTION_UP) {
            audioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_RAISE,
                    AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
        }//from w ww  .  j  a  va2 s.  co m
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (action == KeyEvent.ACTION_DOWN) {
            audioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_LOWER,
                    AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
        }
        return true;
    default:
        return super.dispatchKeyEvent(event);
    }
}

From source file:com.marcopolci.paperwalletvalidator.MainActivity.java

@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_FOCUS:
    case KeyEvent.KEYCODE_CAMERA:
        // don't launch camera app
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        ScanFragment fragment = (ScanFragment) getFragmentManager().findFragmentById(R.id.fragmentScan);
        fragment.setTorch(keyCode == KeyEvent.KEYCODE_VOLUME_UP);
        return true;
    }//from ww w  . j  av  a  2  s .  co  m

    return super.onKeyDown(keyCode, event);
}

From source file:net.reichholf.dreamdroid.fragment.helper.HttpFragmentHelper.java

public boolean onKeyUp(int keyCode, KeyEvent event) {
    return keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN;
}

From source file:com.firefly.sample.cast.refplayer.VideoBrowserActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (!mCastManager.isConnected()) {
        return super.onKeyDown(keyCode, event);
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        changeVolume(CastApplication.VOLUME_INCREMENT);
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        changeVolume(-CastApplication.VOLUME_INCREMENT);
    } else {//from w w  w  .ja  v  a2  s .  c  om
        return super.onKeyDown(keyCode, event);
    }
    return true;
}

From source file:com.manueldeveloper.VolumeButtonsListener.java

/**
*    Overwritten method to receive the Android key events
*
*   @param      view: View object who emit the signal (CordovaWebView)
*   @param      keyCode: int with the identifier of the pressed key
*   @param      keyEvent: KeyEvent object with the information of the event
*
*   @return      "boolean" which indicates if the listener has consumed the event (true) or not (false) [Always false to allow that the event spreading]
* 
*    @date      27/02/2014/* w  w  w  . ja va2 s.co m*/
*    @version   0.0.1
*    @author   ManuelDeveloper(manueldeveloper@gmail.com) 
*/
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {

    // Check if the event is equal to KEY_DOWN
    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
        // Check what button has been pressed
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {

            // Create a new JSONObject with the information and send it
            JSONObject info = new JSONObject();
            try {
                info.put("signal", new String("volume-up"));
                sendSignal(info, true);
            } catch (JSONException ex) {
                Log.e(VolumeButtonsListener_LOG, ex.getMessage());
            }
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {

            // Create a new JSONObject with the information and send it
            JSONObject info = new JSONObject();
            try {
                info.put("signal", new String("volume-down"));
                sendSignal(info, true);
            } catch (JSONException ex) {
                Log.e(VolumeButtonsListener_LOG, ex.getMessage());
            }
        }
    }

    return false;
}

From source file:io.github.hidroh.materialistic.KeyDelegate.java

/**
 * Calls from {@link Activity#onKeyUp(int, KeyEvent)} to delegate
 * @param keyCode    event key code//from  w w  w .j  av a  2  s  .c  o m
 * @param event      key event
 * @return  true if is intercepted as navigation, false otherwise
 */
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (!mEnabled) {
        return false;
    }
    boolean notLongPress = (event.getFlags() & KeyEvent.FLAG_CANCELED_LONG_PRESS) == 0;
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && notLongPress) {
        shortPress(DIRECTION_UP);
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && notLongPress) {
        shortPress(DIRECTION_DOWN);
        return true;
    }
    return false;
}

From source file:au.id.tedp.mapdroid.Picker.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    OSMMapView map = (OSMMapView) findViewById(R.id.mapView);
    int change = 0;

    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
        change = -1;/*from w w  w  .j  a  va2s  . c om*/
    else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP)
        change = +1;

    if (change != 0) {
        map.setZoom(map.getZoom() + change);
        return true;
    }

    // Propagate to the default implementation to get regular back-button
    // behavior.
    return super.onKeyDown(keyCode, event);
}

From source file:com.distantfuture.castcompanionlibrary.lib.cast.player.VideoCastControllerActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mVolumeIncrement == Float.MIN_VALUE) {
        return false;
    }/*from  ww  w .  j a va2  s.c o m*/
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        onVolumeChange(mVolumeIncrement);
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        onVolumeChange(-(double) mVolumeIncrement);
    } else {
        return super.onKeyDown(keyCode, event);
    }
    return true;
}

From source file:de.qspool.clementineremote.ui.Player.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        // Control the volume of clementine if enabled in the options
        switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (mSharedPref.getBoolean(App.SP_KEY_USE_VOLUMEKEYS, true)) {
                Message msgDown = Message.obtain();
                msgDown.obj = new RequestVolume(App.mClementine.getVolume() - 10);
                App.mClementineConnection.mHandler.sendMessage(msgDown);
                return true;
            }/*w  ww  .  java2s .  c o  m*/
            break;
        case KeyEvent.KEYCODE_VOLUME_UP:
            if (mSharedPref.getBoolean(App.SP_KEY_USE_VOLUMEKEYS, true)) {
                Message msgUp = Message.obtain();
                msgUp.obj = new RequestVolume(App.mClementine.getVolume() + 10);
                App.mClementineConnection.mHandler.sendMessage(msgUp);
                return true;
            }
            break;
        default:
            break;
        }
    }
    return super.onKeyDown(keyCode, event);
}