Android - Webview page requires double clicking - how to handle?

  • Replies:0
Dan Freeman
  • Forum posts: 1

Jan 2, 2014, 10:48:55 PM via Website

My app is simply a WebView to display a specific website. Users are not able to simply use the Chrome app because of the inherent programming in Android which alters the functions of tapping.

For simplicity, let's say the website displays a calendar and on that calendar are boxes. The boxes can either be single clicked to be selected or double clicked to be opened to display the event details.

The website has coding that handles what to do if an event is single or double clicked:

1<div class="boardpiece clickable" onclick="select(event, this);" ondblclick="open('5657849');"


I'm completely fine with using longpress to simulate the double click. Here's where my confusion begins. How to I tell my app that when the user performs a SingleTap on the item, it needs to activate the "onclick" the website is calling for? I also need to tell the app that when the user performs a longpress on that same item, activate the "ondblclick" event you see there in the website coding?

Here is my activity code:

1import android.webkit.WebView;
2 import android.webkit.WebViewClient;
3 import android.webkit.SslErrorHandler;
4 import android.net.http.SslError;
5 import android.os.Bundle;
6 import android.app.Activity;
7 import android.util.Log;
8 import android.view.GestureDetector;
9 import android.view.Menu;
10 import android.view.MenuItem;
11 import android.view.View;
12 import android.view.GestureDetector.SimpleOnGestureListener;
13 import android.view.MotionEvent;
14
15 public class MainActivity extends Activity{
16 WebView webview;
17
18 @Override
19 public void onCreate(Bundle savedInstanceState) {
20 super.onCreate(savedInstanceState);
21 setContentView(R.layout.activity_main);
22 webview = (WebView) findViewById(R.id.webview);
23 //Do we want/need to enable Java?
24 webview.getSettings().setJavaScriptEnabled(true);
25 //Here we allow for zoom controls - pinch
26 webview.getSettings().setBuiltInZoomControls(true);
27 //Here we remove the zoom control buttons - requires API 11
28 webview.getSettings().setDisplayZoomControls(false);
29 //Here we clear the Cache and SSL Preferences
30 webview.clearCache(true);
31 webview.clearSslPreferences();
32 //Do we need to enable scroll bars to allow people to scroll left and right?
33 webview.setHorizontalScrollBarEnabled(true);
34 webview.setVerticalScrollBarEnabled(true);
35 webview.setWebViewClient(new WebViewClient());
36 webview.loadUrl("website");
37
38 final GestureDetector gd = new GestureDetector(new MyGestureDetector());
39 View.OnTouchListener gl = new View.OnTouchListener() {
40 public boolean onTouch(View v, MotionEvent event) {
41 return gd.onTouchEvent(event);
42 }
43 };
44 webview.setOnTouchListener(gl);
45 }
46
47 class MyGestureDetector extends SimpleOnGestureListener {
48 @Override
49 public boolean onDoubleTap(MotionEvent e) {
50 Log.i("", "DoubleTap");
51 return true;
52 }
53
54 public boolean onSingleTap(MotionEvent e) {
55 Log.i("", "SingleTap");
56 return true;
57 }
58 }
59
60
61 // Ignore SSL certificate errors
62 public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
63 handler.proceed();
64 }
65
66 //Would like to have a Menu Button to refresh the page - or really just bring you to the login page - for use when the session times out
67 @Override
68 public boolean onCreateOptionsMenu(Menu menu) {
69 menu.add(1, 1, 0, "Reload");
70 //getMenuInflater().inflate(R.menu.activity_main, menu);
71 return true;
72 }
73
74 @Override
75 public boolean onOptionsItemSelected(MenuItem item) {
76 switch(item.getItemId()){
77 case R.id.reload:
78 webview.loadUrl("website");
79 return true;
80 }
81 return super.onOptionsItemSelected(item);
82
83 }
84
85 }

Reply