summaryrefslogtreecommitdiffstats
path: root/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt5/android/QtNative.java')
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtNative.java206
1 files changed, 143 insertions, 63 deletions
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
index e602a6deba..04b8e6a06f 100644
--- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
@@ -1,32 +1,38 @@
/****************************************************************************
**
-** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 BogDan Vatra <bogdan@kde.org>
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the Android port of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $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 The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/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 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 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-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -39,6 +45,7 @@ import java.util.ArrayList;
import java.util.concurrent.Semaphore;
import android.app.Activity;
+import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -66,7 +73,9 @@ public class QtNative
{
private static Activity m_activity = null;
private static boolean m_activityPaused = false;
+ private static Service m_service = null;
private static QtActivityDelegate m_activityDelegate = null;
+ private static QtServiceDelegate m_serviceDelegate = null;
public static Object m_mainActivityMutex = new Object(); // mutex used to synchronize runnable operations
public static final String QtTAG = "Qt JAVA"; // string used for Log.x
@@ -85,6 +94,12 @@ public class QtNative
private static ClipboardManager m_clipboardManager = null;
private static Method m_checkSelfPermissionMethod = null;
private static Boolean m_tabletEventSupported = null;
+ private static final Runnable runPendingCppRunnablesRunnable = new Runnable() {
+ @Override
+ public void run() {
+ runPendingCppRunnables();
+ }
+ };
private static ClassLoader m_classLoader = null;
public static ClassLoader classLoader()
@@ -104,6 +119,14 @@ public class QtNative
}
}
+ public static Service service()
+ {
+ synchronized (m_mainActivityMutex) {
+ return m_service;
+ }
+ }
+
+
public static QtActivityDelegate activityDelegate()
{
synchronized (m_mainActivityMutex) {
@@ -111,6 +134,13 @@ public class QtNative
}
}
+ public static QtServiceDelegate serviceDelegate()
+ {
+ synchronized (m_mainActivityMutex) {
+ return m_serviceDelegate;
+ }
+ }
+
public static boolean openURL(String url, String mime)
{
boolean ok = true;
@@ -175,6 +205,14 @@ public class QtNative
}
}
+ public static void setService(Service qtMainService, QtServiceDelegate qtServiceDelegate)
+ {
+ synchronized (m_mainActivityMutex) {
+ m_service = qtMainService;
+ m_serviceDelegate = qtServiceDelegate;
+ }
+ }
+
public static void setApplicationState(int state)
{
synchronized (m_mainActivityMutex) {
@@ -205,14 +243,14 @@ public class QtNative
}
}
- private static void runQtOnUiThread(final long id)
+ private static void runPendingCppRunnablesOnUiThread()
{
- runAction(new Runnable() {
- @Override
- public void run() {
- QtNative.onAndroidUiThread(id);
- }
- });
+ synchronized (m_mainActivityMutex) {
+ if (!m_activityPaused && m_activity != null)
+ m_activity.runOnUiThread(runPendingCppRunnablesRunnable);
+ else
+ runAction(runPendingCppRunnablesRunnable);
+ }
}
private static void setViewVisibility(final View view, final boolean visible)
@@ -308,7 +346,11 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activity.finish();
+ quitQtAndroidPlugin();
+ if (m_activity != null)
+ m_activity.finish();
+ if (m_service != null)
+ m_service.stopSelf();
}
});
}
@@ -347,16 +389,14 @@ public class QtNative
if (m_tabletEventSupported == null)
m_tabletEventSupported = isTabletEventSupported();
- if (Build.VERSION.SDK_INT >= 14) {
- switch (event.getToolType(0)) {
- case MotionEvent.TOOL_TYPE_STYLUS:
- pointerType = 1; // QTabletEvent::Pen
- break;
- case MotionEvent.TOOL_TYPE_ERASER:
- pointerType = 3; // QTabletEvent::Eraser
- break;
- // TODO TOOL_TYPE_MOUSE
- }
+ switch (event.getToolType(0)) {
+ case MotionEvent.TOOL_TYPE_STYLUS:
+ pointerType = 1; // QTabletEvent::Pen
+ break;
+ case MotionEvent.TOOL_TYPE_ERASER:
+ pointerType = 3; // QTabletEvent::Eraser
+ break;
+ // TODO TOOL_TYPE_MOUSE
}
if (m_tabletEventSupported && pointerType != 0) {
@@ -446,7 +486,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.updateSelection(selStart, selEnd, candidatesStart, candidatesEnd);
+ if (m_activityDelegate != null)
+ m_activityDelegate.updateSelection(selStart, selEnd, candidatesStart, candidatesEnd);
}
});
}
@@ -461,7 +502,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.showSoftwareKeyboard(x, y, width, height, inputHints, enterKeyType);
+ if (m_activityDelegate != null)
+ m_activityDelegate.showSoftwareKeyboard(x, y, width, height, inputHints, enterKeyType);
}
});
}
@@ -471,7 +513,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.resetSoftwareKeyboard();
+ if (m_activityDelegate != null)
+ m_activityDelegate.resetSoftwareKeyboard();
}
});
}
@@ -481,7 +524,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.hideSoftwareKeyboard();
+ if (m_activityDelegate != null)
+ m_activityDelegate.hideSoftwareKeyboard();
}
});
}
@@ -491,7 +535,9 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.setFullScreen(fullScreen);
+ if (m_activityDelegate != null) {
+ m_activityDelegate.setFullScreen(fullScreen);
+ }
updateWindow();
}
});
@@ -499,34 +545,44 @@ public class QtNative
private static void registerClipboardManager()
{
- final Semaphore semaphore = new Semaphore(0);
- runAction(new Runnable() {
- @Override
- public void run() {
- m_clipboardManager = (android.text.ClipboardManager) m_activity.getSystemService(Context.CLIPBOARD_SERVICE);
- semaphore.release();
+ if (m_service == null || m_activity != null) { // Avoid freezing if only service
+ final Semaphore semaphore = new Semaphore(0);
+ runAction(new Runnable() {
+ @Override
+ public void run() {
+ if (m_activity != null)
+ m_clipboardManager = (android.text.ClipboardManager) m_activity.getSystemService(Context.CLIPBOARD_SERVICE);
+ semaphore.release();
+ }
+ });
+ try {
+ semaphore.acquire();
+ } catch (Exception e) {
+ e.printStackTrace();
}
- });
- try {
- semaphore.acquire();
- } catch (Exception e) {
- e.printStackTrace();
}
}
private static void setClipboardText(String text)
{
- m_clipboardManager.setText(text);
+ if (m_clipboardManager != null)
+ m_clipboardManager.setText(text);
}
private static boolean hasClipboardText()
{
- return m_clipboardManager.hasText();
+ if (m_clipboardManager != null)
+ return m_clipboardManager.hasText();
+ else
+ return false;
}
private static String getClipboardText()
{
- return m_clipboardManager.getText().toString();
+ if (m_clipboardManager != null)
+ return m_clipboardManager.getText().toString();
+ else
+ return "";
}
private static void openContextMenu(final int x, final int y, final int w, final int h)
@@ -534,7 +590,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.openContextMenu(x, y, w, h);
+ if (m_activityDelegate != null)
+ m_activityDelegate.openContextMenu(x, y, w, h);
}
});
}
@@ -544,7 +601,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.closeContextMenu();
+ if (m_activityDelegate != null)
+ m_activityDelegate.closeContextMenu();
}
});
}
@@ -554,7 +612,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.resetOptionsMenu();
+ if (m_activityDelegate != null)
+ m_activityDelegate.resetOptionsMenu();
}
});
}
@@ -564,7 +623,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activity.openOptionsMenu();
+ if (m_activity != null)
+ m_activity.openOptionsMenu();
}
});
}
@@ -601,7 +661,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.createSurface(id, onTop, x, y, w, h, imageDepth);
+ if (m_activityDelegate != null)
+ m_activityDelegate.createSurface(id, onTop, x, y, w, h, imageDepth);
}
});
}
@@ -611,7 +672,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.insertNativeView(id, view, x, y, w, h);
+ if (m_activityDelegate != null)
+ m_activityDelegate.insertNativeView(id, view, x, y, w, h);
}
});
}
@@ -621,7 +683,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.setSurfaceGeometry(id, x, y, w, h);
+ if (m_activityDelegate != null)
+ m_activityDelegate.setSurfaceGeometry(id, x, y, w, h);
}
});
}
@@ -631,7 +694,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.bringChildToFront(id);
+ if (m_activityDelegate != null)
+ m_activityDelegate.bringChildToFront(id);
}
});
}
@@ -641,7 +705,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.bringChildToBack(id);
+ if (m_activityDelegate != null)
+ m_activityDelegate.bringChildToBack(id);
}
});
}
@@ -651,7 +716,8 @@ public class QtNative
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.destroySurface(id);
+ if (m_activityDelegate != null)
+ m_activityDelegate.destroySurface(id);
}
});
}
@@ -666,6 +732,17 @@ public class QtNative
});
}
+ private static void hideSplashScreen()
+ {
+ runAction(new Runnable() {
+ @Override
+ public void run() {
+ if (m_activityDelegate != null)
+ m_activityDelegate.hideSplashScreen();
+ }
+ });
+ }
+
// screen methods
public static native void setDisplayMetrics(int screenWidthPixels,
int screenHeightPixels,
@@ -731,5 +808,8 @@ public class QtNative
public static native void onActivityResult(int requestCode, int resultCode, Intent data);
public static native void onNewIntent(Intent data);
- public static native void onAndroidUiThread(long id);
+ public static native void runPendingCppRunnables();
+
+ private static native void setNativeActivity(Activity activity);
+ private static native void setNativeService(Service service);
}