[Libreoffice-commits] core.git: android/experimental vcl/android

Tor Lillqvist tml at iki.fi
Wed Feb 27 14:25:31 PST 2013


 android/experimental/desktop/src/org/libreoffice/android/experimental/desktop/Desktop.java |   35 +++++++-
 vcl/android/androidinst.cxx                                                                |   43 +++++++++-
 2 files changed, 74 insertions(+), 4 deletions(-)

New commits:
commit 3cf4f1a13b61592b1af8040692029216d9c90d4c
Author: Tor Lillqvist <tml at iki.fi>
Date:   Thu Feb 28 00:24:33 2013 +0200

    Handle touch events
    
    Change-Id: I9c9d200731df9ba48ee61f7c97692ed9b9f06648

diff --git a/android/experimental/desktop/src/org/libreoffice/android/experimental/desktop/Desktop.java b/android/experimental/desktop/src/org/libreoffice/android/experimental/desktop/Desktop.java
index 5c54330..ba3d6da 100644
--- a/android/experimental/desktop/src/org/libreoffice/android/experimental/desktop/Desktop.java
+++ b/android/experimental/desktop/src/org/libreoffice/android/experimental/desktop/Desktop.java
@@ -23,6 +23,7 @@ import android.os.Bundle;
 import android.text.InputType;
 import android.util.Log;
 import android.view.MotionEvent;
+import android.view.ScaleGestureDetector;
 import android.view.View;
 import android.view.inputmethod.BaseInputConnection;
 import android.view.inputmethod.EditorInfo;
@@ -46,6 +47,7 @@ public class Desktop
     public static native void renderVCL(Bitmap bitmap);
     public static native void setViewSize(int width, int height);
     public static native void key(char c, short timestamp);
+    public static native void touch(int action, int x, int y, short timestamp);
 
     /**
      * This class contains the state that is initialized once and never changes
@@ -152,11 +154,21 @@ public class Desktop
     {
         Bitmap mBitmap;
         boolean renderedOnce;
+        ScaleGestureDetector gestureDetector;
 
         public BitmapView()
         {
             super(Desktop.this);
             setFocusableInTouchMode(true);
+            gestureDetector =
+                new ScaleGestureDetector(Desktop.this,
+                                         new ScaleGestureDetector.SimpleOnScaleGestureListener() {
+                                             @Override public boolean onScale(ScaleGestureDetector detector)
+                                             {
+                                                 Log.i(TAG, "onScale: " + detector.getScaleFactor());
+                                                 return true;
+                                             }
+                                         });
         }
 
         @Override protected void onDraw(Canvas canvas)
@@ -182,13 +194,32 @@ public class Desktop
                 return super.onTouchEvent(event);
 
             super.onTouchEvent(event);
-            Log.d(TAG, "onTOUCH");
-            if (event.getAction() == MotionEvent.ACTION_UP) {
+            Log.d(TAG, "onTouch (" + event.getX() + "," + event.getY() + ")");
+
+            // Just temporary hack. We should not show the keyboard
+            // unconditionally on a ACTION_UP event here. The LO level
+            // should callback to us requesting showing the keyboard
+            // if the user taps in a text area. Also, if the device
+            // has a hardware keyboard, we probably should not show
+            // the soft one unconditionally? But what if the user
+            // wants to input in another script than what the hardware
+            // keyboard covers?
+            if (event.getActionMasked() == MotionEvent.ACTION_UP) {
                 // show the keyboard so we can enter text
                 InputMethodManager imm = (InputMethodManager) getContext()
                     .getSystemService(Context.INPUT_METHOD_SERVICE);
                 imm.showSoftInput(this, InputMethodManager.SHOW_FORCED);
             }
+
+            switch (event.getActionMasked()) {
+            case MotionEvent.ACTION_DOWN:
+            case MotionEvent.ACTION_UP:
+            case MotionEvent.ACTION_MOVE:
+                short timestamp = (short) (System.currentTimeMillis() % Short.MAX_VALUE);
+                Desktop.touch(event.getActionMasked(), (int) event.getX(), (int) event.getY(), timestamp);
+                break;
+            }
+
             return true;
         }
 
diff --git a/vcl/android/androidinst.cxx b/vcl/android/androidinst.cxx
index b94855d..2773cd3 100644
--- a/vcl/android/androidinst.cxx
+++ b/vcl/android/androidinst.cxx
@@ -900,10 +900,10 @@ int AndroidSalSystem::ShowNativeDialog( const rtl::OUString& rTitle,
     return 0;
 }
 
-// Render everything
+// public static native void renderVCL(Bitmap bitmap);
 extern "C" SAL_JNI_EXPORT void JNICALL
 Java_org_libreoffice_experimental_desktop_Desktop_renderVCL(JNIEnv *env,
-                                                            jobject /* dummy */,
+                                                            jobject /* clazz */,
                                                             jobject bitmap)
 {
     if (!bHitIdle)
@@ -963,6 +963,7 @@ typedef struct ANativeWindow_Buffer {
     AndroidBitmap_unlockPixels(env, bitmap);
 }
 
+// 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 */,
@@ -974,6 +975,7 @@ Java_org_libreoffice_experimental_desktop_Desktop_setViewSize(JNIEnv * /* env */
     viewHeight = height;
 }
 
+// public static native void key(char c, short timestamp);
 extern "C" SAL_JNI_EXPORT void JNICALL
 Java_org_libreoffice_experimental_desktop_Desktop_key(JNIEnv * /* env */,
                                                       jobject /* clazz */,
@@ -996,4 +998,41 @@ Java_org_libreoffice_experimental_desktop_Desktop_key(JNIEnv * /* env */,
         LOGW("No focused frame to emit event on");
 }
 
+// public static native void touch(int action, int x, int y, short timestamp);
+extern "C" SAL_JNI_EXPORT void JNICALL
+Java_org_libreoffice_experimental_desktop_Desktop_touch(JNIEnv * /* env */,
+                                                        jobject /* clazz */,
+                                                        jint action,
+                                                        jint x,
+                                                        jint y,
+                                                        jshort timestamp)
+{
+    SalMouseEvent aEvent;
+
+    aEvent.mnTime = timestamp;
+    aEvent.mnX = x;
+    aEvent.mnY = y;
+    aEvent.mnButton = MOUSE_LEFT;
+    aEvent.mnCode = 0;
+
+    sal_uInt16 eventKind;
+    switch (action) {
+    case AMOTION_EVENT_ACTION_DOWN:
+        eventKind = SALEVENT_MOUSEBUTTONDOWN;
+        break;
+    case AMOTION_EVENT_ACTION_UP:
+        eventKind = SALEVENT_MOUSEBUTTONUP;
+        break;
+    case AMOTION_EVENT_ACTION_MOVE:
+        eventKind = SALEVENT_MOUSEMOVE;
+        break;
+    }
+
+    SalFrame *pFocus = AndroidSalInstance::getInstance()->getFocusFrame();
+    if (pFocus)
+        pFocus->CallCallback( eventKind, &aEvent );
+    else
+        LOGW("No focused frame to emit event on");
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list