[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 6 commits - android/Bootstrap android/experimental
Tomaž Vajngerl
tomaz.vajngerl at collabora.co.uk
Sun Mar 8 22:48:29 PDT 2015
android/Bootstrap/src/org/libreoffice/kit/Document.java | 2
android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java | 205 +++++++---
android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java | 11
android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java | 38 -
android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java | 20
android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java | 27 -
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java | 4
7 files changed, 197 insertions(+), 110 deletions(-)
New commits:
commit f0ce530155064c26f293df5ca8f4f8c8dc71ea11
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Fri Mar 6 22:13:44 2015 +0900
android: add CALLBACK_GRAPHIC_SELECTION to LOK facade
Change-Id: I105f8811f810b393cac8518b42d77f8bd4d0c763
diff --git a/android/Bootstrap/src/org/libreoffice/kit/Document.java b/android/Bootstrap/src/org/libreoffice/kit/Document.java
index 56d92b0..07d4329 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/Document.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/Document.java
@@ -40,7 +40,7 @@ public class Document {
public static final int CALLBACK_TEXT_SELECTION_START = 3;
public static final int CALLBACK_TEXT_SELECTION_END = 4;
public static final int CALLBACK_CURSOR_VISIBLE = 5;
- // LOK_CALLBACK_GRAPHIC_SELECTION = 6
+ public static final int CALLBACK_GRAPHIC_SELECTION = 6;
public static final int CALLBACK_HYPERLINK_CLICKED = 7;
/**
commit 47c64f0ce67dd62a59203b0ebe0210d26274411b
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Fri Mar 6 22:13:14 2015 +0900
android: fix rebase import problem
Change-Id: Id668dc509dc3fa02e9a248716050c16a8cf91419
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
index f50b62a..9419782 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
@@ -1,6 +1,8 @@
package org.libreoffice;
+import android.content.Intent;
import android.graphics.RectF;
+import android.net.Uri;
import android.util.Log;
import org.libreoffice.kit.Document;
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index ae14cc6..3a24120 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -5,8 +5,6 @@ import android.graphics.PointF;
import android.graphics.RectF;
import android.util.Log;
import android.view.KeyEvent;
-import android.net.Uri;
-import android.content.Intent;
import org.libreoffice.kit.DirectBufferAllocator;
import org.libreoffice.kit.Document;
commit b8acb23fc80e1ca8923cd773c97500ee1c99710f
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Fri Mar 6 21:56:49 2015 +0900
android: do all overlay state tracking in InvalidationHandler
Do all overlay changes and state tracking in InvalidationHandler
where we get invalidation and selection / cursor messages from
LibreOfficeKit.
Change-Id: I87ccdefedc01e8bd54666b694a9a429a1fc6af76
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
index 478ab2d..f50b62a 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
@@ -18,8 +18,9 @@ public class InvalidationHandler implements Document.MessageCallback {
private static String LOGTAG = InvalidationHandler.class.getSimpleName();
private TileProvider mTileProvider;
- private TextCursorLayer mTextCursorLayer;
- private TextSelection mTextSelection;
+ private final TextCursorLayer mTextCursorLayer;
+ private final TextSelection mTextSelection;
+
private OverlayState mState;
public InvalidationHandler(LibreOfficeMainActivity mainActivity) {
@@ -52,13 +53,13 @@ public class InvalidationHandler implements Document.MessageCallback {
invalidateCursor(payload);
break;
case Document.CALLBACK_TEXT_SELECTION:
- invalidateSelection(payload);
+ textSelection(payload);
break;
case Document.CALLBACK_TEXT_SELECTION_START:
- invalidateSelectionStart(payload);
+ textSelectionStart(payload);
break;
case Document.CALLBACK_TEXT_SELECTION_END:
- invalidateSelectionEnd(payload);
+ textSelectionEnd(payload);
break;
case Document.CALLBACK_CURSOR_VISIBLE:
cursorVisibility(payload);
@@ -75,14 +76,6 @@ public class InvalidationHandler implements Document.MessageCallback {
}
}
- public OverlayState getOverlayState() {
- return mState;
- }
-
- public void setOverlayState(OverlayState state) {
- this.mState = state;
- }
-
/**
* Parses the payload text with rectangle coordinates and converts to rectangle in pixel coordinates
*
@@ -90,7 +83,7 @@ public class InvalidationHandler implements Document.MessageCallback {
* @return rectangle in pixel coordinates
*/
private RectF convertPayloadToRectangle(String payload) {
- String payloadWithoutWhitespace = payload.replaceAll("\\s",""); // remove all whitespace from the string
+ String payloadWithoutWhitespace = payload.replaceAll("\\s", ""); // remove all whitespace from the string
if (payloadWithoutWhitespace.isEmpty() || payloadWithoutWhitespace.equals("EMPTY")) {
return null;
@@ -157,72 +150,57 @@ public class InvalidationHandler implements Document.MessageCallback {
*
* @param payload
*/
- private void invalidateCursor(String payload) {
+ private synchronized void invalidateCursor(String payload) {
RectF cursorRectangle = convertPayloadToRectangle(payload);
if (cursorRectangle != null) {
- if (mState == OverlayState.CURSOR) {
- mTextSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, cursorRectangle);
- mTextSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
- mTextSelection.hideHandle(TextSelectionHandle.HandleType.START);
- mTextSelection.hideHandle(TextSelectionHandle.HandleType.END);
- }
+ mTextSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, cursorRectangle);
mTextCursorLayer.positionCursor(cursorRectangle);
- mTextCursorLayer.showCursor();
+
+ if (mState == OverlayState.TRANSITION_TO_CURSOR) {
+ changeStateTo(OverlayState.CURSOR);
+ };
}
}
/**
- * Handles the selection start invalidation message
+ * Handles the text selection start message
*
* @param payload
*/
- private void invalidateSelectionStart(String payload) {
- if (mState == OverlayState.NONE) {
- return;
- }
- RectF selectionRectangle = convertPayloadToRectangle(payload);
- if (selectionRectangle != null) {
- mTextSelection.positionHandle(TextSelectionHandle.HandleType.START, selectionRectangle);
- mTextSelection.showHandle(TextSelectionHandle.HandleType.START);
- mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
- mState = OverlayState.SELECTION;
+ private synchronized void textSelectionStart(String payload) {
+ RectF selectionRect = convertPayloadToRectangle(payload);
+ if (selectionRect != null) {
+ mTextSelection.positionHandle(TextSelectionHandle.HandleType.START, selectionRect);
}
}
/**
- * Handles the selection end invalidation message
+ * Handles the text selection end message
*
* @param payload
*/
- private void invalidateSelectionEnd(String payload) {
- if (mState == OverlayState.NONE) {
- return;
- }
+ private synchronized void textSelectionEnd(String payload) {
RectF selectionRect = convertPayloadToRectangle(payload);
if (selectionRect != null) {
mTextSelection.positionHandle(TextSelectionHandle.HandleType.END, selectionRect);
- mTextSelection.showHandle(TextSelectionHandle.HandleType.END);
- mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
- mState = OverlayState.SELECTION;
}
}
/**
- * Handles the selection invalidation message
+ * Handles the text selection message
*
* @param payload
*/
- private void invalidateSelection(String payload) {
- if (mState == OverlayState.NONE) {
- return;
- }
- if (payload.isEmpty()) {
- mState = OverlayState.CURSOR;
- mTextSelection.hideHandle(TextSelectionHandle.HandleType.START);
- mTextSelection.hideHandle(TextSelectionHandle.HandleType.END);
+ private synchronized void textSelection(String payload) {
+ if (payload.isEmpty() || payload.equals("EMPTY")) {
+ if (mState == OverlayState.SELECTION) {
+ changeStateTo(OverlayState.TRANSITION_TO_CURSOR);
+ }
mTextCursorLayer.changeSelections(Collections.EMPTY_LIST);
} else {
- mState = OverlayState.SELECTION;
+ if (mState == OverlayState.TRANSITION_TO_SELECTION) {
+ changeStateTo(OverlayState.SELECTION);
+ }
List<RectF> rects = convertPayloadToRectangles(payload);
mTextCursorLayer.changeSelections(rects);
}
@@ -230,22 +208,110 @@ public class InvalidationHandler implements Document.MessageCallback {
/**
* Handles the cursor visibility message
+ *
* @param payload
*/
- private void cursorVisibility(String payload) {
+ private synchronized void cursorVisibility(String payload) {
if (payload.equals("true")) {
- mTextSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
mTextCursorLayer.showCursor();
} else if (payload.equals("false")) {
- mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
mTextCursorLayer.hideCursor();
- LibreOfficeMainActivity.mAppContext.hideSoftKeyboard();
}
}
+ public synchronized void changeStateTo(OverlayState next) {
+ changeState(mState, next);
+ }
+
+ private synchronized void changeState(OverlayState previous, OverlayState next) {
+ if (isInvalidTransition(previous, next)) {
+ return;
+ }
+
+ Log.i(LOGTAG, "State change: " + previous.name() + " -> " + next.name());
+
+ mState = next;
+
+ switch (next) {
+ case CURSOR:
+ handleCursorState(previous);
+ break;
+ case TRANSITION_TO_CURSOR:
+ handleTransitionToCursorState(previous);
+ break;
+ case SELECTION:
+ handleSelectionState(previous);
+ break;
+ case TRANSITION_TO_SELECTION:
+ handleTransitionToSelectionState(previous);
+ break;
+ case NONE:
+ handleNoneState(previous);
+ break;
+ }
+ }
+
+ private void handleNoneState(OverlayState previous) {
+ if (previous == OverlayState.NONE) {
+ return;
+ }
+ // Just hide everything
+ if (mTileProvider != null) {
+ mTileProvider.setTextSelectionReset();
+ }
+ mTextSelection.hideHandle(TextSelectionHandle.HandleType.START);
+ mTextSelection.hideHandle(TextSelectionHandle.HandleType.END);
+ mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
+ mTextCursorLayer.hideSelections();
+ mTextCursorLayer.hideCursor();
+ LibreOfficeMainActivity.mAppContext.hideSoftKeyboard();
+ }
+
+ private void handleTransitionToSelectionState(OverlayState previous) {
+ if (previous == OverlayState.CURSOR) {
+ mTextSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
+ }
+ }
+
+ private void handleSelectionState(OverlayState previous) {
+ if (previous == OverlayState.TRANSITION_TO_SELECTION) {
+ mTextSelection.showHandle(TextSelectionHandle.HandleType.START);
+ mTextSelection.showHandle(TextSelectionHandle.HandleType.END);
+ mTextCursorLayer.showSelections();
+ }
+ }
+
+ private void handleCursorState(OverlayState previous) {
+ if (previous == OverlayState.CURSOR) {
+ LibreOfficeMainActivity.mAppContext.showSoftKeyboard();
+ } else if (previous == OverlayState.TRANSITION_TO_CURSOR) {
+ LibreOfficeMainActivity.mAppContext.showSoftKeyboard();
+ mTextSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
+ mTextCursorLayer.showCursor();
+ }
+ }
+
+ private void handleTransitionToCursorState(OverlayState previous) {
+ if (previous == OverlayState.SELECTION) {
+ if (mTileProvider != null) {
+ mTileProvider.setTextSelectionReset();
+ }
+ mTextSelection.hideHandle(TextSelectionHandle.HandleType.START);
+ mTextSelection.hideHandle(TextSelectionHandle.HandleType.END);
+ mTextCursorLayer.hideSelections();
+ }
+ }
+
+ private boolean isInvalidTransition(OverlayState previous, OverlayState next) {
+ return (previous == OverlayState.CURSOR && next == OverlayState.TRANSITION_TO_CURSOR)
+ || (previous == OverlayState.SELECTION && next == OverlayState.TRANSITION_TO_SELECTION);
+ }
+
public enum OverlayState {
NONE,
CURSOR,
- SELECTION
+ TRANSITION_TO_CURSOR,
+ SELECTION,
+ TRANSITION_TO_SELECTION
}
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index e3c7c2c..252f64e 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -220,8 +220,6 @@ public class LOKitThread extends Thread {
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) {
@@ -263,19 +261,15 @@ public class LOKitThread extends Thread {
return;
}
if (touchType.equals("LongPress")) {
- mInvalidationHandler.setOverlayState(InvalidationHandler.OverlayState.SELECTION);
+ mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION_TO_SELECTION);
mTileProvider.mouseButtonDown(documentCoordinate, 1);
mTileProvider.mouseButtonUp(documentCoordinate, 1);
mTileProvider.mouseButtonDown(documentCoordinate, 2);
mTileProvider.mouseButtonUp(documentCoordinate, 2);
} else { // "SingleTap"
- LibreOfficeMainActivity.mAppContext.showSoftKeyboard();
- mInvalidationHandler.setOverlayState(InvalidationHandler.OverlayState.CURSOR);
+ mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION_TO_CURSOR);
mTileProvider.mouseButtonDown(documentCoordinate, 1);
mTileProvider.mouseButtonUp(documentCoordinate, 1);
- if (mInvalidationHandler.getOverlayState() == InvalidationHandler.OverlayState.SELECTION) {
- mTileProvider.setTextSelectionReset();
- }
}
}
commit aef18d46a04c4a651ed59cd84ba2e395c122fcbe
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Fri Mar 6 21:52:42 2015 +0900
android: handle callbacks directly in InvalidationHandler
Change-Id: Ic4ceaadcf251f7257001f8043161ce15898d7239
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
index 7bc5824..478ab2d 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
@@ -14,9 +14,10 @@ import java.util.List;
/**
* Parses (interprets) and handles invalidation messages from LibreOffice.
*/
-public class InvalidationHandler {
+public class InvalidationHandler implements Document.MessageCallback {
private static String LOGTAG = InvalidationHandler.class.getSimpleName();
+ private TileProvider mTileProvider;
private TextCursorLayer mTextCursorLayer;
private TextSelection mTextSelection;
private OverlayState mState;
@@ -24,16 +25,25 @@ public class InvalidationHandler {
public InvalidationHandler(LibreOfficeMainActivity mainActivity) {
mTextCursorLayer = mainActivity.getTextCursorLayer();
mTextSelection = mainActivity.getTextSelection();
+ mTileProvider = null;
mState = OverlayState.NONE;
}
+ public void setTileProvider(TileProvider tileProvider) {
+ mTileProvider = tileProvider;
+ }
+
/**
- * Processes invalidation message
+ * Processes callback message
*
* @param messageID - ID of the message
* @param payload - additional invalidation message payload
*/
- public void processMessage(int messageID, String payload) {
+ @Override
+ public void messageRetrieved(int messageID, String payload) {
+ if (!LOKitShell.isEditingEnabled()) {
+ return;
+ }
switch (messageID) {
case Document.CALLBACK_INVALIDATE_TILES:
invalidateTiles(payload);
@@ -53,6 +63,15 @@ public class InvalidationHandler {
case Document.CALLBACK_CURSOR_VISIBLE:
cursorVisibility(payload);
break;
+ case Document.CALLBACK_HYPERLINK_CLICKED:
+ if (!payload.startsWith("http://") && !payload.startsWith("https://")) {
+ payload = "http://" + payload;
+ }
+
+ Intent urlIntent = new Intent(Intent.ACTION_VIEW);
+ urlIntent.setData(Uri.parse(payload));
+ LibreOfficeMainActivity.mAppContext.startActivity(urlIntent);
+ break;
}
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index 78e18d3..e3c7c2c 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -159,6 +159,7 @@ public class LOKitThread extends Thread {
mInvalidationHandler = new InvalidationHandler(LibreOfficeMainActivity.mAppContext);
mTileProvider = TileProviderFactory.create(mLayerClient, mInvalidationHandler, filename);
+ mInvalidationHandler.setTileProvider(mTileProvider);
if (mTileProvider.isReady()) {
LOKitShell.showProgressSpinner();
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index 179c6ff..ae14cc6 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -28,7 +28,7 @@ import java.nio.ByteBuffer;
/**
* LOKit implementation of TileProvider.
*/
-public class LOKitTileProvider implements TileProvider, Document.MessageCallback {
+public class LOKitTileProvider implements TileProvider {
private static final String LOGTAG = LOKitTileProvider.class.getSimpleName();
private static int TILE_SIZE = 256;
private final GeckoLayerClient mLayerClient;
@@ -43,13 +43,13 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
private float mWidthTwip;
private float mHeightTwip;
- private InvalidationHandler mInvalidationHandler;
+ private Document.MessageCallback mMessageCallback;
private long objectCreationTime = System.currentTimeMillis();
- public LOKitTileProvider(GeckoLayerClient layerClient, InvalidationHandler invalidationHandler, String input) {
+ public LOKitTileProvider(GeckoLayerClient layerClient, Document.MessageCallback messageCallback, String input) {
mLayerClient = layerClient;
- mInvalidationHandler = invalidationHandler;
+ mMessageCallback = messageCallback;
mDPI = (float) LOKitShell.getDpi();
mTileWidth = pixelToTwip(TILE_SIZE, mDPI);
mTileHeight = pixelToTwip(TILE_SIZE, mDPI);
@@ -89,7 +89,7 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
}
public void postLoad() {
- mDocument.setMessageCallback(this);
+ mDocument.setMessageCallback(mMessageCallback);
int parts = mDocument.getParts();
Log.i(LOGTAG, "Document parts: " + parts);
@@ -407,32 +407,6 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
return mDocument.getPart();
}
-
- /**
- * Process the retrieved messages from LOK
- */
- @Override
- public void messageRetrieved(int messageID, String payload) {
- /**
- * Handles messages that do not require entering editing mode.
- */
- switch (messageID) {
- case Document.CALLBACK_HYPERLINK_CLICKED:
- if (!payload.startsWith("http://") &&
- !payload.startsWith("https://"))
- payload = "http://" + payload;
-
- Intent url_intent = new Intent(Intent.ACTION_VIEW);
- url_intent.setData(Uri.parse(payload));
- LibreOfficeMainActivity.mAppContext.startActivity(url_intent);
- return;
- }
-
- if (!LOKitShell.isEditingEnabled()) {
- return;
- }
- mInvalidationHandler.processMessage(messageID, payload);
- }
}
// vim:set shiftwidth=4 softtabstop=4 expandtab:
commit 0351e84dee8b3e00e0bac9865e286472137fc1d2
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Fri Mar 6 18:56:13 2015 +0900
android: minor code clean-up in TextSelectionHandle
Change-Id: I5ad3c0f853efe1cf314f3c1afd77cecfdfc59134
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 36472a5..1a7ac97 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/TextSelectionHandle.java
@@ -52,8 +52,8 @@ public class TextSelectionHandle extends ImageView implements View.OnTouchListen
super(context, attrs);
setOnTouchListener(this);
- TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextSelectionHandle);
- int handleType = a.getInt(R.styleable.TextSelectionHandle_handleType, 0x01);
+ TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.TextSelectionHandle);
+ int handleType = array.getInt(R.styleable.TextSelectionHandle_handleType, 0x01);
switch (handleType) {
case 1:
commit 4dedfbd56c827c4166c54d26a35f2b17b827da80
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Fri Mar 6 18:54:27 2015 +0900
android: support to make selections visible/invisible
Change-Id: Iaebf3e5a2f0c11efa7110b7062ecfc3ae38e0e64
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java
index 0fa3764..ce17c68 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java
@@ -80,6 +80,26 @@ public class TextCursorLayer extends Layer {
});
}
+ public void showSelections() {
+ LOKitShell.getMainHandler().post(new Runnable() {
+ public void run() {
+ LayerView layerView = LOKitShell.getLayerView();
+ if (layerView != null) {
+ layerView.addLayer(TextCursorLayer.this);
+ }
+ mCursorView.showSelections();
+ }
+ });
+ }
+
+ public void hideSelections() {
+ LOKitShell.getMainHandler().post(new Runnable() {
+ public void run() {
+ mCursorView.hideSelections();
+ }
+ });
+ }
+
public void changeSelections(final List<RectF> selections) {
LOKitShell.getMainHandler().post(new Runnable() {
public void run() {
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java
index f1e9038..685e8c3 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java
@@ -36,6 +36,7 @@ public class TextCursorView extends View {
private Paint mSelectionPaint = new Paint();
private boolean mCursorVisible;
+ private boolean mSelectionsVisible;
public TextCursorView(Context context) {
super(context);
@@ -57,13 +58,14 @@ public class TextCursorView extends View {
postDelayed(cursorAnimation, 500);
mCursorPaint.setColor(Color.BLACK);
- mCursorPaint.setAlpha(0);
+ mCursorPaint.setAlpha(0xFF);
mCursorVisible = false;
mSelectionPaint.setColor(Color.BLUE);
mSelectionPaint.setAlpha(50);
+ mSelectionsVisible = false;
mInitialized = true;
}
}
@@ -110,10 +112,13 @@ public class TextCursorView extends View {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
- canvas.drawRect(mCursorScaledPosition, mCursorPaint);
-
- for (RectF selection : mScaledSelections) {
- canvas.drawRect(selection, mSelectionPaint);
+ if (mCursorVisible) {
+ canvas.drawRect(mCursorScaledPosition, mCursorPaint);
+ }
+ if (mSelectionsVisible) {
+ for (RectF selection : mScaledSelections) {
+ canvas.drawRect(selection, mSelectionPaint);
+ }
}
}
@@ -129,13 +134,21 @@ public class TextCursorView extends View {
public void showCursor() {
mCursorVisible = true;
- mCursorPaint.setAlpha(0xFF);
invalidate();
}
public void hideCursor() {
mCursorVisible = false;
- mCursorPaint.setAlpha(0);
+ invalidate();
+ }
+
+ public void showSelections() {
+ mSelectionsVisible = true;
+ invalidate();
+ }
+
+ public void hideSelections() {
+ mSelectionsVisible = false;
invalidate();
}
}
\ No newline at end of file
More information about the Libreoffice-commits
mailing list