Isha Dhawan
I have found a little hack to handle a Longpress Key Event:
I did the following. I created a long value to store my last event down time. In addiotion I created a delta member do determine when the LongPress event should be fired:
private long mLastKeyDownTime = 0;
private long mPressedDelta = 1000;
and when pressing on center I check if enough time passed since the press started to dispatch a longpress event:
@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);
}
I know this isn´t the most elegant solution but I think it will do what you´d like it to do. The multiple calls to onKeyDown(..) are caused by the private SDK Amazon uses for handling KeyInput from the remote.