我想为一把钥匙添加倒数计时器5分钟。 按键应该在按键上看到,或者在按下按键后打开帽灯5分钟。 无论如何要在自定义键盘上实现这个? 我使用了eclipse教程并对其进行了更改。但我不知道如何在密钥上添加此功能 我特定键的开关案例是,
case 905:
String chop = "DiscordRPG chop";
ic.commitText(chop, 1);
ic.sendKeyEvent(kd); ic.sendKeyEvent(ku);
break;
答案 0 :(得分:0)
考虑一个密钥有代码1050,当它按下时,你想开始倒计时。在此期间,您要禁用其他键并显示某个键的倒计时,或者可能位于Toast
case 1050:
//To disable keys while countdown, move below 2 lines code to the first line of onKey()
if(isCountDownRunning)
return;
isCountDownRunning = true;
new CountDownTimer(5 * 60 * 1000, 1000) {
public void onTick(long millisUntilFinished) {
//here, update the key label or a toast.
//update label of key 20
keyboard.getKeys().get(20).label = millisUnitFinished / ( 60 * 1000);
//or, show a toast
//Toast.make(this, "Remaining time : " + millisUnitFinished / ( 60 * 1000), Toast.LENGTH_SHORT).show();
}
public void onFinish() {
isCountDownRunning = false;
}
}.start();
现在,在onKey()
内首先检查isCountDownRunning
是否为true
,然后return null
执行方法的其余部分。