From e72a7368b368a822d2400ee7db60312226ad3195 Mon Sep 17 00:00:00 2001 From: Ilhan Yesil Date: Mon, 31 May 2021 15:10:47 +0200 Subject: tdf#131548 Android: jump to cell Added LOK_CALLBACK_SC_FOLLOW_JUMP: fire this signal to jump to cell cursor in android viewer. Payload format same as LOK_CALLBACK_INVALIDATE_TILES. Change-Id: Ic896baccf1327d6ccdf104811446e3454a42679e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116448 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- .../src/org/libreoffice/kit/Document.java | 1 + .../java/org/libreoffice/InvalidationHandler.java | 54 ++++++++++++++++++++-- 2 files changed, 51 insertions(+), 4 deletions(-) (limited to 'android') diff --git a/android/Bootstrap/src/org/libreoffice/kit/Document.java b/android/Bootstrap/src/org/libreoffice/kit/Document.java index 69f8f76c3eb4..ed7208da5924 100644 --- a/android/Bootstrap/src/org/libreoffice/kit/Document.java +++ b/android/Bootstrap/src/org/libreoffice/kit/Document.java @@ -92,6 +92,7 @@ public class Document { public static final int CALLBACK_COMMENT = 32; public static final int CALLBACK_INVALIDATE_HEADER = 33; public static final int CALLBACK_CELL_ADDRESS = 34; + public static final int CALLBACK_SC_FOLLOW_JUMP = 52; /** * Set text selection types diff --git a/android/source/src/java/org/libreoffice/InvalidationHandler.java b/android/source/src/java/org/libreoffice/InvalidationHandler.java index d74f150bfb44..0f3f1dd7b889 100644 --- a/android/source/src/java/org/libreoffice/InvalidationHandler.java +++ b/android/source/src/java/org/libreoffice/InvalidationHandler.java @@ -55,6 +55,7 @@ public class InvalidationHandler implements Document.MessageCallback, Office.Mes && messageID != Document.CALLBACK_DOCUMENT_PASSWORD && messageID != Document.CALLBACK_HYPERLINK_CLICKED && messageID != Document.CALLBACK_SEARCH_RESULT_SELECTION + && messageID != Document.CALLBACK_SC_FOLLOW_JUMP && messageID != Document.CALLBACK_TEXT_SELECTION && messageID != Document.CALLBACK_TEXT_SELECTION_START && messageID != Document.CALLBACK_TEXT_SELECTION_END) @@ -114,6 +115,9 @@ public class InvalidationHandler implements Document.MessageCallback, Office.Mes case Document.CALLBACK_CELL_CURSOR: invalidateCellCursor(payload); break; + case Document.CALLBACK_SC_FOLLOW_JUMP: + jumpToCell(payload); + break; case Document.CALLBACK_INVALIDATE_HEADER: invalidateHeader(); break; @@ -214,6 +218,14 @@ public class InvalidationHandler implements Document.MessageCallback, Office.Mes } } + private void jumpToCell(String payload) { + RectF cellCursorRect = convertPayloadCellToRectangle(payload); + + if (cellCursorRect != null) { + moveViewportToMakeSelectionVisible(cellCursorRect); + } + } + /** * Handles the search result selection message, which is a JSONObject * @@ -368,6 +380,40 @@ public class InvalidationHandler implements Document.MessageCallback, Office.Mes if (coordinates.length != 4) { return null; } + return convertPayloadToRectangle(coordinates); + } + + /** + * Parses the payload text with rectangle coordinates and converts to rectangle in pixel coordinates + * + * @param payload - invalidation message payload text + * @return rectangle in pixel coordinates + */ + public RectF convertPayloadCellToRectangle(String payload) { + String payloadWithoutWhitespace = payload.replaceAll("\\s", ""); // remove all whitespace from the string + + if (payloadWithoutWhitespace.isEmpty() || payloadWithoutWhitespace.equals("EMPTY")) { + return null; + } + + String[] coordinates = payloadWithoutWhitespace.split(","); + + if (coordinates.length != 6 ) { + return null; + } + return convertPayloadToRectangle(coordinates); + } + + /** + * Converts rectangle coordinates to rectangle in pixel coordinates + * + * @param coordinates - the first four items defines the rectangle + * @return rectangle in pixel coordinates + */ + public RectF convertPayloadToRectangle(String[] coordinates) { + if (coordinates.length < 4 ) { + return null; + } int x = Integer.decode(coordinates[0]); int y = Integer.decode(coordinates[1]); @@ -377,10 +423,10 @@ public class InvalidationHandler implements Document.MessageCallback, Office.Mes float dpi = LOKitShell.getDpi(mContext); return new RectF( - LOKitTileProvider.twipToPixel(x, dpi), - LOKitTileProvider.twipToPixel(y, dpi), - LOKitTileProvider.twipToPixel(x + width, dpi), - LOKitTileProvider.twipToPixel(y + height, dpi) + LOKitTileProvider.twipToPixel(x, dpi), + LOKitTileProvider.twipToPixel(y, dpi), + LOKitTileProvider.twipToPixel(x + width, dpi), + LOKitTileProvider.twipToPixel(y + height, dpi) ); } -- cgit