[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 6 commits - android/experimental

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Wed Jan 14 22:24:38 PST 2015


 android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java                     |   12 
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java                  |   25 -
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java                 |    2 
 android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java     |   18 +
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ZoomConstraints.java           |   13 
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java     |  146 ----------
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java |   44 ++-
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java             |    9 
 8 files changed, 92 insertions(+), 177 deletions(-)

New commits:
commit 3e1009406faad076fa665af7ccdbe9c3e9a241f4
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Thu Jan 15 15:20:05 2015 +0900

    android: show soft keyboard on single touch event
    
    Change-Id: I9612b0d5258bbdef81903b3a67307fe54319e9c1

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index 7459580..a488240 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -144,6 +144,8 @@ public class LOKitThread extends Thread implements TileProvider.TileInvalidation
                 break;
             case LOEvent.THUMBNAIL:
                 createThumbnail(event.mTask);
+            case LOEvent.TOUCH:
+                LibreOfficeMainActivity.mAppContext.showSoftKeyboard();
         }
     }
 
commit 2919db2998e9f9f69d9e72cd724777ca899d2c98
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Thu Jan 15 15:19:23 2015 +0900

    android: send touch events in JavaPanZoomController
    
    Change-Id: Icc0c749a0c8687f247c4e42d74b5c839d5723503

diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java
index ccf6280..9440091 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java
@@ -12,6 +12,7 @@ import android.util.Log;
 import android.view.GestureDetector;
 import android.view.MotionEvent;
 
+import org.libreoffice.LOEventFactory;
 import org.libreoffice.LOKitShell;
 import org.libreoffice.LibreOfficeMainActivity;
 import org.mozilla.gecko.ZoomConstraints;
@@ -902,6 +903,7 @@ public class JavaPanZoomController
 
     @Override
     public void onLongPress(MotionEvent motionEvent) {
+        LOKitShell.sentTouchEvent("LongPress", motionEvent);
     }
 
     @Override
@@ -909,6 +911,7 @@ public class JavaPanZoomController
         // When double-tapping is allowed, we have to wait to see if this is
         // going to be a double-tap.
         if (!mWaitForDoubleTap) {
+            LOKitShell.sentTouchEvent("SingleTap", motionEvent);
         }
         // return false because we still want to get the ACTION_UP event that triggers this
         return false;
