Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / android / source / src / java / org / libreoffice / canvas / SelectionHandle.java
blob38b5dc121932e4e8e6f0b3e3f52ffc12dd0d78aa
1 package org.libreoffice.canvas;
3 import android.graphics.Bitmap;
4 import android.graphics.PointF;
6 import org.libreoffice.LOKitShell;
7 import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
9 /**
10 * Selection handle is a common class for "start", "middle" and "end" types
11 * of selection handles.
13 public abstract class SelectionHandle extends BitmapHandle {
14 private static final long MINIMUM_HANDLE_UPDATE_TIME = 50 * 1000000;
16 private final PointF mDragStartPoint = new PointF();
17 private final PointF mDragDocumentPosition = new PointF();
18 private long mLastTime = 0;
20 public SelectionHandle(Bitmap bitmap) {
21 super(bitmap);
24 /**
25 * Start of a touch and drag action on the handle.
27 public void dragStart(PointF point) {
28 mDragStartPoint.x = point.x;
29 mDragStartPoint.y = point.y;
30 mDragDocumentPosition.x = mDocumentPosition.left;
31 mDragDocumentPosition.y = mDocumentPosition.top;
34 /**
35 * End of a touch and drag action on the handle.
37 public void dragEnd(PointF point) {
40 /**
41 * Handle has been dragged.
43 public void dragging(PointF point) {
44 long currentTime = System.nanoTime();
45 if (currentTime - mLastTime > MINIMUM_HANDLE_UPDATE_TIME) {
46 mLastTime = currentTime;
47 signalHandleMove(point.x, point.y);
51 /**
52 * Signal to move the handle to a new position to LO.
54 private void signalHandleMove(float newX, float newY) {
55 ImmutableViewportMetrics viewportMetrics = LOKitShell.getLayerView().getLayerClient().getViewportMetrics();
56 float zoom = viewportMetrics.zoomFactor;
58 float deltaX = (newX - mDragStartPoint.x) / zoom;
59 float deltaY = (newY - mDragStartPoint.y) / zoom;
61 PointF documentPoint = new PointF(mDragDocumentPosition.x + deltaX, mDragDocumentPosition.y + deltaY);
63 LOKitShell.sendChangeHandlePositionEvent(getHandleType(), documentPoint);
66 public abstract HandleType getHandleType();
68 public enum HandleType { START, MIDDLE, END }