I'm still good at SDK attachments and outputs, so carry me here.
So, I'm trying to implement Webview, which keeps multitouch zoom controls and vertical scrolling intact (the webview class handles them), while simultaneously blocking horizontal scrolling in Webview and using horizontal throws to find new data.
I found this: Fling Gesture and Webview on Android , so I adopted this code to figure out how to implement this in my application later, so I work from there (answer of course).
And he began to modify the code in accordance with my purpose. For instance:
if (event1.getRawX() > event2.getRawX() && StrictMath.abs(event1.getRawY()-event2.getRawY())<100) { show_toast("swipe left"); } else if(event1.getRawX() < event2.getRawX() && StrictMath.abs(event1.getRawY()-event2.getRawY())<100){ show_toast("swipe right");
In fact, it detects ONLY horizontal outliers.
However, I did not understand how to make sure that horizontal clicks trigger the action of my choice, while vertical throws still control the scrolling of the WebView in question.
My first thought was to try something like pageUp / pageDown or scrollTo in a web browser, but that would not work, since I am extending the webview class to MyWebView and therefore have not yet created a substring object of this type.
This is the complete code, if necessary:
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 { @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() > event2.getRawX() && StrictMath.abs(event1.getRawY()-event2.getRawY())<100) { show_toast("swipe left"); } else if(event1.getRawX() < event2.getRawX() && StrictMath.abs(event1.getRawY()-event2.getRawY())<100){ show_toast("swipe right"); } else {
Any help would be greatly appreciated. Thanks!