下面列出了android.view.ViewConfiguration#getDoubleTapTimeout ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 隐藏所有输入布局
*/
private void hideAllInputLayout(boolean immediately) {
if (hideAllInputLayoutRunnable == null) {
hideAllInputLayoutRunnable = new Runnable() {
@Override
public void run() {
hideInputMethod();
hideActionPanelLayout();
hideEmojiLayout();
}
};
}
long delay = immediately ? 0 : ViewConfiguration.getDoubleTapTimeout();
uiHandler.postDelayed(hideAllInputLayoutRunnable, delay);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
if (System.currentTimeMillis() - lastClickTime <= ViewConfiguration.getDoubleTapTimeout()) {
event.setAction(MotionEvent.ACTION_CANCEL);
return false;
}
break;
}
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL: {
lastClickTime = System.currentTimeMillis();
break;
}
}
return super.onTouchEvent(event);
}
@Override
public void onClick(View v) {
long time = System.currentTimeMillis();
if (time - lastClickTime < ViewConfiguration.getDoubleTapTimeout()) {
lastClickTime = 0L;
textView.startSelection();
} else {
lastClickTime = time;
}
}
private int getDoubleTapTimeout() {
return ViewConfiguration.getDoubleTapTimeout();
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if (onClickListener == null) {
return false;
}
boolean consume = false;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.d(TAG, "down");
touchDownMs = System.currentTimeMillis();
break;
case MotionEvent.ACTION_UP:
Log.d(TAG, "up");
if ((System.currentTimeMillis() - touchDownMs) > ViewConfiguration.getTapTimeout()) {
//it was not a tap
numberOfTaps = 0;
lastTapTimeMs = 0;
Log.d(TAG, "reset");
break;
}
if (numberOfTaps > 0
&& (System.currentTimeMillis() - lastTapTimeMs) < ViewConfiguration.getDoubleTapTimeout()) {
numberOfTaps += 1;
Log.d(TAG, "+1");
consume = true;
} else {
Log.d(TAG, "1");
numberOfTaps = 1;
}
lastTapTimeMs = System.currentTimeMillis();
if (numberOfTaps >= targetNumberOfTaps) {
Log.d(TAG, "goal");
onClickListener.onClick(v);
numberOfTaps = 0;
lastTapTimeMs = 0;
consume = true;
}
}
return consume;
}
@CalledByNative
private static int getDoubleTapTimeout() {
return ViewConfiguration.getDoubleTapTimeout();
}