当前位置: 首页>>代码示例>>Java>>正文


Java KeyEvent.getEventTime方法代码示例

本文整理汇总了Java中android.view.KeyEvent.getEventTime方法的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.getEventTime方法的具体用法?Java KeyEvent.getEventTime怎么用?Java KeyEvent.getEventTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.KeyEvent的用法示例。


在下文中一共展示了KeyEvent.getEventTime方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onKeyEvent

import android.view.KeyEvent; //导入方法依赖的package包/类
public void onKeyEvent(KeyEvent keyEvent){
    if (keyPressIndex==0){
        return;
    }
    if (keyPressIndex==7){
        if (lastKeyEvent!=null){
            if ((lastKeyEvent.getKeyCode()==KeyEvent.KEYCODE_VOLUME_DOWN && keyEvent.getKeyCode()==KeyEvent.KEYCODE_VOLUME_UP )
                    ||(keyEvent.getKeyCode()==KeyEvent.KEYCODE_VOLUME_DOWN && lastKeyEvent.getKeyCode()==KeyEvent.KEYCODE_VOLUME_UP )){
                if (keyEvent.getEventTime()-lastKeyEvent.getEventTime()<LONG_PRESS_DELAY){
                    longPressRunnable.run();
                }
            }
        }
        lastKeyEvent=keyEvent;
    }else {
        if (keyEvent.getKeyCode() == currentKeyCode) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                mainHandler.postDelayed(longPressRunnable, LONG_PRESS_DELAY);
            }
            if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
                mainHandler.removeCallbacks(longPressRunnable);
            }
        }
    }
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:26,代码来源:KeyPressedTipViewController.java

示例2: handleIntent

import android.view.KeyEvent; //导入方法依赖的package包/类
public static boolean handleIntent(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return false;
        }

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventTime = event.getEventTime();

        String command = null;
        switch (keycode) {
            case KeyEvent.KEYCODE_MEDIA_STOP:
                command = MusicService.ACTION_STOP;
                break;
            case KeyEvent.KEYCODE_HEADSETHOOK:
            case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                command = MusicService.ACTION_TOGGLE_PAUSE;
                break;
            case KeyEvent.KEYCODE_MEDIA_NEXT:
                command = MusicService.ACTION_SKIP;
                break;
            case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                command = MusicService.ACTION_REWIND;
                break;
            case KeyEvent.KEYCODE_MEDIA_PAUSE:
                command = MusicService.ACTION_PAUSE;
                break;
            case KeyEvent.KEYCODE_MEDIA_PLAY:
                command = MusicService.ACTION_PLAY;
                break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (event.getRepeatCount() == 0) {
                    // Only consider the first event in a sequence, not the repeat events,
                    // so that we don't trigger in cases where the first event went to
                    // a different app (e.g. when the user ends a phone call by
                    // long pressing the headset button)

                    // The service may or may not be running, but we need to send it
                    // a command.
                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventTime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG) Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(
                                MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0, context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventTime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:aliumujib,项目名称:Orin,代码行数:73,代码来源:MediaButtonIntentReceiver.java

示例3: onReceive

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    String intentAction = intent.getAction();
    if("android.media.AUDIO_BECOMING_NOISY".equals(intentAction)) {
        sendCommand(context, ACTION_PAUSE);
    } else if(Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        KeyEvent keyEvent = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if(keyEvent == null) {
            return;
        }
        int keyCode = keyEvent.getKeyCode();
        int action = keyEvent.getAction();
        long eventTime = keyEvent.getEventTime();
        String command = null;
        switch (keyCode) {
            case KEYCODE_VOLUME_UP:
                break;
            case KEYCODE_VOLUME_DOWN:
                break;
            case KEYCODE_HEADSETHOOK:
            case KEYCODE_MEDIA_PLAY_PAUSE:
                command = ACTION_TOGGLE_PLAY;
                break;
            case KEYCODE_MEDIA_STOP:
                command = ACTION_STOP;
                break;
            case KEYCODE_MEDIA_NEXT:
                command = ACTION_NEXT;
                break;
            case KEYCODE_MEDIA_PREVIOUS:
                command = ACTION_PRE;
                break;
            case KEYCODE_MEDIA_PLAY:
                command = ACTION_PLAY;
                break;
            case KEYCODE_MEDIA_PAUSE:
                command = ACTION_PAUSE;
                break;
        }

        if(command != null) {
            if(action != 0) {
                mDown = false;
            } else {
                if(mDown) {
                    if(ACTION_TOGGLE_PLAY.equals(command) || ACTION_PLAY.equals(command) && mLastClickTime != 0) {
                        //do nothing
                    }
                } else if(keyEvent.getRepeatCount() == 0) {
                    String comm = command;
                    if(keyCode == KEYCODE_HEADSETHOOK && eventTime - mLastClickTime < 300L) {
                        comm = ACTION_NEXT;
                        mLastClickTime = 0L;
                    } else {
                        mLastClickTime = eventTime;
                    }

                    sendCommand(context, comm);
                    mDown = true;
                }
            }

            if(isOrderedBroadcast()) {
                abortBroadcast();
            }
        }
    }
}
 
开发者ID:suifenge,项目名称:MusicPlayerEngine,代码行数:69,代码来源:MediaButtonIntentReceiver.java

示例4: onKeyUp

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean onKeyUp(int keyCode, KeyEvent event)
{
    // If back key
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // A custom view is currently displayed  (e.g. playing a video)
        if(mCustomView != null) {
            this.hideCustomView();
            return true;
        } else {
            // The webview is currently displayed
            // If back key is bound, then send event to JavaScript
            if (isButtonPlumbedToJs(KeyEvent.KEYCODE_BACK)) {
                sendJavascriptEvent("backbutton");
                return true;
            } else {
                // If not bound
                // Go to previous page in webview if it is possible to go back
                if (this.backHistory()) {
                    return true;
                }
                // If not, then invoke default behavior
            }
        }
    }
    // Legacy
    else if (keyCode == KeyEvent.KEYCODE_MENU) {
        if (this.lastMenuEventTime < event.getEventTime()) {
            sendJavascriptEvent("menubutton");
        }
        this.lastMenuEventTime = event.getEventTime();
        return super.onKeyUp(keyCode, event);
    }
    // If search key
    else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
        sendJavascriptEvent("searchbutton");
        return true;
    }

    //Does webkit change this behavior?
    return super.onKeyUp(keyCode, event);
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:43,代码来源:CordovaWebView.java

