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

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Sun Mar 1 22:30:02 PST 2015


 android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java   |   16 ---
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelection.java       |    2 
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java |   45 +++++++---
 3 files changed, 39 insertions(+), 24 deletions(-)

New commits:
commit f087bd4c2e5cf393439cece75466aa8afac3c36d
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Mon Mar 2 15:17:35 2015 +0900

    android: account for handle repositioning, limit update to 50ms
    
    Text handles are usually shown under the current selection or
    cursor position. Previously this was done in InvalidationHandler,
    now the TextSelectionHandle takes this into account just before
    drawing. The reason is that the repositioning needs to be taken
    into account when the handle moves to reposition the coordinates
    back to original position.
    In addition to that, the number of times the move handle update
    event is send is now limited to 50ms to reduce stress for the
    device (less in queue, less messages via LOKit). This also makes
    the handle more fluid and jump around less.
    
    Change-Id: Idc401375c82b3eeac66328d98c80bf3cb7b675ea

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
index 1f3b39b..8efc6f4 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
@@ -119,16 +119,6 @@ public class InvalidationHandler {
     }
 
     /**
-     * From input rectangle, create a new rectangle which positions under the input rectangle.
-     *
-     * @param rectangle - input rectangle
-     * @return new rectangle positioned under the input rectangle
-     */
-    private RectF createRectangleUnderSelection(RectF rectangle) {
-        return new RectF(rectangle.centerX(), rectangle.bottom, rectangle.centerX(), rectangle.bottom);
-    }
-
-    /**
      * Handles the tile invalidation message
      *
      * @param payload
@@ -149,7 +139,7 @@ public class InvalidationHandler {
         RectF cursorRectangle = convertPayloadToRectangle(payload);
         if (cursorRectangle != null) {
             if (mState == OverlayState.CURSOR) {
-                mTextSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, createRectangleUnderSelection(cursorRectangle));
+                mTextSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, cursorRectangle);
                 mTextSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
                 mTextSelection.hideHandle(TextSelectionHandle.HandleType.START);
                 mTextSelection.hideHandle(TextSelectionHandle.HandleType.END);
@@ -170,7 +160,7 @@ public class InvalidationHandler {
         }
         RectF selectionRectangle = convertPayloadToRectangle(payload);
         if (selectionRectangle != null) {
-            mTextSelection.positionHandle(TextSelectionHandle.HandleType.START, createRectangleUnderSelection(selectionRectangle));
+            mTextSelection.positionHandle(TextSelectionHandle.HandleType.START, selectionRectangle);
             mTextSelection.showHandle(TextSelectionHandle.HandleType.START);
             mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
             mState = OverlayState.SELECTION;
@@ -188,7 +178,7 @@ public class InvalidationHandler {
         }
         RectF selectionRect = convertPayloadToRectangle(payload);
         if (selectionRect != null) {
-            mTextSelection.positionHandle(TextSelectionHandle.HandleType.END, createRectangleUnderSelection(selectionRect));
+            mTextSelection.positionHandle(TextSelectionHandle.HandleType.END, selectionRect);
             mTextSelection.showHandle(TextSelectionHandle.HandleType.END);
             mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
             mState = OverlayState.SELECTION;
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelection.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelection.java
index 2f05e4f..94f9b90 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelection.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelection.java
@@ -108,7 +108,7 @@ public class TextSelection extends Layer {
         LOKitShell.getMainHandler().post(new Runnable() {
             public void run() {
                 TextSelectionHandle handle = getHandle(handleType);
-                handle.positionFromGecko((int) position.left, (int) position.top, false);
+                handle.positionFromGecko(position, false);
             }
         });
     }
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java
index 0bd1486..61f5355 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java
@@ -7,6 +7,7 @@ package org.mozilla.gecko;
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.PointF;
+import android.graphics.RectF;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.MotionEvent;
@@ -22,6 +23,10 @@ import org.mozilla.gecko.gfx.LayerView;
 
 public class TextSelectionHandle extends ImageView implements View.OnTouchListener {
     private static final String LOGTAG = TextSelectionHandle.class.getSimpleName();
+    private long mLastTime = 0;
+
+    // Minimum time lapsed between 2 handle updates
+    private static final long MINIMUM_HANDLE_UPDATE_TIME = 50 * 1000000;
 
     public enum HandleType { START, MIDDLE, END };
 
@@ -33,7 +38,8 @@ public class TextSelectionHandle extends ImageView implements View.OnTouchListen
     private int mLeft;
     private int mTop;
     private boolean mIsRTL;
-    private PointF mGeckoPoint;
+    private PointF mPoint;
+    private PointF mReposition;
     private int mTouchStartX;
     private int mTouchStartY;
 
@@ -49,15 +55,16 @@ public class TextSelectionHandle extends ImageView implements View.OnTouchListen
         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextSelectionHandle);
         int handleType = a.getInt(R.styleable.TextSelectionHandle_handleType, 0x01);
 
-        if (handleType == 0x01)
+        if (handleType == 0x01) {
             mHandleType = HandleType.START;
-        else if (handleType == 0x02)
+        } else if (handleType == 0x02) {
             mHandleType = HandleType.MIDDLE;
-        else
+        } else if (handleType == 0x03) {
             mHandleType = HandleType.END;
+        }
 
         mIsRTL = false;
-        mGeckoPoint = new PointF(0.0f, 0.0f);
+        mPoint = new PointF(0.0f, 0.0f);
 
         mWidth = getResources().getDimensionPixelSize(R.dimen.text_selection_handle_width);
         mHeight = getResources().getDimensionPixelSize(R.dimen.text_selection_handle_height);
@@ -77,7 +84,11 @@ public class TextSelectionHandle extends ImageView implements View.OnTouchListen
                 break;
             }
             case MotionEvent.ACTION_MOVE: {
-                move(event.getX(), event.getY());
+                long currentTime = System.nanoTime();
+                if (currentTime - mLastTime > MINIMUM_HANDLE_UPDATE_TIME) {
+                    mLastTime = currentTime;
+                    move(event.getX(), event.getY());
+                }
                 break;
             }
         }
@@ -99,18 +110,32 @@ public class TextSelectionHandle extends ImageView implements View.OnTouchListen
 
         PointF documentPoint = new PointF(left, newTop);
         documentPoint = layerView.getLayerClient().convertViewPointToLayerPoint(documentPoint);
+        documentPoint.x += mReposition.x;
+        documentPoint.y += mReposition.y;
 
         LOKitShell.sendChangeHandlePositionEvent(mHandleType, documentPoint);
     }
 
-    void positionFromGecko(int left, int top, boolean rtl) {
+    /**
+     * Calculate the position just under (and centered horizontally) rectangle from the input rectangle.
+     *
+     * @param rectangle - input rectangle
+     * @return position just under the selection
+     */
+    private PointF positionUnderSelection(RectF rectangle) {
+        return new PointF(rectangle.centerX(), rectangle.bottom);
+    }
+
+    void positionFromGecko(RectF position,  boolean rtl) {
         LayerView layerView = LOKitShell.getLayerView();
         if (layerView == null) {
             Log.e(LOGTAG, "Can't position handle because layerView is null");
             return;
         }
 
-        mGeckoPoint = new PointF((float) left, (float) top);
+        mPoint = positionUnderSelection(position);
+        mReposition = new PointF(position.left - mPoint.x, position.top - mPoint.y);
+
         if (mIsRTL != rtl) {
             mIsRTL = rtl;
             setImageLevel(mIsRTL ? IMAGE_LEVEL_RTL : IMAGE_LEVEL_LTR);
@@ -121,8 +146,8 @@ public class TextSelectionHandle extends ImageView implements View.OnTouchListen
     }
 
     void repositionWithViewport(float x, float y, float zoom) {
-        PointF viewPoint = new PointF((mGeckoPoint.x * zoom) - x,
-                                      (mGeckoPoint.y * zoom) - y);
+        PointF viewPoint = new PointF(mPoint.x * zoom - x,
+                                      mPoint.y * zoom - y);
 
         mLeft = Math.round(viewPoint.x) - (int) adjustLeftForHandle();
         mTop = Math.round(viewPoint.y);


More information about the Libreoffice-commits mailing list