diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-03-18 14:53:24 +0900 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-03-23 09:19:02 +0100 |
commit | 7f4ac9025458916790a5982ba39e064bbb43ff41 (patch) | |
tree | 4f230676a830009fce5ecef7f9f0babbca62a5b7 /android | |
parent | e48d983d55ffd97d3c74535a00dc5d817a15b955 (diff) |
android: move handle code to DrawElementHandle
Change-Id: Ica316ed9660e235e756ef380da8f441c976de07f
Diffstat (limited to 'android')
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/libreoffice/DrawElementHandle.java | 40 | ||||
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java | 53 |
2 files changed, 66 insertions, 27 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/DrawElementHandle.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/DrawElementHandle.java new file mode 100644 index 000000000000..1af0724a424f --- /dev/null +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/DrawElementHandle.java @@ -0,0 +1,40 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.libreoffice; + +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.PointF; + +public class DrawElementHandle { + public PointF mPosition = new PointF(); + private float mRadius = 20.0f; + private Paint mGraphicHandleFillPaint = new Paint(); + private Paint mGraphicSelectionPaint = new Paint(); + + public DrawElementHandle(Paint graphicSelectionPaint) { + mGraphicSelectionPaint = graphicSelectionPaint; + + mGraphicHandleFillPaint.setStyle(Paint.Style.FILL); + mGraphicHandleFillPaint.setColor(Color.WHITE); + } + + public void draw(Canvas canvas) { + canvas.drawCircle(mPosition.x, mPosition.y, mRadius, mGraphicHandleFillPaint); + canvas.drawCircle(mPosition.x, mPosition.y, mRadius, mGraphicSelectionPaint); + } + + public void reposition(float x, float y) { + mPosition.x = x; + mPosition.y = y; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java index 0128f9441548..c9ecabb6255f 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TextCursorView.java @@ -51,14 +51,16 @@ public class TextCursorView extends View implements View.OnTouchListener { private RectF mGraphicSelection = new RectF(); private RectF mGraphicScaledSelection = new RectF(); private Paint mGraphicSelectionPaint = new Paint(); - private Paint mGraphicHandleFillPaint = new Paint(); - private float mRadius = 20.0f; + + private boolean mGraphicSelectionVisible; private PointF mTouchStart = new PointF(); private PointF mDeltaPoint = new PointF(); private boolean mGraphicSelectionMove = false; private LayerView mLayerView; + private DrawElementHandle mHandles[] = new DrawElementHandle[8]; + public TextCursorView(Context context) { super(context); initialize(); @@ -92,11 +94,17 @@ public class TextCursorView extends View implements View.OnTouchListener { mGraphicSelectionPaint.setStyle(Paint.Style.STROKE); mGraphicSelectionPaint.setColor(Color.BLACK); mGraphicSelectionPaint.setStrokeWidth(2); - - mGraphicHandleFillPaint.setStyle(Paint.Style.FILL); - mGraphicHandleFillPaint.setColor(Color.WHITE); mGraphicSelectionVisible = false; + mHandles[0] = new DrawElementHandle(mGraphicSelectionPaint); + mHandles[1] = new DrawElementHandle(mGraphicSelectionPaint); + mHandles[2] = new DrawElementHandle(mGraphicSelectionPaint); + mHandles[3] = new DrawElementHandle(mGraphicSelectionPaint); + mHandles[4] = new DrawElementHandle(mGraphicSelectionPaint); + mHandles[5] = new DrawElementHandle(mGraphicSelectionPaint); + mHandles[6] = new DrawElementHandle(mGraphicSelectionPaint); + mHandles[7] = new DrawElementHandle(mGraphicSelectionPaint); + postDelayed(cursorAnimation, CURSOR_BLINK_TIME); mInitialized = true; @@ -156,6 +164,16 @@ public class TextCursorView extends View implements View.OnTouchListener { mGraphicScaledSelection = RectUtils.scale(mGraphicSelection, zoom); mGraphicScaledSelection.offset(-x, -y); + + mHandles[0].reposition(mGraphicScaledSelection.left, mGraphicScaledSelection.top); + mHandles[1].reposition(mGraphicScaledSelection.centerX(), mGraphicScaledSelection.top); + mHandles[2].reposition(mGraphicScaledSelection.right, mGraphicScaledSelection.top); + mHandles[3].reposition(mGraphicScaledSelection.left, mGraphicScaledSelection.centerY()); + mHandles[4].reposition(mGraphicScaledSelection.right, mGraphicScaledSelection.centerY()); + mHandles[5].reposition(mGraphicScaledSelection.left, mGraphicScaledSelection.bottom); + mHandles[6].reposition(mGraphicScaledSelection.centerX(), mGraphicScaledSelection.bottom); + mHandles[7].reposition(mGraphicScaledSelection.right, mGraphicScaledSelection.bottom); + invalidate(); } @@ -172,29 +190,10 @@ public class TextCursorView extends View implements View.OnTouchListener { } if (mGraphicSelectionVisible) { canvas.drawRect(mGraphicScaledSelection, mGraphicSelectionPaint); - canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.top, mRadius, mGraphicHandleFillPaint); - canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.top, mRadius, mGraphicSelectionPaint); - canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.top, mRadius, mGraphicHandleFillPaint); - canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.top, mRadius, mGraphicSelectionPaint); - - canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.bottom, mRadius, mGraphicHandleFillPaint); - canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.bottom, mRadius, mGraphicSelectionPaint); - - canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.bottom, mRadius, mGraphicHandleFillPaint); - canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.bottom, mRadius, mGraphicSelectionPaint); - - canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.centerY(), mRadius, mGraphicHandleFillPaint); - canvas.drawCircle(mGraphicScaledSelection.left, mGraphicScaledSelection.centerY(), mRadius, mGraphicSelectionPaint); - - canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.centerY(), mRadius, mGraphicHandleFillPaint); - canvas.drawCircle(mGraphicScaledSelection.right, mGraphicScaledSelection.centerY(), mRadius, mGraphicSelectionPaint); - - canvas.drawCircle(mGraphicScaledSelection.centerX(), mGraphicScaledSelection.top, mRadius, mGraphicHandleFillPaint); - canvas.drawCircle(mGraphicScaledSelection.centerX(), mGraphicScaledSelection.top, mRadius, mGraphicSelectionPaint); - - canvas.drawCircle(mGraphicScaledSelection.centerX(), mGraphicScaledSelection.bottom, mRadius, mGraphicHandleFillPaint); - canvas.drawCircle(mGraphicScaledSelection.centerX(), mGraphicScaledSelection.bottom, mRadius, mGraphicSelectionPaint); + for (DrawElementHandle handle : mHandles) { + handle.draw(canvas); + } if (mGraphicSelectionMove) { RectF one = new RectF(mGraphicScaledSelection); |