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:org.apache.cordova.CordovaWebView.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyDownCodes.contains(keyCode)) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            // only override default behaviour is event bound
            LOG.d(TAG, "Down Key Hit");
            this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');");
            return true;
        }//  w  w  w.  ja  va 2  s .co  m
        // If volumeup key
        else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            LOG.d(TAG, "Up Key Hit");
            this.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:net.evendanan.android.thumbremote.ui.RemoteUiActivity.java

/**
 * Handler an android keypress and send it to boxee if appropriate.
 *///w  ww.  ja  v  a 2  s. co m
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        if (RemoteApplication.getConfig().getHandleBack()) {
            Log.d(TAG, "Will handle back");
            if (mBoundService != null)
                mBoundService.remoteBack();
            return true;
        } else {
            Log.d(TAG, "Will NOT handle back");
            return super.onKeyDown(keyCode, event);
        }

    case KeyEvent.KEYCODE_DPAD_CENTER:
        if (mBoundService != null)
            mBoundService.remoteSelect();
        return true;

    case KeyEvent.KEYCODE_DPAD_DOWN:
        if (mBoundService != null)
            mBoundService.remoteDown();
        return true;

    case KeyEvent.KEYCODE_DPAD_UP:
        if (mBoundService != null)
            mBoundService.remoteUp();
        return true;

    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (mBoundService != null)
            mBoundService.remoteLeft();
        return true;

    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (mBoundService != null)
            mBoundService.remoteRight();
        return true;

    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        final int volumeFactor = (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) ? -1 : 1;
        final int volumeOffset = (volumeFactor * RemoteApplication.getConfig().getVolumeStep());
        if (mBoundService != null)
            mBoundService.remoteVolumeOffset(volumeOffset);
        return true;
    case KeyEvent.KEYCODE_DEL:
        if (mBoundService != null)
            mBoundService.remoteKeypress((char) 8);
        return true;
    default:
        final char unicodeChar = (char) event.getUnicodeChar();

        // Log.d(TAG, "Unicode is " + ((char)unicodeChar));

        if (Character.isLetterOrDigit(unicodeChar) || msPunctuation.contains(unicodeChar)) {
            // Log.d(TAG, "handling " + ((char)unicodeChar));
            if (mBoundService != null)
                mBoundService.remoteKeypress(unicodeChar);
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }
}

From source file:net.evendanan.android.thumbremote.ui.RemoteUiActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        if (RemoteApplication.getConfig().getHandleBack()) {
            return true;
        } else {/*www  . j  av  a 2  s  .  com*/
            return super.onKeyUp(keyCode, event);
        }
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        // I catch these two to handle the annoying sound feedback given
        // in some hand-held (Samsung Tab, e.g.)
        return true;

    default:
        return super.onKeyDown(keyCode, event);
    }
}

From source file:org.apache.cordova.AndroidWebView.java

public void bindButton(String button, boolean override) {
    // TODO Auto-generated method stub
    if (button.compareTo("volumeup") == 0) {
        keyDownCodes.add(KeyEvent.KEYCODE_VOLUME_UP);
    } else if (button.compareTo("volumedown") == 0) {
        keyDownCodes.add(KeyEvent.KEYCODE_VOLUME_DOWN);
    }/*from w w w. j a va2  s. c  o  m*/
}

From source file:github.popeen.dsub.activity.SubsonicActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isVolumeDown = keyCode == KeyEvent.KEYCODE_VOLUME_DOWN;
    boolean isVolumeUp = keyCode == KeyEvent.KEYCODE_VOLUME_UP;
    boolean isVolumeAdjust = isVolumeDown || isVolumeUp;
    boolean isJukebox = getDownloadService() != null && getDownloadService().isRemoteEnabled();

    if (isVolumeAdjust && isJukebox) {
        getDownloadService().updateRemoteVolume(isVolumeUp);
        return true;
    }/*from   w w w.  jav a2  s . c  o  m*/
    return super.onKeyDown(keyCode, event);
}

