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:Main.java

public static void volumeAdd() {
    new Thread(new Runnable() {
        @Override//from   w  ww  .  jav  a  2 s.  c  o  m
        public void run() {
            Instrumentation m_Instrumentation = new Instrumentation();
            m_Instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_VOLUME_UP);
        }
    }).start();
}

From source file:com.darly.im.ui.BaseFragment.java

/**
 * ?,??//from  w ww. j  av  a  2  s .  c  om
 * @param keyCode
 * @param event
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) && mAudioManager != null) {
        int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        if (streamVolume >= mMusicMaxVolume) {
            LogUtil.d(LogUtil.getLogUtilsTag(BaseFragment.class), "has set the max volume");
            return true;
        }
        int mean = mMusicMaxVolume / 7;
        if (mean == 0) {
            mean = 1;
        }
        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, streamVolume + mean,
                AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
        return true;
    }
    if ((event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) && mAudioManager != null) {
        int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        int mean = mMusicMaxVolume / 7;
        if (mean == 0) {
            mean = 1;
        }
        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, streamVolume - mean,
                AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.gao.im.ui.BaseFragment.java

/**
 * ?,??//w w  w.j  a  va  2 s  . c o  m
 * @param keyCode
 * @param event
 */
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) && mAudioManager != null) {
        int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        if (streamVolume >= mMusicMaxVolume) {
            LogUtil.d(LogUtil.getLogUtilsTag(BaseFragment.class), "has set the max volume");
            return true;
        }
        int mean = mMusicMaxVolume / 7;
        if (mean == 0) {
            mean = 1;
        }
        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, streamVolume + mean,
                AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
        return true;
    }
    if ((event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) && mAudioManager != null) {
        int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        int mean = mMusicMaxVolume / 7;
        if (mean == 0) {
            mean = 1;
        }
        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, streamVolume - mean,
                AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:uk.org.ngo.squeezer.dialog.TipsDialog.java

@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        return getActivity().onKeyDown(keyCode, event);
    }// w  ww.ja  va 2 s . c o m

    return false;
}

From source file:com.google.android.car.kitchensink.input.InputTestFragment.java

@Nullable
@Override//from   w ww.j av a  2  s  .c  o  m
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.input_test, container, false);

    Collections.addAll(mButtons, BREAK_LINE, createButton(R.string.home, KeyEvent.KEYCODE_HOME),
            createButton(R.string.volume_up, KeyEvent.KEYCODE_VOLUME_UP),
            createButton(R.string.volume_down, KeyEvent.KEYCODE_VOLUME_DOWN),
            createButton(R.string.volume_mute, KeyEvent.KEYCODE_VOLUME_MUTE),
            createButton(R.string.voice, KeyEvent.KEYCODE_VOICE_ASSIST), BREAK_LINE,
            createButton(R.string.music, KeyEvent.KEYCODE_MUSIC),
            createButton(R.string.music_play, KeyEvent.KEYCODE_MEDIA_PLAY),
            createButton(R.string.music_stop, KeyEvent.KEYCODE_MEDIA_STOP),
            createButton(R.string.next_song, KeyEvent.KEYCODE_MEDIA_NEXT),
            createButton(R.string.prev_song, KeyEvent.KEYCODE_MEDIA_PREVIOUS),
            createButton(R.string.tune_right, KeyEvent.KEYCODE_CHANNEL_UP),
            createButton(R.string.tune_left, KeyEvent.KEYCODE_CHANNEL_DOWN), BREAK_LINE,
            createButton(R.string.call_send, KeyEvent.KEYCODE_CALL),
            createButton(R.string.call_end, KeyEvent.KEYCODE_ENDCALL));

    mCarEmulator = CarEmulator.create(getContext());
    addButtonsToPanel((LinearLayout) view.findViewById(R.id.input_buttons), mButtons);

    return view;
}

From source file:com.microsoft.mimickeralarm.globalsettings.AlarmGlobalSettingsActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) || (keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
        List<Fragment> fragments = getSupportFragmentManager().getFragments();
        ((AlarmGlobalSettingsFragment) fragments.get(0)).onKeyDown(keyCode);
    } else {// w  ww .j ava  2 s  . c  om
        return super.onKeyDown(keyCode, event);
    }
    return true;
}

From source file:com.dwdesign.tweetings.activity.SearchActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    SharedPreferences mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);

    if (mPreferences.getBoolean(PREFERENCE_KEY_VOLUME_NAVIGATION, false)) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_VOLUME_UP: {
                Intent broadcast = new Intent();
                broadcast.setAction(BROADCAST_VOLUME_UP);
                sendBroadcast(broadcast);
                //scrollToPrevious();
                return true;
            }//from  w w  w  .j a v a  2 s  .  c  o m
            case KeyEvent.KEYCODE_VOLUME_DOWN: {
                Intent broadcast = new Intent();
                broadcast.setAction(BROADCAST_VOLUME_DOWN);
                sendBroadcast(broadcast);
                //scrollToNext();
                return true;
            }
            }
        }
        if (event.getAction() == KeyEvent.ACTION_UP && (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP
                || event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN)) {
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:io.github.hidroh.materialistic.VolumeNavigationDelegate.java

/**
 * Calls from {@link Activity#onKeyDown(int, KeyEvent)} to delegate
 * @param keyCode    event key code//from   w  w w .java 2s .co m
 * @param event      key event
 * @return  true if is intercepted as navigation, false otherwise
 */
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (!mEnabled) {
        return false;
    }
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        event.startTracking();
        return true;
    }
    return false;
}

From source file:com.google.mist.plot.MainActivity.java

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

    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        toggleRecording(RecordingType.POSITIVE);
        return true;
    }// w w w  .ja  v a2  s.co m

    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        toggleRecording(RecordingType.NEGATIVE);
        return true;
    }

    /* To label magnet pulls with ground truth, connect with ADB and run command:
       $ input keyevent 66
       or from console, not inside adb shell,
       $ adb shell input keyevent 66
       or connect a bluetooth keyboard and hit "enter" key
     */
    if (mIsRecording && (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_DPAD_UP
            || keyCode == KeyEvent.KEYCODE_DPAD_DOWN || keyCode == KeyEvent.KEYCODE_DPAD_LEFT
            || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)) {
        mVibrator.vibrate(30);
        int recordedLabel = 0;
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
            recordedLabel = POSITIVE_LABEL;
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            recordedLabel = UP_LABEL;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            recordedLabel = DOWN_LABEL;
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            recordedLabel = LEFT_LABEL;
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            recordedLabel = RIGHT_LABEL;
            break;
        }
        long lastFiring = mSensorTime.get(mSensorTime.size() - 1);
        mPositivesTime.add(lastFiring);
        mPositivesData.add(recordedLabel);
    }

    return super.onKeyDown(keyCode, event);
}

From source file:io.github.hidroh.materialistic.KeyDelegate.java

/**
 * Calls from {@link Activity#onKeyDown(int, KeyEvent)} to delegate
 * @param keyCode    event key code//from   w w  w . j  a  v  a  2 s  . c  om
 * @param event      key event
 * @return  true if is intercepted as navigation, false otherwise
 */
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        return mBackInterceptor != null && mBackInterceptor.onBackPressed();
    }
    if (!mEnabled) {
        return false;
    }
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        event.startTracking();
        return true;
    }
    return false;
}