Update git submodules
[LibreOffice.git] / android / source / src / java / org / libreoffice / canvas / AdjustLengthLine.java
bloba6f8cb17c1cb00a96bd58af0a76fb843e788336b
1 package org.libreoffice.canvas;
3 import android.graphics.Canvas;
4 import android.graphics.Color;
5 import android.graphics.Paint;
6 import android.graphics.PointF;
7 import android.graphics.RectF;
9 import org.json.JSONException;
10 import org.json.JSONObject;
11 import org.libreoffice.LOEvent;
12 import org.libreoffice.LOKitShell;
13 import org.libreoffice.LibreOfficeMainActivity;
14 import org.libreoffice.overlay.CalcHeadersView;
15 import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
17 import static org.libreoffice.SearchController.addProperty;
18 import static org.libreoffice.UnitConverter.pixelToTwip;
19 import static org.libreoffice.UnitConverter.twipsToHMM;
21 public class AdjustLengthLine extends CommonCanvasElement {
23 private static final float STROKE_WIDTH = 4f;
24 private static final float TOUCH_VICINITY_RADIUS = 24f;
26 private LibreOfficeMainActivity mContext;
27 private CalcHeadersView mCalcHeadersView;
28 private boolean mIsRow;
29 private PointF mScreenPosition;
30 private float mWidth;
31 private float mHeight;
32 private Paint mPaint;
33 private PointF mStartScreenPosition;
34 private int mIndex;
36 public AdjustLengthLine(LibreOfficeMainActivity context, CalcHeadersView view, boolean isRow, float width, float height) {
37 super();
38 mContext = context;
39 mCalcHeadersView = view;
40 mIsRow = isRow;
41 mWidth = width;
42 mHeight = height;
43 mPaint = new Paint();
44 mPaint.setColor(Color.BLACK);
45 mPaint.setStrokeWidth(STROKE_WIDTH);
48 @Override
49 public boolean onHitTest(float x, float y) {
50 if (mIsRow) {
51 return mScreenPosition.y - TOUCH_VICINITY_RADIUS < y &&
52 y < mScreenPosition.y + TOUCH_VICINITY_RADIUS;
53 } else {
54 return mScreenPosition.x - TOUCH_VICINITY_RADIUS < x &&
55 x < mScreenPosition.x + TOUCH_VICINITY_RADIUS;
59 @Override
60 public void onDraw(Canvas canvas) {
61 if (mIsRow) {
62 canvas.drawLine(0f, mScreenPosition.y, mWidth, mScreenPosition.y, mPaint);
63 } else {
64 canvas.drawLine(mScreenPosition.x, 0f, mScreenPosition.x, mHeight, mPaint);
68 public void dragStart(PointF point) {
71 public void dragging(PointF point) {
72 mScreenPosition = point;
75 public void dragEnd(PointF point) {
76 ImmutableViewportMetrics viewportMetrics = mContext.getLayerClient().getViewportMetrics();
77 float zoom = viewportMetrics.zoomFactor;
79 PointF documentDistance = new PointF(pixelToTwip((point.x-mStartScreenPosition.x)/zoom, LOKitShell.getDpi(mContext)),
80 pixelToTwip((point.y-mStartScreenPosition.y)/zoom, LOKitShell.getDpi(mContext)));
82 try {
83 JSONObject rootJson = new JSONObject();
84 if (mIsRow) {
85 addProperty(rootJson, "Row", "long", String.valueOf(mIndex));
86 addProperty(rootJson, "RowHeight", "unsigned short", String.valueOf(Math.round(documentDistance.y > 0 ? twipsToHMM(documentDistance.y) : 0)));
87 LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:RowHeight", rootJson.toString()));
88 } else {
89 addProperty(rootJson, "Column", "long", String.valueOf(mIndex));
90 addProperty(rootJson, "ColumnWidth", "unsigned short", String.valueOf(documentDistance.x > 0 ? twipsToHMM(documentDistance.x) : 0));
91 LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:ColumnWidth", rootJson.toString()));
93 } catch (JSONException e) {
94 e.printStackTrace();
98 public void setScreenRect(RectF position) {
99 mScreenPosition = new PointF(position.right, position.bottom);
100 mStartScreenPosition = new PointF(position.left, position.top);
101 mIndex = 1 + mCalcHeadersView.getIndexFromPointOfTouch(new PointF(position.centerX(), position.centerY()));