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.kevinshen.beyondupnp.ui.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    SystemManager systemManager = SystemManager.getInstance();
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        int volume = systemManager.getDeviceVolume();
        volume += 5;/*  w  w w. j a va2  s.c om*/
        if (volume > 100)
            volume = 100;
        sendBroadcast(new Intent(Intents.ACTION_SET_VOLUME).putExtra("currentVolume", volume));
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        int volume = systemManager.getDeviceVolume();
        volume -= 5;
        if (volume < 0)
            volume = 0;
        sendBroadcast(new Intent(Intents.ACTION_SET_VOLUME).putExtra("currentVolume", volume));
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}

From source file:com.groundupworks.partyphotobooth.fragments.CaptureFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final KioskActivity activity = (KioskActivity) getActivity();
    final Context appContext = activity.getApplicationContext();
    final Bundle args = getArguments();
    final int totalFrames = args.getInt(FRAGMENT_BUNDLE_KEY_TOTAL_FRAMES);
    final int currentFrame = args.getInt(FRAGMENT_BUNDLE_KEY_CURRENT_FRAME);

    /*//from w w w.  j  av a  2s.co m
     * Select camera from preference.
     */
    // Get from preference.
    PreferencesHelper preferencesHelper = new PreferencesHelper();
    PhotoBoothMode mode = preferencesHelper.getPhotoBoothMode(appContext);

    int cameraPreference = CameraInfo.CAMERA_FACING_FRONT;
    if (PhotoBoothMode.PHOTOGRAPHER.equals(mode)) {
        cameraPreference = CameraInfo.CAMERA_FACING_BACK;
    }

    // Default to first camera available.
    final int numCameras = Camera.getNumberOfCameras();
    if (numCameras > 0) {
        mCameraId = 0;
    }

    // Select preferred camera.
    CameraInfo cameraInfo = new CameraInfo();
    for (int cameraId = 0; cameraId < numCameras; cameraId++) {
        Camera.getCameraInfo(cameraId, cameraInfo);

        // Break on finding the preferred camera.
        if (cameraInfo.facing == cameraPreference) {
            mCameraId = cameraId;
            break;
        }
    }

    /*
    * Initialize and set key event handlers.
    */
    mKeyEventHandler = new KioskActivity.KeyEventHandler() {
        @Override
        public boolean onKeyEvent(KeyEvent event) {
            final int keyCode = event.getKeyCode();
            if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                mStartButton.dispatchKeyEvent(event);
                return true;
            }
            return false;
        }
    };
    activity.setKeyEventHandler(mKeyEventHandler);

    /*
     * Functionalize views.
     */
    // Configure start button and trigger behaviour.
    switch (mode) {
    case PHOTOGRAPHER:
        mStartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initiateCapture();
            }
        });
        mStartButton.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                initiateCapture();
                return true;
            }
        });
        linkStartButton();
        break;
    case AUTOMATIC:
        if (currentFrame > 1) {
            // Auto-trigger when camera is ready and preview has started.
            mPreview.setOnPreviewListener(new CenteredPreview.OnPreviewListener() {
                @Override
                public void onStarted() {
                    if (isActivityAlive()) {
                        mPreview.post(new Runnable() {
                            @Override
                            public void run() {
                                if (isActivityAlive()) {
                                    initiateCountdownCapture();
                                }
                            }
                        });
                    }
                }

                @Override
                public void onStopped() {
                    // Do nothing.
                }
            });
            break;
        } else {
            // Fall through to self-serve behaviour. Do not break.
        }
    case SELF_SERVE:
    default:
        mStartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initiateCountdownCapture();
            }
        });
        mStartButton.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                initiateCountdownCapture();
                return true;
            }
        });
        linkStartButton();
    }

    // Show frame count only if more than one frame is to be captured.
    if (totalFrames > 1) {
        String frameCountText = getString(R.string.capture__frame_count, currentFrame, totalFrames);
        mFrameCount.setTypeface(
                Theme.from(appContext, preferencesHelper.getPhotoBoothTheme(appContext)).getFont());
        mFrameCount.setText(frameCountText);
        mFrameCount.setVisibility(View.VISIBLE);
    }
}

