summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-02-26 16:29:43 +0900
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-03-02 08:50:57 +0100
commit39d4b4010f93b490ebcb46b43fee1dedfc0902d1 (patch)
treecdd708161d29b515bd2c6565b217f72094ee73c3
parenta8547448f08c6b5083faf72ed3cdf7cac3ab4a1b (diff)
android: add OverlayState to track the state of overlay
Overlay can either be in state NONE - no overlay elements should be shown (this is the deocument reader state), CURSOR - cursor and the cursor handle are shown, SELECTION - selection and selection handles are shown. The states can change either by an invalidation or touch input. Change-Id: Ia15eb58193675b3799c0014a91f4429a729e30d4
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java52
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java2
2 files changed, 40 insertions, 14 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
index 8933c881e834..fb46c77c642d 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
@@ -18,10 +18,12 @@ public class InvalidationHandler {
private TextCursorLayer mTextCursorLayer;
private TextSelection mTextSelection;
+ private OverlayState mState;
public InvalidationHandler(LibreOfficeMainActivity mainActivity) {
mTextCursorLayer = mainActivity.getTextCursorLayer();
mTextSelection = mainActivity.getTextSelection();
+ mState = OverlayState.NONE;
}
/**
@@ -54,6 +56,10 @@ public class InvalidationHandler {
}
}
+ public void setOverlayState(OverlayState state) {
+ this.mState = state;
+ }
+
/**
* Parses the payload text with rectangle coordinates and converts to rectangle in pixel coordinates
*
@@ -133,18 +139,19 @@ public class InvalidationHandler {
* @param payload
*/
private void invalidateCursor(String payload) {
- RectF cursorRectangle = convertPayloadToRectangle(payload);
- if (cursorRectangle != null) {
- TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
- textSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, createRectangleUnderSelection(cursorRectangle));
- textSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
-
- textSelection.hideHandle(TextSelectionHandle.HandleType.START);
- textSelection.hideHandle(TextSelectionHandle.HandleType.END);
-
- TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
- textCursorLayer.positionCursor(cursorRectangle);
- textCursorLayer.showCursor();
+ if (mState == OverlayState.CURSOR) {
+ RectF cursorRectangle = convertPayloadToRectangle(payload);
+ if (cursorRectangle != null) {
+ TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
+ textSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, createRectangleUnderSelection(cursorRectangle));
+ textSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
+ textSelection.hideHandle(TextSelectionHandle.HandleType.START);
+ textSelection.hideHandle(TextSelectionHandle.HandleType.END);
+
+ TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
+ textCursorLayer.positionCursor(cursorRectangle);
+ textCursorLayer.showCursor();
+ }
}
}
@@ -154,12 +161,15 @@ public class InvalidationHandler {
* @param payload
*/
private void invalidateSelectionStart(String payload) {
+ if (mState == OverlayState.NONE) {
+ return;
+ }
RectF selectionRectangle = convertPayloadToRectangle(payload);
if (selectionRectangle != null) {
mTextSelection.positionHandle(TextSelectionHandle.HandleType.START, createRectangleUnderSelection(selectionRectangle));
mTextSelection.showHandle(TextSelectionHandle.HandleType.START);
mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
- mTextCursorLayer.hideCursor();
+ mState = OverlayState.SELECTION;
}
}
@@ -169,12 +179,15 @@ public class InvalidationHandler {
* @param payload
*/
private void invalidateSelectionEnd(String payload) {
+ if (mState == OverlayState.NONE) {
+ return;
+ }
RectF selectionRect = convertPayloadToRectangle(payload);
if (selectionRect != null) {
mTextSelection.positionHandle(TextSelectionHandle.HandleType.END, createRectangleUnderSelection(selectionRect));
mTextSelection.showHandle(TextSelectionHandle.HandleType.END);
mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
- mTextCursorLayer.hideCursor();
+ mState = OverlayState.SELECTION;
}
}
@@ -184,12 +197,23 @@ public class InvalidationHandler {
* @param payload
*/
private void invalidateSelection(String payload) {
+ if (mState == OverlayState.NONE) {
+ return;
+ }
if (payload.isEmpty()) {
+ mState = OverlayState.CURSOR;
mTextSelection.hideHandle(TextSelectionHandle.HandleType.START);
mTextSelection.hideHandle(TextSelectionHandle.HandleType.END);
} else {
+ mState = OverlayState.SELECTION;
List<RectF> rects = convertPayloadToRectangles(payload);
mTextCursorLayer.changeSelections(rects);
}
}
+
+ public enum OverlayState {
+ NONE,
+ CURSOR,
+ SELECTION
+ }
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index fa7fb59a14f9..c2dbb2351d71 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -233,10 +233,12 @@ public class LOKitThread extends Thread {
if (touchType.equals("LongPress")) {
LibreOfficeMainActivity.mAppContext.hideSoftKeyboard();
mTileProvider.mouseButtonDown(mDocumentTouchCoordinate, 2);
+ mInvalidationHandler.setOverlayState(InvalidationHandler.OverlayState.SELECTION);
} else { // "SingleTap"
LibreOfficeMainActivity.mAppContext.showSoftKeyboard();
mTileProvider.mouseButtonDown(mDocumentTouchCoordinate, 1);
mTileProvider.mouseButtonUp(mDocumentTouchCoordinate, 1);
+ mInvalidationHandler.setOverlayState(InvalidationHandler.OverlayState.CURSOR);
}
}