[Java for Android App Development] TheArchNemesis:
This is a very simple webview app, its used to load a remote website and allow users to browse the site from the app.

What i want it to do, is support swipe gestures, for example

Swipe left to right go back a page

Swipe right to left go forward a page

Eventually i'm going to try to add in page turn animations but for not i just need to get the swipe gesture support to work for the initial release

The code needs a lot of cleanup as well, the vertical swipe detection needs to come out, but its only there for testing purposes

package com.bno.bnoonline;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.view.MotionEvent;
import android.view.View;

public class MainActivity extends Activity {

WebView mWebView;

/** Called when the activity is first created. */
[MENTION=439709]override[/MENTION]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

WebViewClient yourWebClient = new WebViewClient() {
// Override page so it's load on my view only
[MENTION=439709]override[/MENTION]
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// This line we let me load only pages inside Firstdroid Webpage
if (url.contains("myurl") == true)
// Load new URL Don't override URL Link
return false;

// Return true to override url loading (In this case do
// nothing).
return true;
}
};

// Get Web view
mWebView = (WebView) findViewById(R.id.webView1); // This is the id you
// gave
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setSupportZoom(true); // Zoom Control on web (You
// don't need this
// if ROM supports Multi-Touch
mWebView.getSettings().setBuiltInZoomControls(true); // Enable
// Multitouch if
// supported by
// ROM
mWebView.setWebViewClient(yourWebClient);

// Load URL
mWebView.loadUrl("myurl.com");

}

public static enum Action {
LR, // Left to right
RL, // Right to left
TB, // Top to bottom
BT, // Bottom to top
None // Action not found
}

private static final int HORIZONTAL_MIN_DISTANCE = 30; // The minimum
// distance for
// horizontal swipe
private static final int VERTICAL_MIN_DISTANCE = 80; // The minimum distance
// for vertical
// swipe
private float downX, downY, upX, upY; // Coordinates
private Action mSwipeDetected = Action.None; // Last action

public boolean swipeDetected() {
return mSwipeDetected != Action.None;
}

public Action getAction() {
return mSwipeDetected;
}

/**
* Swipe detection
* [MENTION=2056652]return[/MENTION]
*/public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
{
downX = event.getX();
downY = event.getY();
mSwipeDetected = Action.None;
return false; // allow other events like Click to be processed
}
case MotionEvent.ACTION_MOVE:
{
upX = event.getX();
upY = event.getY();

float deltaX = downX - upX;
float deltaY = downY - upY;

// horizontal swipe detection
if (Math.abs(deltaX) > HORIZONTAL_MIN_DISTANCE) {
// left or right
if (deltaX < 0) {

mSwipeDetected = Action.LR;
if(mWebView.canGoForward() == true){
mWebView.goForward();
return true;
}
if (deltaX > 0) {

mSwipeDetected = Action.RL;
if(mWebView.canGoBack() == true){
mWebView.goBack();
return true;

}
} else

// vertical swipe detection
if (Math.abs(deltaY) > VERTICAL_MIN_DISTANCE) {
// top or down
if (deltaY < 0) {

mSwipeDetected = Action.TB;
return false;
}
if (deltaY > 0) {

mSwipeDetected = Action.BT;
return false;
}
}
return true;
}
}
return false;
}
}
return false;
}
}

Here is a logcat, though its not very revealing

09-30 01:01:18.331: E/Trace(10259): error opening trace file: No such file or directory (2)

09-30 01:01:19.151: D/dalvikvm(10259): GC_FOR_ALLOC freed 45K, 6% free 2662K/2828K, paused 246ms, total 254ms

09-30 01:01:19.161: I/dalvikvm-heap(10259): Grow heap (frag case) to 3.787MB for 1127536-byte allocation

09-30 01:01:19.351: D/dalvikvm(10259): GC_FOR_ALLOC freed 2K, 5% free 3760K/3932K, paused 188ms, total 188ms

09-30 01:01:19.461: D/dalvikvm(10259): GC_CONCURRENT freed <1K, 5% free 3766K/3932K, paused 5ms+14ms, total 112ms

09-30 01:01:19.991: D/libEGL(10259): loaded /system/lib/egl/libEGL_emulation.so

09-30 01:01:20.021: D/(10259): HostConnection::get() New Host Connection established 0x2a17cbe0, tid 10259

09-30 01:01:20.061: D/libEGL(10259): loaded /system/lib/egl/libGLESv1_CM_emulation.so

09-30 01:01:20.091: D/libEGL(10259): loaded /system/lib/egl/libGLESv2_emulation.so

09-30 01:01:20.231: W/EGL_emulation(10259): eglSurfaceAttrib not implemented

09-30 01:01:20.291: D/OpenGLRenderer(10259): Enabling debug mode 0

09-30 01:01:20.301: I/Choreographer(10259): Skipped 37 frames! The application may be doing too much work on its main thread.

09-30 01:01:29.534: D/TilesManager(10259): Starting TG #0, 0x2a561340

09-30 01:01:29.541: D/TilesManager(10259): new EGLContext from framework: 2a1b9bc0

09-30 01:01:29.541: D/GLWebViewState(10259): Reinit shader

09-30 01:01:29.912: D/GLWebViewState(10259): Reinit transferQueue

09-30 01:01:31.451: D/(10259): HostConnection::get() New Host Connection established 0x2a4d6ae8, tid 10286

09-30 01:02:44.795: D/dalvikvm(10259): GC_CONCURRENT freed 196K, 8% free 3956K/4272K, paused 20ms+17ms, total 104ms

09-30 01:02:54.462: D/dalvikvm(10259): GC_FOR_ALLOC freed 37K, 8% free 4239K/4592K, paused 36ms, total 41ms