From source file:com.fatelon.partyphotobooth.fragments.CaptureFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final KioskActivity activity = (KioskActivity) getActivity();
    final Context appContext = activity.getApplicationContext();
    final Bundle args = getArguments();
    final int totalFrames = args.getInt(FRAGMENT_BUNDLE_KEY_TOTAL_FRAMES);
    final int currentFrame = args.getInt(FRAGMENT_BUNDLE_KEY_CURRENT_FRAME);

    /*/* ww w. j a  v a 2  s. c  o  m*/
     * Select camera from preference.
     */
    // Get from preference.
    PreferencesHelper preferencesHelper = new PreferencesHelper();
    mPhotoBoothMode = preferencesHelper.getPhotoBoothMode(appContext);

    int cameraPreference = CameraInfo.CAMERA_FACING_FRONT;
    if (PreferencesHelper.PhotoBoothMode.PHOTOGRAPHER.equals(mPhotoBoothMode)) {
        cameraPreference = CameraInfo.CAMERA_FACING_BACK;
    }

    // Default to first camera available.
    final int numCameras = Camera.getNumberOfCameras();
    if (numCameras > 0) {
        mCameraId = 0;
    }

    // Select preferred camera.
    CameraInfo cameraInfo = new CameraInfo();
    for (int cameraId = 0; cameraId < numCameras; cameraId++) {
        Camera.getCameraInfo(cameraId, cameraInfo);

        // Break on finding the preferred camera.
        if (cameraInfo.facing == cameraPreference) {
            mCameraId = cameraId;
            break;
        }
    }

    /*
    * Initialize and set key event handlers.
    */
    mKeyEventHandler = new KioskActivity.KeyEventHandler() {
        @Override
        public boolean onKeyEvent(KeyEvent event) {
            final int keyCode = event.getKeyCode();
            if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                mStartButton.dispatchKeyEvent(event);
                return true;
            }
            return false;
        }
    };
    activity.setKeyEventHandler(mKeyEventHandler);

    /*
     * Functionalize views.
     */
    // Configure start button and trigger behaviour.
    switch (mPhotoBoothMode) {
    case PHOTOGRAPHER:
        mStartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initiateCapture();
            }
        });
        mStartButton.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                initiateCapture();
                return true;
            }
        });
        linkStartButton();
        break;
    case AUTOMATIC:
        mStartButtonLong.setVisibility(View.VISIBLE);
        mStartButton.setVisibility(View.GONE);
        mStartButton = mStartButtonLong;
        if (currentFrame > 1) {
            // Auto-trigger when camera is ready and preview has started.
            mPreview.setOnPreviewListener(new CenteredPreview.OnPreviewListener() {
                @Override
                public void onStarted() {
                    if (isActivityAlive()) {
                        mPreview.post(new Runnable() {
                            @Override
                            public void run() {
                                if (isActivityAlive()) {
                                    initiateCountdownCapture();
                                }
                            }
                        });
                    }
                }

                @Override
                public void onStopped() {
                    // Do nothing.
                }
            });
            break;
        } else {
            // Fall through to self-serve behaviour. Do not break.
        }
    case SELF_SERVE:
    default:
        mStartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initiateCountdownCapture();
            }
        });
        mStartButton.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                initiateCountdownCapture();
                return true;
            }
        });
        linkStartButton();
    }

    // Show frame count only if more than one frame is to be captured.
    if (totalFrames > 1) {
        String frameCountText = getString(R.string.capture__frame_count, currentFrame, totalFrames);
        mFrameCount.setTypeface(
                Theme.from(appContext, preferencesHelper.getPhotoBoothTheme(appContext)).getFont());
        mFrameCount.setText(frameCountText);
        mFrameCount.setVisibility(View.VISIBLE);
    }
}

From source file:com.nextgis.rehacompdemo.RoutingActivity.java

