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

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Thu Mar 26 03:31:55 PDT 2015


 android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionCanvasElement.java       |  146 +++++++++-
 android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionHandleCanvasElement.java |   63 +++-
 android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java                     |  129 +-------
 3 files changed, 197 insertions(+), 141 deletions(-)

New commits:
commit 28a19256aeef3431bedc9b3cc62171963ecefdc9
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Thu Mar 26 19:29:41 2015 +0900

    android: fix handle and selection behaviour, clean-up
    
    Change-Id: I1f4404b1beb8dc3d5f64c21443c8e50cefe6fc63

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionCanvasElement.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionCanvasElement.java
index 39b2fe0..909d808 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionCanvasElement.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionCanvasElement.java
@@ -9,6 +9,7 @@
 package org.libreoffice.canvas;
 
 import android.graphics.Canvas;
+import android.graphics.Color;
 import android.graphics.Paint;
 import android.graphics.PointF;
 import android.graphics.RectF;
@@ -16,12 +17,14 @@ import android.graphics.RectF;
 import org.libreoffice.LOKitShell;
 import org.mozilla.gecko.gfx.LayerView;
 
+import static org.libreoffice.canvas.GraphicSelectionHandleCanvasElement.HandlePosition;
+
 /**
  * This class is responsible to draw and reposition the selection
  * rectangle.
  */
 public class GraphicSelectionCanvasElement {
-    private final Paint mGraphicSelectionPaint;
+    private final Paint mPaint;
     public RectF mRectangle = new RectF();
     public RectF mScaledRectangle = new RectF();
     private RectF mDrawRectangle = new RectF();
@@ -31,17 +34,20 @@ public class GraphicSelectionCanvasElement {
     private GraphicSelectionHandleCanvasElement mHandles[] = new GraphicSelectionHandleCanvasElement[8];
     private GraphicSelectionHandleCanvasElement mDragHandle = null;
 
-    public GraphicSelectionCanvasElement(Paint graphicSelectionPaint) {
-        mGraphicSelectionPaint = graphicSelectionPaint;
-
-        mHandles[0] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-        mHandles[1] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-        mHandles[2] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-        mHandles[3] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-        mHandles[4] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-        mHandles[5] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-        mHandles[6] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-        mHandles[7] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
+    public GraphicSelectionCanvasElement() {
+        mPaint = new Paint();
+        mPaint.setStyle(Paint.Style.STROKE);
+        mPaint.setColor(Color.BLACK);
+        mPaint.setStrokeWidth(2);
+
+        mHandles[0] = new GraphicSelectionHandleCanvasElement(HandlePosition.TOP_LEFT);
+        mHandles[1] = new GraphicSelectionHandleCanvasElement(HandlePosition.TOP);
+        mHandles[2] = new GraphicSelectionHandleCanvasElement(HandlePosition.TOP_RIGHT);
+        mHandles[3] = new GraphicSelectionHandleCanvasElement(HandlePosition.LEFT);
+        mHandles[4] = new GraphicSelectionHandleCanvasElement(HandlePosition.RIGHT);
+        mHandles[5] = new GraphicSelectionHandleCanvasElement(HandlePosition.BOTTOM_LEFT);
+        mHandles[6] = new GraphicSelectionHandleCanvasElement(HandlePosition.BOTTOM);
+        mHandles[7] = new GraphicSelectionHandleCanvasElement(HandlePosition.BOTTOM_RIGHT);
     }
 
     public void reposition(RectF scaledRectangle) {
@@ -69,13 +75,9 @@ public class GraphicSelectionCanvasElement {
     }
 
     public void draw(Canvas canvas) {
-        canvas.drawRect(mDrawRectangle, mGraphicSelectionPaint);
+        canvas.drawRect(mDrawRectangle, mPaint);
         for (GraphicSelectionHandleCanvasElement handle : mHandles) {
-            if (mType == DragType.MOVE || mType == DragType.EXTEND) {
-                handle.drawSelected(canvas);
-            } else {
-                handle.draw(canvas);
-            }
+            handle.draw(canvas);
         }
     }
 
@@ -85,6 +87,7 @@ public class GraphicSelectionCanvasElement {
         for (GraphicSelectionHandleCanvasElement handle : mHandles) {
             if (handle.contains(position.x, position.y)) {
                 mDragHandle = handle;
+                mDragHandle.select();
                 mType = DragType.EXTEND;
                 sendGraphicSelectionStart(handle.mPosition);
             }
@@ -99,15 +102,47 @@ public class GraphicSelectionCanvasElement {
 
     public void dragging(PointF position) {
         if (mType == DragType.MOVE) {
-
             float deltaX = position.x - mStartDragPosition.x;
             float deltaY = position.y - mStartDragPosition.y;
 
             mDrawRectangle = new RectF(mScaledRectangle);
             mDrawRectangle.offset(deltaX, deltaY);
         } else if (mType == DragType.EXTEND) {
-            mDrawRectangle = new RectF(mScaledRectangle);
-            mDrawRectangle.union(position.x, position.y);
+            adaptDrawRectangle(position.x, position.y);
+        }
+    }
+
+    private void adaptDrawRectangle(float x, float y) {
+        mDrawRectangle = new RectF(mScaledRectangle);
+        switch(mDragHandle.getHandlePosition()) {
+            case TOP_LEFT:
+                mDrawRectangle.left = x;
+                mDrawRectangle.top = y;
+                break;
+            case TOP:
+                mDrawRectangle.top = y;
+                break;
+            case TOP_RIGHT:
+                mDrawRectangle.right = x;
+                mDrawRectangle.top = y;
+                break;
+            case LEFT:
+                mDrawRectangle.left = x;
+                break;
+            case RIGHT:
+                mDrawRectangle.right = x;
+                break;
+            case BOTTOM_LEFT:
+                mDrawRectangle.left = x;
+                mDrawRectangle.bottom = y;
+                break;
+            case BOTTOM:
+                mDrawRectangle.bottom = y;
+                break;
+            case BOTTOM_RIGHT:
+                mDrawRectangle.right = x;
+                mDrawRectangle.bottom = y;
+                break;
         }
     }
 
@@ -116,6 +151,8 @@ public class GraphicSelectionCanvasElement {
         if (mDragHandle != null) {
             point.x = mDragHandle.mPosition.x;
             point.y = mDragHandle.mPosition.y;
+            mDragHandle.reset();
+            mDragHandle = null;
         } else {
             point.x = mStartDragPosition.x;
             point.y = mStartDragPosition.y;
@@ -127,7 +164,6 @@ public class GraphicSelectionCanvasElement {
         sendGraphicSelectionEnd(point);
 
         mDrawRectangle = mScaledRectangle;
-        mDragHandle = null;
         mType = DragType.NONE;
     }
 
@@ -147,6 +183,13 @@ public class GraphicSelectionCanvasElement {
         }
     }
 
+    public void reset() {
+        mDragHandle = null;
+        for (GraphicSelectionHandleCanvasElement handle : mHandles) {
+            handle.reset();
+        }
+    }
+
     public enum DragType {
         NONE,
         MOVE,
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionHandleCanvasElement.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionHandleCanvasElement.java
index 90b9a38..62b6bc1 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionHandleCanvasElement.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionHandleCanvasElement.java
@@ -20,29 +20,39 @@ import android.graphics.RectF;
  * touched.
  */
 public class GraphicSelectionHandleCanvasElement {
+    private final HandlePosition mHandlePosition;
     public PointF mPosition = new PointF();
     private float mRadius = 20.0f;
-    private Paint mGraphicHandleFillPaint = new Paint();
-    private Paint mGraphicSelectionPaint = new Paint();
-    private Paint mGraphicHandleSelectedFillPaint = new Paint();
+    private Paint mStrokePaint = new Paint();
+    private Paint mFillPaint = new Paint();
+    private Paint mSelectedFillPaint = new Paint();
     private RectF mHitRect = new RectF();
+    private boolean mSelected = false;
 
-    public GraphicSelectionHandleCanvasElement(Paint graphicSelectionPaint) {
-        mGraphicSelectionPaint = graphicSelectionPaint;
+    public GraphicSelectionHandleCanvasElement(HandlePosition position) {
+        mHandlePosition = position;
 
-        mGraphicHandleFillPaint.setStyle(Paint.Style.FILL);
-        mGraphicHandleFillPaint.setColor(Color.WHITE);
+        mStrokePaint.setStyle(Paint.Style.STROKE);
+        mStrokePaint.setColor(Color.BLACK);
+        mStrokePaint.setStrokeWidth(3);
 
-        mGraphicHandleSelectedFillPaint.setStyle(Paint.Style.FILL);
-        mGraphicHandleSelectedFillPaint.setColor(Color.BLACK);
+        mFillPaint.setStyle(Paint.Style.FILL);
+        mFillPaint.setColor(Color.WHITE);
+
+        mSelectedFillPaint.setStyle(Paint.Style.FILL);
+        mSelectedFillPaint.setColor(Color.BLUE);
     }
 
-    public void draw(Canvas canvas) {
-        drawFilledCircle(canvas, mPosition.x, mPosition.y, mRadius, mGraphicSelectionPaint, mGraphicHandleFillPaint);
+    public HandlePosition getHandlePosition() {
+        return mHandlePosition;
     }
 
-    public void drawSelected(Canvas canvas) {
-        drawFilledCircle(canvas, mPosition.x, mPosition.y, mRadius, mGraphicSelectionPaint, mGraphicHandleSelectedFillPaint);
+    public void draw(Canvas canvas) {
+        if (mSelected) {
+            drawFilledCircle(canvas, mPosition.x, mPosition.y, mRadius, mStrokePaint, mSelectedFillPaint);
+        } else {
+            drawFilledCircle(canvas, mPosition.x, mPosition.y, mRadius, mStrokePaint, mFillPaint);
+        }
     }
 
     private void drawFilledCircle(Canvas canvas, float x, float y, float radius, Paint strokePaint, Paint fillPaint) {
@@ -62,6 +72,25 @@ public class GraphicSelectionHandleCanvasElement {
     public boolean contains(float x, float y) {
         return mHitRect.contains(x, y);
     }
+
+    public void select() {
+        mSelected = true;
+    }
+
+    public void reset() {
+        mSelected = false;
+    }
+
+    public enum HandlePosition {
+        TOP_LEFT,
+        TOP,
+        TOP_RIGHT,
+        RIGHT,
+        BOTTOM_RIGHT,
+        BOTTOM,
+        BOTTOM_LEFT,
+        LEFT
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java
index 16d639f..97230cf 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java
@@ -49,8 +49,6 @@ public class TextCursorView extends View implements View.OnTouchListener {
     private Paint mSelectionPaint = new Paint();
     private boolean mSelectionsVisible;
 
-    private Paint mGraphicSelectionPaint = new Paint();
-
     private GraphicSelectionCanvasElement mGraphicSelection;
 
     private boolean mGraphicSelectionVisible;
@@ -88,11 +86,7 @@ public class TextCursorView extends View implements View.OnTouchListener {
             mSelectionPaint.setAlpha(50);
             mSelectionsVisible = false;
 
-            mGraphicSelectionPaint.setStyle(Paint.Style.STROKE);
-            mGraphicSelectionPaint.setColor(Color.BLACK);
-            mGraphicSelectionPaint.setStrokeWidth(2);
-
-            mGraphicSelection = new GraphicSelectionCanvasElement(mGraphicSelectionPaint);
+            mGraphicSelection = new GraphicSelectionCanvasElement();
 
             mGraphicSelectionVisible = false;
 
@@ -211,6 +205,8 @@ public class TextCursorView extends View implements View.OnTouchListener {
 
     public void showGraphicSelection() {
         mGraphicSelectionVisible = true;
+        mGraphicSelectionMove = false;
+        mGraphicSelection.reset();
         invalidate();
     }
 
commit cdd335b3bfbde50210aadd9b3e0ad18fcfefae9d
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Mar 25 21:45:20 2015 +0900

    android: increase handle hit area
    
    Change-Id: I0148815d9152c0bcd7e3d724ebdd0bc50a4c4c9a

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionHandleCanvasElement.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionHandleCanvasElement.java
index 64d369f..90b9a38 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionHandleCanvasElement.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionHandleCanvasElement.java
@@ -53,10 +53,10 @@ public class GraphicSelectionHandleCanvasElement {
     public void reposition(float x, float y) {
         mPosition.x = x;
         mPosition.y = y;
-        mHitRect.left = mPosition.x - mRadius * 1.5f;
-        mHitRect.right = mPosition.x + mRadius * 1.5f;
-        mHitRect.top = mPosition.y - mRadius * 1.5f;
-        mHitRect.bottom = mPosition.y + mRadius * 1.5f;
+        mHitRect.left = mPosition.x - mRadius * 1.75f;
+        mHitRect.right = mPosition.x + mRadius * 1.75f;
+        mHitRect.top = mPosition.y - mRadius * 1.75f;
+        mHitRect.bottom = mPosition.y + mRadius * 1.75f;
     }
 
     public boolean contains(float x, float y) {
commit 70e45d1b3cb1982e3cdb053ff3bbffae1b6c07db
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Mar 25 21:44:00 2015 +0900

    android: move handles into GraphicSelectionCanvasElement
    
    Change-Id: Ib372b4fac35ae77bf06c65913b142ae3e80b0eb5

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionCanvasElement.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionCanvasElement.java
index 5adf8d3..39b2fe0 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionCanvasElement.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/GraphicSelectionCanvasElement.java
@@ -13,6 +13,9 @@ import android.graphics.Paint;
 import android.graphics.PointF;
 import android.graphics.RectF;
 
+import org.libreoffice.LOKitShell;
+import org.mozilla.gecko.gfx.LayerView;
+
 /**
  * This class is responsible to draw and reposition the selection
  * rectangle.
@@ -25,25 +28,72 @@ public class GraphicSelectionCanvasElement {
     private DragType mType = DragType.NONE;
     private PointF mStartDragPosition;
 
+    private GraphicSelectionHandleCanvasElement mHandles[] = new GraphicSelectionHandleCanvasElement[8];
+    private GraphicSelectionHandleCanvasElement mDragHandle = null;
+
     public GraphicSelectionCanvasElement(Paint graphicSelectionPaint) {
         mGraphicSelectionPaint = graphicSelectionPaint;
+
+        mHandles[0] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
+        mHandles[1] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
+        mHandles[2] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
+        mHandles[3] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
+        mHandles[4] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
+        mHandles[5] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
+        mHandles[6] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
+        mHandles[7] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
     }
 
     public void reposition(RectF scaledRectangle) {
         mScaledRectangle = scaledRectangle;
         mDrawRectangle = scaledRectangle;
+
+        mHandles[0].reposition(scaledRectangle.left, scaledRectangle.top);
+        mHandles[1].reposition(scaledRectangle.centerX(), scaledRectangle.top);
+        mHandles[2].reposition(scaledRectangle.right, scaledRectangle.top);
+        mHandles[3].reposition(scaledRectangle.left, scaledRectangle.centerY());
+        mHandles[4].reposition(scaledRectangle.right, scaledRectangle.centerY());
+        mHandles[5].reposition(scaledRectangle.left, scaledRectangle.bottom);
+        mHandles[6].reposition(scaledRectangle.centerX(), scaledRectangle.bottom);
+        mHandles[7].reposition(scaledRectangle.right, scaledRectangle.bottom);
     }
 
     public boolean contains(float x, float y) {
+        // Check if handle was hit
+        for (GraphicSelectionHandleCanvasElement handle : mHandles) {
+            if (handle.contains(x, y)) {
+                return true;
+            }
+        }
         return mScaledRectangle.contains(x, y);
     }
 
     public void draw(Canvas canvas) {
         canvas.drawRect(mDrawRectangle, mGraphicSelectionPaint);
+        for (GraphicSelectionHandleCanvasElement handle : mHandles) {
+            if (mType == DragType.MOVE || mType == DragType.EXTEND) {
+                handle.drawSelected(canvas);
+            } else {
+                handle.draw(canvas);
+            }
+        }
     }
 
-    public void dragStart(DragType type, PointF position) {
-        mType = type;
+    public void dragStart(PointF position) {
+        mDragHandle = null;
+        mType = DragType.NONE;
+        for (GraphicSelectionHandleCanvasElement handle : mHandles) {
+            if (handle.contains(position.x, position.y)) {
+                mDragHandle = handle;
+                mType = DragType.EXTEND;
+                sendGraphicSelectionStart(handle.mPosition);
+            }
+        }
+        if (mDragHandle == null) {
+            mType = DragType.MOVE;
+            sendGraphicSelectionStart(position);
+        }
+
         mStartDragPosition = position;
     }
 
@@ -61,9 +111,40 @@ public class GraphicSelectionCanvasElement {
         }
     }
 
-    public void dragEnd() {
-        mType = DragType.NONE;
+    public void dragEnd(PointF position) {
+        PointF point = new PointF();
+        if (mDragHandle != null) {
+            point.x = mDragHandle.mPosition.x;
+            point.y = mDragHandle.mPosition.y;
+        } else {
+            point.x = mStartDragPosition.x;
+            point.y = mStartDragPosition.y;
+        }
+        float deltaX = position.x - mStartDragPosition.x;
+        float deltaY = position.y - mStartDragPosition.y;
+        point.offset(deltaX, deltaY);
+
+        sendGraphicSelectionEnd(point);
+
         mDrawRectangle = mScaledRectangle;
+        mDragHandle = null;
+        mType = DragType.NONE;
+    }
+
+    private void sendGraphicSelectionStart(PointF screenPosition) {
+        LayerView layerView = LOKitShell.getLayerView();
+        if (layerView != null) {
+            PointF documentPoint = layerView.getLayerClient().convertViewPointToLayerPoint(screenPosition);
+            LOKitShell.sendTouchEvent("GraphicSelectionStart", documentPoint);
+        }
+    }
+
+    private void sendGraphicSelectionEnd(PointF screenPosition) {
+        LayerView layerView = LOKitShell.getLayerView();
+        if (layerView != null) {
+            PointF documentPoint = layerView.getLayerClient().convertViewPointToLayerPoint(screenPosition);
+            LOKitShell.sendTouchEvent("GraphicSelectionEnd", documentPoint);
+        }
     }
 
     public enum DragType {
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java
index d952b80..16d639f 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java
@@ -53,17 +53,11 @@ public class TextCursorView extends View implements View.OnTouchListener {
 
     private GraphicSelectionCanvasElement mGraphicSelection;
 
-    private PointF mTouchStart = new PointF();
-    private PointF mDeltaPoint = new PointF();
-
     private boolean mGraphicSelectionVisible;
     private boolean mGraphicSelectionMove = false;
 
     private LayerView mLayerView;
 
-    private GraphicSelectionHandleCanvasElement mHandles[] = new GraphicSelectionHandleCanvasElement[8];
-    private GraphicSelectionHandleCanvasElement mDragHandle = null;
-
     public TextCursorView(Context context) {
         super(context);
         initialize();
@@ -102,15 +96,6 @@ public class TextCursorView extends View implements View.OnTouchListener {
 
             mGraphicSelectionVisible = false;
 
-            mHandles[0] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-            mHandles[1] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-            mHandles[2] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-            mHandles[3] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-            mHandles[4] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-            mHandles[5] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-            mHandles[6] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-            mHandles[7] = new GraphicSelectionHandleCanvasElement(mGraphicSelectionPaint);
-
             postDelayed(cursorAnimation, CURSOR_BLINK_TIME);
 
             mInitialized = true;
@@ -169,15 +154,6 @@ public class TextCursorView extends View implements View.OnTouchListener {
         RectF scaledGraphicSelection = convertPosition(mGraphicSelection.mRectangle, x, y, zoom);
         mGraphicSelection.reposition(scaledGraphicSelection);
 
-        mHandles[0].reposition(scaledGraphicSelection.left, scaledGraphicSelection.top);
-        mHandles[1].reposition(scaledGraphicSelection.centerX(), scaledGraphicSelection.top);
-        mHandles[2].reposition(scaledGraphicSelection.right, scaledGraphicSelection.top);
-        mHandles[3].reposition(scaledGraphicSelection.left, scaledGraphicSelection.centerY());
-        mHandles[4].reposition(scaledGraphicSelection.right, scaledGraphicSelection.centerY());
-        mHandles[5].reposition(scaledGraphicSelection.left, scaledGraphicSelection.bottom);
-        mHandles[6].reposition(scaledGraphicSelection.centerX(), scaledGraphicSelection.bottom);
-        mHandles[7].reposition(scaledGraphicSelection.right, scaledGraphicSelection.bottom);
-
         invalidate();
     }
 
@@ -200,20 +176,6 @@ public class TextCursorView extends View implements View.OnTouchListener {
         }
         if (mGraphicSelectionVisible) {
             mGraphicSelection.draw(canvas);
-
-            if (mGraphicSelectionMove) {
-                for (GraphicSelectionHandleCanvasElement handle : mHandles) {
-                    if (mDragHandle == handle) {
-                        handle.drawSelected(canvas);
-                    } else {
-                        handle.draw(canvas);
-                    }
-                }
-            } else {
-                for (GraphicSelectionHandleCanvasElement handle : mHandles) {
-                    handle.draw(canvas);
-                }
-            }
         }
     }
 
@@ -259,32 +221,30 @@ public class TextCursorView extends View implements View.OnTouchListener {
 
     @Override
     public boolean onTouch(View view, MotionEvent event) {
-        if (mLayerView == null) {
-            mLayerView = LOKitShell.getLayerView();
-            if (mLayerView == null) {
-                return false;
-            }
-        }
-
         switch (event.getActionMasked()) {
             case MotionEvent.ACTION_DOWN: {
-                mTouchStart.x = event.getX();
-                mTouchStart.y = event.getY();
                 if (mGraphicSelectionVisible) {
-                    return checkIfGraphicSelectionWasHit();
+                    // Check if inside graphic selection was hit
+                    PointF startPosition = new PointF(event.getX(), event.getY());
+                    if (mGraphicSelection.contains(startPosition.x, startPosition.y)) {
+                        mGraphicSelectionMove = true;
+                        mGraphicSelection.dragStart(startPosition);
+                        invalidate();
+                        return true;
+                    }
+                    return false;
                 }
             }
             case MotionEvent.ACTION_UP: {
                 if (mGraphicSelectionVisible && mGraphicSelectionMove) {
-                    mDeltaPoint.x = event.getX() - mTouchStart.x;
-                    mDeltaPoint.y = event.getY() - mTouchStart.y;
-                    return stopGraphicSelection();
+                    mGraphicSelectionMove = false;
+                    mGraphicSelection.dragEnd(new PointF(event.getX(), event.getY()));
+                    invalidate();
+                    return true;
                 }
             }
             case MotionEvent.ACTION_MOVE: {
                 if (mGraphicSelectionVisible && mGraphicSelectionMove) {
-                    mDeltaPoint.x = event.getX() - mTouchStart.x;
-                    mDeltaPoint.y = event.getY() - mTouchStart.y;
                     mGraphicSelection.dragging(new PointF(event.getX(), event.getY()));
                     invalidate();
                     return true;
@@ -293,59 +253,6 @@ public class TextCursorView extends View implements View.OnTouchListener {
         }
         return false;
     }
-
-    private boolean checkIfGraphicSelectionWasHit() {
-        // Check if handle was hit
-        mDragHandle = null;
-        for (GraphicSelectionHandleCanvasElement handle : mHandles) {
-            if (handle.contains(mTouchStart.x, mTouchStart.y)) {
-                mDragHandle = handle;
-                mGraphicSelectionMove = true;
-                mGraphicSelection.dragStart(GraphicSelectionCanvasElement.DragType.EXTEND, mTouchStart);
-                sendGraphicSelectionStart(handle.mPosition);
-                return true;
-            }
-        }
-        // Check if inside graphic selection was hit
-        if (mGraphicSelection.contains(mTouchStart.x, mTouchStart.y)) {
-            mGraphicSelectionMove = true;
-            mGraphicSelection.dragStart(GraphicSelectionCanvasElement.DragType.MOVE, mTouchStart);
-            sendGraphicSelectionStart(mTouchStart);
-            return true;
-        }
-        return false;
-    }
-
-    private boolean stopGraphicSelection() {
-        mGraphicSelectionMove = false;
-
-        PointF point = new PointF();
-        if (mDragHandle != null) {
-            point.x = mDragHandle.mPosition.x;
-            point.y = mDragHandle.mPosition.y;
-        } else {
-            point.x = mTouchStart.x;
-            point.y = mTouchStart.y;
-        }
-        point.offset(mDeltaPoint.x, mDeltaPoint.y);
-        sendGraphicSelectionEnd(point);
-
-        mGraphicSelection.dragEnd();
-        invalidate();
-        return true;
-    }
-
-    private void sendGraphicSelectionStart(PointF screenPosition) {
-        PointF documentPoint = mLayerView.getLayerClient().convertViewPointToLayerPoint(screenPosition);
-        Log.i(LOGTAG, "Selection Start P: " + documentPoint + " : " + mGraphicSelection);
-        LOKitShell.sendTouchEvent("GraphicSelectionStart", documentPoint);
-    }
-
-    private void sendGraphicSelectionEnd(PointF screenPosition) {
-        PointF documentPoint = mLayerView.getLayerClient().convertViewPointToLayerPoint(screenPosition);
-        Log.i(LOGTAG, "Selection End P: " + documentPoint + " : " + mGraphicSelection);
-        LOKitShell.sendTouchEvent("GraphicSelectionEnd", documentPoint);
-    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list