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.zorgblub.typhon.fragment.ReadingFragment.java

@TargetApi(Build.VERSION_CODES.FROYO)
private boolean handleVolumeButtonEvent(KeyEvent event) {

    //Disable volume button handling during TTS
    if (!config.isVolumeKeyNavEnabled() || ttsIsRunning()) {
        return false;
    }//from w w  w  .j av a2 s.  c  om

    Activity activity = getActivity();

    if (activity == null) {
        return false;
    }

    boolean invert = false;

    int rotation = Surface.ROTATION_0;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        Display display = activity.getWindowManager().getDefaultDisplay();
        rotation = display.getRotation();
    }

    switch (rotation) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_90:
        invert = false;
        break;
    case Surface.ROTATION_180:
    case Surface.ROTATION_270:
        invert = true;
        break;
    }

    if (event.getAction() != KeyEvent.ACTION_DOWN) {
        return true;
    }

    if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
        if (config.isVolumeKeyNavChaptersEnabled()) {
            if (invert) {
                bookView.navigateForward();
            } else {
                bookView.navigateBack();
            }
        } else {
            if (invert) {
                pageDown(Orientation.HORIZONTAL);
            } else {
                pageUp(Orientation.HORIZONTAL);
            }
        }
    } else if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (config.isVolumeKeyNavChaptersEnabled()) {
            if (invert) {
                bookView.navigateBack();
            } else {
                bookView.navigateForward();
            }
        } else {
            if (invert) {
                pageUp(Orientation.HORIZONTAL);
            } else {
                pageDown(Orientation.HORIZONTAL);
            }
        }
    }

    return true;
}

From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (volumeButtons && !vbListenerPause) {
        InputConnection ic = getCurrentInputConnection();

        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            ic.commitText("", -1);
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            ic.commitText("", 2);
        }//from w  ww.  ja v  a2s .c o  m

        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}

From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (volumeButtons && (keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
        return true;
    } else if (!vbListenerPause && keyCode == KeyEvent.KEYCODE_BACK) {
        screen = 1;/*  w  w  w. j a  v a 2 s. com*/

        if (shakeDelete) {
            mShaker.pause();
        }

        vbListenerPause = true;

        return true;
    } else {
        return super.onKeyUp(keyCode, event);
    }
}

From source file:com.aujur.ebookreader.activity.ReadingFragment.java

public boolean dispatchKeyEvent(KeyEvent event) {

    int action = event.getAction();
    int keyCode = event.getKeyCode();

    LOG.debug("Got key event: " + keyCode + " with action " + action);

    if (searchMenuItem != null && searchMenuItem.isActionViewExpanded()) {
        boolean result = searchMenuItem.getActionView().dispatchKeyEvent(event);

        if (result) {
            return true;
        }/*from w  ww.j a  v a2  s.c o m*/
    }

    final int KEYCODE_NOOK_TOUCH_BUTTON_LEFT_TOP = 92;
    final int KEYCODE_NOOK_TOUCH_BUTTON_LEFT_BOTTOM = 93;
    final int KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_TOP = 94;
    final int KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_BOTTOM = 95;

    boolean nook_touch_up_press = false;

    if (isAnimating() && action == KeyEvent.ACTION_DOWN) {
        stopAnimating();
        return true;
    }

    /*
     * Tricky bit of code here: if we are NOT running TTS, we want to be
     * able to start it using the play/pause button.
     * 
     * When we ARE running TTS, we'll get every media event twice: once
     * through the receiver and once here if focused.
     * 
     * So, we only try to read media events here if tts is running.
     */
    if (!ttsIsRunning() && dispatchMediaKeyEvent(event)) {
        return true;
    }

    LOG.debug("Key event is NOT a media key event.");

    switch (keyCode) {

    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        return handleVolumeButtonEvent(event);

    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (action == KeyEvent.ACTION_DOWN) {
            pageDown(Orientation.HORIZONTAL);
        }

        return true;

    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (action == KeyEvent.ACTION_DOWN) {
            pageUp(Orientation.HORIZONTAL);
        }

        return true;

    case KeyEvent.KEYCODE_BACK:
        if (action == KeyEvent.ACTION_DOWN) {

            if (titleBarLayout.getVisibility() == View.VISIBLE) {
                hideTitleBar();
                updateFromPrefs();
                return true;
            } else if (bookView.hasPrevPosition()) {
                bookView.goBackInHistory();
                return true;
            }
        }

        return false;

    case KEYCODE_NOOK_TOUCH_BUTTON_LEFT_TOP:
    case KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_TOP:
        nook_touch_up_press = true;
    case KEYCODE_NOOK_TOUCH_BUTTON_LEFT_BOTTOM:
    case KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_BOTTOM:
        if (!Configuration.IS_NOOK_TOUCH || action == KeyEvent.ACTION_UP)
            return false;
        if (nook_touch_up_press == config.isNookUpButtonForward())
            pageDown(Orientation.HORIZONTAL);
        else
            pageUp(Orientation.HORIZONTAL);
        return true;
    }

    LOG.debug("Not handling key event: returning false.");
    return false;
}

From source file:net.zorgblub.typhon.fragment.ReadingFragment.java

