summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToma┼ż Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-04-08 12:18:44 +0900
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-04-13 09:07:00 +0200
commit6d9af889984cf047f4724cc6087b4b4cfda2a6c3 (patch)
tree075a5d0dd643ea2314e42062f3e97177eb4e876a
parent4e0d2fcdda3f639a05118b25ef99d8a4848302ce (diff)
android: add Cursor class for drawing the cursor to the canvas
Change-Id: I5d8191ffb3d3dd3d3ab11c757a3b7d5dc3fb2e82
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/Cursor.java38
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java42
2 files changed, 57 insertions, 23 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/Cursor.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/Cursor.java
new file mode 100644
index 000000000000..bdb8e091454c
--- /dev/null
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/Cursor.java
@@ -0,0 +1,38 @@
+package org.libreoffice.canvas;
+
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.RectF;
+
+public class Cursor extends CommonCanvasElement {
+ private static final float CURSOR_WIDTH = 2f;
+ private final Paint mCursorPaint = new Paint();
+ public RectF mPosition = new RectF();
+ public RectF mScaledPosition = new RectF();
+ public int mAlpha = 0;
+
+ public Cursor() {
+ mCursorPaint.setColor(Color.BLACK);
+ mCursorPaint.setAlpha(0xFF);
+ }
+
+ @Override
+ public boolean onHitTest(float x, float y) {
+ return false;
+ }
+
+ @Override
+ public void onDraw(Canvas canvas) {
+ canvas.drawRect(mScaledPosition, mCursorPaint);
+ }
+
+ public void reposition(RectF rect) {
+ mScaledPosition = rect;
+ mScaledPosition.right = mScaledPosition.left + CURSOR_WIDTH;
+ }
+
+ public void cycleAlpha() {
+ mCursorPaint.setAlpha(mCursorPaint.getAlpha() == 0 ? 0xFF : 0);
+ }
+}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java
index 44d0d5100e06..4e52f6e08eda 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/overlay/TextCursorView.java
@@ -23,6 +23,7 @@ import android.view.View;
import org.libreoffice.LOKitShell;
import org.libreoffice.R;
+import org.libreoffice.canvas.Cursor;
import org.libreoffice.canvas.GraphicSelection;
import org.libreoffice.canvas.SelectionHandle;
import org.libreoffice.canvas.SelectionHandleEnd;
@@ -40,15 +41,10 @@ import java.util.List;
*/
public class TextCursorView extends View implements View.OnTouchListener {
private static final String LOGTAG = TextCursorView.class.getSimpleName();
- private static final float CURSOR_WIDTH = 2f;
+
private static final int CURSOR_BLINK_TIME = 500;
private boolean mInitialized = false;
- private RectF mCursorPosition = new RectF();
- private RectF mCursorScaledPosition = new RectF();
- private Paint mCursorPaint = new Paint();
- private int mCursorAlpha = 0;
- private boolean mCursorVisible;
private List<RectF> mSelections = new ArrayList<RectF>();
private List<RectF> mScaledSelections = new ArrayList<RectF>();
@@ -65,6 +61,8 @@ public class TextCursorView extends View implements View.OnTouchListener {
private SelectionHandle mHandleStart;
private SelectionHandle mHandleEnd;
+ private Cursor mCursor;
+
private SelectionHandle mDragHandle = null;
public TextCursorView(Context context) {
@@ -87,9 +85,8 @@ public class TextCursorView extends View implements View.OnTouchListener {
setOnTouchListener(this);
mLayerView = layerView;
- mCursorPaint.setColor(Color.BLACK);
- mCursorPaint.setAlpha(0xFF);
- mCursorVisible = false;
+ mCursor = new Cursor();
+ mCursor.setVisible(false);
mSelectionPaint.setColor(Color.BLUE);
mSelectionPaint.setAlpha(50);
@@ -113,10 +110,10 @@ public class TextCursorView extends View implements View.OnTouchListener {
* @param position - new position of the cursor
*/
public void changeCursorPosition(RectF position) {
- if (RectUtils.fuzzyEquals(mCursorPosition, position)) {
+ if (RectUtils.fuzzyEquals(mCursor.mPosition, position)) {
return;
}
- mCursorPosition = position;
+ mCursor.mPosition = position;
ImmutableViewportMetrics metrics = mLayerView.getViewportMetrics();
repositionWithViewport(metrics.viewportRectLeft, metrics.viewportRectTop, metrics.zoomFactor);
@@ -149,10 +146,10 @@ public class TextCursorView extends View implements View.OnTouchListener {
}
public void repositionWithViewport(float x, float y, float zoom) {
- mCursorScaledPosition = convertToScreen(mCursorPosition, x, y, zoom);
- mCursorScaledPosition.right = mCursorScaledPosition.left + CURSOR_WIDTH;
+ RectF rect = convertToScreen(mCursor.mPosition, x, y, zoom);
+ mCursor.reposition(rect);
- RectF rect = convertToScreen(mHandleMiddle.mDocumentPosition, x, y, zoom);
+ rect = convertToScreen(mHandleMiddle.mDocumentPosition, x, y, zoom);
mHandleMiddle.reposition(rect.left, rect.bottom);
rect = convertToScreen(mHandleStart.mDocumentPosition, x, y, zoom);
@@ -189,9 +186,8 @@ public class TextCursorView extends View implements View.OnTouchListener {
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
- if (mCursorVisible) {
- canvas.drawRect(mCursorScaledPosition, mCursorPaint);
- }
+ mCursor.draw(canvas);
+
mHandleMiddle.draw(canvas);
mHandleStart.draw(canvas);
mHandleEnd.draw(canvas);
@@ -211,8 +207,8 @@ public class TextCursorView extends View implements View.OnTouchListener {
*/
private Runnable cursorAnimation = new Runnable() {
public void run() {
- if (mCursorVisible) {
- mCursorPaint.setAlpha(mCursorPaint.getAlpha() == 0 ? 0xFF : 0);
+ if (mCursor.isVisible()) {
+ mCursor.cycleAlpha();
invalidate();
}
postDelayed(cursorAnimation, CURSOR_BLINK_TIME);
@@ -223,8 +219,8 @@ public class TextCursorView extends View implements View.OnTouchListener {
* Show the cursor on the view.
*/
public void showCursor() {
- if (!mCursorVisible) {
- mCursorVisible = true;
+ if (!mCursor.isVisible()) {
+ mCursor.setVisible(true);
invalidate();
}
}
@@ -233,8 +229,8 @@ public class TextCursorView extends View implements View.OnTouchListener {
* Hide the cursor.
*/
public void hideCursor() {
- if (mCursorVisible) {
- mCursorVisible = false;
+ if (mCursor.isVisible()) {
+ mCursor.setVisible(false);
invalidate();
}
}