示例5: onReceive

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    String intentAction = intent.getAction();
    String command = null;
    if (intent.getAction() != null) {
        if (intentAction.equals(Intent.ACTION_MEDIA_BUTTON)) {
            KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);

            if (event == null) {
                return;
            }

            int keycode = event.getKeyCode();
            final int action = event.getAction();
            final long eventTime = event.getEventTime();


            switch (keycode) {
                case KeyEvent.KEYCODE_MEDIA_STOP:
                    Log.d(TAG, "stop");
                    command = Constants.ACTION_STOP;
                    break;
                case KeyEvent.KEYCODE_HEADSETHOOK:
                case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                    Log.d(TAG, "toggle");
                    command = Constants.ACTION_TOGGLE;
                    break;
                case KeyEvent.KEYCODE_MEDIA_NEXT:
                    Log.d(TAG, "next");
                    command = Constants.ACTION_NEXT;
                    break;
                case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                    Log.d(TAG, "prev");
                    command = Constants.ACTION_PREVIOUS;
                    break;
                case KeyEvent.KEYCODE_MEDIA_PAUSE:
                    Log.d(TAG, "pause");
                    command = Constants.ACTION_PAUSE;
                    break;
                case KeyEvent.KEYCODE_MEDIA_PLAY:
                    Log.d(TAG, "play");
                    command = Constants.ACTION_PLAY;
                    break;
            }
            // startServices(context, command);
            if (command != null) {
                if (action == KeyEvent.ACTION_DOWN) {
                    if (event.getRepeatCount() == 0) {
                        if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                            if (eventTime - mLastClickTime >= DOUBLE_CLICK) {
                                mClickCounter = 0;
                            }

                            mClickCounter++;
                            Log.e("MediaButton", "Got headset click, count = " + mClickCounter);
                            mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                            Message msg = mHandler.obtainMessage(
                                    MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0, context);

                            long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                            if (mClickCounter >= 3) {
                                mClickCounter = 0;
                            }
                            mLastClickTime = eventTime;
                            acquireWakeLockAndSendMessage(context, msg, delay);
                        } else {
                            startServices(context, command);
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:76,代码来源:MediaButtonReceiver.java

示例6: handleIntent

import android.view.KeyEvent; //导入方法依赖的package包/类
public static boolean handleIntent(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return false;
        }

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventTime = event.getEventTime();

        String command = null;
        switch (keycode) {
            case KeyEvent.KEYCODE_MEDIA_STOP:
                command = ACTION_STOP;
                break;
            case KeyEvent.KEYCODE_HEADSETHOOK:
            case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                command = ACTION_TOGGLE_PAUSE;
                break;
            case KeyEvent.KEYCODE_MEDIA_NEXT:
                command = ACTION_SKIP;
                break;
            case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                command = ACTION_REWIND;
                break;
            case KeyEvent.KEYCODE_MEDIA_PAUSE:
                command = ACTION_PAUSE;
                break;
            case KeyEvent.KEYCODE_MEDIA_PLAY:
                command = ACTION_PLAY;
                break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (event.getRepeatCount() == 0) {
                    // Only consider the first event in a sequence, not the repeat events,
                    // so that we don't trigger in cases where the first event went to
                    // a different app (e.g. when the user ends a phone call by
                    // long pressing the headset button)

                    // The service may or may not be running, but we need to send it
                    // a command.
                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK || keycode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
                        if (eventTime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG) Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(
                                MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0, context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventTime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:73,代码来源:MediaButtonIntentReceiver.java


注:本文中的android.view.KeyEvent.getEventTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。