diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-02-26 18:58:38 +0900 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-03-02 08:50:59 +0100 |
commit | ae53e0841d86b33c81ae17eea3aa809d99bce8ca (patch) | |
tree | f36255249645171d2a6bb09624398a6c1de37aac /android | |
parent | d5ad8429df278f029ed0117cea8c2bf93460ca66 (diff) |
android: fix parsing of selection coordinates and make more robust
Change-Id: Ie2fb81cc9c2096df4d9361887ed5bab8a0b841d3
Diffstat (limited to 'android')
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java index fb46c77c642d..d9d4f5ee43d5 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; |