Example usage for android.view KeyEvent getDownTime

List of usage examples for android.view KeyEvent getDownTime

Introduction

In this page you can find the example usage for android.view KeyEvent getDownTime.

Prototype

public final long getDownTime() 

Source Link

Document

Retrieve the time of the most recent key down event, in the android.os.SystemClock#uptimeMillis time base.

Usage

From source file:org.yaawp.hmi.activities.CustomActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    Log.i(TAG, "onKeyDown( KeyCode=" + keyCode + " KeyEvent=" + event.getAction());
    boolean status = false;

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (event.getKeyCode() == lastKeyCode
                && event.getDownTime() - lastPressedTime < Const.DOUBLE_PRESS_HK_BACK_PERIOD) {
            status = onKeyTwiceDown(event.getKeyCode(), event);
        } else {/*from   w  w w. j  a v a2 s  . co  m*/
            lastPressedTime = event.getDownTime();
            lastKeyCode = event.getKeyCode();
            status = onKeyOnceDown(keyCode, event);
        }
    } else {
        status = super.onKeyDown(keyCode, event);
    }
    return status;
}

From source file:com.example.angel.parkpanda.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        switch (event.getAction()) {
        case KeyEvent.ACTION_DOWN:
            if (event.getDownTime() - lastPressedTime < PERIOD) {
                System.exit(0);//from   w  ww.j  av a 2s .c om
                finish();

            } else {
                Toast.makeText(getApplicationContext(), "Press again to exit.", Toast.LENGTH_SHORT).show();
                lastPressedTime = event.getEventTime();
            }
            return true;
        }
    }
    return false;
}

