android: use onDraw for element drawing in CanvasElement interface
Use onDraw to override the drawing to canvas. CommonCanvasElement uses the draw method to call onDraw depending on visibility. Change-Id: Id98991935168caab9d39665e72f33cfb3a91d8dc
This commit is contained in:
committed by
Miklos Vajna
parent
7a53938342
commit
8f6b3d6421
@@ -17,11 +17,21 @@ import android.graphics.Canvas;
|
|||||||
*/
|
*/
|
||||||
public interface CanvasElement {
|
public interface CanvasElement {
|
||||||
/**
|
/**
|
||||||
* Called when the element needs to be draw no the canvas.
|
* Called when the element needs to be draw no the canvas. This method
|
||||||
|
* should call onDraw when conditions to draw are satisfied.
|
||||||
|
*
|
||||||
* @param canvas - the canvas
|
* @param canvas - the canvas
|
||||||
*/
|
*/
|
||||||
void draw(Canvas canvas);
|
void draw(Canvas canvas);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called inside draw if the element is visible. Override this method to
|
||||||
|
* draw the element on the canvas.
|
||||||
|
*
|
||||||
|
* @param canvas - the canvas
|
||||||
|
*/
|
||||||
|
void onDraw(Canvas canvas);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hit test - returns true if the object has been hit
|
* Hit test - returns true if the object has been hit
|
||||||
* @param x - x coordinate of the
|
* @param x - x coordinate of the
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
package org.libreoffice.canvas;
|
package org.libreoffice.canvas;
|
||||||
|
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common implementation to canvas elements.
|
* Common implementation to canvas elements.
|
||||||
*/
|
*/
|
||||||
@@ -16,4 +18,11 @@ public abstract class CommonCanvasElement implements CanvasElement {
|
|||||||
public void setVisible(boolean visible) {
|
public void setVisible(boolean visible) {
|
||||||
mVisible = visible;
|
mVisible = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(Canvas canvas) {
|
||||||
|
if (isVisible()) {
|
||||||
|
onDraw(canvas);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -103,7 +103,7 @@ public class GraphicSelection extends CommonCanvasElement {
|
|||||||
* @see org.libreoffice.canvas.CanvasElement#draw(android.graphics.Canvas)
|
* @see org.libreoffice.canvas.CanvasElement#draw(android.graphics.Canvas)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
public void onDraw(Canvas canvas) {
|
||||||
canvas.drawRect(mDrawRectangle, mPaintStroke);
|
canvas.drawRect(mDrawRectangle, mPaintStroke);
|
||||||
if (mType != DragType.NONE) {
|
if (mType != DragType.NONE) {
|
||||||
canvas.drawRect(mDrawRectangle, mPaintFill);
|
canvas.drawRect(mDrawRectangle, mPaintFill);
|
||||||
|
@@ -71,7 +71,7 @@ public class GraphicSelectionHandle extends CommonCanvasElement {
|
|||||||
* @see org.libreoffice.canvas.CanvasElement#draw(android.graphics.Canvas)
|
* @see org.libreoffice.canvas.CanvasElement#draw(android.graphics.Canvas)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
public void onDraw(Canvas canvas) {
|
||||||
if (mSelected) {
|
if (mSelected) {
|
||||||
drawFilledCircle(canvas, mPosition.x, mPosition.y, mRadius, mStrokePaint, mSelectedFillPaint);
|
drawFilledCircle(canvas, mPosition.x, mPosition.y, mRadius, mStrokePaint, mSelectedFillPaint);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user