android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java | 96 ++++------ android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java | 6 android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java | 24 ++ android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java | 64 ++++++ 4 files changed, 128 insertions(+), 62 deletions(-)
New commits: commit a8ecb26342674acce377d2ccac9c8fae8d4aa77c Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Mar 10 17:28:26 2015 +0900 android: simplify state tracking, make graphic selection work Simplify by removing all but one transition state (which disables handles depending on previous state). Additionally show/hide/change the graphic selection depending on the messages we get from LO. Change-Id: I95d22a58e0a7f3cb034b18034cb816816a48f355 diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java index 5ea89be..0f9b997 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java @@ -3,7 +3,6 @@ package org.libreoffice; import android.content.Intent; import android.graphics.RectF; import android.net.Uri; -import android.util.Log; import org.libreoffice.kit.Document; import org.mozilla.gecko.TextSelection; @@ -18,11 +17,9 @@ import java.util.List; */ public class InvalidationHandler implements Document.MessageCallback { private static String LOGTAG = InvalidationHandler.class.getSimpleName(); - - private TileProvider mTileProvider; private final TextCursorLayer mTextCursorLayer; private final TextSelection mTextSelection; - + private TileProvider mTileProvider; private OverlayState mState; public InvalidationHandler(LibreOfficeMainActivity mainActivity) { @@ -161,9 +158,9 @@ public class InvalidationHandler implements Document.MessageCallback { mTextSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, cursorRectangle); mTextCursorLayer.positionCursor(cursorRectangle); - if (mState == OverlayState.TRANSITION_TO_CURSOR) { + if (mState == OverlayState.TRANSITION || mState == OverlayState.CURSOR) { changeStateTo(OverlayState.CURSOR); - }; + } } } @@ -199,15 +196,16 @@ public class InvalidationHandler implements Document.MessageCallback { private synchronized void textSelection(String payload) { if (payload.isEmpty() || payload.equals("EMPTY")) { if (mState == OverlayState.SELECTION) { - changeStateTo(OverlayState.TRANSITION_TO_CURSOR); + changeStateTo(OverlayState.TRANSITION); } mTextCursorLayer.changeSelections(Collections.EMPTY_LIST); } else { - if (mState == OverlayState.TRANSITION_TO_SELECTION) { - changeStateTo(OverlayState.SELECTION); + List<RectF> rectangles = convertPayloadToRectangles(payload); + if (mState != OverlayState.SELECTION) { + changeStateTo(OverlayState.TRANSITION); } - List<RectF> rects = convertPayloadToRectangles(payload); - mTextCursorLayer.changeSelections(rects); + changeStateTo(OverlayState.SELECTION); + mTextCursorLayer.changeSelections(rectangles); } } @@ -219,21 +217,30 @@ public class InvalidationHandler implements Document.MessageCallback { private synchronized void cursorVisibility(String payload) { if (payload.equals("true")) { mTextCursorLayer.showCursor(); + mTextSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE); } else if (payload.equals("false")) { mTextCursorLayer.hideCursor(); + mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE); } } /** * Handles the graphic selection change message + * * @param payload */ private void graphicSelection(String payload) { if (payload.isEmpty() || payload.equals("EMPTY")) { - mTextCursorLayer.changeSelections(Collections.EMPTY_LIST); + if (mState == OverlayState.GRAPHIC_SELECTION) { + changeStateTo(OverlayState.TRANSITION); + } } else { - List<RectF> rects = convertPayloadToRectangles(payload); - mTextCursorLayer.changeSelections(rects); + RectF rectangle = convertPayloadToRectangle(payload); + mTextCursorLayer.changeGraphicSelection(rectangle); + if (mState != OverlayState.GRAPHIC_SELECTION) { + changeStateTo(OverlayState.TRANSITION); + } + changeStateTo(OverlayState.GRAPHIC_SELECTION); } } @@ -242,26 +249,20 @@ public class InvalidationHandler implements Document.MessageCallback { } private synchronized void changeState(OverlayState previous, OverlayState next) { - if (isInvalidTransition(previous, next)) { - return; - } - - Log.i(LOGTAG, "State change: " + previous.name() + " -> " + next.name()); - mState = next; switch (next) { case CURSOR: handleCursorState(previous); break; - case TRANSITION_TO_CURSOR: - handleTransitionToCursorState(previous); - break; case SELECTION: handleSelectionState(previous); break; - case TRANSITION_TO_SELECTION: - handleTransitionToSelectionState(previous); + case GRAPHIC_SELECTION: + handleGraphicSelectionState(previous); + break; + case TRANSITION: + handleTransitionState(previous); break; case NONE: handleNoneState(previous); @@ -273,63 +274,52 @@ public class InvalidationHandler implements Document.MessageCallback { if (previous == OverlayState.NONE) { return; } + // Just hide everything - if (mTileProvider != null) { - mTileProvider.setTextSelectionReset(); - } mTextSelection.hideHandle(TextSelectionHandle.HandleType.START); mTextSelection.hideHandle(TextSelectionHandle.HandleType.END); mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE); mTextCursorLayer.hideSelections(); mTextCursorLayer.hideCursor(); + mTextCursorLayer.hideGraphicSelection(); LibreOfficeMainActivity.mAppContext.hideSoftKeyboard(); } - private void handleTransitionToSelectionState(OverlayState previous) { - if (previous == OverlayState.CURSOR) { - mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE); - } - } - private void handleSelectionState(OverlayState previous) { - if (previous == OverlayState.TRANSITION_TO_SELECTION) { - mTextSelection.showHandle(TextSelectionHandle.HandleType.START); - mTextSelection.showHandle(TextSelectionHandle.HandleType.END); - mTextCursorLayer.showSelections(); - } + mTextSelection.showHandle(TextSelectionHandle.HandleType.START); + mTextSelection.showHandle(TextSelectionHandle.HandleType.END); + mTextCursorLayer.showSelections(); } private void handleCursorState(OverlayState previous) { - if (previous == OverlayState.CURSOR) { - LibreOfficeMainActivity.mAppContext.showSoftKeyboard(); - } else if (previous == OverlayState.TRANSITION_TO_CURSOR) { - LibreOfficeMainActivity.mAppContext.showSoftKeyboard(); + LibreOfficeMainActivity.mAppContext.showSoftKeyboard(); + if (previous == OverlayState.TRANSITION) { mTextSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE); mTextCursorLayer.showCursor(); } } - private void handleTransitionToCursorState(OverlayState previous) { + private void handleTransitionState(OverlayState previous) { if (previous == OverlayState.SELECTION) { - if (mTileProvider != null) { - mTileProvider.setTextSelectionReset(); - } mTextSelection.hideHandle(TextSelectionHandle.HandleType.START); mTextSelection.hideHandle(TextSelectionHandle.HandleType.END); mTextCursorLayer.hideSelections(); + } else if (previous == OverlayState.CURSOR) { + mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE); + } else if (previous == OverlayState.GRAPHIC_SELECTION) { + mTextCursorLayer.hideGraphicSelection(); } } - private boolean isInvalidTransition(OverlayState previous, OverlayState next) { - return (previous == OverlayState.CURSOR && next == OverlayState.TRANSITION_TO_CURSOR) - || (previous == OverlayState.SELECTION && next == OverlayState.TRANSITION_TO_SELECTION); + private void handleGraphicSelectionState(OverlayState previous) { + mTextCursorLayer.showGraphicSelection(); } public enum OverlayState { NONE, + TRANSITION, CURSOR, - TRANSITION_TO_CURSOR, - SELECTION, - TRANSITION_TO_SELECTION + GRAPHIC_SELECTION, + SELECTION } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java index 252f64e..d3918b2 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java @@ -3,9 +3,7 @@ package org.libreoffice; import android.graphics.Bitmap; import android.graphics.PointF; import android.graphics.RectF; -import android.util.Log; import android.view.KeyEvent; -import android.view.MotionEvent; import org.mozilla.gecko.TextSelectionHandle; import org.mozilla.gecko.gfx.CairoImage; @@ -261,13 +259,13 @@ public class LOKitThread extends Thread { return; } if (touchType.equals("LongPress")) { - mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION_TO_SELECTION); + mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION); mTileProvider.mouseButtonDown(documentCoordinate, 1); mTileProvider.mouseButtonUp(documentCoordinate, 1); mTileProvider.mouseButtonDown(documentCoordinate, 2); mTileProvider.mouseButtonUp(documentCoordinate, 2); } else { // "SingleTap" - mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION_TO_CURSOR); + mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION); mTileProvider.mouseButtonDown(documentCoordinate, 1); mTileProvider.mouseButtonUp(documentCoordinate, 1); } commit 480c7a2d5ba952f5656b61e17d91af605952efd3 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Tue Mar 10 17:24:13 2015 +0900 android: add graphic selection to TextCursorLayer{View} Change-Id: I13d26dd8b38d0b6817f3d0dbcb8a063fef559c2a diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java index ce17c68..a2b1abc 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java @@ -107,4 +107,28 @@ public class TextCursorLayer extends Layer { } }); } + + public void showGraphicSelection() { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.showGraphicSelection(); + } + }); + } + + public void hideGraphicSelection() { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.hideGraphicSelection(); + } + }); + } + + public void changeGraphicSelection(final RectF rectangle) { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.changeGraphicSelection(rectangle); + } + }); + } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java index 685e8c3..3c5383b 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java @@ -28,16 +28,22 @@ public class TextCursorView extends View { private boolean mInitialized = false; private RectF mCursorPosition = new RectF(); private RectF mCursorScaledPosition = new RectF(); + private Paint mCursorPaint = new Paint(); private int mCursorAlpha = 0; + private boolean mCursorVisible; private List<RectF> mSelections = new ArrayList<RectF>(); private List<RectF> mScaledSelections = new ArrayList<RectF>(); - private Paint mCursorPaint = new Paint(); private Paint mSelectionPaint = new Paint(); - - private boolean mCursorVisible; private boolean mSelectionsVisible; + private RectF mGraphicSelection = new RectF(); + private RectF mGraphicScaledSelection = new RectF(); + private Paint mGraphicSelectionPaint = new Paint(); + private Paint mGraphicHandleFillPaint = new Paint(); + private float mRadius = 20.0f; + private boolean mGraphicSelectionVisible; + public TextCursorView(Context context) { super(context); initialize(); @@ -59,13 +65,20 @@ public class TextCursorView extends View { mCursorPaint.setColor(Color.BLACK); mCursorPaint.setAlpha(0xFF); - mCursorVisible = false; mSelectionPaint.setColor(Color.BLUE); mSelectionPaint.setAlpha(50); - mSelectionsVisible = false; + + mGraphicSelectionPaint.setStyle(Paint.Style.STROKE); + mGraphicSelectionPaint.setColor(Color.BLACK); + mGraphicSelectionPaint.setStrokeWidth(2); + + mGraphicHandleFillPaint.setStyle(Paint.Style.FILL); + mGraphicHandleFillPaint.setColor(Color.WHITE); + mGraphicSelectionVisible = false; + mInitialized = true; } } @@ -78,6 +91,7 @@ public class TextCursorView extends View { } mCursorPosition = position; + ImmutableViewportMetrics metrics = layerView.getViewportMetrics(); repositionWithViewport(metrics.viewportRectLeft, metrics.viewportRectTop, metrics.zoomFactor); } @@ -95,6 +109,19 @@ public class TextCursorView extends View { repositionWithViewport(metrics.viewportRectLeft, metrics.viewportRectTop, metrics.zoomFactor); } + public void changeGraphicSelection(RectF rectangle) { + LayerView layerView = LOKitShell.getLayerView(); + if (layerView == null) { + Log.e(LOGTAG, "Can't position selections because layerView is null"); + return; + } + + mGraphicSelection = rectangle; + + ImmutableViewportMetrics metrics = layerView.getViewportMetrics(); + repositionWithViewport(metrics.viewportRectLeft, metrics.viewportRectTop, metrics.zoomFactor); + } + public void repositionWithViewport(float x, float y, float zoom) { mCursorScaledPosition = RectUtils.scale(mCursorPosition, zoom); mCursorScaledPosition.offset(-x, -y); @@ -106,6 +133,9 @@ public class TextCursorView extends View { scaledSelection.offset(-x, -y); mScaledSelections.add(scaledSelection); } + + mGraphicScaledSelection = RectUtils.scale(mGraphicSelection, zoom); + mGraphicScaledSelection.offset(-x, -y); invalidate(); } @@ -120,6 +150,20 @@ public class TextCursorView extends View { canvas.drawRect(selection, mSelectionPaint); } } + if (mGraphicSelectionVisible) { + canvas.drawRect(mGraphicScaledSelection, mGraphicSelectionPaint); + canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.top, mRadius, mGraphicHandleFillPaint); + canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.top, mRadius, mGraphicSelectionPaint); + + canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.top, mRadius, mGraphicHandleFillPaint); + canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.top, mRadius, mGraphicSelectionPaint); + + canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.bottom, mRadius, mGraphicHandleFillPaint); + canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.bottom, mRadius, mGraphicSelectionPaint); + + canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.bottom, mRadius, mGraphicHandleFillPaint); + canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.bottom, mRadius, mGraphicSelectionPaint); + } } private Runnable cursorAnimation = new Runnable() { @@ -151,4 +195,14 @@ public class TextCursorView extends View { mSelectionsVisible = false; invalidate(); } + + public void showGraphicSelection() { + mGraphicSelectionVisible = true; + invalidate(); + } + + public void hideGraphicSelection() { + mGraphicSelectionVisible = false; + invalidate(); + } } \ No newline at end of file
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits