diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-04-01 21:48:28 +0900 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-04-07 09:18:09 +0200 |
commit | 2502121e5e16888e92cc2da93da8d930ca01b348 (patch) | |
tree | 693434e90baa16715b7bbbd669e3d7fc62671810 /android | |
parent | 01a1cf2adc3667f3243927de4d34168bfe67a46a (diff) |
android: extract BitmapHandle from SelectionHandle
Change-Id: I16ef07414eb7ab9b4a9b8169c8f1d8bfe9bd628e
Diffstat (limited to 'android')
5 files changed, 109 insertions, 35 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/BitmapHandle.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/BitmapHandle.java new file mode 100644 index 000000000000..9a581956c9e5 --- /dev/null +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/BitmapHandle.java @@ -0,0 +1,61 @@ +package org.libreoffice.canvas; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.RectF; + +/** + * Bitmap handle canvas element is used to show a handle on the screen. + * The handle visual comes from the bitmap, which must be provided in time + * of construction. + */ +public abstract class BitmapHandle extends CommonCanvasElement { + public final RectF mDocumentPosition; + protected final Bitmap mBitmap; + protected final RectF mScreenPosition; + + public BitmapHandle(Bitmap bitmap) { + mBitmap = bitmap; + mScreenPosition = new RectF(0, 0, mBitmap.getWidth(), mBitmap.getHeight()); + mDocumentPosition = new RectF(); + } + + /** + * Return a bitmap for a drawable id. + */ + protected static Bitmap getBitmapForDrawable(Context context, int drawableId) { + BitmapFactory.Options options = new BitmapFactory.Options(); + return BitmapFactory.decodeResource(context.getResources(), drawableId, options); + } + + /** + * Draw the bitmap handle to the canvas. + * @param canvas - the canvas + */ + @Override + public void onDraw(Canvas canvas) { + canvas.drawBitmap(mBitmap, mScreenPosition.left, mScreenPosition.top, null); + } + + /** + * Test if the bitmap has been hit. + * @param x - x coordinate + * @param y - y coordinate + * @return + */ + @Override + public boolean onHitTest(float x, float y) { + return mScreenPosition.contains(x, y); + } + + /** + * Change the position of the handle. + * @param x - x coordinate + * @param y - y coordinate + */ + public void reposition(float x, float y) { + mScreenPosition.offsetTo(x, y); + } +} diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandle.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandle.java index 9d244122e9a1..bcf22b53499f 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandle.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandle.java @@ -1,52 +1,29 @@ package org.libreoffice.canvas; -import android.content.Context; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Paint; import android.graphics.PointF; -import android.graphics.RectF; -import android.util.Log; import org.libreoffice.LOKitShell; import org.mozilla.gecko.gfx.ImmutableViewportMetrics; -public abstract class SelectionHandle extends CommonCanvasElement { +/** + * Selection handle is a common class for "start", "middle" and "end" types + * of selection handles. + */ +public abstract class SelectionHandle extends BitmapHandle { private static final long MINIMUM_HANDLE_UPDATE_TIME = 50 * 1000000; - public final RectF mDocumentPosition; - protected final Bitmap mBitmap; - protected final RectF mScreenPosition; private final PointF mDragStartPoint = new PointF(); private long mLastTime = 0; private final PointF mDragDocumentPosition = new PointF(); public SelectionHandle(Bitmap bitmap) { - mBitmap = bitmap; - mScreenPosition = new RectF(0, 0, mBitmap.getWidth(), mBitmap.getHeight()); - mDocumentPosition = new RectF(); - } - - protected static Bitmap getBitmapForDrawable(Context context, int drawableId) { - BitmapFactory.Options options = new BitmapFactory.Options(); - return BitmapFactory.decodeResource(context.getResources(), drawableId, options); - } - - @Override - public void onDraw(Canvas canvas) { - canvas.drawBitmap(mBitmap, mScreenPosition.left, mScreenPosition.top, null); - } - - @Override - public boolean onHitTest(float x, float y) { - return mScreenPosition.contains(x, y); - } - - public void reposition(float x, float y) { - mScreenPosition.offsetTo(x, y); + super(bitmap); } + /** + * Start of a touch and drag action on the handle. + */ public void dragStart(PointF point) { mDragStartPoint.x = point.x; mDragStartPoint.y = point.y; @@ -54,19 +31,27 @@ public abstract class SelectionHandle extends CommonCanvasElement { mDragDocumentPosition.y = mDocumentPosition.top; } + /** + * End of a touch and drag action on the handle. + */ public void dragEnd(PointF point) { - //move(point.x, point.y); } + /** + * Handle has been dragged. + */ public void dragging(PointF point) { long currentTime = System.nanoTime(); if (currentTime - mLastTime > MINIMUM_HANDLE_UPDATE_TIME) { mLastTime = currentTime; - move(point.x, point.y); + signalHandleMove(point.x, point.y); } } - private void move(float newX, float newY) { + /** + * Signal to move the handle to a new position to LO. + */ + private void signalHandleMove(float newX, float newY) { ImmutableViewportMetrics viewportMetrics = LOKitShell.getLayerView().getLayerClient().getViewportMetrics(); float zoom = viewportMetrics.zoomFactor; diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandleEnd.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandleEnd.java index ec8b93c4681f..c13ad1fc8f7d 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandleEnd.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandleEnd.java @@ -5,11 +5,17 @@ import android.graphics.Bitmap; import org.libreoffice.R; +/** + * Selection handle for showing and manipulating the end of a selection. + */ public class SelectionHandleEnd extends SelectionHandle { public SelectionHandleEnd(Context context) { super(getBitmapForDrawable(context, R.drawable.handle_end)); } + /** + * Define the type of the handle. + */ @Override public HandleType getHandleType() { return HandleType.END; diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandleMiddle.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandleMiddle.java index 7cbb847008af..ab30a8bfad1d 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandleMiddle.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandleMiddle.java @@ -5,18 +5,29 @@ import android.graphics.Bitmap; import org.libreoffice.R; +/** + * Selection handle that is used to manipulate the cursor. + */ public class SelectionHandleMiddle extends SelectionHandle { public SelectionHandleMiddle(Context context) { super(getBitmapForDrawable(context, R.drawable.handle_middle)); } @Override + /** + * Change the position of the handle on the screen. Take into account the + * handle alignment to the center. + */ public void reposition(float x, float y) { super.reposition(x, y); + // align to the center float offset = mScreenPosition.width() / 2.0f; mScreenPosition.offset(-offset, 0); } + /** + * Define the type of the handle. + */ @Override public HandleType getHandleType() { return HandleType.MIDDLE; diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandleStart.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandleStart.java index aa1d3828b98a..af2e7ba7cf0a 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandleStart.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/canvas/SelectionHandleStart.java @@ -5,18 +5,29 @@ import android.graphics.Bitmap; import org.libreoffice.R; +/** + * Selection handle for showing and manipulating the start of a selection. + */ public class SelectionHandleStart extends SelectionHandle { public SelectionHandleStart(Context context) { super(getBitmapForDrawable(context, R.drawable.handle_start)); } + /** + * Change the position of the handle on the screen. Take into account the + * handle alignment to the right. + */ @Override public void reposition(float x, float y) { super.reposition(x, y); + // align to the right float offset = mScreenPosition.width(); mScreenPosition.offset(-offset, 0); } + /** + * Define the type of the handle. + */ @Override public HandleType getHandleType() { return HandleType.START; |