summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/Bootstrap/src/org/libreoffice/android/AppSupport.java31
-rw-r--r--android/experimental/desktop/native-code.cxx8
-rw-r--r--android/experimental/desktop/project.properties1
-rw-r--r--android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java36
-rw-r--r--desktop/source/app/sofficemain.cxx4
-rw-r--r--vcl/android/androidinst.cxx89
6 files changed, 97 insertions, 72 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/android/AppSupport.java b/android/Bootstrap/src/org/libreoffice/android/AppSupport.java
new file mode 100644
index 000000000000..ef37f183e074
--- /dev/null
+++ b/android/Bootstrap/src/org/libreoffice/android/AppSupport.java
@@ -0,0 +1,31 @@
+// -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+//
+// This file is part of the LibreOffice project.
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+// Native functions that are used by "desktop" approach apps. That means apps
+// that have a "real" LibreOffice "main loop" running (headless).
+
+package org.libreoffice.android;
+
+import android.graphics.Bitmap;
+
+public final class AppSupport
+{
+ /* In desktop */
+ public static native void runMain();
+
+ /* In vcl */
+ public static native void renderVCL(Bitmap bitmap);
+ public static native void registerForDamageCallback(Class destinationClass);
+ public static native void setViewSize(int width, int height);
+ public static native void key(char c);
+ public static native void touch(int action, int x, int y);
+ public static native void zoom(float scale, int x, int y);
+ public static native void scroll(int x, int y);
+}
+
+// vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/android/experimental/desktop/native-code.cxx b/android/experimental/desktop/native-code.cxx
index ca80bdfd7b4f..3b86d464bb60 100644
--- a/android/experimental/desktop/native-code.cxx
+++ b/android/experimental/desktop/native-code.cxx
@@ -151,11 +151,11 @@ lo_get_libmap(void)
// Guard against possible function-level link-time pruning of
// "unused" code. We need to pull these in, too, as they aren't in
// any of the libs we link with -Wl,--whole-archive. Is this necessary?
- extern void Java_org_libreoffice_experimental_desktop_Desktop_runMain();
- volatile void *p = (void *) Java_org_libreoffice_experimental_desktop_Desktop_runMain;
+ extern void Java_org_libreoffice_android_AppSupport_runMain();
+ volatile void *p = (void *) Java_org_libreoffice_android_AppSupport_runMain;
- extern void Java_org_libreoffice_experimental_desktop_Desktop_renderVCL();
- p = (void *) Java_org_libreoffice_experimental_desktop_Desktop_renderVCL;
+ extern void Java_org_libreoffice_android_AppSupport_renderVCL();
+ p = (void *) Java_org_libreoffice_android_AppSupport_renderVCL;
return map;
}
diff --git a/android/experimental/desktop/project.properties b/android/experimental/desktop/project.properties
index 06b2d880c3d4..cffbf1ffe426 100644
--- a/android/experimental/desktop/project.properties
+++ b/android/experimental/desktop/project.properties
@@ -10,5 +10,4 @@
# Project target.
target=android-14
-# Use the Bootstrap class
android.library.reference.1=../../Bootstrap
diff --git a/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java b/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java
index 59e59943d0e4..b24b0d70665e 100644
--- a/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java
+++ b/android/experimental/desktop/src/org/libreoffice/experimental/desktop/Desktop.java
@@ -34,6 +34,7 @@ import android.view.inputmethod.InputMethodManager;
import com.sun.star.awt.Key;
+import org.libreoffice.android.AppSupport;
import org.libreoffice.android.Bootstrap;
public class Desktop
@@ -41,17 +42,6 @@ public class Desktop
{
private static final String TAG = "LODesktop";
- /* In desktop */
- private static native void runMain();
-
- /* In vcl */
- public static native void renderVCL(Bitmap bitmap);
- public static native void setViewSize(int width, int height);
- public static native void key(char c);
- public static native void touch(int action, int x, int y);
- public static native void zoom(float scale, int x, int y);
- public static native void scroll(int x, int y);
-
/**
* This class contains the state that is initialized once and never changes
* (not specific to a document or a view).
@@ -142,6 +132,8 @@ public class Desktop
theView = new BitmapView();
setContentView(theView);
+ AppSupport.registerForDamageCallback(getClass());
+
// Start a Java thread to run soffice_main(). We don't
// want to start the thread from native code becauce
// native threads apparently have no Java class loaders in
@@ -152,7 +144,7 @@ public class Desktop
new Thread(new Runnable() {
@Override public void run() {
- runMain();
+ AppSupport.runMain();
}
}).start();
}
@@ -223,7 +215,7 @@ public class Desktop
@Override public void onScaleEnd(ScaleGestureDetector detector)
{
accumulatedScale *= detector.getScaleFactor();
- Desktop.zoom(accumulatedScale, (int) pivotX, (int) pivotY);
+ AppSupport.zoom(accumulatedScale, (int) pivotX, (int) pivotY);
accumulatedScale = 1;
pivotX = pivotY = 0;
scalingInProgress = false;
@@ -237,9 +229,9 @@ public class Desktop
if (mBitmap == null) {
Log.i(TAG, "calling Bitmap.createBitmap(" + getWidth() + ", " + getHeight() + ", Bitmap.Config.ARGB_8888)");
mBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
- setViewSize(getWidth(), getHeight());
+ AppSupport.setViewSize(getWidth(), getHeight());
}
- renderVCL(mBitmap);
+ AppSupport.renderVCL(mBitmap);
if (scrollInProgress) {
canvas.save();
canvas.translate(translateX, translateY);
@@ -269,16 +261,16 @@ public class Desktop
case KeyEvent.KEYCODE_7:
case KeyEvent.KEYCODE_8:
case KeyEvent.KEYCODE_9:
- Desktop.key((char) ('0' + keyCode - KeyEvent.KEYCODE_0));
+ AppSupport.key((char) ('0' + keyCode - KeyEvent.KEYCODE_0));
return true;
case KeyEvent.KEYCODE_DEL:
- Desktop.key((char) Key.BACKSPACE);
+ AppSupport.key((char) Key.BACKSPACE);
return true;
case KeyEvent.KEYCODE_ENTER:
- Desktop.key((char) Key.RETURN);
+ AppSupport.key((char) Key.RETURN);
return true;
case KeyEvent.KEYCODE_TAB:
- Desktop.key((char) Key.TAB);
+ AppSupport.key((char) Key.TAB);
return true;
default:
return false;
@@ -301,7 +293,7 @@ public class Desktop
// the scroll must have ended.
if (scrollInProgress) {
- Desktop.scroll((int) translateX, (int) translateY);
+ AppSupport.scroll((int) translateX, (int) translateY);
translateX = translateY = 0;
scrollInProgress = false;
scrollJustEnded = true;
@@ -339,7 +331,7 @@ public class Desktop
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_MOVE:
- Desktop.touch(event.getActionMasked(), (int) event.getX(), (int) event.getY());
+ AppSupport.touch(event.getActionMasked(), (int) event.getX(), (int) event.getY());
break;
}
}
@@ -370,7 +362,7 @@ public class Desktop
@Override public boolean commitText(CharSequence text, int newCursorPosition) {
for (int i = 0; i < text.length(); i++) {
- Desktop.key(text.charAt(i));
+ AppSupport.key(text.charAt(i));
}
return true;
}
diff --git a/desktop/source/app/sofficemain.cxx b/desktop/source/app/sofficemain.cxx
index 6f92ba221175..44de16e3816e 100644
--- a/desktop/source/app/sofficemain.cxx
+++ b/desktop/source/app/sofficemain.cxx
@@ -93,8 +93,8 @@ extern "C" int DESKTOP_DLLPUBLIC soffice_main()
#ifdef ANDROID
extern "C" SAL_JNI_EXPORT void JNICALL
-Java_org_libreoffice_experimental_desktop_Desktop_runMain(JNIEnv* /* env */,
- jobject /* clazz */)
+Java_org_libreoffice_android_AppSupport_runMain(JNIEnv* /* env */,
+ jobject /* clazz */)
#else
extern "C"
void
diff --git a/vcl/android/androidinst.cxx b/vcl/android/androidinst.cxx
index 563769cb5b10..32b8353e92ea 100644
--- a/vcl/android/androidinst.cxx
+++ b/vcl/android/androidinst.cxx
@@ -46,6 +46,8 @@
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, LOGTAG, __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOGTAG, __VA_ARGS__))
+static jclass appClass = 0;
+
// Horrible hack
static int viewWidth = 1, viewHeight = 1;
@@ -144,29 +146,21 @@ void AndroidSalInstance::RedrawWindows(ANativeWindow_Buffer *pBuffer)
void AndroidSalInstance::damaged(AndroidSalFrame */* frame */)
{
static bool beenHere = false;
- static jclass nDesktopClass = 0;
static jmethodID nCallbackDamaged = 0;
- // Check if we are running in the experimental Desktop app
- if (!beenHere) {
- nDesktopClass = m_pJNIEnv->FindClass("org/libreoffice/experimental/desktop/Desktop");
- if (nDesktopClass == 0) {
- LOGI("Could not find Desktop class (this is normal if this isn't the \"desktop\" app)");
- // We don't want the exception to kill the app
- m_pJNIEnv->ExceptionClear();
- } else {
- nCallbackDamaged = m_pJNIEnv->GetStaticMethodID(nDesktopClass, "callbackDamaged", "()V");
- if (nCallbackDamaged == 0)
- LOGE("Could not find the callbackDamaged method");
- }
+ // Check if we are running in an app that has registered for damage callbacks
+ // static public void callbackDamaged();
+ // Call the Java layer to post an invalidate if necessary
+
+ if (appClass != 0 && !beenHere) {
+ nCallbackDamaged = m_pJNIEnv->GetStaticMethodID(appClass, "callbackDamaged", "()V");
+ if (nCallbackDamaged == 0)
+ LOGE("Could not find the callbackDamaged method");
beenHere = true;
}
- // Call the Java layer to post an invalidate if necessary
- // static public void org.libreoffice.experimental.desktop.Desktop.callbackDamaged();
-
- if (nDesktopClass != 0 && nCallbackDamaged != 0)
- m_pJNIEnv->CallStaticVoidMethod(nDesktopClass, nCallbackDamaged);
+ if (appClass != 0 && nCallbackDamaged != 0)
+ m_pJNIEnv->CallStaticVoidMethod(appClass, nCallbackDamaged);
}
void AndroidSalInstance::GetWorkArea( Rectangle& rRect )
@@ -408,9 +402,9 @@ int AndroidSalSystem::ShowNativeDialog( const OUString& rTitle,
// public static native void renderVCL(Bitmap bitmap);
extern "C" SAL_JNI_EXPORT void JNICALL
-Java_org_libreoffice_experimental_desktop_Desktop_renderVCL(JNIEnv *env,
- jobject /* clazz */,
- jobject bitmap)
+Java_org_libreoffice_android_AppSupport_renderVCL(JNIEnv *env,
+ jobject /* clazz */,
+ jobject bitmap)
{
AndroidBitmapInfo info;
void* pixels;
@@ -459,12 +453,21 @@ typedef struct ANativeWindow_Buffer {
AndroidBitmap_unlockPixels(env, bitmap);
}
+// public static native void registerForDamageCallback(Class destinationClass);
+extern "C" SAL_JNI_EXPORT void JNICALL
+Java_org_libreoffice_android_AppSupport_registerForDamageCallback(JNIEnv * env,
+ jobject /* clazz */,
+ jclass destinationClass)
+{
+ appClass = (jclass) env->NewGlobalRef(destinationClass);
+}
+
// public static native void setViewSize(int width, int height);
extern "C" SAL_JNI_EXPORT void JNICALL
-Java_org_libreoffice_experimental_desktop_Desktop_setViewSize(JNIEnv * /* env */,
- jobject /* clazz */,
- jint width,
- jint height)
+Java_org_libreoffice_android_AppSupport_setViewSize(JNIEnv * /* env */,
+ jobject /* clazz */,
+ jint width,
+ jint height)
{
// Horrible
viewWidth = width;
@@ -473,9 +476,9 @@ Java_org_libreoffice_experimental_desktop_Desktop_setViewSize(JNIEnv * /* env */
// public static native void key(char c);
extern "C" SAL_JNI_EXPORT void JNICALL
-Java_org_libreoffice_experimental_desktop_Desktop_key(JNIEnv * /* env */,
- jobject /* clazz */,
- jchar c)
+Java_org_libreoffice_android_AppSupport_key(JNIEnv * /* env */,
+ jobject /* clazz */,
+ jchar c)
{
SalFrame *pFocus = AndroidSalInstance::getInstance()->getFocusFrame();
if (pFocus) {
@@ -489,11 +492,11 @@ Java_org_libreoffice_experimental_desktop_Desktop_key(JNIEnv * /* env */,
// public static native void touch(int action, int x, int y);
extern "C" SAL_JNI_EXPORT void JNICALL
-Java_org_libreoffice_experimental_desktop_Desktop_touch(JNIEnv * /* env */,
- jobject /* clazz */,
- jint action,
- jint x,
- jint y)
+Java_org_libreoffice_android_AppSupport_touch(JNIEnv * /* env */,
+ jobject /* clazz */,
+ jint action,
+ jint x,
+ jint y)
{
SalFrame *pFocus = AndroidSalInstance::getInstance()->getFocusFrame();
if (pFocus) {
@@ -514,7 +517,7 @@ Java_org_libreoffice_experimental_desktop_Desktop_touch(JNIEnv * /* env */,
nEvent = VCLEVENT_WINDOW_MOUSEMOVE;
break;
default:
- LOGE("Java_org_libreoffice_experimental_desktop_Desktop_touch: Invalid action %d", action);
+ LOGE("AppSupport.touch: Invalid action %d", action);
return;
}
Application::PostMouseEvent(nEvent, pFocus->GetWindow(), &aEvent);
@@ -525,11 +528,11 @@ Java_org_libreoffice_experimental_desktop_Desktop_touch(JNIEnv * /* env */,
// public static native void zoom(float scale, int x, int y);
extern "C" SAL_JNI_EXPORT void JNICALL
-Java_org_libreoffice_experimental_desktop_Desktop_zoom(JNIEnv * /* env */,
- jobject /* clazz */,
- jfloat scale,
- jint x,
- jint y)
+Java_org_libreoffice_android_AppSupport_zoom(JNIEnv * /* env */,
+ jobject /* clazz */,
+ jfloat scale,
+ jint x,
+ jint y)
{
SalFrame *pFocus = AndroidSalInstance::getInstance()->getFocusFrame();
if (pFocus) {
@@ -543,10 +546,10 @@ Java_org_libreoffice_experimental_desktop_Desktop_zoom(JNIEnv * /* env */,
// public static native void scroll(int x, int y);
extern "C" SAL_JNI_EXPORT void JNICALL
-Java_org_libreoffice_experimental_desktop_Desktop_scroll(JNIEnv * /* env */,
- jobject /* clazz */,
- jint x,
- jint y)
+Java_org_libreoffice_android_AppSupport_scroll(JNIEnv * /* env */,
+ jobject /* clazz */,
+ jint x,
+ jint y)
{
SalFrame *pFocus = AndroidSalInstance::getInstance()->getFocusFrame();
if (pFocus) {