android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java | 26 +++--- android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java | 13 ++- android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java | 8 ++ android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java | 27 +++++- android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java | 14 +++ android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java | 10 ++ android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java | 4 + android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java | 40 ++-------- 8 files changed, 94 insertions(+), 48 deletions(-)
New commits: commit 694d3f19c0386145d85e9f2cf22a8d1d9529667e Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Thu Feb 26 18:58:38 2015 +0900 android: fix parsing of selection coordinates and make more robust Change-Id: Ie2fb81cc9c2096df4d9361887ed5bab8a0b841d3 diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java index fb46c77..d9d4f5e 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java @@ -38,19 +38,15 @@ public class InvalidationHandler { invalidateTiles(payload); break; case Document.CALLBACK_INVALIDATE_VISIBLE_CURSOR: - Log.i(LOGTAG, "Cursor: " + payload); 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; } @@ -67,19 +63,22 @@ public class InvalidationHandler { * @return rectangle in pixel coordinates */ private RectF convertPayloadToRectangle(String payload) { - if (payload.equals("EMPTY")) { + String payloadWithoutWhitespace = payload.replaceAll("\\s",""); // remove all whitespace from the string + + if (payloadWithoutWhitespace.isEmpty() || payloadWithoutWhitespace.equals("EMPTY")) { return null; } - String[] coordinates = payload.split(","); + String[] coordinates = payloadWithoutWhitespace.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()); + + int width = Integer.decode(coordinates[0]); + int height = Integer.decode(coordinates[1]); + int x = Integer.decode(coordinates[2]); + int y = Integer.decode(coordinates[3]); float dpi = (float) LOKitShell.getDpi(); @@ -104,8 +103,11 @@ public class InvalidationHandler { String[] rectangleArray = payload.split(";"); for (String coordinates : rectangleArray) { - RectF rectangle = convertPayloadToRectangle(payload); - rectangles.add(rectangle); + RectF rectangle = convertPayloadToRectangle(coordinates); + if (rectangle != null) { + rectangles.add(rectangle); + } + } return rectangles; commit 87d1c3e5f6979ebb722553b3f9db5182d8e1a6f6 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Thu Feb 26 18:56:41 2015 +0900 android: send selection/cursor change from TextSelectionHandle Change-Id: Iac570c890717d8e2dcfde7f29da996c809df81dc diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java index 6b07a3f..0bd1486 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java @@ -74,51 +74,33 @@ public class TextSelectionHandle extends ImageView implements View.OnTouchListen case MotionEvent.ACTION_UP: { mTouchStartX = 0; mTouchStartY = 0; - - // Reposition handles to line up with ends of selection - JSONObject args = new JSONObject(); - try { - args.put("handleType", mHandleType.toString()); - } catch (Exception e) { - Log.e(LOGTAG, "Error building JSON arguments for TextSelection:Position"); - } - //GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("TextSelection:Position", args.toString())); break; } case MotionEvent.ACTION_MOVE: { - move(Math.round(event.getX()), Math.round(event.getY())); + move(event.getX(), event.getY()); break; } } return true; } - private void move(int newX, int newY) { - mLeft = mLeft + newX - mTouchStartX; - mTop = mTop + newY - mTouchStartY; - + private void move(float newX, float newY) { LayerView layerView = LOKitShell.getLayerView(); if (layerView == null) { Log.e(LOGTAG, "Can't move selection because layerView is null"); return; } + + float newLeft = mLeft + newX - mTouchStartX; + float newTop = mTop + newY - mTouchStartY; + // Send x coordinate on the right side of the start handle, left side of the end handle. - float left = (float) mLeft + adjustLeftForHandle(); - - PointF geckoPoint = new PointF(left, (float) mTop); - geckoPoint = layerView.getLayerClient().convertViewPointToLayerPoint(geckoPoint); - - JSONObject args = new JSONObject(); - try { - args.put("handleType", mHandleType.toString()); - args.put("x", Math.round(geckoPoint.x)); - args.put("y", Math.round(geckoPoint.y)); - } catch (Exception e) { - Log.e(LOGTAG, "Error building JSON arguments for TextSelection:Move"); - } - //GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("TextSelection:Move", args.toString())); + float left = (float) newLeft + adjustLeftForHandle(); - setLayoutPosition(); + PointF documentPoint = new PointF(left, newTop); + documentPoint = layerView.getLayerClient().convertViewPointToLayerPoint(documentPoint); + + LOKitShell.sendChangeHandlePositionEvent(mHandleType, documentPoint); } void positionFromGecko(int left, int top, boolean rtl) { commit 51e629275ad2acc6e65aa8795739e04c07183be2 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Thu Feb 26 18:55:34 2015 +0900 android: connect the selection change LOEvent with TileProvider Change-Id: Ic0b499fcafb56fd5cff6559b66a1698992c1c6ed diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java index 295d982..fc576c6b 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java @@ -7,6 +7,7 @@ import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; +import org.mozilla.gecko.TextSelectionHandle; import org.mozilla.gecko.gfx.CairoImage; import org.mozilla.gecko.gfx.ComposedTileLayer; import org.mozilla.gecko.gfx.GeckoLayerClient; @@ -204,6 +205,22 @@ public class LOKitThread extends Thread { case LOEvent.TILE_REEVALUATION_REQUEST: tileReevaluationRequest(event.mComposedTileLayer); break; + case LOEvent.CHANGE_HANDLE_POSITION: + changeHandlePosition(event.mHandleType, event.mDocumentCoordinate); + break; + } + } + + private void changeHandlePosition(TextSelectionHandle.HandleType handleType, PointF documentCoordinate) { + if (handleType == TextSelectionHandle.HandleType.MIDDLE) { + LibreOfficeMainActivity.mAppContext.showSoftKeyboard(); + mInvalidationHandler.setOverlayState(InvalidationHandler.OverlayState.CURSOR); + mTileProvider.mouseButtonDown(documentCoordinate, 1); + mTileProvider.mouseButtonUp(documentCoordinate, 1); + } else if (handleType == TextSelectionHandle.HandleType.START) { + mTileProvider.setTextSelectionStart(documentCoordinate); + } else if (handleType == TextSelectionHandle.HandleType.END) { + mTileProvider.setTextSelectionEnd(documentCoordinate); } } commit 0f60fdb2cd1304d75e133983cc484cb1c8093d25 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Thu Feb 26 18:51:41 2015 +0900 android: support selection change (start,end) to TileProvider Change-Id: If983699dacbd6c992ffff886215e8f686e0f5a2d diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java index f1faf71..f3af706 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java @@ -340,6 +340,20 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback } @Override + public void setTextSelectionStart(PointF documentCoordinate) { + int x = (int) pixelToTwip(documentCoordinate.x, mDPI); + int y = (int) pixelToTwip(documentCoordinate.y, mDPI); + mDocument.setTextSelection(Document.TEXT_SELECTION_START, x, y); + } + + @Override + public void setTextSelectionEnd(PointF documentCoordinate) { + int x = (int) pixelToTwip(documentCoordinate.x, mDPI); + int y = (int) pixelToTwip(documentCoordinate.y, mDPI); + mDocument.setTextSelection(Document.TEXT_SELECTION_END, x, y); + } + + @Override protected void finalize() throws Throwable { close(); super.finalize(); diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java index fe934a1..b4f1b82 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java @@ -105,6 +105,16 @@ public class MockTileProvider implements TileProvider { } @Override + public void setTextSelectionStart(PointF documentCoordinate) { + + } + + @Override + public void setTextSelectionEnd(PointF documentCoordinate) { + + } + + @Override public void changePart(int partIndex) { } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java index ea868bd..d749f78 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java @@ -82,4 +82,8 @@ public interface TileProvider { * @param numberOfClicks - number of clicks (1 - single click, 2 - double click) */ void mouseButtonUp(PointF documentCoordinate, int numberOfClicks); + + void setTextSelectionStart(PointF documentCoordinate); + + void setTextSelectionEnd(PointF documentCoordinate); } commit 3ad4b764f088049e0341c8a3469b0fc0942bfccb Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Thu Feb 26 18:48:47 2015 +0900 android: add LOEvent to report handle position changes With LOEvent CHANGE_HANDLE_POSITION we can report handle (start and end selelection change and cursor change) to the LOKitThread. Change-Id: Ia247acc147e54a1f05999a5e55786367c4377091 diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java index e5afe16..a046988 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java @@ -5,6 +5,7 @@ import android.graphics.RectF; import android.view.KeyEvent; import android.view.MotionEvent; +import org.mozilla.gecko.TextSelectionHandle; import org.mozilla.gecko.gfx.ComposedTileLayer; import org.mozilla.gecko.gfx.IntSize; import org.mozilla.gecko.gfx.SubTile; @@ -19,6 +20,7 @@ public class LOEvent implements Comparable<LOEvent> { public static final int TILE_INVALIDATION = 7; public static final int TOUCH = 8; public static final int KEY_EVENT = 9; + public static final int CHANGE_HANDLE_POSITION = 10; public final int mType; public int mPriority = 0; @@ -29,9 +31,10 @@ public class LOEvent implements Comparable<LOEvent> { public String mFilename; public ComposedTileLayer mComposedTileLayer; public String mTouchType; - public PointF mDocumentTouchCoordinate; + public PointF mDocumentCoordinate; public KeyEvent mKeyEvent; public RectF mInvalidationRect; + public TextSelectionHandle.HandleType mHandleType; public LOEvent(int type) { mType = type; @@ -65,7 +68,7 @@ public class LOEvent implements Comparable<LOEvent> { mType = type; mTypeString = "Touch"; mTouchType = touchType; - mDocumentTouchCoordinate = documentTouchCoordinate; + mDocumentCoordinate = documentTouchCoordinate; } public LOEvent(int type, KeyEvent keyEvent) { @@ -80,6 +83,12 @@ public class LOEvent implements Comparable<LOEvent> { mInvalidationRect = rect; } + public LOEvent(int type, TextSelectionHandle.HandleType handleType, PointF documentCoordinate) { + mType = type; + mHandleType = handleType; + mDocumentCoordinate = documentCoordinate; + } + public String getTypeString() { if (mTypeString == null) { return "Event type: " + mType; diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java index 809b4c1..68ab523 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java @@ -10,6 +10,7 @@ import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.MotionEvent; +import org.mozilla.gecko.TextSelectionHandle; import org.mozilla.gecko.gfx.ComposedTileLayer; import org.mozilla.gecko.gfx.LayerView; import org.mozilla.gecko.gfx.SubTile; @@ -126,4 +127,11 @@ public class LOKitShell { public static void sendTileInvalidationRequest(RectF rect) { LOKitShell.sendEvent(new LOEvent(LOEvent.TILE_INVALIDATION, rect)); } + + /** + * Send change handle position event to LOKitThread. + */ + public static void sendChangeHandlePositionEvent(TextSelectionHandle.HandleType handleType, PointF documentCoordinate) { + LOKitShell.sendEvent(new LOEvent(LOEvent.CHANGE_HANDLE_POSITION, handleType, documentCoordinate)); + } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java index 6fb6f3a..295d982 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java @@ -196,7 +196,7 @@ public class LOKitThread extends Thread { createThumbnail(event.mTask); break; case LOEvent.TOUCH: - touch(event.mTouchType, event.mDocumentTouchCoordinate); + touch(event.mTouchType, event.mDocumentCoordinate); break; case LOEvent.KEY_EVENT: keyEvent(event.mKeyEvent); @@ -223,7 +223,7 @@ public class LOKitThread extends Thread { /** * Processes touch events. */ - private void touch(String touchType, PointF mDocumentTouchCoordinate) { + private void touch(String touchType, PointF documentCoordinate) { if (!LOKitShell.isEditingEnabled()) { return; } @@ -233,12 +233,12 @@ public class LOKitThread extends Thread { if (touchType.equals("LongPress")) { LibreOfficeMainActivity.mAppContext.hideSoftKeyboard(); mInvalidationHandler.setOverlayState(InvalidationHandler.OverlayState.SELECTION); - mTileProvider.mouseButtonDown(mDocumentTouchCoordinate, 2); + mTileProvider.mouseButtonDown(documentCoordinate, 2); } else { // "SingleTap" LibreOfficeMainActivity.mAppContext.showSoftKeyboard(); mInvalidationHandler.setOverlayState(InvalidationHandler.OverlayState.CURSOR); - mTileProvider.mouseButtonDown(mDocumentTouchCoordinate, 1); - mTileProvider.mouseButtonUp(mDocumentTouchCoordinate, 1); + mTileProvider.mouseButtonDown(documentCoordinate, 1); + mTileProvider.mouseButtonUp(documentCoordinate, 1); } }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits