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: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.j  av  a2s. 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:com.fvd.nimbus.PaintActivity.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_DOWN) {
            drawView.zoom(1.25f);//w w  w  . ja  v  a2  s  . com
        }
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (action == KeyEvent.ACTION_DOWN) {
            drawView.zoom(0.75f);
        }
        return true;
    case KeyEvent.KEYCODE_BACK:
        if (action == KeyEvent.ACTION_DOWN) {
            if (drawer.isDrawerOpen(GravityCompat.START)) {
                drawer.closeDrawer(GravityCompat.START);
                return true;
            } else if (findViewById(R.id.text_field).getVisibility() != View.GONE) {
                findViewById(R.id.text_field).setVisibility(View.GONE);
                drawView.hideCrop();
                drawView.startEdit();
                setSelectedFoot(0);
                return true;
            } else if (findViewById(R.id.color_menu).getVisibility() != View.GONE) {
                findViewById(R.id.color_menu).setVisibility(View.GONE);
                drawView.hideCrop();
                drawView.startEdit();
                setSelectedFoot(0);
                return true;
            } else if (findViewById(R.id.draw_tools).getVisibility() != View.GONE) {
                findViewById(R.id.draw_tools).setVisibility(View.GONE);
                drawView.hideCrop();
                drawView.startEdit();
                setSelectedFoot(0);
                return false;
            } else if (!drawView.hideCrop()) {
                if (!saved && storePath.length() == 0)
                    showDialog(0);
                else {
                    drawView.recycle();
                    finish();
                    return true;
                }
            } else {
                ((ImageButton) findViewById(R.id.bToolCrop)).setSelected(false);
                drawView.startEdit();
                setSelectedFoot(0);
                return true;
            }

        }
    default:
        return super.dispatchKeyEvent(event);
    }
}

From source file:org.appcelerator.titanium.TiBaseActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    boolean handled = false;

    TiViewProxy window;//www  .j a  va  2s  .c om
    if (this.window != null) {
        window = this.window;
    } else {
        window = this.view;
    }

    if (window == null) {
        return super.dispatchKeyEvent(event);
    }

    switch (event.getKeyCode()) {
    case KeyEvent.KEYCODE_BACK: {

        if (event.getAction() == KeyEvent.ACTION_UP) {
            String backEvent = "android:back";
            KrollProxy proxy = null;
            //android:back could be fired from a tabGroup window (activityProxy)
            //or hw window (window).This event is added specifically to the activity
            //proxy of a tab group in window.js
            if (activityProxy.hasListeners(backEvent)) {
                proxy = activityProxy;
            } else if (window.hasListeners(backEvent)) {
                proxy = window;
            }

            if (proxy != null) {
                proxy.fireEvent(backEvent, null);
                handled = true;
            }

        }
        break;
    }
    case KeyEvent.KEYCODE_CAMERA: {
        if (window.hasListeners(TiC.EVENT_ANDROID_CAMERA)) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                window.fireEvent(TiC.EVENT_ANDROID_CAMERA, null);
            }
            handled = true;
        }
        // TODO: Deprecate old event
        if (window.hasListeners("android:camera")) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                window.fireEvent("android:camera", null);
            }
            handled = true;
        }

        break;
    }
    case KeyEvent.KEYCODE_FOCUS: {
        if (window.hasListeners(TiC.EVENT_ANDROID_FOCUS)) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                window.fireEvent(TiC.EVENT_ANDROID_FOCUS, null);
            }
            handled = true;
        }
        // TODO: Deprecate old event
        if (window.hasListeners("android:focus")) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                window.fireEvent("android:focus", null);
            }
            handled = true;
        }

        break;
    }
    case KeyEvent.KEYCODE_SEARCH: {
        if (window.hasListeners(TiC.EVENT_ANDROID_SEARCH)) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                window.fireEvent(TiC.EVENT_ANDROID_SEARCH, null);
            }
            handled = true;
        }
        // TODO: Deprecate old event
        if (window.hasListeners("android:search")) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                window.fireEvent("android:search", null);
            }
            handled = true;
        }

        break;
    }
    case KeyEvent.KEYCODE_VOLUME_UP: {
        if (window.hasListeners(TiC.EVENT_ANDROID_VOLUP)) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                window.fireEvent(TiC.EVENT_ANDROID_VOLUP, null);
            }
            handled = true;
        }
        // TODO: Deprecate old event
        if (window.hasListeners("android:volup")) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                window.fireEvent("android:volup", null);
            }
            handled = true;
        }

        break;
    }
    case KeyEvent.KEYCODE_VOLUME_DOWN: {
        if (window.hasListeners(TiC.EVENT_ANDROID_VOLDOWN)) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                window.fireEvent(TiC.EVENT_ANDROID_VOLDOWN, null);
            }
            handled = true;
        }
        // TODO: Deprecate old event
        if (window.hasListeners("android:voldown")) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                window.fireEvent("android:voldown", null);
            }
            handled = true;
        }

        break;
    }
    }

    if (!handled) {
        handled = super.dispatchKeyEvent(event);
    }

    return handled;
}

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

/**
 * Handler an android keypress and send it to boxee if appropriate.
 *//*  w ww . j  a  va  2s .c  o  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 {//from w w  w  .  j a v a 2  s .  c om
            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 v  a 2 s. c  om*/
}

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 ww .j a  va  2 s  .c  om
    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:
        ///*  ww  w. ja  va2s . c o m*/
        // 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  w w  . ja  v  a  2 s.  co 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/*from ww  w . ja  va2 s.  co 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;
}