我正在创建一个我正在实施Ontouchlistener
的应用,但我没有得到正确的代码。请有人帮我写正确的代码。这是我使用各种教程为我的活动编写的代码。任何形式的帮助将不胜感激。
public class ActivitySwipeDetector
implements OnTouchListener
{
private static final int MIN_DISTANCE = 100;
private static final String logTag = "SwipeDetector";
private float downX;
private float downY;
public Action mSwipeDetected = Action.None;
private float upX;
private float upY;
public Action getAction()
{
return this.mSwipeDetected;
}
public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
{
switch (paramMotionEvent.getAction())
{
default:
case 0:
case 1:
}
float f2;
do {
do {
float f1;
do {
//return false;
this.downX = paramMotionEvent.getX();
this.downY = paramMotionEvent.getY();
this.mSwipeDetected = Action.None;
// return false;
this.upX = paramMotionEvent.getX();
this.upY = paramMotionEvent.getY();
f1 = this.downX - this.upX;
f2 = this.downY - this.upY;
if (Math.abs(f1) <= 100.0F)
break;
if (f1 < 0.0F) {
Log.i("SwipeDetector", "Swipe Left to Right");
this.mSwipeDetected = Action.LR;
return false;
}
}
while (f1 <= 0.0F);
Log.i("SwipeDetector", "Swipe Right to Left");
this.mSwipeDetected = Action.RL;
return false;
}
while (Math.abs(f2) <= 100.0F);
if (f2 < 0.0F) {
Log.i("SwipeDetector", "Swipe Top to Bottom");
this.mSwipeDetected = Action.TB;
return false;
}
}
while (f2 <= 0.0F);
Log.i("SwipeDetector", "Swipe Bottom to Top");
this.mSwipeDetected = Action.BT;
return false;
}
public boolean swipeDetected()
{
return this.mSwipeDetected != Action.None;
}
public static enum Action
{
LR, RL, TB, BT, None;
static
{
Action[] arrayOfAction = new Action[5];
arrayOfAction[0] = LR;
arrayOfAction[1] = RL;
arrayOfAction[2] = TB;
arrayOfAction[3] = BT;
arrayOfAction[4] = None;
}
}
}
答案 0 :(得分:0)
HTH!