LibreOffice Module android (master) 1
CalcSelectionBox.java
Go to the documentation of this file.
1package org.libreoffice.canvas;
2
3import android.graphics.Canvas;
4import android.graphics.Color;
5import android.graphics.Paint;
6import android.graphics.PointF;
7import android.graphics.RectF;
8
12
19 private static final long MINIMUM_HANDLE_UPDATE_TIME = 50 * 1000000;
20 private static final float CIRCLE_HANDLE_RADIUS = 8f;
21
22 public RectF mDocumentPosition;
23
25 private RectF mScreenPosition;
26 private long mLastTime = 0;
27 private Paint mPaint;
29
31 mContext = context;
32 mScreenPosition = new RectF();
33 mDocumentPosition = new RectF();
34 mPaint = new Paint();
35 mPaint.setStyle(Paint.Style.STROKE);
36 mPaint.setColor(Color.BLACK);
37 mPaint.setStrokeWidth(2f);
38 mCirclePaint = new Paint();
39 mCirclePaint.setColor(Color.BLACK);
40 mCirclePaint.setStyle(Paint.Style.FILL);
41 }
42
46 public void dragStart(PointF point) {}
47
51 public void dragEnd(PointF point) {}
52
56 public void dragging(PointF point) {
57 long currentTime = System.nanoTime();
58 if (currentTime - mLastTime > MINIMUM_HANDLE_UPDATE_TIME) {
59 mLastTime = currentTime;
61 }
62 }
63
67 private void signalHandleMove(float newX, float newY) {
69 float zoom = viewportMetrics.zoomFactor;
70 PointF origin = viewportMetrics.getOrigin();
71
72 PointF documentPoint = new PointF((newX+origin.x)/zoom , (newY+origin.y)/zoom);
73
74 if (documentPoint.x < mDocumentPosition.left || documentPoint.y < mDocumentPosition.top) {
76 } else if (documentPoint.x > mDocumentPosition.right || documentPoint.y > mDocumentPosition.bottom){
78 }
79 }
80
81 @Override
82 public boolean onHitTest(float x, float y) {
83 return mScreenPosition.contains(x, y);
84 }
85
86 @Override
87 public void onDraw(Canvas canvas) {
88 canvas.drawRect(mScreenPosition, mPaint);
91 }
92
93 public void reposition(RectF rect) {
94 mScreenPosition = rect;
95 }
96
97 @Override
98 public boolean contains(float x, float y) {
99 // test if in range of the box or the circular handles
100 boolean inRange = new RectF(mScreenPosition.left - CIRCLE_HANDLE_RADIUS,
103 mScreenPosition.top + CIRCLE_HANDLE_RADIUS).contains(x, y)
104 || new RectF(mScreenPosition.right - CIRCLE_HANDLE_RADIUS,
107 mScreenPosition.bottom + CIRCLE_HANDLE_RADIUS).contains(x, y)
108 || onHitTest(x, y);
109 return inRange && isVisible();
110 }
111}
Common static LOKit functions, functions to send events.
Definition: LOKitShell.java:26
static void sendChangeHandlePositionEvent(SelectionHandle.HandleType handleType, PointF documentCoordinate)
Send change handle position event to LOKitThread.
Main activity of the LibreOffice App.
CalcSelectionBox is the selection frame for the current highlighted area/cells in Calc.
CalcSelectionBox(LibreOfficeMainActivity context)
void dragEnd(PointF point)
End of a touch and drag action on the box.
void signalHandleMove(float newX, float newY)
Signal to move the handle to a new position to LO.
void dragging(PointF point)
Box has been dragged.
boolean contains(float x, float y)
Hit test.
void dragStart(PointF point)
Start of a touch and drag action on the box.
Common implementation to canvas elements.
Selection handle is a common class for "start", "middle" and "end" types of selection handles.
ImmutableViewportMetrics getViewportMetrics()
Implementation of PanZoomTarget.
ImmutableViewportMetrics are used to store the viewport metrics in way that we can access a version o...
float y
float x
def point()