您现在的位置是:主页 > news > 做网站语言排名2018/网站优化公司哪家效果好
做网站语言排名2018/网站优化公司哪家效果好
admin2025/5/2 16:33:16【news】
简介做网站语言排名2018,网站优化公司哪家效果好,丽水企业网站建设,衢州做网站我想要一个简单且可重复使用的界面,它可以监听两个手指双击并且表现得像GestureDetector.所以你可以像这样使用它(所有剪切和粘贴可运行的代码):public class Example extends Activity {SimpleTwoFingerDoubleTapDetector multiTouchListener new SimpleTwoFinger…
我想要一个简单且可重复使用的界面,它可以监听两个手指双击并且表现得像GestureDetector.所以你可以像这样使用它(所有剪切和粘贴可运行的代码):
public class Example extends Activity {
SimpleTwoFingerDoubleTapDetector multiTouchListener = new SimpleTwoFingerDoubleTapDetector() {
@Override
public void onTwoFingerDoubleTap() {
// Do what you want here, I used a Toast for demonstration
Toast.makeText(Example.this, "Two Finger Double Tap", Toast.LENGTH_SHORT).show();
}
};
// Override onCreate() and anything else you want
@Override
public boolean onTouchEvent(MotionEvent event) {
if(multiTouchListener.onTouchEvent(event))
return true;
return super.onTouchEvent(event);
}
}
我创建了SimpleTwoFingerDoubleTapDetector. (这是一个很长的名称,但它是描述性的.您可以将其重命名为您想要的任何内容.)将此新文件保存在项目中或作为库:
public abstract class SimpleTwoFingerDoubleTapDetector {
private static final int TIMEOUT = ViewConfiguration.getDoubleTapTimeout() + 100;
private long mFirstDownTime = 0;
private boolean mSeparateTouches = false;
private byte mTwoFingerTapCount = 0;
private void reset(long time) {
mFirstDownTime = time;
mSeparateTouches = false;
mTwoFingerTapCount = 0;
}
public boolean onTouchEvent(MotionEvent event) {
switch(event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
if(mFirstDownTime == 0 || event.getEventTime() - mFirstDownTime > TIMEOUT)
reset(event.getDownTime());
break;
case MotionEvent.ACTION_POINTER_UP:
if(event.getPointerCount() == 2)
mTwoFingerTapCount++;
else
mFirstDownTime = 0;
break;
case MotionEvent.ACTION_UP:
if(!mSeparateTouches)
mSeparateTouches = true;
else if(mTwoFingerTapCount == 2 && event.getEventTime() - mFirstDownTime < TIMEOUT) {
onTwoFingerDoubleTap();
mFirstDownTime = 0;
return true;
}
}
return false;
}
public abstract void onTwoFingerDoubleTap();
}
首先,关于Android(一键式)GestureDetector的一些注意事项:
> Android的onDoubleTap()事件使用ViewConfiguration中的标准超时值.我指的是同一时间.
>它们测量从第一次敲击手指向下事件到第二次敲击手指向下事件所经过的时间,然后广播onDoubleTap()和onDoubleTapEvent().
> onDoubleTap()仅在第二次敲击手指向下事件发生时触发.
> onDoubleTapEvent()在第二次点击时为每个动作触发:向下,向上和向上.
关于SimpleTwoFingerDoubleTapDetector的一些注意事项:
>我的超时是从第一个手指向下事件到最后一个手指向上事件测量的,以防止错误的双击通知.我为默认的ViewConfiguration双击超时添加了一点额外的时间来解决这个问题.
> Android的GestureDetector测量slop(两个水龙头相隔多远).我没有看到这里的需要,也没有检查每个水龙头上两个手指之间的距离.
>我只在onTwoFingerDoubleTap()上播放了一个事件.
最后说明:
您可以轻松地将其更改为OnTouchListener:
>更改SimpleTwoFingerDoubleTapDetector的定义:
public abstract class SimpleTwoFingerDoubleTapListener implements OnTouchListener {
>添加一个新的类变量:
private View mFirstView;
>更改ACTION_DOWN案例:
case MotionEvent.ACTION_DOWN:
if(mFirstDownTime == -1 || mFirstView != v || hasTimedOut(event.getEventTime())) {
mFirstView = v;
reset(event.getDownTime());
}
break;
>在ACTION_UP案例中传递mFirstView:
onTwoFingerDoubleTap(mFirstView);
>最后,更改onTwoFingerDoubleTap()方法以反映点击了哪个View:
public abstract void onTwoFingerDoubleTap(View v);