1 package org
.libreoffice
.canvas
;
3 import android
.content
.Context
;
4 import android
.graphics
.Bitmap
;
5 import android
.graphics
.Canvas
;
6 import android
.graphics
.RectF
;
7 import android
.graphics
.drawable
.Drawable
;
8 import androidx
.core
.content
.ContextCompat
;
11 * Bitmap handle canvas element is used to show a handle on the screen.
12 * The handle visual comes from the bitmap, which must be provided in time
15 public abstract class BitmapHandle
extends CommonCanvasElement
{
16 public final RectF mDocumentPosition
;
17 private final Bitmap mBitmap
;
18 final RectF mScreenPosition
;
20 BitmapHandle(Bitmap bitmap
) {
22 mScreenPosition
= new RectF(0, 0, mBitmap
.getWidth(), mBitmap
.getHeight());
23 mDocumentPosition
= new RectF();
27 * Return a bitmap for a drawable id.
29 static Bitmap
getBitmapForDrawable(Context context
, int drawableId
) {
30 Drawable drawable
= ContextCompat
.getDrawable(context
, drawableId
);
32 return ImageUtils
.getBitmapForDrawable(drawable
);
36 * Draw the bitmap handle to the canvas.
37 * @param canvas - the canvas
40 public void onDraw(Canvas canvas
) {
41 canvas
.drawBitmap(mBitmap
, mScreenPosition
.left
, mScreenPosition
.top
, null);
45 * Test if the bitmap has been hit.
46 * @param x - x coordinate
47 * @param y - y coordinate
48 * @return true if the bitmap has been hit
51 public boolean onHitTest(float x
, float y
) {
52 return mScreenPosition
.contains(x
, y
);
56 * Change the position of the handle.
57 * @param x - x coordinate
58 * @param y - y coordinate
60 public void reposition(float x
, float y
) {
61 mScreenPosition
.offsetTo(x
, y
);