summaryrefslogtreecommitdiffstats
path: root/src/jar
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>2014-08-20 10:28:12 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>2014-08-20 10:30:13 +0200
commita2dd3fb028d731b3971e442db81b693c98849900 (patch)
tree457a392b5710da2f0f8f170ba105623239fcd297 /src/jar
Long live Qt Web View!
Diffstat (limited to 'src/jar')
-rw-r--r--src/jar/bundledjar.pro3
-rw-r--r--src/jar/distributedjar.pro2
-rw-r--r--src/jar/jar.pri11
-rw-r--r--src/jar/jar.pro3
-rw-r--r--src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java253
5 files changed, 272 insertions, 0 deletions
diff --git a/src/jar/bundledjar.pro b/src/jar/bundledjar.pro
new file mode 100644
index 0000000..abe173b
--- /dev/null
+++ b/src/jar/bundledjar.pro
@@ -0,0 +1,3 @@
+TARGET = QtAndroidWebView-bundled
+CONFIG += bundled_jar_file
+include(jar.pri)
diff --git a/src/jar/distributedjar.pro b/src/jar/distributedjar.pro
new file mode 100644
index 0000000..710983e
--- /dev/null
+++ b/src/jar/distributedjar.pro
@@ -0,0 +1,2 @@
+TARGET = QtAndroidWebView
+include(jar.pri)
diff --git a/src/jar/jar.pri b/src/jar/jar.pri
new file mode 100644
index 0000000..0c4f499
--- /dev/null
+++ b/src/jar/jar.pri
@@ -0,0 +1,11 @@
+load(qt_build_paths)
+CONFIG += java
+DESTDIR = $$MODULE_BASE_OUTDIR/jar
+
+JAVACLASSPATH += $$PWD/src
+
+JAVASOURCES += $$PWD/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java
+
+# install
+target.path = $$[QT_INSTALL_PREFIX]/jar
+INSTALLS += target
diff --git a/src/jar/jar.pro b/src/jar/jar.pro
new file mode 100644
index 0000000..6a4fcd3
--- /dev/null
+++ b/src/jar/jar.pro
@@ -0,0 +1,3 @@
+TEMPLATE=subdirs
+SUBDIRS += distributedjar.pro bundledjar.pro
+
diff --git a/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java b/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java
new file mode 100644
index 0000000..de3d374
--- /dev/null
+++ b/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java
@@ -0,0 +1,253 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebView module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+package org.qtproject.qt5.android.view;
+
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.webkit.WebChromeClient;
+import java.lang.Runnable;
+import android.app.Activity;
+import java.lang.String;
+import android.webkit.WebSettings;
+import android.webkit.URLUtil;
+import android.util.Log;
+import android.webkit.WebSettings.PluginState;
+import android.graphics.Bitmap;
+import java.util.concurrent.Semaphore;
+
+public class QtAndroidWebViewController
+{
+ private final Activity m_activity;
+ private final long m_id;
+ private WebView m_webView = null;
+ private static final String TAG = "QtAndroidWebViewController";
+ // Native callbacks
+ private native void c_onPageFinished(long id, String url);
+ private native void c_onPageStarted(long id, String url, Bitmap icon);
+ private native void c_onProgressChanged(long id, int newProgress);
+ private native void c_onReceivedIcon(long id, Bitmap icon);
+ private native void c_onReceivedTitle(long id, String title);
+
+ private class QtAndroidWebViewClient extends WebViewClient
+ {
+ QtAndroidWebViewClient() { super(); }
+
+ @Override
+ public void onLoadResource(WebView view, String url)
+ {
+ super.onLoadResource(view, url);
+ }
+
+ @Override
+ public void onPageFinished(WebView view, String url)
+ {
+ super.onPageFinished(view, url);
+ c_onPageFinished(m_id, url);
+ }
+
+ @Override
+ public void onPageStarted(WebView view, String url, Bitmap favicon)
+ {
+ super.onPageStarted(view, url, favicon);
+ c_onPageStarted(m_id, url, favicon);
+ }
+ }
+
+ private class QtAndroidWebChromeClient extends WebChromeClient
+ {
+ QtAndroidWebChromeClient() { super(); }
+ @Override
+ public void onProgressChanged(WebView view, int newProgress)
+ {
+ super.onProgressChanged(view, newProgress);
+ c_onProgressChanged(m_id, newProgress);
+ }
+
+ @Override
+ public void onReceivedIcon(WebView view, Bitmap icon)
+ {
+ super.onReceivedIcon(view, icon);
+ c_onReceivedIcon(m_id, icon);
+ }
+
+ @Override
+ public void onReceivedTitle(WebView view, String title)
+ {
+ super.onReceivedTitle(view, title);
+ c_onReceivedTitle(m_id, title);
+ }
+ }
+
+ public QtAndroidWebViewController(final Activity activity, final long id)
+ {
+ m_activity = activity;
+ m_id = id;
+ final Semaphore sem = new Semaphore(0);
+ m_activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ m_webView = new WebView(m_activity);
+ WebSettings webSettings = m_webView.getSettings();
+ webSettings.setJavaScriptEnabled(true);
+ webSettings.setBuiltInZoomControls(true);
+ webSettings.setPluginState(PluginState.ON);
+ m_webView.setWebViewClient((WebViewClient)new QtAndroidWebViewClient());
+ m_webView.setWebChromeClient((WebChromeClient)new QtAndroidWebChromeClient());
+ sem.release();
+ }
+ });
+
+ try {
+ sem.acquire();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void loadUrl(final String url)
+ {
+ if (url == null) {
+ return;
+ }
+
+ m_activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() { m_webView.loadUrl(URLUtil.guessUrl(url)); }
+ });
+ }
+
+ public void goBack()
+ {
+ m_activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() { m_webView.goBack(); }
+ });
+ }
+
+ public boolean canGoBack()
+ {
+ final boolean[] back = {false};
+ final Semaphore sem = new Semaphore(0);
+ m_activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() { back[0] = m_webView.canGoBack(); sem.release(); }
+ });
+
+ try {
+ sem.acquire();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return back[0];
+ }
+
+ public void goForward()
+ {
+ m_activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() { m_webView.goForward(); }
+ });
+ }
+
+ public boolean canGoForward()
+ {
+ final boolean[] forward = {false};
+ final Semaphore sem = new Semaphore(0);
+ m_activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() { forward[0] = m_webView.canGoForward(); sem.release(); }
+ });
+
+ try {
+ sem.acquire();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return forward[0];
+ }
+
+ public void stopLoading()
+ {
+ m_activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() { m_webView.stopLoading(); }
+ });
+ }
+
+ public String getTitle()
+ {
+ final String[] title = {""};
+ final Semaphore sem = new Semaphore(0);
+ m_activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() { title[0] = m_webView.getTitle(); sem.release(); }
+ });
+
+ try {
+ sem.acquire();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return title[0];
+ }
+
+ public String getUrl()
+ {
+ final String[] url = {""};
+ final Semaphore sem = new Semaphore(0);
+ m_activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() { url[0] = m_webView.getUrl(); sem.release(); }
+ });
+
+ try {
+ sem.acquire();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return url[0];
+ }
+
+ public WebView getWebView()
+ {
+ return m_webView;
+ }
+}