diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-03-10 17:24:13 +0900 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-03-16 09:38:02 +0100 |
commit | 003a62fb640bbce26c1f688e6fef2c074ee0fb37 (patch) | |
tree | 2700077fc8fc92b0944feb17533a118404e6faba /android | |
parent | a14d29259e552d35722b42a8cbf73e97339ba745 (diff) |
android: add graphic selection to TextCursorLayer{View}
Change-Id: I13d26dd8b38d0b6817f3d0dbcb8a063fef559c2a
Diffstat (limited to 'android')
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java | 24 | ||||
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java | 64 |
2 files changed, 83 insertions, 5 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java index ce17c68eb386..a2b1abc1e188 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorLayer.java @@ -107,4 +107,28 @@ public class TextCursorLayer extends Layer { } }); } + + public void showGraphicSelection() { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.showGraphicSelection(); + } + }); + } + + public void hideGraphicSelection() { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.hideGraphicSelection(); + } + }); + } + + public void changeGraphicSelection(final RectF rectangle) { + LOKitShell.getMainHandler().post(new Runnable() { + public void run() { + mCursorView.changeGraphicSelection(rectangle); + } + }); + } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java index 685e8c3f7dc5..3c5383b2aa93 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java @@ -28,16 +28,22 @@ public class TextCursorView extends View { 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>(); - private Paint mCursorPaint = new Paint(); private Paint mSelectionPaint = new Paint(); - - private boolean mCursorVisible; private boolean mSelectionsVisible; + private RectF mGraphicSelection = new RectF(); + private RectF mGraphicScaledSelection = new RectF(); + private Paint mGraphicSelectionPaint = new Paint(); + private Paint mGraphicHandleFillPaint = new Paint(); + private float mRadius = 20.0f; + private boolean mGraphicSelectionVisible; + public TextCursorView(Context context) { super(context); initialize(); @@ -59,13 +65,20 @@ public class TextCursorView extends View { mCursorPaint.setColor(Color.BLACK); mCursorPaint.setAlpha(0xFF); - mCursorVisible = false; mSelectionPaint.setColor(Color.BLUE); mSelectionPaint.setAlpha(50); - mSelectionsVisible = false; + + mGraphicSelectionPaint.setStyle(Paint.Style.STROKE); + mGraphicSelectionPaint.setColor(Color.BLACK); + mGraphicSelectionPaint.setStrokeWidth(2); + + mGraphicHandleFillPaint.setStyle(Paint.Style.FILL); + mGraphicHandleFillPaint.setColor(Color.WHITE); + mGraphicSelectionVisible = false; + mInitialized = true; } } @@ -78,6 +91,7 @@ public class TextCursorView extends View { } mCursorPosition = position; + ImmutableViewportMetrics metrics = layerView.getViewportMetrics(); repositionWithViewport(metrics.viewportRectLeft, metrics.viewportRectTop, metrics.zoomFactor); } @@ -95,6 +109,19 @@ public class TextCursorView extends View { repositionWithViewport(metrics.viewportRectLeft, metrics.viewportRectTop, metrics.zoomFactor); } + public void changeGraphicSelection(RectF rectangle) { + LayerView layerView = LOKitShell.getLayerView(); + if (layerView == null) { + Log.e(LOGTAG, "Can't position selections because layerView is null"); + return; + } + + mGraphicSelection = rectangle; + + 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); @@ -106,6 +133,9 @@ public class TextCursorView extends View { scaledSelection.offset(-x, -y); mScaledSelections.add(scaledSelection); } + + mGraphicScaledSelection = RectUtils.scale(mGraphicSelection, zoom); + mGraphicScaledSelection.offset(-x, -y); invalidate(); } @@ -120,6 +150,20 @@ public class TextCursorView extends View { canvas.drawRect(selection, mSelectionPaint); } } + if (mGraphicSelectionVisible) { + canvas.drawRect(mGraphicScaledSelection, mGraphicSelectionPaint); + canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.top, mRadius, mGraphicHandleFillPaint); + canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.top, mRadius, mGraphicSelectionPaint); + + canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.top, mRadius, mGraphicHandleFillPaint); + canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.top, mRadius, mGraphicSelectionPaint); + + canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.bottom, mRadius, mGraphicHandleFillPaint); + canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.bottom, mRadius, mGraphicSelectionPaint); + + canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.bottom, mRadius, mGraphicHandleFillPaint); + canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.bottom, mRadius, mGraphicSelectionPaint); + } } private Runnable cursorAnimation = new Runnable() { @@ -151,4 +195,14 @@ public class TextCursorView extends View { mSelectionsVisible = false; invalidate(); } + + public void showGraphicSelection() { + mGraphicSelectionVisible = true; + invalidate(); + } + + public void hideGraphicSelection() { + mGraphicSelectionVisible = false; + invalidate(); + } }
\ No newline at end of file |