我正在尝试编写一个程序,当输入“区域”时,我的手机会振动……这不符合系统的逻辑。振动后,我要等x量的MS才能再次振动。
public void buzz(final long[] pattern, final int ms, final int currentZone)
{
int repeat = (int)(SP.getFloat("my_zone_slider", 0.0f));
if(currentZone != lastZone)
{
repeatCount = 0;
vibrating = false;
}
lastZone = currentZone;
repeatCount = repeat;
if(!vibrating) {
vibrating = true;
v.vibrate(pattern, -1);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// this code will be executed after 2 seconds
vibrating = false;
repeatCount--;
if(repeatCount > 0)
{
buzz(pattern, ms, currentZone);
}
}
}, ms);
}
}
这就是我目前拥有的。我的计时器不尊重“ ms”。关于如何可以在不中断主线程的情况下等待x数量的MS的任何想法。