diff options
Diffstat (limited to 'android/source/src/java/org/libreoffice/canvas/BitmapHandle.java')
-rw-r--r-- | android/source/src/java/org/libreoffice/canvas/BitmapHandle.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/android/source/src/java/org/libreoffice/canvas/BitmapHandle.java b/android/source/src/java/org/libreoffice/canvas/BitmapHandle.java new file mode 100644 index 000000000000..9a581956c9e5 --- /dev/null +++ b/android/source/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); + } +} |