通过电视遥控器长按D Pad中心按钮

时间:2016-12-08 10:31:50

标签: android amazon

我正在使用亚马逊Fire Stick TV进行电视应用。我需要通过电视遥控器处理Dpad中心按钮的长按事件。 对于Dpad中心按钮,如果我长按DPad中心按钮,我只会多次接到onKeyDown()的来电。

在尝试长按DPad中心按钮时,我没有收到对OnKeyUp()方法和onLongKeyPress()方法的任何调用。这是一个错误吗?

编译SDK版本是' 23'

2 个答案:

答案 0 :(得分:0)

Isha Dhawan 我找到了一个小小的黑客来处理Longpress Key事件:

我做了以下事情。我创建了一个很长的值来存储我的最后一个事件。另外,我创建了一个delta成员来确定何时应该触发LongPress事件:

private long mLastKeyDownTime = 0;
private long mPressedDelta = 1000;

当按下中心时,我会检查自印刷机开始发送长按事件后是否有足够的时间过去了:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean handled = false;
    switch (keyCode) {
        case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
            break;

        case KeyEvent.KEYCODE_MEDIA_REWIND:
            break;

        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            break;

        case KeyEvent.KEYCODE_DPAD_CENTER:
            handled = true;
            long time = SystemClock.uptimeMillis();
            if (mLastKeyDownTime + mPressedDelta <= time) {
                onCenterLongress();
            }
            mLastKeyDownTime = event.getDownTime();
            onCenter();
            break;

        case KeyEvent.KEYCODE_DPAD_LEFT:
            handled = true;
            onLeft();
            break;

        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = true;
            onRight();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            handled = true;
            onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            handled = true;
            onDown();
            break;

        case KeyEvent.KEYCODE_BACK:
            handled = true;
            onBack();
            break;

        case KeyEvent.KEYCODE_MENU:
            handled = true;
            if (event.getDownTime() == mLastKeyDownTime) {
                break;
            }
            mLastKeyDownTime = event.getDownTime();
            onMenu();
            break;
    }
    return handled || super.onKeyDown(keyCode, event);
}

我知道这不是最优雅的解决方案,但我认为它会做你喜欢的事情。对onKeyDown(..)的多次调用是由Amazon用于处理来自远程的KeyInput的私有SDK引起的。

答案 1 :(得分:0)

我通过KEYCODE_DPAD_CENTER中的dispatchKeyEvent(KeyEvent event)处理@Override public boolean dispatchKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: Log.d(TAG,"Down time is" + event.getDownTime()+"with action:" + event.getAction()+ "with repeat count"+ event.getRepeatCount()+"with long press"+ event.isLongPress()); if (action == KeyEvent.ACTION_DOWN && event.isLongPress()) { Log.d(TAG,"LOng pres Down time is" + event.getDownTime()); Log.d(TAG, "Inside long press of Dpad center event"); onCenter(); return true; } default: return super.dispatchKeyEvent(event); } } 关键字来解决这个问题:

<table description="Résultats de recherche" class="selectable">
    <thead>
    <tr>
        <th (click)="setOrder('id')" [ngClass]="setOrderClass('id')">Id</th>
        <th (click)="setOrder('nom')" [ngClass]="setOrderClass('nom')">Nom</th>
        <th (click)="setOrder('creePar')" [ngClass]="setOrderClass('creePar')">Crée par</th>
        <th></th>
    </tr>
    </thead>
    <tbody>
    <tr *ngIf="!documentList || documentList.length == 0">
        <td colspan="3">Aucun résultat trouvé</td>
    </tr>
    <tr *ngFor="let document of (documentList | documentFilter:selectedMetaDataFilter:filter) | orderBy: [sortingOrder+sortingPredicate]"
         title="{{ showMetaDatas(document.metaData) }}">
        <td>{{ document.id }}</td>
        <td>{{ document.nom }}</td>
        <td>{{ document.creePar }}</td>
        <td ng-repeat-end class="inline-tools">
           <a href="#">Link</a>
        </td>
    </tr>
    </tbody>
</table>