public boolean dispatchKeyEvent(KeyEvent event) {

    int action = event.getAction();
    int keyCode = event.getKeyCode();

    LOG.debug("Got key event: " + keyCode + " with action " + action);

    if (searchMenuItem != null && MenuItemCompat.isActionViewExpanded(searchMenuItem)) {
        boolean result = MenuItemCompat.getActionView(searchMenuItem).dispatchKeyEvent(event);

        if (result) {
            return true;
        }/*  w ww .  j  a  v a 2s  .  c  om*/
    }

    final int KEYCODE_NOOK_TOUCH_BUTTON_LEFT_TOP = 92;
    final int KEYCODE_NOOK_TOUCH_BUTTON_LEFT_BOTTOM = 93;
    final int KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_TOP = 94;
    final int KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_BOTTOM = 95;

    boolean nook_touch_up_press = false;

    if (isAnimating() && action == KeyEvent.ACTION_DOWN) {
        stopAnimating();
        return true;
    }

    /*
       * Tricky bit of code here: if we are NOT running TTS,
     * we want to be able to start it using the play/pause button.
     *
     * When we ARE running TTS, we'll get every media event twice:
     * once through the receiver and once here if focused.
     *
     * So, we only try to read media events here if tts is running.
     */
    if (!ttsIsRunning() && dispatchMediaKeyEvent(event)) {
        return true;
    }

    LOG.debug("Key event is NOT a media key event.");

    switch (keyCode) {

    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        return handleVolumeButtonEvent(event);

    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (action == KeyEvent.ACTION_DOWN) {
            pageDown(Orientation.HORIZONTAL);
        }

        return true;

    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (action == KeyEvent.ACTION_DOWN) {
            pageUp(Orientation.HORIZONTAL);
        }

        return true;

    case KeyEvent.KEYCODE_BACK:
        if (action == KeyEvent.ACTION_DOWN) {

            if (titleBarLayout.getVisibility() == View.VISIBLE) {
                hideTitleBar();
                updateFromPrefs();
                return true;
            } else if (bookView.hasPrevPosition()) {
                bookView.goBackInHistory();
                return true;
            }
        }

        return false;

    case KEYCODE_NOOK_TOUCH_BUTTON_LEFT_TOP:
    case KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_TOP:
        nook_touch_up_press = true;
    case KEYCODE_NOOK_TOUCH_BUTTON_LEFT_BOTTOM:
    case KEYCODE_NOOK_TOUCH_BUTTON_RIGHT_BOTTOM:
        if (action == KeyEvent.ACTION_UP)
            return false;
        if (nook_touch_up_press == config.isNookUpButtonForward())
            pageDown(Orientation.HORIZONTAL);
        else
            pageUp(Orientation.HORIZONTAL);
        return true;
    }

    LOG.debug("Not handling key event: returning false.");
    return false;
}

From source file:com.android.email.activity.MessageView.java

@Override
public boolean onKeyDown(int keycode, KeyEvent event) {
    switch (keycode) {
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        moveToOlder();/*from w w w. j a  v a 2 s.c o m*/
        break;
    case KeyEvent.KEYCODE_VOLUME_UP:
        moveToNewer();
        break;
    default:
        return super.onKeyDown(keycode, event);
    }
    return true;
}

From source file:com.youku.player.base.YoukuBasePlayerActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    try {//from   ww  w  .  ja  v a2  s. c  om
        switch (keyCode) {
        case KeyEvent.KEYCODE_MENU:
            // ?menu?
            if (event.getRepeatCount() > 0) {
                return true;
            }
            return mediaPlayerDelegate.isFullScreen;
        case KeyEvent.KEYCODE_BACK:
            // ???
            if (event.getRepeatCount() > 0) {
                return true;
            }
            if (!mediaPlayerDelegate.isDLNA) {
                if (mediaPlayerDelegate.isFullScreen && !isFromLocal()
                        && (mediaPlayerDelegate.videoInfo != null && !mediaPlayerDelegate.videoInfo.isHLS)) {
                    goSmall();
                    return true;
                } else {
                    onkeyback();
                    return true;
                }
            } else {
                return true;
            }
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            return volumeDown();
        case KeyEvent.KEYCODE_VOLUME_UP:
            return volumeUp();
        case KeyEvent.KEYCODE_SEARCH:
            return mediaPlayerDelegate.isFullScreen;
        case 125:
            /** popupwindow */
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.android.email.activity.MessageView.java

@Override
public boolean onKeyUp(int keycode, KeyEvent event) {
    switch (keycode) {
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        break;/*from   w ww.j ava  2  s .c o  m*/
    default:
        return super.onKeyUp(keycode, event);
    }
    return true;
}

From source file:de.danoeh.antennapod.core.cast.CastManager.java

/**
 * Clients can call this method to delegate handling of the volume. Clients should override
 * {@code dispatchEvent} and call this method:
 * <pre>//  ww  w  .  j  a  v  a  2s . co  m
 public boolean dispatchKeyEvent(KeyEvent event) {
 if (mCastManager.onDispatchVolumeKeyEvent(event, VOLUME_DELTA)) {
 return true;
 }
 return super.dispatchKeyEvent(event);
 }
 * </pre>
 * @param event The dispatched event.
 * @param volumeDelta The amount by which volume should be increased or decreased in each step
 * @return <code>true</code> if volume is handled by the library, <code>false</code> otherwise.
 */
public boolean onDispatchVolumeKeyEvent(KeyEvent event, double volumeDelta) {
    if (isConnected()) {
        boolean isKeyDown = event.getAction() == KeyEvent.ACTION_DOWN;
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            return changeVolume(volumeDelta, isKeyDown);
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            return changeVolume(-volumeDelta, isKeyDown);
        }
    }
    return false;
}