Example usage for android.view KeyEvent KEYCODE_VOLUME_UP

List of usage examples for android.view KeyEvent KEYCODE_VOLUME_UP

Introduction

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

Prototype

int KEYCODE_VOLUME_UP

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

Click Source Link

Document

Key code constant: Volume Up key.

Usage

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

/**
 * Handle hotkeys/*from w w  w.  j  av  a 2s . c o  m*/
 * 
 * <p>
 * This method is called by {@link #dispatchKeyEvent(KeyEvent)} before any
 * view had the chance to consume this key event.
 * </p>
 * 
 * @param keyCode
 *            The value in {@code event.getKeyCode()}.
 * @param event
 *            Description of the key event.
 * 
 * @return {@code true} if this event was consumed.
 */
public boolean onCustomKeyDown(final int keyCode, final KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP: {
        if (mMessageViewFragment != null && mDisplayMode != DisplayMode.MESSAGE_LIST
                && K9.useVolumeKeysForNavigationEnabled()) {
            showPreviousMessage();
            return true;
        } else if (mDisplayMode != DisplayMode.MESSAGE_VIEW && K9.useVolumeKeysForListNavigationEnabled()) {
            mMessageListFragment.onMoveUp();
            return true;
        }

        break;
    }
    case KeyEvent.KEYCODE_VOLUME_DOWN: {
        if (mMessageViewFragment != null && mDisplayMode != DisplayMode.MESSAGE_LIST
                && K9.useVolumeKeysForNavigationEnabled()) {
            showNextMessage();
            return true;
        } else if (mDisplayMode != DisplayMode.MESSAGE_VIEW && K9.useVolumeKeysForListNavigationEnabled()) {
            mMessageListFragment.onMoveDown();
            return true;
        }

        break;
    }
    case KeyEvent.KEYCODE_C: {
        mMessageListFragment.onCompose();
        return true;
    }
    case KeyEvent.KEYCODE_Q: {
        if (mMessageListFragment != null && mMessageListFragment.isSingleAccountMode()) {
            onShowFolderList();
        }
        return true;
    }
    case KeyEvent.KEYCODE_O: {
        mMessageListFragment.onCycleSort();
        return true;
    }
    case KeyEvent.KEYCODE_I: {
        mMessageListFragment.onReverseSort();
        return true;
    }
    case KeyEvent.KEYCODE_DEL:
    case KeyEvent.KEYCODE_D: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onDelete();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onDelete();
        }
        return true;
    }
    case KeyEvent.KEYCODE_S: {
        mMessageListFragment.toggleMessageSelect();
        return true;
    }
    case KeyEvent.KEYCODE_G: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onToggleFlagged();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onToggleFlagged();
        }
        return true;
    }
    case KeyEvent.KEYCODE_M: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onMove();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onMove();
        }
        return true;
    }
    case KeyEvent.KEYCODE_V: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onArchive();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onArchive();
        }
        return true;
    }
    case KeyEvent.KEYCODE_Y: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onCopy();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onCopy();
        }
        return true;
    }
    case KeyEvent.KEYCODE_Z: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onToggleRead();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onToggleRead();
        }
        return true;
    }
    case KeyEvent.KEYCODE_F: {
        if (mMessageViewFragment != null) {
            mMessageViewFragment.onForward();
        }
        return true;
    }
    case KeyEvent.KEYCODE_A: {
        if (mMessageViewFragment != null) {
            mMessageViewFragment.onReplyAll();
        }
        return true;
    }
    case KeyEvent.KEYCODE_R: {
        if (mMessageViewFragment != null) {
            mMessageViewFragment.onReply();
        }
        return true;
    }
    case KeyEvent.KEYCODE_J:
    case KeyEvent.KEYCODE_P: {
        if (mMessageViewFragment != null) {
            showPreviousMessage();
        }
        return true;
    }
    case KeyEvent.KEYCODE_N:
    case KeyEvent.KEYCODE_K: {
        if (mMessageViewFragment != null) {
            showNextMessage();
        }
        return true;
    }
    /*
     * FIXME case KeyEvent.KEYCODE_Z: { mMessageViewFragment.zoom(event);
     * return true; }
     */
    case KeyEvent.KEYCODE_H: {
        Toast toast = Toast.makeText(this, R.string.message_list_help_key, Toast.LENGTH_LONG);
        toast.show();
        return true;
    }

    }

    return false;
}

From source file:com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.java

/**
 * Clients can call this method to delegate handling of the volume. Clients should override
 * {@code dispatchEvent} and call this method:
 * <pre>//w w  w  .j a  v a2 s. com
 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:
            if (changeVolume(volumeDelta, isKeyDown)) {
                return true;
            }
            break;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (changeVolume(-volumeDelta, isKeyDown)) {
                return true;
            }
            break;
        }
    }
    return false;
}

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    // Swallow these events too to avoid the audible notification of a
    // volume change
    if (K9.useVolumeKeysForListNavigationEnabled()) {
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
            if (K9.DEBUG)
                Log.v(K9.LOG_TAG, "Swallowed key up.");
            return true;
        }//  w  ww .  j a v a  2  s.c  o m
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.rfo.basic.Run.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) { // The user hit a key
    // Log.v(LOGTAG, "onKeyDown" + keyCode);

    // Eat the MENU key Down event, will handle the Up event.
    if (keyCode == KeyEvent.KEYCODE_MENU)
        return true;

    // If event is null, we called this directly from runLoop(),
    // so the return value does not matter.
    if (event == null)
        return true;

    // Alternate: if the user program has set mBlockVolKeys, block everything but BACK
    // if (mBlockVolKeys && (keyCode != KeyEvent.KEYCODE_BACK)) return true;

    // If the user program has set mBlockVolKeys, block volume and headset keys.
    if (mBlockVolKeys && ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
            || (keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) || (keyCode == KeyEvent.KEYCODE_MUTE)
            || (keyCode == KeyEvent.KEYCODE_HEADSETHOOK))) {
        return true;
    }/*  w  w w .  ja va 2 s  .c  o  m*/

    // Otherwise pass the KeyEvent up the chain.
    return super.onKeyDown(keyCode, event);
}