From source file:com.tumblr.cardboard.Tumblr3DActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        onCardboardTrigger();//  w w w . j a  va  2s . c  o  m
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.csipsimple.ui.incall.CallActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    Log.d(TAG, "Key down : " + keyCode);
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        ////from  www  . ja  va2s.  com
        // Volume has been adjusted by the user.
        //
        Log.d(TAG, "onKeyDown: Volume button pressed");
        int action = AudioManager.ADJUST_RAISE;
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            action = AudioManager.ADJUST_LOWER;
        }

        // Detect if ringing
        SipCallSession currentCallInfo = getActiveCallInfo();
        // If not any active call active
        if (currentCallInfo == null && serviceConnected) {
            break;
        }

        //TODO: adjust volume here
        if (service != null) {
            try {
                service.adjustVolume(currentCallInfo, action, AudioManager.FLAG_SHOW_UI);
            } catch (RemoteException e) {
                Log.e(TAG, "Can't adjust volume", e);
            }
        }

        return true;
    case KeyEvent.KEYCODE_CALL:
    case KeyEvent.KEYCODE_ENDCALL:
        return inCallAnswerControls.onKeyDown(keyCode, event);
    case KeyEvent.KEYCODE_SEARCH:
        // Prevent search
        return true;
    default:
        // Nothing to do
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.tweetlanes.android.core.view.BaseLaneActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    // Early exit on these events so that the volume up/down sound doesn't
    // play//from w  ww .  j  ava  2  s  . c  o  m
    // TODO: Handle user options for volume scrolling
    return (keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
            || super.onKeyUp(keyCode, event);
}

From source file:paulscode.android.mupen64plusae.game.GameFragment.java

/**
 * Handle view onKey callbacks// ww w  . j  a  v a2s  .c o  m
 * @param view If view is NULL then this keycode will not be handled by the key provider. This is to avoid
 *             the situation where user maps the menu key to the menu command.
 * @param keyCode key code
 * @param event key event
 * @return True if handled
 */
@Override
public boolean onKey(View view, int keyCode, KeyEvent event) {
    final boolean keyDown = event.getAction() == KeyEvent.ACTION_DOWN;

    boolean handled = false;

    // Attempt to reconnect any disconnected devices
    mGamePrefs.playerMap.reconnectDevice(AbstractProvider.getHardwareId(event));

    if (!mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
        // If PeripheralControllers exist and handle the event,
        // they return true. Else they return false, signaling
        // Android to handle the event (menu button, vol keys).
        if (mKeyProvider != null && view != null) {
            handled = mKeyProvider.onKey(view, keyCode, event);

            //Don't use built in keys in the device to hide the touch controls
            if (handled && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_BACK
                    && keyCode != KeyEvent.KEYCODE_VOLUME_UP && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN
                    && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE && mGlobalPrefs.touchscreenAutoHideEnabled) {
                mOverlay.onTouchControlsHide();
            }
        }
    }

    if (!handled) {
        if (keyDown && keyCode == KeyEvent.KEYCODE_MENU) {
            if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
                mDrawerLayout.closeDrawer(GravityCompat.START);
                mOverlay.requestFocus();
            } else {
                mCoreFragment.pauseEmulator();
                mDrawerLayout.openDrawer(GravityCompat.START);
                mDrawerOpenState = true;
                mGameSidebar.requestFocus();
                mGameSidebar.smoothScrollToPosition(0);
            }
            return true;
        } else if (keyDown && keyCode == KeyEvent.KEYCODE_BACK) {
            if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
                mDrawerLayout.closeDrawer(GravityCompat.START);
                mOverlay.requestFocus();
            } else {
                //We are using the slide gesture for the menu, so the back key can be used to exit
                if (mGlobalPrefs.inGameMenuIsSwipGesture) {
                    mWaitingOnConfirmation = true;
                    mCoreFragment.exit();
                }
                //Else the back key bring up the in-game menu
                else {
                    mCoreFragment.pauseEmulator();
                    mDrawerLayout.openDrawer(GravityCompat.START);
                    mDrawerOpenState = true;
                    mGameSidebar.requestFocus();
                    mGameSidebar.smoothScrollToPosition(0);
                }
            }
            return true;
        }
    }

    return handled;
}

From source file:com.shafiq.mytwittle.view.BaseLaneActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            if (AppSettings.get().isVolScrollEnabled()) {
                Intent intent = new Intent("" + SystemEvent.VOLUME_UP_KEY_DOWN);
                LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
                return true;
            }/*from  www . j a va 2 s  .  c om*/

        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            if (AppSettings.get().isVolScrollEnabled()) {
                Intent intent = new Intent("" + SystemEvent.VOLUME_DOWN_KEY_DOWN);
                LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
                return true;
            }
        }
    }

    return super.onKeyDown(keyCode, event);
}