Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wrote the class which is extended from WebView and can detect the swipes easily. </p> <pre><code>import android.content.Context; import android.util.AttributeSet; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.GestureDetector.SimpleOnGestureListener; import android.webkit.WebView; import android.widget.Toast; public class HtmlImageView extends WebView { Context mContext; GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector()); public HtmlImageView(Context context) { super(context); mContext=context; } public HtmlImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mContext=context; } public HtmlImageView(Context context, AttributeSet attrs) { super(context, attrs); mContext=context; } private static final int SWIPE_MIN_DISTANCE = 120; private static final int SWIPE_MAX_OFF_PATH = 250; private static final int SWIPE_THRESHOLD_VELOCITY = 200; class MyGestureDetector extends SimpleOnGestureListener { @Override public boolean onDown(MotionEvent e) { return true; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return super.onScroll(e1, e2, distanceX, distanceY); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) &gt; SWIPE_MAX_OFF_PATH) return false; // right to left swipe if (e1.getX() - e2.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(mContext, "Left Swipe", Toast.LENGTH_SHORT) .show(); } else if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(mContext, "Right Swipe", Toast.LENGTH_SHORT) .show(); } } catch (Exception e) { // nothing } return false; } } public boolean onTouchEvent(MotionEvent event) { return (gestureDetector.onTouchEvent(event) || super.onTouchEvent(event)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload