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
This commit is contained in:
Tomaž Vajngerl
2015-02-26 16:29:43 +09:00
committed by Miklos Vajna
parent a8547448f0
commit 39d4b4010f
2 changed files with 39 additions and 13 deletions

View File

@@ -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);
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);
textSelection.hideHandle(TextSelectionHandle.HandleType.START);
textSelection.hideHandle(TextSelectionHandle.HandleType.END);
TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
textCursorLayer.positionCursor(cursorRectangle);
textCursorLayer.showCursor();
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
}
}

View File

@@ -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);
}
}