@@ -918,16 +921,20 @@ public class JavaPanZoomController
     public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
         // In cases where we don't wait for double-tap, we handle this in onSingleTapUp.
         if (mWaitForDoubleTap) {
+            LOKitShell.sentTouchEvent("SingleTap", motionEvent);
         }
         return true;
     }
 
     @Override
     public boolean onDoubleTap(MotionEvent motionEvent) {
+        LOKitShell.sentTouchEvent("DoubleTap", motionEvent);
         return true;
     }
 
     private void cancelTouch() {
+        //GeckoEvent e = GeckoEvent.createBroadcastEvent("Gesture:CancelTouch", "");
+        //GeckoAppShell.sendEventToGecko(e);
     }
 
     /**
commit 8c61778b3666d2073a94d4f6ba0623e9d7978222
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Thu Jan 15 15:14:46 2015 +0900

    android: show software keyboard on main view in main thread
    
    Change-Id: I2df86c2837fc6469384df5626a2d54856e96f8e7

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
index b83422c..a40d78c 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -2,6 +2,7 @@ package org.libreoffice;
 
 import android.app.Activity;
 import android.app.AlertDialog;
+import android.content.Context;
 import android.content.DialogInterface;
 import android.os.Bundle;
 import android.os.Handler;
@@ -12,6 +13,7 @@ import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
+import android.view.inputmethod.InputMethodManager;
 import android.widget.AdapterView;
 import android.widget.ListView;
 import android.widget.RelativeLayout;
@@ -189,6 +191,22 @@ public class LibreOfficeMainActivity extends LOAbout {
         return mDocumentPartViewListAdapter;
     }
 
+    public void showSoftKeyboard() {
+        Log.i(LOGTAG, "SoftKeyboard show request..");
+
+        LOKitShell.getMainHandler().post(new Runnable() {
+            @Override
+            public void run() {
+                LayerView layerView = (LayerView) findViewById(R.id.layer_view);
+
+                if (layerView.requestFocus()) {
+                    InputMethodManager inputMethodManager = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+                    inputMethodManager.showSoftInput(layerView, InputMethodManager.SHOW_FORCED);
+                }
+            }
+        });
+    }
+
     public void showProgressSpinner() {
         findViewById(R.id.loadingPanel).setVisibility(View.VISIBLE);
     }
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java
index 0d2b067..6c71eeb 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerView.java
@@ -351,15 +351,6 @@ public class LayerView extends FrameLayout {
         }
     }
 
-    public void showSoftKeyboard() {
-        View view = mSurfaceView != null ? mSurfaceView : mTextureView;
-
-        if (view.requestFocus()) {
-            InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
-            inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
-        }
-    }
-
     private class SurfaceTextureListener implements TextureView.SurfaceTextureListener {
         public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
             // We don't do this for surfaceCreated above because it is always followed by a surfaceChanged,
commit f94b0003e5338dee8799850f2ce7888ce9d90e46
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Thu Jan 15 15:13:02 2015 +0900

    android: add support for touch event to LOEvent
    
    Change-Id: Ie4b3e48d3f06545ebfd8638cdb8e4664ad85f493

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
index 5b13da4..7ec346b 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
@@ -1,5 +1,7 @@
 package org.libreoffice;
 
+import android.view.MotionEvent;
+
 import org.mozilla.gecko.gfx.ComposedTileLayer;
 import org.mozilla.gecko.gfx.IntSize;
 import org.mozilla.gecko.gfx.SubTile;
@@ -14,6 +16,7 @@ public class LOEvent implements Comparable<LOEvent> {
     public static final int TILE_REQUEST = 7;
     public static final int THUMBNAIL = 8;
     public static final int TILE_RERENDER = 9;
+    public static final int TOUCH = 10;
 
     public final int mType;
     public int mPriority = 0;
@@ -26,6 +29,8 @@ public class LOEvent implements Comparable<LOEvent> {
     public ComposedTileLayer mComposedTileLayer;
     public boolean mForceRedraw;
     public SubTile mTile;
+    public String mTouchType;
+    public MotionEvent mMotionEvent;
 
     public LOEvent(int type) {
         mType = type;
@@ -73,6 +78,13 @@ public class LOEvent implements Comparable<LOEvent> {
         mTile = tile;
     }
 
+    public LOEvent(int type, String touchType, MotionEvent motionEvent) {
+        mType = type;
+        mTypeString = "Touch";
+        mTouchType = touchType;
+        mMotionEvent = motionEvent;
+    }
+
     public String getTypeString() {
         if (mTypeString == null) {
             return "Event type: " + mType;
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
index 8091627..e894690 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
@@ -3,6 +3,7 @@ package org.libreoffice;
 
 import android.os.Handler;
 import android.util.DisplayMetrics;
+import android.view.MotionEvent;
 
 
 public class LOKitShell {
@@ -13,21 +14,11 @@ public class LOKitShell {
         return metrics.density * 160;
     }
 
-    public static void sendEvent(LOEvent event) {
-        if (LibreOfficeMainActivity.mAppContext != null && LibreOfficeMainActivity.mAppContext.getLOKitThread() != null) {
-            LibreOfficeMainActivity.mAppContext.getLOKitThread().queueEvent(event);
-        }
-    }
-
     // Get a Handler for the main java thread
     public static Handler getMainHandler() {
         return LibreOfficeMainActivity.mAppContext.mMainHandler;
     }
 
-    public static void queueRedraw() {
-        LOKitShell.sendEvent(LOEventFactory.redraw());
-    }
-
     public static void showProgressSpinner() {
         getMainHandler().post(new Runnable() {
             @Override
@@ -55,7 +46,19 @@ public class LOKitShell {
         return metrics;
     }
 
+    // EVENTS
+
+    public static void sendEvent(LOEvent event) {
+        if (LibreOfficeMainActivity.mAppContext != null && LibreOfficeMainActivity.mAppContext.getLOKitThread() != null) {
+            LibreOfficeMainActivity.mAppContext.getLOKitThread().queueEvent(event);
+        }
+    }
+
     public static void sendThumbnailEvent(ThumbnailCreator.ThumbnailCreationTask task) {
-        LOKitShell.sendEvent(LOEventFactory.thumbnail(task));
+        LOKitShell.sendEvent(new LOEvent(LOEvent.THUMBNAIL, task));
+    }
+
+    public static void sentTouchEvent(String touchType, MotionEvent motionEvent) {
+        LOKitShell.sendEvent(new LOEvent(LOEvent.TOUCH, "SingleTap", motionEvent));
     }
 }
commit 6ecef605693895e89c3884d495e5208cc83720f3
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Thu Jan 15 15:09:00 2015 +0900

    android: fennec import - double tap zoom in JavaPanZoomController
    
    Change-Id: I0fedb5bb353e4d6f9926a8c0f0b80a81b7257d0e

diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ZoomConstraints.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ZoomConstraints.java
index 40d1817..4ac49f7 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ZoomConstraints.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ZoomConstraints.java
@@ -10,28 +10,27 @@ import org.json.JSONObject;
 
 public final class ZoomConstraints {
     private final boolean mAllowZoom;
+    private final boolean mAllowDoubleTapZoom;
     private final float mDefaultZoom;
     private final float mMinZoom;
     private final float mMaxZoom;
 
     public ZoomConstraints(boolean allowZoom) {
         mAllowZoom = allowZoom;
+        mAllowDoubleTapZoom = allowZoom;
         mDefaultZoom = 0.0f;
         mMinZoom = 0.0f;
         mMaxZoom = 0.0f;
     }
 
-    ZoomConstraints(JSONObject message) throws JSONException {
-        mAllowZoom = message.getBoolean("allowZoom");
-        mDefaultZoom = (float)message.getDouble("defaultZoom");
-        mMinZoom = (float)message.getDouble("minZoom");
-        mMaxZoom = (float)message.getDouble("maxZoom");
-    }
-
     public final boolean getAllowZoom() {
         return mAllowZoom;
     }
 
+    public final boolean getAllowDoubleTapZoom() {
+        return mAllowDoubleTapZoom;
+    }
+
     public final float getDefaultZoom() {
         return mDefaultZoom;
     }
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java
index 3b3d33e..ccf6280 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java
@@ -87,6 +87,8 @@ public class JavaPanZoomController
     private long mLastEventTime;
     /* Current state the pan/zoom UI is in. */
     private PanZoomState mState;
