我使用droidQuery库来处理使用方法
的滑动事件$.with(myView).swipe(new Function(...));
(请参阅我之前的帖子here),我想知道他们是否是一种扩展答案的方法,以便检查用户刷卡的时间,并根据下降的时间做出不同的反应时间是。谢谢你的回答!
答案 0 :(得分:1)
您可以按照所讨论的模型here,在滑动逻辑中添加一些其他代码。从链接代码中,我们有以下switch语句:
switch(swipeDirection) {
case DOWN :
//TODO: Down swipe complete, so do something
break;
case UP :
//TODO: Up swipe complete, so do something
break;
case LEFT :
//TODO: Left swipe complete, so do something
break;
case RIGHT :
//TODO: Right swipe complete, so do something (such as):
day++;
Fragment1 rightFragment = new Fragment1();
Bundle args = new Bundle();
args.putInt("day", day);
rightFragment.setArguments(args);
android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, rightFragment);
transaction.addToBackStack(null);
transaction.commit();
break;
default :
break;
}
要添加停机检查,请添加以下类变量:
private Date start;
public static final int LONG_SWIPE_TIME = 400;//this will be the number of milliseconds needed to recognize the event as a swipe
然后将其添加到DOWN
案例逻辑:
start = new Date();
在每个滑动案例中,您都可以添加此项检查:
if (start != null && new Date().getTime() - start.getTime() >= LONG_SWIPE_TIME) {
start = null;
//handle swipe code here.
}
最后在你的UP
案例中,添加:
start = null;
这样可以使滑动代码仅处理停留时间超过LONG_SWIPE_TIME
的滑动。例如,对于RIGHT
案例,您将拥有:
case RIGHT :
if (start != null && new Date().getTime() - start.getTime() >= LONG_SWIPE_TIME) {
start = null;
//TODO: Right swipe complete, so do something (such as):
day++;
Fragment1 rightFragment = new Fragment1();
Bundle args = new Bundle();
args.putInt("day", day);
rightFragment.setArguments(args);
android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, rightFragment);
transaction.addToBackStack(null);
transaction.commit();
}
break;