@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
    int position;

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

    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (action == KeyEvent.ACTION_DOWN) {
            position = mSteps.getSelectedItemPosition();
            if (position == AdapterView.INVALID_POSITION)
                position = 0;/*from  w  w w  .j  a v a2 s.co  m*/
            else
                position--;

            mSteps.requestFocusFromTouch();
            mSteps.setSelection(position);
            break;
        } else
            return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (action == KeyEvent.ACTION_DOWN) {
            position = mSteps.getSelectedItemPosition();
            if (position == AdapterView.INVALID_POSITION)
                position = 0;
            else
                position++;

            mSteps.requestFocusFromTouch();
            mSteps.setSelection(position);
            break;
        } else
            return true;
    default:
        return super.dispatchKeyEvent(event);
    }

    return true;
}

From source file:com.mplayer_remote.RemoteControl.java

/**
 * Metoda wywoywana w reakcji na wciniecie, ktrego z przyciskw fizycznych urzdzenia.
 * W tym wypadku definiuje akcje wykonywane, kiedy uytkownik wcinie przycisk poganiania i przyciszania.
 * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
 *//* w w w  . ja v a  2 s .c  om*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    super.onKeyUp(keyCode, event);
    //onBackPressed();
    if ((keyCode == KeyEvent.KEYCODE_BACK))
        onBackPressed();
    if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
        if (mBound == true) {
            mConnectAndPlayService.sendCommand("echo key_down_event 42 > fifofile");
        }
        return true; //because I handled the event
    }
    if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
        if (mBound == true) {
            mConnectAndPlayService.sendCommand("echo key_down_event 47 > fifofile");
        }
        return true; //because I handled the event
    }
    return false; //otherwise the system can handle it        
}

From source file:com.google.android.marvin.mytalkback.ProcessorVolumeStream.java

private boolean attemptEditTextNavigation(int keyCode) {
    AccessibilityNodeInfoCompat currentNode = mCursorController.getCursor();
    try {/*  w ww .  j  av a 2  s .com*/
        if ((currentNode == null) || !AccessibilityNodeInfoUtils.nodeMatchesClassByType(mContext, currentNode,
                android.widget.EditText.class)) {
            return false;
        }

        final CursorGranularity currentGranularity = mCursorController.getGranularityAt(currentNode);
        if (currentGranularity == CursorGranularity.DEFAULT) {
            mCursorController.setGranularity(CursorGranularity.CHARACTER, false /* fromUser */);
        }

        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            return mCursorController.next(false /* shouldWrap */, false /* shouldScroll */);
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            return mCursorController.previous(false /* shouldWarp */, false /* shouldScroll */);
        }

        return false;
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(currentNode);
    }
}

From source file:com.audiokernel.euphonyrmt.library.SimpleLibraryActivity.java

@Override
public boolean onKeyUp(final int keyCode, @NonNull final KeyEvent event) {
    boolean result = true;

    if (event.isTracking() && !event.isCanceled() && !mApp.isLocalAudible()) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            MPDControl.run(MPDControl.ACTION_VOLUME_STEP_UP);
            break;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            MPDControl.run(MPDControl.ACTION_VOLUME_STEP_DOWN);
            break;
        default://from  w ww  .j  a va 2s .c  o  m
            result = super.onKeyUp(keyCode, event);
            break;
        }
    } else {
        result = super.onKeyUp(keyCode, event);
    }

    return result;
}

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

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (PreferenceManager.getDefaultSharedPreferences(getActionBarActivity()).getBoolean("volume_control",
            false)) {//from  ww w.ja va 2  s. 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:co.jlabs.cersei_retailer.zxingfragmentlib.BarCodeScannerFragment.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_FOCUS:
    case KeyEvent.KEYCODE_CAMERA:
        // Handle these events so they don't launch the Camera app
        return true;
    // Use volume up/down to turn on light
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        //                cameraManager.setTorch(false);
        setTorchOff();/*from w ww  . j av  a 2  s  .c  o  m*/
        return true;
    case KeyEvent.KEYCODE_VOLUME_UP:
        setTorchOn();
        return true;
    }
    return false; //super.onKeyDown(keyCode, event);
}