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
;
31 private float mHeight
;
33 private PointF mStartScreenPosition
;
36 public AdjustLengthLine(LibreOfficeMainActivity context
, CalcHeadersView view
, boolean isRow
, float width
, float height
) {
39 mCalcHeadersView
= view
;
44 mPaint
.setColor(Color
.BLACK
);
45 mPaint
.setStrokeWidth(STROKE_WIDTH
);
49 public boolean onHitTest(float x
, float y
) {
51 return mScreenPosition
.y
- TOUCH_VICINITY_RADIUS
< y
&&
52 y
< mScreenPosition
.y
+ TOUCH_VICINITY_RADIUS
;
54 return mScreenPosition
.x
- TOUCH_VICINITY_RADIUS
< x
&&
55 x
< mScreenPosition
.x
+ TOUCH_VICINITY_RADIUS
;
60 public void onDraw(Canvas canvas
) {
62 canvas
.drawLine(0f
, mScreenPosition
.y
, mWidth
, mScreenPosition
.y
, mPaint
);
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
)));
83 JSONObject rootJson
= new JSONObject();
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()));
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
) {
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()));