summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-02-23 20:53:03 +0900
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-03-02 08:50:51 +0100
commite3cd64d378ba44397285d9858624155a4eaffecd (patch)
tree08389da2280f9b81e0f0c4f290e32286a92911b8 /android
parentd33f3215b2957c288890b47b5ef57c3dff4f7e1b (diff)
android: extrac invalidations into InvalidationHandler
Change-Id: Iccdb5e64acac603fbc623d1c325d6e922568de81
Diffstat (limited to 'android')
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java125
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java111
2 files changed, 131 insertions, 105 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
new file mode 100644
index 000000000000..a37d3d4378f5
--- /dev/null
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
@@ -0,0 +1,125 @@
+package org.libreoffice;
+
+import android.graphics.RectF;
+import android.util.Log;
+
+import org.libreoffice.kit.Document;
+import org.mozilla.gecko.TextSelection;
+import org.mozilla.gecko.TextSelectionHandle;
+
+public class InvalidationHandler {
+ private static String LOGTAG = InvalidationHandler.class.getSimpleName();
+
+ public InvalidationHandler() {
+ }
+
+ public void processMessage(int messageID, String payload) {
+ switch (messageID) {
+ case Document.CALLBACK_INVALIDATE_TILES:
+ invalidateTiles(payload);
+ break;
+ case Document.CALLBACK_INVALIDATE_VISIBLE_CURSOR:
+ invalidateCursor(payload);
+ break;
+ case Document.CALLBACK_INVALIDATE_TEXT_SELECTION:
+ Log.i(LOGTAG, "Selection: " + payload);
+ invalidateSelection(payload);
+ break;
+ case Document.CALLBACK_INVALIDATE_TEXT_SELECTION_START:
+ Log.i(LOGTAG, "Selection start: " + payload);
+ invalidateSelectionStart(payload);
+ break;
+ case Document.CALLBACK_INVALIDATE_TEXT_SELECTION_END:
+ Log.i(LOGTAG, "Selection end: " + payload);
+ invalidateSelectionEnd(payload);
+ break;
+ }
+ }
+
+ private RectF convertCallbackMessageStringToRectF(String text) {
+ if (text.equals("EMPTY")) {
+ return null;
+ }
+
+ String[] coordinates = text.split(",");
+
+ if (coordinates.length != 4) {
+ return null;
+ }
+ int width = Integer.decode(coordinates[0].trim());
+ int height = Integer.decode(coordinates[1].trim());
+ int x = Integer.decode(coordinates[2].trim());
+ int y = Integer.decode(coordinates[3].trim());
+
+ float dpi = (float) LOKitShell.getDpi();
+
+ RectF rect = new RectF(
+ LOKitTileProvider.twipToPixel(x, dpi),
+ LOKitTileProvider.twipToPixel(y, dpi),
+ LOKitTileProvider.twipToPixel(x + width, dpi),
+ LOKitTileProvider.twipToPixel(y + height, dpi)
+ );
+
+ return rect;
+ }
+
+ private void invalidateCursor(String payload) {
+ RectF rect = convertCallbackMessageStringToRectF(payload);
+ if (rect != null) {
+ RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
+ TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
+ textSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, underSelection);
+ textSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
+
+ TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
+ textCursorLayer.positionCursor(rect);
+ textCursorLayer.showCursor();
+ }
+ }
+
+ private void invalidateTiles(String payload) {
+ RectF rect = convertCallbackMessageStringToRectF(payload);
+ if (rect != null) {
+ LOKitShell.sendTileInvalidationRequest(rect);
+ }
+ }
+
+ private void invalidateSelectionStart(String payload) {
+ RectF rect = convertCallbackMessageStringToRectF(payload);
+ if (rect != null) {
+ RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
+ TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
+ textSelection.positionHandle(TextSelectionHandle.HandleType.START, underSelection);
+ textSelection.showHandle(TextSelectionHandle.HandleType.START);
+
+ textSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
+
+ TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
+ textCursorLayer.hideCursor();
+ }
+ }
+
+ private void invalidateSelectionEnd(String payload) {
+ RectF rect = convertCallbackMessageStringToRectF(payload);
+ if (rect != null) {
+ RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
+ TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
+ textSelection.positionHandle(TextSelectionHandle.HandleType.END, underSelection);
+ textSelection.showHandle(TextSelectionHandle.HandleType.END);
+
+ textSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
+
+ TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
+ textCursorLayer.hideCursor();
+ }
+ }
+
+ private void invalidateSelection(String payload) {
+ if (payload.isEmpty()) {
+ TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
+ textSelection.hideHandle(TextSelectionHandle.HandleType.START);
+ textSelection.hideHandle(TextSelectionHandle.HandleType.END);
+ }
+ }
+
+}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index 1fd138871d13..f99cda0c8f52 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -37,6 +37,8 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
private float mWidthTwip;
private float mHeightTwip;
+ private InvalidationHandler mInvalidationHandler = new InvalidationHandler();
+
private long objectCreationTime = System.currentTimeMillis();
public LOKitTileProvider(GeckoLayerClient layerClient, String input) {
@@ -133,11 +135,11 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
}
}
- private float twipToPixel(float input, float dpi) {
+ public static float twipToPixel(float input, float dpi) {
return input / 1440.0f * dpi;
}
- private float pixelToTwip(float input, float dpi) {
+ public static float pixelToTwip(float input, float dpi) {
return (input / dpi) * 1440.0f;
}
@@ -359,117 +361,16 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
return mDocument.getPart();
}
- private RectF convertCallbackMessageStringToRectF(String text) {
- if (text.equals("EMPTY")) {
- return null;
- }
-
- String[] coordinates = text.split(",");
-
- if (coordinates.length != 4) {
- return null;
- }
- int width = Integer.decode(coordinates[0].trim());
- int height = Integer.decode(coordinates[1].trim());
- int x = Integer.decode(coordinates[2].trim());
- int y = Integer.decode(coordinates[3].trim());
- RectF rect = new RectF(
- twipToPixel(x, mDPI),
- twipToPixel(y, mDPI),
- twipToPixel(x + width, mDPI),
- twipToPixel(y + height, mDPI)
- );
- return rect;
- }
-
/**
* Process the retrieved messages from LOK
*/
@Override
- public void messageRetrieved(int signalNumber, String payload) {
+ public void messageRetrieved(int messageID, String payload) {
if (!LOKitShell.isEditingEnabled()) {
return;
}
- switch (signalNumber) {
- case Document.CALLBACK_INVALIDATE_TILES:
- invalidateTiles(payload);
- break;
- case Document.CALLBACK_INVALIDATE_VISIBLE_CURSOR:
- invalidateCursor(payload);
- break;
- case Document.CALLBACK_INVALIDATE_TEXT_SELECTION:
- Log.i(LOGTAG, "Selection: " + payload);
- invalidateSelection(payload);
- break;
- case Document.CALLBACK_INVALIDATE_TEXT_SELECTION_START:
- Log.i(LOGTAG, "Selection start: " + payload);
- invalidateSelectionStart(payload);
- break;
- case Document.CALLBACK_INVALIDATE_TEXT_SELECTION_END:
- Log.i(LOGTAG, "Selection end: " + payload);
- invalidateSelectionEnd(payload);
- break;
- }
- }
-
- private void invalidateCursor(String payload) {
- RectF rect = convertCallbackMessageStringToRectF(payload);
- if (rect != null) {
- RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
- TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
- textSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, underSelection);
- textSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
-
- TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
- textCursorLayer.positionCursor(rect);
- textCursorLayer.showCursor();
- }
- }
-
- private void invalidateTiles(String payload) {
- RectF rect = convertCallbackMessageStringToRectF(payload);
- if (rect != null) {
- LOKitShell.sendTileInvalidationRequest(rect);
- }
- }
-
- private void invalidateSelectionStart(String payload) {
- RectF rect = convertCallbackMessageStringToRectF(payload);
- if (rect != null) {
- RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
- TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
- textSelection.positionHandle(TextSelectionHandle.HandleType.START, underSelection);
- textSelection.showHandle(TextSelectionHandle.HandleType.START);
-
- textSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
-
- TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
- textCursorLayer.hideCursor();
- }
- }
-
- private void invalidateSelectionEnd(String payload) {
- RectF rect = convertCallbackMessageStringToRectF(payload);
- if (rect != null) {
- RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
- TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
- textSelection.positionHandle(TextSelectionHandle.HandleType.END, underSelection);
- textSelection.showHandle(TextSelectionHandle.HandleType.END);
-
- textSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
-
- TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
- textCursorLayer.hideCursor();
- }
- }
-
- private void invalidateSelection(String payload) {
- if (payload.isEmpty()) {
- TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
- textSelection.hideHandle(TextSelectionHandle.HandleType.START);
- textSelection.hideHandle(TextSelectionHandle.HandleType.END);
- }
+ mInvalidationHandler.processMessage(messageID, payload);
}
}