summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-03-04 19:05:36 +0900
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-03-09 10:16:13 +0100
commit73732482562c56953df190078c67cb8820c6a23f (patch)
treeec09a8f7f3cdf8c281662c7a8d3d6fd9100e4422 /android
parent706691bd976476bfe33260cb6141b2e1d359291a (diff)
android: add and handle show/hide cursor message from LOK
Change-Id: I42c0971b10e3926f8fca989884da089bec8d59d4
Diffstat (limited to 'android')
-rw-r--r--android/Bootstrap/src/org/libreoffice/kit/Document.java1
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java17
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java7
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java21
4 files changed, 39 insertions, 7 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/kit/Document.java b/android/Bootstrap/src/org/libreoffice/kit/Document.java
index 7c996e5c4414..8c20f7086829 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/Document.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/Document.java
@@ -39,6 +39,7 @@ public class Document {
public static final int CALLBACK_TEXT_SELECTION = 2;
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;
/**
* Text selection types
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
index 5abdcb14a2be..e0899161d614 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
@@ -50,6 +50,9 @@ public class InvalidationHandler {
case Document.CALLBACK_TEXT_SELECTION_END:
invalidateSelectionEnd(payload);
break;
+ case Document.CALLBACK_CURSOR_VISIBLE:
+ cursorVisibility(payload);
+ break;
}
}
@@ -206,6 +209,20 @@ public class InvalidationHandler {
}
}
+ /**
+ * Handles the cursor visibility message
+ * @param payload
+ */
+ private 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();
+ }
+ }
+
public enum OverlayState {
NONE,
CURSOR,
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java
index 92080e9592ce..0fa3764cdbd9 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java
@@ -44,7 +44,7 @@ public class TextCursorLayer extends Layer {
LOKitShell.getMainHandler().post(new Runnable() {
public void run() {
- mCursorView.repositionWithViewport(context.viewport.left, context.viewport.top, context.zoomFactor);
+ mCursorView.repositionWithViewport(mViewLeft, mViewTop, mViewZoom);
}
});
}
@@ -52,8 +52,6 @@ public class TextCursorLayer extends Layer {
public void showCursor() {
LOKitShell.getMainHandler().post(new Runnable() {
public void run() {
- mCursorView.setVisibility(View.VISIBLE);
-
mViewLeft = 0.0f;
mViewTop = 0.0f;
mViewZoom = 0.0f;
@@ -61,6 +59,7 @@ public class TextCursorLayer extends Layer {
if (layerView != null) {
layerView.addLayer(TextCursorLayer.this);
}
+ mCursorView.showCursor();
}
});
}
@@ -68,7 +67,7 @@ public class TextCursorLayer extends Layer {
public void hideCursor() {
LOKitShell.getMainHandler().post(new Runnable() {
public void run() {
- mCursorView.setVisibility(View.GONE);
+ mCursorView.hideCursor();
}
});
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java
index 1aa24ce41397..2949fd8f1f0a 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java
@@ -35,6 +35,8 @@ public class TextCursorView extends View {
private Paint mCursorPaint = new Paint();
private Paint mSelectionPaint = new Paint();
+ private boolean mCursorVisible = true;
+
public TextCursorView(Context context) {
super(context);
initialize();
@@ -55,7 +57,6 @@ public class TextCursorView extends View {
postDelayed(cursorAnimation, 500);
mCursorPaint.setColor(Color.BLACK);
- mCursorPaint.setAlpha(0);
mSelectionPaint.setColor(Color.BLUE);
mSelectionPaint.setAlpha(50);
@@ -114,9 +115,23 @@ public class TextCursorView extends View {
private Runnable cursorAnimation = new Runnable() {
public void run() {
- mCursorPaint.setAlpha(mCursorPaint.getAlpha() == 0 ? 0xFF : 0);
- invalidate();
+ if (mCursorVisible) {
+ mCursorPaint.setAlpha(mCursorPaint.getAlpha() == 0 ? 0xFF : 0);
+ invalidate();
+ }
postDelayed(cursorAnimation, 500);
}
};
+
+ public void showCursor() {
+ mCursorVisible = true;
+ mCursorPaint.setAlpha(0xFF);
+ invalidate();
+ }
+
+ public void hideCursor() {
+ mCursorVisible = false;
+ mCursorPaint.setAlpha(0);
+ invalidate();
+ }
} \ No newline at end of file