Kaydet (Commit) ae53e084 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Miklos Vajna

android: fix parsing of selection coordinates and make more robust

Change-Id: Ie2fb81cc9c2096df4d9361887ed5bab8a0b841d3
üst d5ad8429
...@@ -38,19 +38,15 @@ public class InvalidationHandler { ...@@ -38,19 +38,15 @@ public class InvalidationHandler {
invalidateTiles(payload); invalidateTiles(payload);
break; break;
case Document.CALLBACK_INVALIDATE_VISIBLE_CURSOR: case Document.CALLBACK_INVALIDATE_VISIBLE_CURSOR:
Log.i(LOGTAG, "Cursor: " + payload);
invalidateCursor(payload); invalidateCursor(payload);
break; break;
case Document.CALLBACK_INVALIDATE_TEXT_SELECTION: case Document.CALLBACK_INVALIDATE_TEXT_SELECTION:
Log.i(LOGTAG, "Selection: " + payload);
invalidateSelection(payload); invalidateSelection(payload);
break; break;
case Document.CALLBACK_INVALIDATE_TEXT_SELECTION_START: case Document.CALLBACK_INVALIDATE_TEXT_SELECTION_START:
Log.i(LOGTAG, "Selection start: " + payload);
invalidateSelectionStart(payload); invalidateSelectionStart(payload);
break; break;
case Document.CALLBACK_INVALIDATE_TEXT_SELECTION_END: case Document.CALLBACK_INVALIDATE_TEXT_SELECTION_END:
Log.i(LOGTAG, "Selection end: " + payload);
invalidateSelectionEnd(payload); invalidateSelectionEnd(payload);
break; break;
} }
...@@ -67,19 +63,22 @@ public class InvalidationHandler { ...@@ -67,19 +63,22 @@ public class InvalidationHandler {
* @return rectangle in pixel coordinates * @return rectangle in pixel coordinates
*/ */
private RectF convertPayloadToRectangle(String payload) { 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; return null;
} }
String[] coordinates = payload.split(","); String[] coordinates = payloadWithoutWhitespace.split(",");
if (coordinates.length != 4) { if (coordinates.length != 4) {
return null; return null;
} }
int width = Integer.decode(coordinates[0].trim());
int height = Integer.decode(coordinates[1].trim()); int width = Integer.decode(coordinates[0]);
int x = Integer.decode(coordinates[2].trim()); int height = Integer.decode(coordinates[1]);
int y = Integer.decode(coordinates[3].trim()); int x = Integer.decode(coordinates[2]);
int y = Integer.decode(coordinates[3]);
float dpi = (float) LOKitShell.getDpi(); float dpi = (float) LOKitShell.getDpi();
...@@ -104,8 +103,11 @@ public class InvalidationHandler { ...@@ -104,8 +103,11 @@ public class InvalidationHandler {
String[] rectangleArray = payload.split(";"); String[] rectangleArray = payload.split(";");
for (String coordinates : rectangleArray) { for (String coordinates : rectangleArray) {
RectF rectangle = convertPayloadToRectangle(payload); RectF rectangle = convertPayloadToRectangle(coordinates);
rectangles.add(rectangle); if (rectangle != null) {
rectangles.add(rectangle);
}
} }
return rectangles; return rectangles;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment