summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-02-26 15:43:42 +0900
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-03-02 08:50:56 +0100
commit5b4fc00b12f71926623f0f6e3f7c355ee627f42c (patch)
tree9d2771a38fb502f9360c0c50e7c540e2ac482f10
parentc1299f0cab7eaa7fae2b445fca3b9c808c5030cd (diff)
android: add selection support to TextCursorView{Layer}
TextCursorView is a overlay view on top of document view which is used to draw the cursor (and blink it too). This also adds selection rectangles drawing to the same view so both can be drawn at the same time. Change-Id: I3ce034d90597bac4569f04ac903a5443c28cb38e
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java12
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java81
2 files changed, 64 insertions, 29 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java
index 1e6f167d7d7c..92080e9592ce 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java
@@ -9,6 +9,8 @@ import org.mozilla.gecko.gfx.Layer;
import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.util.FloatUtils;
+import java.util.List;
+
/**
* The TextCursorLayer is a layer which is responsible for showing the cursor and
* controls its position, height and visibility.
@@ -74,7 +76,15 @@ public class TextCursorLayer extends Layer {
public void positionCursor(final RectF position) {
LOKitShell.getMainHandler().post(new Runnable() {
public void run() {
- mCursorView.changePosition(position);
+ mCursorView.changeCursorPosition(position);
+ }
+ });
+ }
+
+ public void changeSelections(final List<RectF> selections) {
+ LOKitShell.getMainHandler().post(new Runnable() {
+ public void run() {
+ mCursorView.changeSelections(selections);
}
});
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java
index 93600c639ea8..1aa24ce41397 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java
@@ -15,47 +15,58 @@ import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.gfx.RectUtils;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Text cursor view responsible to show the cursor drawable on the screen.
*/
public class TextCursorView extends View {
private static final String LOGTAG = TextCursorView.class.getSimpleName();
+ private static final float CURSOR_WIDTH = 2f;
- private boolean mCursorAnimationEnabled = false;
+ private boolean mInitialized = false;
private RectF mCursorPosition = new RectF();
- private PointF mCursorScaledPosition = new PointF();
-
- private float mCursorHeight = 0f;
- private float mCursorWidth = 2f;
-
+ private RectF mCursorScaledPosition = new RectF();
private int mCursorAlpha = 0;
+ private List<RectF> mSelections = new ArrayList<RectF>();
+ private List<RectF> mScaledSelections = new ArrayList<RectF>();
+ private Paint mCursorPaint = new Paint();
+ private Paint mSelectionPaint = new Paint();
+
public TextCursorView(Context context) {
super(context);
- startCursorAnimation();
+ initialize();
}
public TextCursorView(Context context, AttributeSet attrs) {
super(context, attrs);
- startCursorAnimation();
+ initialize();
}
public TextCursorView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
- startCursorAnimation();
+ initialize();
}
- private void startCursorAnimation() {
- if (!mCursorAnimationEnabled) {
- mCursorAnimationEnabled = true;
+ private void initialize() {
+ if (!mInitialized) {
postDelayed(cursorAnimation, 500);
+
+ mCursorPaint.setColor(Color.BLACK);
+ mCursorPaint.setAlpha(0);
+ mSelectionPaint.setColor(Color.BLUE);
+ mSelectionPaint.setAlpha(50);
+
+ mInitialized = true;
}
}
- public void changePosition(RectF position) {
+ public void changeCursorPosition(RectF position) {
LayerView layerView = LOKitShell.getLayerView();
if (layerView == null) {
- Log.e(LOGTAG, "Can't position handle because layerView is null");
+ Log.e(LOGTAG, "Can't position cursor because layerView is null");
return;
}
@@ -64,32 +75,46 @@ public class TextCursorView extends View {
repositionWithViewport(metrics.viewportRectLeft, metrics.viewportRectTop, metrics.zoomFactor);
}
- public void repositionWithViewport(float x, float y, float zoom) {
- RectF scaledRectangle = RectUtils.scale(mCursorPosition, zoom);
+ public void changeSelections(List<RectF> selectionRects) {
+ LayerView layerView = LOKitShell.getLayerView();
+ if (layerView == null) {
+ Log.e(LOGTAG, "Can't position selections because layerView is null");
+ return;
+ }
+
+ mSelections = selectionRects;
- mCursorScaledPosition = new PointF(scaledRectangle.left - x, scaledRectangle.top - y);
- mCursorHeight = scaledRectangle.height();
+ ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
+ repositionWithViewport(metrics.viewportRectLeft, metrics.viewportRectTop, metrics.zoomFactor);
+ }
+ public void repositionWithViewport(float x, float y, float zoom) {
+ mCursorScaledPosition = RectUtils.scale(mCursorPosition, zoom);
+ mCursorScaledPosition.offset(-x, -y);
+ mCursorScaledPosition.right = mCursorScaledPosition.left + CURSOR_WIDTH;
+
+ mScaledSelections.clear();
+ for (RectF selection : mSelections) {
+ RectF scaledSelection = RectUtils.scale(selection, zoom);
+ scaledSelection.offset(-x, -y);
+ mScaledSelections.add(scaledSelection);
+ }
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
- Paint paint = new Paint();
- paint.setColor(Color.BLACK);
- paint.setAlpha(mCursorAlpha);
- RectF cursorRect = new RectF(
- mCursorScaledPosition.x,
- mCursorScaledPosition.y,
- mCursorScaledPosition.x + mCursorWidth,
- mCursorScaledPosition.y + mCursorHeight);
- canvas.drawRect(cursorRect, paint);
+ canvas.drawRect(mCursorScaledPosition, mCursorPaint);
+
+ for (RectF selection : mScaledSelections) {
+ canvas.drawRect(selection, mSelectionPaint);
+ }
}
private Runnable cursorAnimation = new Runnable() {
public void run() {
- mCursorAlpha = mCursorAlpha == 0 ? 0xFF : 0;
+ mCursorPaint.setAlpha(mCursorPaint.getAlpha() == 0 ? 0xFF : 0);
invalidate();
postDelayed(cursorAnimation, 500);
}