I could not find this answer myself, so I manually coded the solution. I used a timer in the onPress()
and onRelease()
events of the KeyboardView.OnKeyboardActionListener
. Here is the important code. Many TRY / CATCHes have been omitted for brevity. In English, when a key is pressed, I start a timer that waits the same moment that it usually expects to wait for a long click ( ViewConfiguration.getLongPressTimeout()
), and then ViewConfiguration.getLongPressTimeout()
long click event in the source stream. Subsequent keystrokes and keystrokes can cancel any active timer.
public class MyIME extends InputMethodService implements KeyboardView.OnKeyboardActionListener { : : private Timer timerLongPress = null; : : @Override public void onCreate() { super.onCreate(); : : timerLongPress = new Timer(); : : } @Override public void onRelease(final int primaryCode) { : : timerLongPress.cancel(); : : } @Override public void onPress(final int primaryCode) { : : timerLongPress.cancel(); : : timerLongPress = new Timer(); timerLongPress.schedule(new TimerTask() { @Override public void run() { try { Handler uiHandler = new Handler(Looper.getMainLooper()); Runnable runnable = new Runnable() { @Override public void run() { try { MyIME.this.onKeyLongPress(primaryCode); } catch (Exception e) { Log.e(MyIME.class.getSimpleName(), "uiHandler.run: " + e.getMessage(), e); } } }; uiHandler.post(runnable); } catch (Exception e) { Log.e(MyIME.class.getSimpleName(), "Timer.run: " + e.getMessage(), e); } } }, ViewConfiguration.getLongPressTimeout()); : : } public void onKeyLongPress(int keyCode) {
source share