From source file:org.mariotaku.harmony.activity.MusicPlaybackActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mService == null)
        return super.onKeyDown(keyCode, event);
    final int repcnt = event.getRepeatCount();

    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (!useDpadMusicControl()) {
            break;
        }//from ww w. j  a va2s. c  o m
        if (!mPrevButton.hasFocus()) {
            mPrevButton.requestFocus();
        }
        scanBackward(repcnt, event.getEventTime() - event.getDownTime());
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (!useDpadMusicControl()) {
            break;
        }
        if (!mNextButton.hasFocus()) {
            mNextButton.requestFocus();
        }
        scanForward(repcnt, event.getEventTime() - event.getDownTime());
        return true;

    // case KeyEvent.KEYCODE_R:
    // toggleRepeat();
    // return true;
    //
    // case KeyEvent.KEYCODE_S:
    // toggleShuffle();
    // return true;

    case KeyEvent.KEYCODE_N: {
        doNext();
        return true;
    }
    case KeyEvent.KEYCODE_P: {
        doPrev();
        return true;
    }
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_SPACE: {
        doPauseResume();
        return true;
    }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.mariotaku.harmony.activity.MusicPlaybackActivity.java

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

    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (!useDpadMusicControl()) {
            break;
        }//from ww  w . j a v a 2 s  .  co  m
        if (mService != null) {
            if (!mSeeking && mStartSeekPos >= 0) {
                mPlayPauseButton.requestFocus();
                if (mStartSeekPos < 1000) {
                    mService.prev();
                } else {
                    mService.seek(0);
                }
            } else {
                scanBackward(-1, event.getEventTime() - event.getDownTime());
                mPlayPauseButton.requestFocus();
                mStartSeekPos = -1;
            }
        }
        mSeeking = false;
        mPosOverride = -1;
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (!useDpadMusicControl()) {
            break;
        }
        if (mService != null) {
            if (!mSeeking && mStartSeekPos >= 0) {
                mPlayPauseButton.requestFocus();
                mService.next();
            } else {
                scanForward(-1, event.getEventTime() - event.getDownTime());
                mPlayPauseButton.requestFocus();
                mStartSeekPos = -1;
            }
        }
        mSeeking = false;
        mPosOverride = -1;
        return true;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:net.sourceforge.servestream.activity.MediaPlayerActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    int repcnt = event.getRepeatCount();

    if ((seekmethod == 0) ? seekMethod1(keyCode) : seekMethod2(keyCode))
        return true;

    switch (keyCode) {
    case KeyEvent.KEYCODE_SLASH:
        seekmethod = 1 - seekmethod;/*from   w w  w .  j a  v a 2 s .  c o  m*/
        return true;

    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (!useDpadMusicControl()) {
            break;
        }
        if (!mPrevButton.hasFocus()) {
            mPrevButton.requestFocus();
        }
        scanBackward(repcnt, event.getEventTime() - event.getDownTime());
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (!useDpadMusicControl()) {
            break;
        }
        if (!mNextButton.hasFocus()) {
            mNextButton.requestFocus();
        }
        scanForward(repcnt, event.getEventTime() - event.getDownTime());
        return true;

    case KeyEvent.KEYCODE_S:
        toggleShuffle();
        return true;

    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_SPACE:
        doPauseResume();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.yammp.app.MusicPlaybackActivity.java

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

    int repcnt = event.getRepeatCount();

    switch (keyCode) {

    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (!useDpadMusicControl()) {
            break;
        }//from w  w  w.j  av a 2 s.c  om
        if (!mPrevButton.hasFocus()) {
            mPrevButton.requestFocus();
        }
        scanBackward(repcnt, event.getEventTime() - event.getDownTime());
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (!useDpadMusicControl()) {
            break;
        }
        if (!mNextButton.hasFocus()) {
            mNextButton.requestFocus();
        }
        scanForward(repcnt, event.getEventTime() - event.getDownTime());
        return true;

    // case KeyEvent.KEYCODE_R:
    // toggleRepeat();
    // return true;
    //
    // case KeyEvent.KEYCODE_S:
    // toggleShuffle();
    // return true;

    case KeyEvent.KEYCODE_N:
        if (mService != null) {
            try {
                mService.next();
                return true;
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        } else
            return false;

    case KeyEvent.KEYCODE_P:
        if (mService != null) {
            try {
                mService.prev();
                return true;
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        } else
            return false;

    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_SPACE:
        doPauseResume();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.musicmod.android.app.MusicPlaybackActivity.java

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

    int repcnt = event.getRepeatCount();

    switch (keyCode) {

    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (!useDpadMusicControl()) {
            break;
        }// ww w .j av a 2s.  c  o  m
        if (!mPrevButton.hasFocus()) {
            mPrevButton.requestFocus();
        }
        scanBackward(repcnt, event.getEventTime() - event.getDownTime());
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (!useDpadMusicControl()) {
            break;
        }
        if (!mNextButton.hasFocus()) {
            mNextButton.requestFocus();
        }
        scanForward(repcnt, event.getEventTime() - event.getDownTime());
        return true;

    //         case KeyEvent.KEYCODE_R:
    //            toggleRepeat();
    //            return true;
    //
    //         case KeyEvent.KEYCODE_S:
    //            toggleShuffle();
    //            return true;

    case KeyEvent.KEYCODE_N:
        if (mService != null) {
            try {
                mService.next();
                return true;
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        } else {
            return false;
        }

    case KeyEvent.KEYCODE_P:
        if (mService != null) {
            try {
                mService.prev();
                return true;
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        } else {
            return false;
        }

    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_SPACE:
        doPauseResume();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.android.app.MediaPlaybackActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    try {//w  w  w .j av a  2  s.  co m
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (!useDpadMusicControl()) {
                break;
            }
            if (mService != null) {
                if (!mSeeking && mStartSeekPos >= 0) {
                    mPauseButton.requestFocus();
                    if (mStartSeekPos < 1000) {
                        mService.prev();
                    } else {
                        mService.seek(0);
                    }
                } else {
                    scanBackward(-1, event.getEventTime() - event.getDownTime());
                    mPauseButton.requestFocus();
                    mStartSeekPos = -1;
                }
            }
            mSeeking = false;
            mPosOverride = -1;
            return true;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (!useDpadMusicControl()) {
                break;
            }
            if (mService != null) {
                if (!mSeeking && mStartSeekPos >= 0) {
                    mPauseButton.requestFocus();
                    mService.next();
                } else {
                    scanForward(-1, event.getEventTime() - event.getDownTime());
                    mPauseButton.requestFocus();
                    mStartSeekPos = -1;
                }
            }
            mSeeking = false;
            mPosOverride = -1;
            return true;
        }
    } catch (RemoteException ex) {
    }
    return super.onKeyUp(keyCode, event);
}

From source file:org.musicmod.android.app.MusicPlaybackActivity.java

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

    try {//ww  w .j  a v  a 2  s  . c  o m
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (!useDpadMusicControl()) {
                break;
            }
            if (mService != null) {
                if (!mSeeking && mStartSeekPos >= 0) {
                    mPauseButton.requestFocus();
                    if (mStartSeekPos < 1000) {
                        mService.prev();
                    } else {
                        mService.seek(0);
                    }
                } else {
                    scanBackward(-1, event.getEventTime() - event.getDownTime());
                    mPauseButton.requestFocus();
                    mStartSeekPos = -1;
                }
            }
            mSeeking = false;
            mPosOverride = -1;
            return true;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (!useDpadMusicControl()) {
                break;
            }
            if (mService != null) {
                if (!mSeeking && mStartSeekPos >= 0) {
                    mPauseButton.requestFocus();
                    mService.next();
                } else {
                    scanForward(-1, event.getEventTime() - event.getDownTime());
                    mPauseButton.requestFocus();
                    mStartSeekPos = -1;
                }
            }
            mSeeking = false;
            mPosOverride = -1;
            return true;
        }
    } catch (RemoteException ex) {
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.android.app.MediaPlaybackActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    int direction = -1;
    int repcnt = event.getRepeatCount();

    if ((seekmethod == 0) ? seekMethod1(keyCode) : seekMethod2(keyCode))
        return true;

    switch (keyCode) {
    /*/*from www.  j a v a2s. c o m*/
    // image scale
    case KeyEvent.KEYCODE_Q: av.adjustParams(-0.05, 0.0, 0.0, 0.0, 0.0,-1.0); break;
    case KeyEvent.KEYCODE_E: av.adjustParams( 0.05, 0.0, 0.0, 0.0, 0.0, 1.0); break;
    // image translate
    case KeyEvent.KEYCODE_W: av.adjustParams(    0.0, 0.0,-1.0, 0.0, 0.0, 0.0); break;
    case KeyEvent.KEYCODE_X: av.adjustParams(    0.0, 0.0, 1.0, 0.0, 0.0, 0.0); break;
    case KeyEvent.KEYCODE_A: av.adjustParams(    0.0,-1.0, 0.0, 0.0, 0.0, 0.0); break;
    case KeyEvent.KEYCODE_D: av.adjustParams(    0.0, 1.0, 0.0, 0.0, 0.0, 0.0); break;
    // camera rotation
    case KeyEvent.KEYCODE_R: av.adjustParams(    0.0, 0.0, 0.0, 0.0, 0.0,-1.0); break;
    case KeyEvent.KEYCODE_U: av.adjustParams(    0.0, 0.0, 0.0, 0.0, 0.0, 1.0); break;
    // camera translate
    case KeyEvent.KEYCODE_Y: av.adjustParams(    0.0, 0.0, 0.0, 0.0,-1.0, 0.0); break;
    case KeyEvent.KEYCODE_N: av.adjustParams(    0.0, 0.0, 0.0, 0.0, 1.0, 0.0); break;
    case KeyEvent.KEYCODE_G: av.adjustParams(    0.0, 0.0, 0.0,-1.0, 0.0, 0.0); break;
    case KeyEvent.KEYCODE_J: av.adjustParams(    0.0, 0.0, 0.0, 1.0, 0.0, 0.0); break;
            
    */

    case KeyEvent.KEYCODE_SLASH:
        seekmethod = 1 - seekmethod;
        return true;

    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (!useDpadMusicControl()) {
            break;
        }
        if (!mPrevButton.hasFocus()) {
            mPrevButton.requestFocus();
        }
        scanBackward(repcnt, event.getEventTime() - event.getDownTime());
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (!useDpadMusicControl()) {
            break;
        }
        if (!mNextButton.hasFocus()) {
            mNextButton.requestFocus();
        }
        scanForward(repcnt, event.getEventTime() - event.getDownTime());
        return true;

    case KeyEvent.KEYCODE_S:
        toggleShuffle();
        return true;

    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_SPACE:
        doPauseResume();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}