Update git submodules
[LibreOffice.git] / android / source / src / java / org / libreoffice / canvas / BitmapHandle.java
blob51f6f7cf861187feeef21aa7cd52ec52e36c3fd7
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;
10 /**
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
13 * of construction.
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) {
21 mBitmap = bitmap;
22 mScreenPosition = new RectF(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
23 mDocumentPosition = new RectF();
26 /**
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);
35 /**
36 * Draw the bitmap handle to the canvas.
37 * @param canvas - the canvas
39 @Override
40 public void onDraw(Canvas canvas) {
41 canvas.drawBitmap(mBitmap, mScreenPosition.left, mScreenPosition.top, null);
44 /**
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
50 @Override
51 public boolean onHitTest(float x, float y) {
52 return mScreenPosition.contains(x, y);
55 /**
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);