LibreOffice Module android (master) 1
BitmapHandle.java
Go to the documentation of this file.
1package org.libreoffice.canvas;
2
3import android.content.Context;
4import android.graphics.Bitmap;
5import android.graphics.Canvas;
6import android.graphics.RectF;
7import android.graphics.drawable.Drawable;
8import androidx.core.content.ContextCompat;
9
15public abstract class BitmapHandle extends CommonCanvasElement {
16 public final RectF mDocumentPosition;
17 private final Bitmap mBitmap;
18 final RectF mScreenPosition;
19
20 BitmapHandle(Bitmap bitmap) {
21 mBitmap = bitmap;
22 mScreenPosition = new RectF(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
23 mDocumentPosition = new RectF();
24 }
25
29 static Bitmap getBitmapForDrawable(Context context, int drawableId) {
30 Drawable drawable = ContextCompat.getDrawable(context, drawableId);
31
32 return ImageUtils.getBitmapForDrawable(drawable);
33 }
34
39 @Override
40 public void onDraw(Canvas canvas) {
41 canvas.drawBitmap(mBitmap, mScreenPosition.left, mScreenPosition.top, null);
42 }
43
50 @Override
51 public boolean onHitTest(float x, float y) {
52 return mScreenPosition.contains(x, y);
53 }
54
60 public void reposition(float x, float y) {
61 mScreenPosition.offsetTo(x, y);
62 }
63}
Bitmap handle canvas element is used to show a handle on the screen.
void reposition(float x, float y)
Change the position of the handle.
void onDraw(Canvas canvas)
Draw the bitmap handle to the canvas.
boolean onHitTest(float x, float y)
Test if the bitmap has been hit.
Common implementation to canvas elements.
float y
float x