我遵循了安东尼的建议,使用
TimerTask
和ButtonField。
以某种方式,用“消费点击”的风格装车。
excludes navigationClick event
.
此外,我还使用了Bold 9000/8900模拟器,导航点击在跟踪轮启动后被触发。
未点击的
. 但样品在暴风雨中效果很好。
接口:
public interface LongClickListener {
public void longClickEvent(Field field, int eventNumber);
}
控制本身:
public class LongClickButtonField extends ButtonField {
boolean mContinuousMode = false;
Timer mLongClickTimer = null;
long mLongClickDelay = 1000;
long mContinuousPeriod = 500;
LongClickListener mLongClickListener = null;
public LongClickButtonField(String label) {
super(label);
}
public LongClickButtonField(String label, boolean continuousMode) {
this(label);
mContinuousMode = continuousMode;
}
public void setLongClickListener(LongClickListener longClickListener) {
mLongClickListener = longClickListener;
}
protected boolean navigationClick(int status, int time) {
mLongClickTimer = new Timer();
final Field eventArg = this;
if(!mContinuousMode)
{
mLongClickTimer.schedule(new TimerTask() {public void run() {
mLongClickListener.longClickEvent(eventArg, 0);
}}, mLongClickDelay);
}
else
{
mLongClickTimer.schedule(new TimerTask(){
int eventNum= 0;
public void run() {
mLongClickListener.longClickEvent(eventArg, eventNum);
eventNum++;
}}, mLongClickDelay, mContinuousPeriod);
}
return true;
}
protected boolean navigationUnclick(int status, int time) {
mLongClickTimer.cancel();
return true;
}
}
用途:
public class Scr extends MainScreen implements LongClickListener {
LabelField mStatusLabel = new LabelField("status") {
protected void paint(Graphics graphics) {
graphics.setColor(Color.BLACK);
super.paint(graphics);
};
};
public Scr() {
LongClickButtonField button = new LongClickButtonField(
"click & hold 5 s");
LongClickButtonField buttonContinuous = new LongClickButtonField(
"click & hold > 5 s", true);
button.setLongClickListener(this);
buttonContinuous.setLongClickListener(this);
add(mStatusLabel);
add(button);
add(buttonContinuous);
}
public void longClickEvent(final Field field, final int eventNumber) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
mStatusLabel.setText(
((ButtonField) field).getLabel()
+ " event #"
+ String.valueOf(eventNumber));
}
});
}
}