3

I am using a WebView to display a web site. This part is working basically OK.

On the actually website when viewed in a normal browser (Chrome etc) you can 'left click' on items and then drag them around the page to rearrange them. This is not working when the page is viewed on and Android device using WebView.

When you 'click' (and hold) on the items in the WebView the copy/cut popup comes up on the top of the screen and when you try and move/swipe it just scrolls the page vertically or horizontally.

I am not sure what I need to add to make the same sort of 'click-n-drag' gesture action that happens on the website occurs in the WebView.

Also on the website version if you 'right click' on an item it brings up a context menu. This part sort of works on the Android device. If you click on an item, then click again it brings up the context menu as per the website version. It is just the 'click n drag' functionality that I am not sure how to implement...

Any advice would be great!

Below is code.

ManiActivity.java

package org.webview.test;

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

public class MainActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Initialize the myWebView object
        WebView myWebView = (WebView) findViewById(R.id.webview);

        // Zoom control - sets onsreen controls
        myWebView.getSettings().setSupportZoom(true);
        myWebView.getSettings().setBuiltInZoomControls(true);

        // Make webpage fit to screen size
        myWebView.getSettings().setLoadWithOverviewMode(true);
        myWebView.getSettings().setUseWideViewPort(true);

        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        // Force links and redirects to open in the WebView instead of in a browser
        myWebView.setWebViewClient(new CustomWebViewClient());

        // Make scroll bars visible
        myWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
        myWebView.setScrollbarFadingEnabled(false);

        // Web page to load in WebView
        myWebView.loadUrl(getString(R.string.url));

    }


    // Force links and redirects to open in the WebView instead of in a browser
        private class CustomWebViewClient extends WebViewClient {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url);
         return true; }

    }
}

Main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="org.webview.test"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <activity android:name="MainActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <!-- Gives device access to internet-->
    <uses-permission android:name="android.permission.INTERNET" />

</manifest>
pelagos
  • 1,025
  • 3
  • 17
  • 27
  • I think I am making some progress but still do not have any real idea how to implement this correctly/properly if it can be down at all? I think in the actual webpage that the WebView links to i need to add relevant Meta tags so it is recognised as mobile but still not sure what to do on the Android side of things. Any info greatly appreciated! – pelagos Jun 01 '15 at 03:58

0 Answers0