Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to override some gesture events over a webview, but let others through?
    primarykey
    data
    text
    <p>I'm still figuring out the ins and outs of the SDK so bear with me here. </p> <p>So i'm trying to implement a Webview, that keeps multitouch zoom controls and vertical scroll intact (webview class handles them) while locking horizontal scroll on the Webview, and implementing horizontal flings to seek new data.</p> <p>I found this: <a href="https://stackoverflow.com/questions/4229177/fling-gesture-and-webview-in-android">Fling Gesture and Webview in Android</a> . I therefore took this code to understand how to implement this in my app later, so I'm working from there (the answer, of course).</p> <p>And started modyfing the code to my suiting. For example:</p> <pre><code> if (event1.getRawX() &gt; event2.getRawX() &amp;&amp; StrictMath.abs(event1.getRawY()-event2.getRawY())&lt;100) { show_toast("swipe left"); } else if(event1.getRawX() &lt; event2.getRawX() &amp;&amp; StrictMath.abs(event1.getRawY()-event2.getRawY())&lt;100){ show_toast("swipe right"); </code></pre> <p>Actually detects ONLY horizontal flings. </p> <p>However, I have not figured out how to make sure that horizontal flings trigger an action of my choosing, while vertical flings still control the scroll of the WebView in question.</p> <p>My first thought was to try something like pageUp/pageDown or scrollTo on the webview but that can't work since i'm extending the webview class to MyWebView and therefore don't yet have an instanciated object of this type.</p> <p>This is the full code, if needed:</p> <pre><code>package test.fling; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.GestureDetector; import android.view.MotionEvent; import android.webkit.WebView; import android.widget.Toast; public class testicules extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyWebView webview = new MyWebView(this); webview.loadUrl("http://en.wikipedia.org/wiki/Android"); setContentView(webview); } class MyWebView extends WebView { Context context; GestureDetector gd; public MyWebView(Context context) { super(context); this.context = context; gd = new GestureDetector(context, sogl); } @Override public boolean onTouchEvent(MotionEvent event) { return gd.onTouchEvent(event); } GestureDetector.SimpleOnGestureListener sogl = new GestureDetector.SimpleOnGestureListener() { public boolean onDown(MotionEvent event) { return true; } public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) { if (event1.getRawX() &gt; event2.getRawX() &amp;&amp; StrictMath.abs(event1.getRawY()-event2.getRawY())&lt;100) { show_toast("swipe left"); } else if(event1.getRawX() &lt; event2.getRawX() &amp;&amp; StrictMath.abs(event1.getRawY()-event2.getRawY())&lt;100){ show_toast("swipe right"); } else { //MyWebView.pageUp(true); /*can't work, as explained above*/ } return true; } }; void show_toast(final String text) { Toast t = Toast.makeText(context, text, Toast.LENGTH_SHORT); t.show(); } } } </code></pre> <p>Any Help would be greatly appreciated. Thanks!</p>
    singulars
    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.
 

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