LibreOffice Module android (master) 1
AdjustLengthLine.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
9import org.json.JSONException;
10import org.json.JSONObject;
16
20
22
23 private static final float STROKE_WIDTH = 4f;
24 private static final float TOUCH_VICINITY_RADIUS = 24f;
25
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;
35
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);
46 }
47
48 @Override
49 public boolean onHitTest(float x, float y) {
50 if (mIsRow) {
53 } else {
56 }
57 }
58
59 @Override
60 public void onDraw(Canvas canvas) {
61 if (mIsRow) {
63 } else {
65 }
66 }
67
68 public void dragStart(PointF point) {
69 }
70
71 public void dragging(PointF point) {
73 }
74
75 public void dragEnd(PointF point) {
77 float zoom = viewportMetrics.zoomFactor;
78
79 PointF documentDistance = new PointF(pixelToTwip((point.x-mStartScreenPosition.x)/zoom, LOKitShell.getDpi(mContext)),
81
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()));
92 }
93 } catch (JSONException e) {
94 e.printStackTrace();
95 }
96 }
97
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()));
102 }
103}
Events and data that is queued and processed by LOKitThread.
Definition: LOEvent.java:21
static final int UNO_COMMAND
Definition: LOEvent.java:35
Common static LOKit functions, functions to send events.
Definition: LOKitShell.java:26
static void sendEvent(LOEvent event)
Make sure LOKitThread is running and send event to it.
Definition: LOKitShell.java:72
static float getDpi(Context context)
Definition: LOKitShell.java:27
Main activity of the LibreOffice App.
static void addProperty(JSONObject json, String parentValue, String type, String value)
static float twipsToHMM(float twips)
static float pixelToTwip(float input, float dpi)
AdjustLengthLine(LibreOfficeMainActivity context, CalcHeadersView view, boolean isRow, float width, float height)
Common implementation to canvas elements.
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 position(n=-1)
def point()
float pixelToTwip(float fInput, float zoom)