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.smc.tw.waltz.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (DEBUG)//  w w  w.j a va 2 s  .  com
        Log.d(TAG, "onKeyDown code:" + keyCode);

    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP: {
        mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE,
                AudioManager.FLAG_SHOW_UI);

        return true;
    }

    case KeyEvent.KEYCODE_VOLUME_DOWN: {
        mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER,
                AudioManager.FLAG_SHOW_UI);

        return true;
    }

    default:
        break;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:android.support.v7.app.MediaRouteControllerDialog.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        mRoute.requestUpdateVolume(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ? -1 : 1);
        return true;
    }//from  w w w . jav  a2s  .co  m
    return super.onKeyDown(keyCode, event);
}

From source file:com.mschlauch.comfortreader.FullscreenActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {

    int duration = Toast.LENGTH_SHORT;

    //VOLUME KEY DOWN
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        Context context = getApplicationContext();
        CharSequence text = "??";

        if (started == false) {
            previousButtonClicked(contentView);

            text = "<<";

        }/*from  w  w w  .  j  a v a 2  s.c om*/
        toast = Toast.makeText(context, text, duration);
        toast.show();

        stop();
        keyCode = -900000;
        return true;
    }
    //VOLUME KEY UP
    else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {

        Context context = getApplicationContext();
        CharSequence text = "";

        if (started == true) {

            text = "??";
            toast = Toast.makeText(context, text, duration);
            toast.show();

        }

        playButtonClicked(contentView);
        keyCode = -900000;
        return true;

    }

    else if (keyCode == KeyEvent.KEYCODE_MENU) {
        menuButtonClicked(contentView);
        return true;
    }
    super.onKeyDown(keyCode, event);

    return true;
}

From source file:de.spiritcroc.modular_remote.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (volumeButtonSettingsShortcutCount) {
    case 0://from w  w w  .  ja va  2s .c  o  m
    case 1:
    case 4:
    case 6:
        resetVolumeButtonSettingsShortcutHandler.removeCallbacks(resetVolumeButtonSettingsShortcut);
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            volumeButtonSettingsShortcutCount++;
            resetVolumeButtonSettingsShortcutHandler.postDelayed(resetVolumeButtonSettingsShortcut, 1000);
        } else {
            volumeButtonSettingsShortcutCount = 0;
        }
        break;
    case 2:
    case 3:
    case 5:
        resetVolumeButtonSettingsShortcutHandler.removeCallbacks(resetVolumeButtonSettingsShortcut);
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            volumeButtonSettingsShortcutCount++;
            resetVolumeButtonSettingsShortcutHandler.postDelayed(resetVolumeButtonSettingsShortcut, 1000);
        } else {
            volumeButtonSettingsShortcutCount = 0;
        }
        break;
    case 7:
        resetVolumeButtonSettingsShortcutHandler.removeCallbacks(resetVolumeButtonSettingsShortcut);
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            Toast.makeText(getApplicationContext(), R.string.toast_volume_button_settings_shortcut,
                    Toast.LENGTH_LONG).show();
            startActivity(
                    new Intent(this, SettingsActivity.class).addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
        }
        volumeButtonSettingsShortcutCount = 0;
        break;
    default:
        volumeButtonSettingsShortcutCount = 0;
        break;
    }
    return pages.get(viewPager.getCurrentItem()).onKeyDown(keyCode) || super.onKeyDown(keyCode, event);
}

From source file:android.support.v7.app.MediaRouteControllerDialog.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        return true;
    }//ww  w. java  2 s . c  o  m
    return super.onKeyUp(keyCode, event);
}

From source file:android.widget.TiVideoView4.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mIsPrepared && keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP
            && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_MENU
            && keyCode != KeyEvent.KEYCODE_CALL && keyCode != KeyEvent.KEYCODE_ENDCALL && mMediaPlayer != null
            && mMediaController != null) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();/*  ww w .  ja  v  a2 s.  c om*/
                mMediaController.show();
            } else {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP && mMediaPlayer.isPlaying()) {
            pause();
            mMediaController.show();
        } else {
            toggleMediaControlsVisiblity();
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:org.huxizhijian.hhcomicviewer.ui.entry.GalleryActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (useVolButtonChangePage) {
        //??/*from   w  w  w  . j  av  a  2 s . c  om*/
        switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            if (mViewPagerAdapter != null) {
                if (mViewPager.getCurrentItem() - 1 >= 0) {
                    mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1, false);
                } else {
                    openPrevChapter();
                }
            }
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (mViewPagerAdapter != null) {
                if (mViewPager.getCurrentItem() + 1 < mComicChapter.getPageCount()) {
                    mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1, false);
                } else {
                    openNextChapter();
                }
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.protocoderrunner.apprunner.AppRunnerActivity.java

public boolean checkVolumeKeys(int keyCode) {
    boolean r;/*from  w w w.  j av a  2 s . co m*/

    if (keyVolumeEnabled
            && (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
        r = true;
    } else {
        r = false;
    }

    return r;

}

From source file:CookieVideoView.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP
            && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
            && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_CALL
            && keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();//from w  w  w.jav  a 2 s.  co  m
                mMediaController.show();
            } else {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
            if (!mMediaPlayer.isPlaying()) {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();
                mMediaController.show();
            }
            return true;
        } else {
            toggleMediaControlsVisiblity();
        }
    }

    return super.onKeyDown(keyCode, event);
}