Kaydet (Commit) b6df97c3 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Miklos Vajna

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
üst 003a62fb
...@@ -3,7 +3,6 @@ package org.libreoffice; ...@@ -3,7 +3,6 @@ package org.libreoffice;
import android.content.Intent; import android.content.Intent;
import android.graphics.RectF; import android.graphics.RectF;
import android.net.Uri; import android.net.Uri;
import android.util.Log;
import org.libreoffice.kit.Document; import org.libreoffice.kit.Document;
import org.mozilla.gecko.TextSelection; import org.mozilla.gecko.TextSelection;
...@@ -18,11 +17,9 @@ import java.util.List; ...@@ -18,11 +17,9 @@ import java.util.List;
*/ */
public class InvalidationHandler implements Document.MessageCallback { public class InvalidationHandler implements Document.MessageCallback {
private static String LOGTAG = InvalidationHandler.class.getSimpleName(); private static String LOGTAG = InvalidationHandler.class.getSimpleName();
private TileProvider mTileProvider;
private final TextCursorLayer mTextCursorLayer; private final TextCursorLayer mTextCursorLayer;
private final TextSelection mTextSelection; private final TextSelection mTextSelection;
private TileProvider mTileProvider;
private OverlayState mState; private OverlayState mState;
public InvalidationHandler(LibreOfficeMainActivity mainActivity) { public InvalidationHandler(LibreOfficeMainActivity mainActivity) {
...@@ -161,9 +158,9 @@ public class InvalidationHandler implements Document.MessageCallback { ...@@ -161,9 +158,9 @@ public class InvalidationHandler implements Document.MessageCallback {
mTextSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, cursorRectangle); mTextSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, cursorRectangle);
mTextCursorLayer.positionCursor(cursorRectangle); mTextCursorLayer.positionCursor(cursorRectangle);
if (mState == OverlayState.TRANSITION_TO_CURSOR) { if (mState == OverlayState.TRANSITION || mState == OverlayState.CURSOR) {
changeStateTo(OverlayState.CURSOR); changeStateTo(OverlayState.CURSOR);
}; }
} }
} }
...@@ -199,15 +196,16 @@ public class InvalidationHandler implements Document.MessageCallback { ...@@ -199,15 +196,16 @@ public class InvalidationHandler implements Document.MessageCallback {
private synchronized void textSelection(String payload) { private synchronized void textSelection(String payload) {
if (payload.isEmpty() || payload.equals("EMPTY")) { if (payload.isEmpty() || payload.equals("EMPTY")) {
if (mState == OverlayState.SELECTION) { if (mState == OverlayState.SELECTION) {
changeStateTo(OverlayState.TRANSITION_TO_CURSOR); changeStateTo(OverlayState.TRANSITION);
} }
mTextCursorLayer.changeSelections(Collections.EMPTY_LIST); mTextCursorLayer.changeSelections(Collections.EMPTY_LIST);
} else { } else {
if (mState == OverlayState.TRANSITION_TO_SELECTION) { List<RectF> rectangles = convertPayloadToRectangles(payload);
changeStateTo(OverlayState.SELECTION); if (mState != OverlayState.SELECTION) {
changeStateTo(OverlayState.TRANSITION);
} }
List<RectF> rects = convertPayloadToRectangles(payload); changeStateTo(OverlayState.SELECTION);
mTextCursorLayer.changeSelections(rects); mTextCursorLayer.changeSelections(rectangles);
} }
} }
...@@ -219,21 +217,30 @@ public class InvalidationHandler implements Document.MessageCallback { ...@@ -219,21 +217,30 @@ public class InvalidationHandler implements Document.MessageCallback {
private synchronized void cursorVisibility(String payload) { private synchronized void cursorVisibility(String payload) {
if (payload.equals("true")) { if (payload.equals("true")) {
mTextCursorLayer.showCursor(); mTextCursorLayer.showCursor();
mTextSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
} else if (payload.equals("false")) { } else if (payload.equals("false")) {
mTextCursorLayer.hideCursor(); mTextCursorLayer.hideCursor();
mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
} }
} }
/** /**
* Handles the graphic selection change message * Handles the graphic selection change message
*
* @param payload * @param payload
*/ */
private void graphicSelection(String payload) { private void graphicSelection(String payload) {
if (payload.isEmpty() || payload.equals("EMPTY")) { if (payload.isEmpty() || payload.equals("EMPTY")) {
mTextCursorLayer.changeSelections(Collections.EMPTY_LIST); if (mState == OverlayState.GRAPHIC_SELECTION) {
changeStateTo(OverlayState.TRANSITION);
}
} else { } else {
List<RectF> rects = convertPayloadToRectangles(payload); RectF rectangle = convertPayloadToRectangle(payload);
mTextCursorLayer.changeSelections(rects); 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 { ...@@ -242,26 +249,20 @@ public class InvalidationHandler implements Document.MessageCallback {
} }
private synchronized void changeState(OverlayState previous, OverlayState next) { private synchronized void changeState(OverlayState previous, OverlayState next) {
if (isInvalidTransition(previous, next)) {
return;
}
Log.i(LOGTAG, "State change: " + previous.name() + " -> " + next.name());
mState = next; mState = next;
switch (next) { switch (next) {
case CURSOR: case CURSOR:
handleCursorState(previous); handleCursorState(previous);
break; break;
case TRANSITION_TO_CURSOR:
handleTransitionToCursorState(previous);
break;
case SELECTION: case SELECTION:
handleSelectionState(previous); handleSelectionState(previous);
break; break;
case TRANSITION_TO_SELECTION: case GRAPHIC_SELECTION:
handleTransitionToSelectionState(previous); handleGraphicSelectionState(previous);
break;
case TRANSITION:
handleTransitionState(previous);
break; break;
case NONE: case NONE:
handleNoneState(previous); handleNoneState(previous);
...@@ -273,63 +274,52 @@ public class InvalidationHandler implements Document.MessageCallback { ...@@ -273,63 +274,52 @@ public class InvalidationHandler implements Document.MessageCallback {
if (previous == OverlayState.NONE) { if (previous == OverlayState.NONE) {
return; return;
} }
// Just hide everything // Just hide everything
if (mTileProvider != null) {
mTileProvider.setTextSelectionReset();
}
mTextSelection.hideHandle(TextSelectionHandle.HandleType.START); mTextSelection.hideHandle(TextSelectionHandle.HandleType.START);
mTextSelection.hideHandle(TextSelectionHandle.HandleType.END); mTextSelection.hideHandle(TextSelectionHandle.HandleType.END);
mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE); mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
mTextCursorLayer.hideSelections(); mTextCursorLayer.hideSelections();
mTextCursorLayer.hideCursor(); mTextCursorLayer.hideCursor();
mTextCursorLayer.hideGraphicSelection();
LibreOfficeMainActivity.mAppContext.hideSoftKeyboard(); LibreOfficeMainActivity.mAppContext.hideSoftKeyboard();
} }
private void handleTransitionToSelectionState(OverlayState previous) {
if (previous == OverlayState.CURSOR) {
mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
}
}
private void handleSelectionState(OverlayState previous) { private void handleSelectionState(OverlayState previous) {
if (previous == OverlayState.TRANSITION_TO_SELECTION) {
mTextSelection.showHandle(TextSelectionHandle.HandleType.START); mTextSelection.showHandle(TextSelectionHandle.HandleType.START);
mTextSelection.showHandle(TextSelectionHandle.HandleType.END); mTextSelection.showHandle(TextSelectionHandle.HandleType.END);
mTextCursorLayer.showSelections(); mTextCursorLayer.showSelections();
} }
}
private void handleCursorState(OverlayState previous) { 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); mTextSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
mTextCursorLayer.showCursor(); mTextCursorLayer.showCursor();
} }
} }
private void handleTransitionToCursorState(OverlayState previous) { private void handleTransitionState(OverlayState previous) {
if (previous == OverlayState.SELECTION) { if (previous == OverlayState.SELECTION) {
if (mTileProvider != null) {
mTileProvider.setTextSelectionReset();
}
mTextSelection.hideHandle(TextSelectionHandle.HandleType.START); mTextSelection.hideHandle(TextSelectionHandle.HandleType.START);
mTextSelection.hideHandle(TextSelectionHandle.HandleType.END); mTextSelection.hideHandle(TextSelectionHandle.HandleType.END);
mTextCursorLayer.hideSelections(); 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) { private void handleGraphicSelectionState(OverlayState previous) {
return (previous == OverlayState.CURSOR && next == OverlayState.TRANSITION_TO_CURSOR) mTextCursorLayer.showGraphicSelection();
|| (previous == OverlayState.SELECTION && next == OverlayState.TRANSITION_TO_SELECTION);
} }
public enum OverlayState { public enum OverlayState {
NONE, NONE,
TRANSITION,
CURSOR, CURSOR,
TRANSITION_TO_CURSOR, GRAPHIC_SELECTION,
SELECTION, SELECTION
TRANSITION_TO_SELECTION
} }
} }
...@@ -3,9 +3,7 @@ package org.libreoffice; ...@@ -3,9 +3,7 @@ package org.libreoffice;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.RectF; import android.graphics.RectF;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent;
import org.mozilla.gecko.TextSelectionHandle; import org.mozilla.gecko.TextSelectionHandle;
import org.mozilla.gecko.gfx.CairoImage; import org.mozilla.gecko.gfx.CairoImage;
...@@ -261,13 +259,13 @@ public class LOKitThread extends Thread { ...@@ -261,13 +259,13 @@ public class LOKitThread extends Thread {
return; return;
} }
if (touchType.equals("LongPress")) { if (touchType.equals("LongPress")) {
mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION_TO_SELECTION); mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION);
mTileProvider.mouseButtonDown(documentCoordinate, 1); mTileProvider.mouseButtonDown(documentCoordinate, 1);
mTileProvider.mouseButtonUp(documentCoordinate, 1); mTileProvider.mouseButtonUp(documentCoordinate, 1);
mTileProvider.mouseButtonDown(documentCoordinate, 2); mTileProvider.mouseButtonDown(documentCoordinate, 2);
mTileProvider.mouseButtonUp(documentCoordinate, 2); mTileProvider.mouseButtonUp(documentCoordinate, 2);
} else { // "SingleTap" } else { // "SingleTap"
mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION_TO_CURSOR); mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION);
mTileProvider.mouseButtonDown(documentCoordinate, 1); mTileProvider.mouseButtonDown(documentCoordinate, 1);
mTileProvider.mouseButtonUp(documentCoordinate, 1); mTileProvider.mouseButtonUp(documentCoordinate, 1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment