Update git submodules
[LibreOffice.git] / android / source / src / java / org / libreoffice / canvas / SelectionHandle.java
blobddd16fe5eb4bd4c5153d4d2362841bfd32a785cf
1 package org.libreoffice.canvas;
3 import android.graphics.Bitmap;
4 import android.graphics.PointF;
6 import org.libreoffice.LOKitShell;
7 import org.libreoffice.LibreOfficeMainActivity;
8 import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
10 /**
11 * Selection handle is a common class for "start", "middle" and "end" types
12 * of selection handles.
14 public abstract class SelectionHandle extends BitmapHandle {
15 private static final long MINIMUM_HANDLE_UPDATE_TIME = 50 * 1000000;
17 private final PointF mDragStartPoint = new PointF();
18 private final PointF mDragDocumentPosition = new PointF();
19 private long mLastTime = 0;
21 private LibreOfficeMainActivity mContext;
23 public SelectionHandle(LibreOfficeMainActivity context, Bitmap bitmap) {
24 super(bitmap);
25 mContext = context;
28 /**
29 * Start of a touch and drag action on the handle.
31 public void dragStart(PointF point) {
32 mDragStartPoint.x = point.x;
33 mDragStartPoint.y = point.y;
34 mDragDocumentPosition.x = mDocumentPosition.left;
35 mDragDocumentPosition.y = mDocumentPosition.top;
38 /**
39 * End of a touch and drag action on the handle.
41 public void dragEnd(PointF point) {
44 /**
45 * Handle has been dragged.
47 public void dragging(PointF point) {
48 long currentTime = System.nanoTime();
49 if (currentTime - mLastTime > MINIMUM_HANDLE_UPDATE_TIME) {
50 mLastTime = currentTime;
51 signalHandleMove(point.x, point.y);
55 /**
56 * Signal to move the handle to a new position to LO.
58 private void signalHandleMove(float newX, float newY) {
59 ImmutableViewportMetrics viewportMetrics = mContext.getLayerClient().getViewportMetrics();
60 float zoom = viewportMetrics.zoomFactor;
62 float deltaX = (newX - mDragStartPoint.x) / zoom;
63 float deltaY = (newY - mDragStartPoint.y) / zoom;
65 PointF documentPoint = new PointF(mDragDocumentPosition.x + deltaX, mDragDocumentPosition.y + deltaY);
67 LOKitShell.sendChangeHandlePositionEvent(getHandleType(), documentPoint);
70 public abstract HandleType getHandleType();
72 public enum HandleType { START, MIDDLE, END }