+    /* Whether or not to wait for a double-tap before dispatching a single-tap */
+    private boolean mWaitForDoubleTap;
 
     public JavaPanZoomController(PanZoomTarget target) {
         mTarget = target;
@@ -865,6 +867,7 @@ public class JavaPanZoomController
         mTarget.setViewportMetrics(viewportMetrics);
     }
 
+    @Override
     public boolean getRedrawHint() {
         switch (mState) {
             case PINCHING:
@@ -881,18 +884,41 @@ public class JavaPanZoomController
     }
 
     @Override
+    public boolean onDown(MotionEvent motionEvent) {
+        mWaitForDoubleTap = mTarget.getZoomConstraints().getAllowDoubleTapZoom();
+        return false;
+    }
+
+    @Override
+    public void onShowPress(MotionEvent motionEvent) {
+        // If we get this, it will be followed either by a call to
+        // onSingleTapUp (if the user lifts their finger before the
+        // long-press timeout) or a call to onLongPress (if the user
+        // does not). In the former case, we want to make sure it is
+        // treated as a click. (Note that if this is called, we will
+        // not get a call to onDoubleTap).
+        mWaitForDoubleTap = false;
+    }
+
+    @Override
     public void onLongPress(MotionEvent motionEvent) {
     }
 
     @Override
     public boolean onSingleTapUp(MotionEvent motionEvent) {
-        // When zooming is enabled, wait to see if there's a double-tap.
+        // When double-tapping is allowed, we have to wait to see if this is
+        // going to be a double-tap.
+        if (!mWaitForDoubleTap) {
+        }
+        // return false because we still want to get the ACTION_UP event that triggers this
         return false;
     }
 
     @Override
     public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
-        // When zooming is disabled, we handle this in onSingleTapUp.
+        // In cases where we don't wait for double-tap, we handle this in onSingleTapUp.
+        if (mWaitForDoubleTap) {
+        }
         return true;
     }
 
@@ -938,8 +964,8 @@ public class JavaPanZoomController
 
         ImmutableViewportMetrics finalMetrics = getMetrics();
         finalMetrics = finalMetrics.setViewportOrigin(
-                zoomToRect.left * finalMetrics.zoomFactor,
-                zoomToRect.top * finalMetrics.zoomFactor);
+            zoomToRect.left * finalMetrics.zoomFactor,
+            zoomToRect.top * finalMetrics.zoomFactor);
         finalMetrics = finalMetrics.scaleTo(finalZoom, new PointF(0.0f, 0.0f));
 
         // 2. now run getValidViewportMetrics on it, so that the target viewport is
@@ -951,16 +977,19 @@ public class JavaPanZoomController
     }
 
     /** This function must be called from the UI thread. */
+    @Override
     public void abortPanning() {
         checkMainThread();
         bounce();
     }
 
+    @Override
     public void setOverScrollMode(int overscrollMode) {
         mX.setOverScrollMode(overscrollMode);
         mY.setOverScrollMode(overscrollMode);
     }
 
+    @Override
     public int getOverScrollMode() {
         return mX.getOverScrollMode();
     }
commit fd39aee5a7ac3e62d0f12283e4aa554878673748
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Jan 14 13:57:18 2015 +0900

    android: remove CheckerboardImage class as it is not needed
    
    Change-Id: I937eac9e613695490c8617aac85575f5e6fe290b

diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java
deleted file mode 100644
index 1343733..0000000
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * 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/. */
-
-package org.mozilla.gecko.gfx;
-
-import android.graphics.Color;
-
-import org.libreoffice.kit.DirectBufferAllocator;
-
-import java.nio.ByteBuffer;
-import java.nio.ShortBuffer;
-import java.util.Arrays;
-
-/** A Cairo image that displays a tinted checkerboard. */
-public class CheckerboardImage extends CairoImage {
-    // The width and height of the checkerboard tile.
-    private static final int SIZE = 16;
-    // The pixel format of the checkerboard tile.
-    private static final int FORMAT = CairoImage.FORMAT_RGB16_565;
-    // The color to mix in to tint the background color.
-    private static final int TINT_COLOR = Color.GRAY;
-    // The amount to mix in.
-    private static final float TINT_OPACITY = 0.4f;
-
-    private ByteBuffer mBuffer;
-    private int mMainColor;
-    private boolean mShowChecks;
-
-    /** Creates a new checkerboard image. */
-    public CheckerboardImage() {
-        int bpp = CairoUtils.bitsPerPixelForCairoFormat(FORMAT);
-        mBuffer = DirectBufferAllocator.allocate(SIZE * SIZE * bpp / 8);
-        update(true, Color.WHITE);
-    }
-
-    /** Returns the current color of the checkerboard. */
-    public int getColor() {
-        return mMainColor;
-    }
-
-    /** Returns whether or not we are currently showing checks on the checkerboard. */
-    public boolean getShowChecks() {
-        return mShowChecks;
-    }
-
-    /** Updates the checkerboard image. If showChecks is true, then create a
-        checkerboard image that is tinted to the color. Otherwise just return a flat
-        image of the color. */
-    public void update(boolean showChecks, int color) {
-        mMainColor = color;
-        mShowChecks = showChecks;
-
-        short mainColor16 = convertTo16Bit(mMainColor);
-
-        mBuffer.rewind();
-        ShortBuffer shortBuffer = mBuffer.asShortBuffer();
-
-        if (!mShowChecks) {
-            short color16 = convertTo16Bit(mMainColor);
-            short[] fillBuffer = new short[SIZE];
-            Arrays.fill(fillBuffer, color16);
-
-            for (int i = 0; i < SIZE; i++) {
-                shortBuffer.put(fillBuffer);
-            }
-
-            return;
-        }
-
-        short tintColor16 = convertTo16Bit(tint(mMainColor));
-
-        short[] mainPattern = new short[SIZE / 2], tintPattern = new short[SIZE / 2];
-        Arrays.fill(mainPattern, mainColor16);
-        Arrays.fill(tintPattern, tintColor16);
-
-        // The checkerboard pattern looks like this:
-        //
-        // +---+---+
-        // | N | T |  N = normal
-        // +---+---+  T = tinted
-        // | T | N |
-        // +---+---+
-
-        for (int i = 0; i < SIZE / 2; i++) {
-            shortBuffer.put(mainPattern);
-            shortBuffer.put(tintPattern);
-        }
-        for (int i = SIZE / 2; i < SIZE; i++) {
-            shortBuffer.put(tintPattern);
-            shortBuffer.put(mainPattern);
-        }
-    }
-
-    // Tints the given color appropriately and returns the tinted color.
-    private int tint(int color) {
-        float negTintOpacity = 1.0f - TINT_OPACITY;
-        float r = Color.red(color) * negTintOpacity + Color.red(TINT_COLOR) * TINT_OPACITY;
-        float g = Color.green(color) * negTintOpacity + Color.green(TINT_COLOR) * TINT_OPACITY;
-        float b = Color.blue(color) * negTintOpacity + Color.blue(TINT_COLOR) * TINT_OPACITY;
-        return Color.rgb(Math.round(r), Math.round(g), Math.round(b));
-    }
-
-    // Converts a 32-bit ARGB color to 16-bit R5G6B5, truncating values and discarding the alpha
-    // channel.
-    private short convertTo16Bit(int color) {
-        int r = Color.red(color) >> 3, g = Color.green(color) >> 2, b = Color.blue(color) >> 3;
-        int c = ((r << 11) | (g << 5) | b);
-        // Swap endianness.
-        return (short)((c >> 8) | ((c & 0xff) << 8));
-    }
-
-    @Override
-    protected void finalize() throws Throwable {
-        try {
-            if (mBuffer != null) {
-                DirectBufferAllocator.free(mBuffer);
-                mBuffer = null;
-            }
-        } finally {
-            super.finalize();
-        }
-    }
-
-    @Override
-    public ByteBuffer getBuffer() {
-        return mBuffer;
-    }
-
-    @Override
-    public void destroy() {
-
-    }
-
-    @Override
-    public IntSize getSize() {
-        return new IntSize(SIZE, SIZE);
-    }
-
-    @Override
-    public int getFormat() {
-        return FORMAT;
-    }
-}
-


More information about the Libreoffice-commits mailing list