1 package com
.owncloud
.android
.ui
;
3 import android
.content
.Context
;
4 import android
.util
.Log
;
5 import android
.view
.GestureDetector
;
6 import android
.view
.GestureDetector
.SimpleOnGestureListener
;
7 import android
.view
.MotionEvent
;
8 import android
.view
.View
;
9 import android
.view
.View
.OnTouchListener
;
10 import android
.widget
.Toast
;
12 public class OnSwipeTouchListener
implements OnTouchListener
{
14 private final Context mContext
;
15 private final GestureDetector mGestureDetector
;
17 public OnSwipeTouchListener(Context context
) {
19 mGestureDetector
= new GestureDetector(context
, new GestureListener());
22 public boolean onTouch(final View v
, final MotionEvent event
) {
23 //super.onTouch(v, event);
24 Log
.d("SWIPE", "Swipe listener touched");
25 return mGestureDetector
.onTouchEvent(event
);
28 private final class GestureListener
extends SimpleOnGestureListener
{
30 private static final int SWIPE_THRESHOLD
= 100;
31 private static final int SWIPE_VELOCITY_THRESHOLD
= 100;
34 public boolean onDown(MotionEvent e
) {
39 public boolean onFling(MotionEvent e1
, MotionEvent e2
, float velocityX
, float velocityY
) {
40 boolean result
= false
;
42 float diffY
= e2
.getY() - e1
.getY();
43 float diffX
= e2
.getX() - e1
.getX();
44 if (Math
.abs(diffX
) > Math
.abs(diffY
)) {
45 if (Math
.abs(diffX
) > SWIPE_THRESHOLD
&& Math
.abs(velocityX
) > SWIPE_VELOCITY_THRESHOLD
) {
53 if (Math
.abs(diffY
) > SWIPE_THRESHOLD
&& Math
.abs(velocityY
) > SWIPE_VELOCITY_THRESHOLD
) {
61 } catch (Exception exception
) {
62 exception
.printStackTrace();
68 public void onSwipeTop() {
69 Toast
.makeText(mContext
, "top", Toast
.LENGTH_SHORT
).show();
71 public void onSwipeRight() {
72 Toast
.makeText(mContext
, "right", Toast
.LENGTH_SHORT
).show();
74 public void onSwipeLeft() {
75 Toast
.makeText(mContext
, "left", Toast
.LENGTH_SHORT
).show();
77 public void onSwipeBottom() {
78 Toast
.makeText(mContext
, "bottom", Toast
.LENGTH_SHORT
).show();