private float downX ; //按下时 的X坐标
private float downY ; //按下时 的Y坐标
private float moveX ;
private float moveY ;
public ControlViewLinearLayout(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
downX = event.getX();
downY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
moveX =event.getX();
moveY = event.getY();
break;
case MotionEvent.ACTION_UP:
float dx= moveX - downX;
float dy = moveY - downY;
int orientation = getOrientation(dx, dy);
switch (orientation) {
case 'r':
break;
case 'l':
break;
case 't':
// Log.e(TAG, "slide top .............");
hideXPanel();
break;
case 'b':
// Log.e(TAG, "slide bottom .............");
break;
}
break;
}
return super.onTouchEvent(event);
}
private int getOrientation(float dx, float dy) {
if (Math.abs(dx)>Math.abs(dy)){
//X轴移动
return dx>0?'r':'l';
}else{
//Y轴移动
return dy>0?'b':'t';
}
}
}、
GesterTouchEvent
+
+ /**
+ * if(beginX - endX > minMove && Math.abs(velocityX) > minVelocity){ //左滑
+ }else if(endX - beginX > minMove && Math.abs(velocityX) > minVelocity){ //右滑
+ }else if(beginY - endY > minMove && Math.abs(velocityY) > minVelocity){ //上滑
+ }else if(endY - beginY > minMove && Math.abs(velocityY) > minVelocity){ //下滑
+ }
+ */
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
Log.i(TAG, "[onFling] (" + velocityX + ", " + velocityY + ")");
+ //add by larry
+ int currentCameraId = mCameraActivity.getCameraId();
+ float minMove = 60; //最小滑动距离
+ float minVelocity = 0; //最小滑动速度
+ float beginX = e1.getX();
+ float endX = e2.getX();
+ float beginY = e1.getY();
+ float endY = e2.getY();
+ if ((beginY - endY > minMove && Math.abs(velocityY) > minVelocity) ||(endY - beginY > minMove && Math.abs(velocityY) > minVelocity) ) {
+ mCameraActivity.onCameraPicked(currentCameraId == 0 ? 1 : 0);
+ }
+// if ((beginY - endY > minMove && Math.abs(velocityY) > minVelocity) ) { //上下滑动
+// //todo
+// }else if(endY - beginY > minMove && Math.abs(velocityY) > minVelocity){
+// //todo
+// }
+ //add by larry end
return false;
}