This tool makes it easier to use the built in Android tools to draw
points, lines, shapes, and bitmaps.
- Drawing shapes in Android no longer requires dealing with canvas, revalidating, and handling the data yourself.
- Simple built in functions let you draw anything you want
- Setup and use takes seconds, and saves you many lines of code.
- Great for reusability.
-
Head over to latest releases and download the latest JAR file.
-
Add the JAR file as an external library to your code. Here is an example for Android Studio.
- Clone the easyandroidgraph git repo.
- Copy the contents of the source folder into your own project's src folder.
easyandroidgraph provides you with a single view that can be added to a layout and contains utility functions to draw on said view.
import com.masesk.easyandroidgraph.DrawView;
NOTE: com.masesk.easyandroidgraph would be replaced with your package name if you use the source installation.
Use the following in your layout XML as an example:
<com.masesk.easyandroidgraph.DrawView
android:id="@+id/drawView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
NOTE: com.masesk.easyandroidgraph would be replaced with your package name if you use the source installation.
NOTE: Change the id ("drawView" in this example) as need but keep track of it
Use the following in your Java Activity as an example:
DrawView drawView = findViewById(R.id.drawView);
Use the following in your Java Activity as an example:
DrawView drawView = new DrawView(context, attributeSet);
layout.addView(view);
-
-
-
public DrawView(Context context, AttributeSet attr)
-
-
-
public boolean setCenter(java.lang.String id, float x, float y)Parameters: :
id- unique shape identifier :x- shape's new X value :y- shape's new Y value Returns: : false if id does not exist, true if operation completed. ONLY WORKS FOR CIRCLES, POINTS, AND BITMAPS -
public boolean setX(java.lang.String id, float x)Parameters: :
id- unique shape identifier :x- shape's new X value Returns: : false if id does not exist, true if operation completed. ONLY WORKS FOR CIRCLES, POINTS, AND BITMAPS -
public float getX(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : shape's X value ONLY WORKS FOR CIRCLES, POINTS, AND BITMAPS -
public boolean setY(java.lang.String id, float y)Parameters: :
id- unique shape identifier :y- shape's new Y value Returns: : false if id does not exist, true if operation completed. ONLY WORKS FOR CIRCLES, POINTS, AND BITMAPS -
public float getY(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : shape's Y value ONLY WORKS FOR CIRCLES, POINTS, AND BITMAPS -
public boolean setRadius(java.lang.String id, float radius)Parameters: :
id- unique shape identifier :radius- circle's new radius Returns: : false if id does not exist, true if operation completed. ONLY WORKS FOR CIRCLES -
public float getRadius(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : circle's radius ONLY WORKS FOR CIRCLES -
public boolean setLinePoints(java.lang.String id, float startX, float startY, float endX, float endY)Parameters: :
id- shape unique identifier :startX- line's new starting X value :startY- line's new starting Y value :endX- line's new ending X value :endY- line's new ending Y value Returns: : false if id does not exist, true if operation completed. ONLY WORKS FOR LINES -
public boolean setStartPoint(java.lang.String id, float startX, float startY)Parameters: :
id- unique shape identifier :startX- line's new starting X value :startY- line's new starting Y value Returns: : false if id does not exist, true if operation completed. ONLY WORKS FOR LINES AND RECTANGLES -
public boolean setEndPoint(java.lang.String id, float endX, float endY)Parameters: :
id- shape unique identifier :endX- line's new ending X value :endY- line's new ending Y value Returns: : false if id does not exist, true if operation completed. ONLY WORKS FOR LINES AND RECTANGLES -
public boolean setStartX(java.lang.String id, float startX)Parameters: :
id- unique shape identifier :startX- line's new starting X value Returns: : false if id does not exist, true if operation completed. -
public float getStartX(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : shape's starting X value ONLY WORKS WITH LINES AND RECTANGLES -
public boolean setStartY(java.lang.String id, float startY)Parameters: :
id- unique shape identifier :startY- shape's new starting Y value Returns: : false if id does not exist, true if operation completed. ONLY WORKS WITH LINES AND RECTANGLES -
public float getStartY(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : shape's starting Y value ONLY WORKS WITH RECTANGLES AND LINES -
public boolean setEndX(java.lang.String id, float endX)Parameters: :
id- unique shape identifier :endX- shape's new ending X value Returns: : false if id does not exist, true if operation completed. ONLY WORKS WITH LINES AND RECTANGLES -
public float getEndX(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : shape's ending X value ONLY WORKS WITH LINES AND RECTANGLES -
public boolean setEndY(java.lang.String id, float endY)Parameters: :
id- unique shape identifier :endY- shape's new ending Y value Returns: : false if id does not exist, true if operation completed. ONLY WORKS WITH LINES AND RECTANGLES -
public float getEndY(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : shape's ending Y value ONLY WORKS WITH LINES AND RECTANGLES -
public boolean setBitmap(java.lang.String id, Bitmap bitmap)Parameters: :
id- unique shape identifier :bitmap- new bitmap instance Returns: : false if id does not exist, true if operation completed. ONLY WORKS WITH BITMAPS -
public Bitmap getBitmap(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : current bitmap instance ONLY WORKS WITH BITMAPS -
public boolean setOvalLengths(java.lang.String id, float left, float top, float right, float bottom)Parameters: :
id- unique shape identifier :left- oval's new left length :top- oval's new top length :right- oval's new right length :bottom- oval's new bottom length Returns: : false if id does not exist, true if operation completed. ONLY WORKS WITH OVALS -
public boolean setRectPoints(java.lang.String id, float left, float top, float right, float bottom)Parameters: :
id- unique shape identifier :left- rectangle's new left length :top- rectangle's new top length :right- rectangle's new right length :bottom- rectangle's new bottom length Returns: : false if id does not exist, true if operation completed. ONLY WORKS WITH RECTANGLES -
public boolean setCircleCenterAndRadius(java.lang.String id, float x, float y, float radius)Parameters: :
id- unique shape identifier :x- circle's new center x value :y- circle's new center y value :radius- circle's new radius value Returns: : false if id does not exist, true if operation completed. ONLY WORKS WITH CIRCLES -
public boolean setLeft(java.lang.String id, float left)Parameters: :
id- unqiue shape identifier :left- shape's new left value Returns: : false if id does not exist, true if operation completed. ONLY WORKS WITH OVALS AND RECTANGLES -
public float getLeft(java.lang.String id)Parameters: :
id- unique shape identifer Returns: : false if id does not exist, true if operation completed. ONLY WORKS WITH OVALS AND RECTANGLES -
public boolean setTop(java.lang.String id, float top)Parameters: :
id- unique shape identifer :top- shape's new top value Returns: : false if id does not exist, true if operation completed. ONLY WORKS WITH OVALS AND RECTANGLES -
public float getTop(java.lang.String id)Parameters: :
id- unique shape identifer Returns: : shape's top value ONLY WORKS WITH OVALS AND RECTANGLES -
public boolean setRight(java.lang.String id, float right)Parameters: :
id- unique shape identifier :right- shape's new right value Returns: : false if id does not exist, true if operation completed. ONLY WORKS WITH OVALS AND RECTANGLES -
public float getRight(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : shape's right value ONLY WORKS WITH OVALS AND RECTANGLES -
public boolean setBottom(java.lang.String id, float bottom)Parameters: :
id- unique shape identifier :bottom- shape's new bottom value Returns: : false if id does not exist, true if operation completed. ONLY WORKS WITH OVAL AND RECTANGLES -
public float getBottom(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : shape's bottom value ONLY WORKS WITH OVALS AND RECTANGLES -
public boolean setPaint(java.lang.String id, Paint paint)Parameters: :
id- unique shape identifier :paint- new paint instance Returns: : false if id does not exist, true if operation completed. -
public Paint getPaint(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : paint instance belonging to given id -
public boolean bringToFront(java.lang.String id)Parameters: :
id- unique shshapeape identifier Returns: : false if id does not exist, true if operation completed. -
public boolean drawCircle(java.lang.String id, float x, float y, float radius, Paint paint, boolean visible)Parameters:
id- unique shape identifierx- center x valuey- center y valueradius- radius of circlepaint- describes color, stroke width, etcvisible- visibility of shapeReturns:
-
public boolean drawBitmap(java.lang.String id, Bitmap bitmap, float x, float y, Paint paint, boolean visible)Parameters:
id- unique shape identifierbitmap- bitmap instancex- bitmap x valuey- bitmap y valuepaint- describes color, stroke width, etcvisible- visibility of shapeReturns:
-
public boolean drawOval(java.lang.String id, float left, float top, float right, float bottom, Paint paint, boolean visible)Parameters:
id- unique shape identifierleft- positiontop- length valueright- length valuebottom- length valuepaint- describe color, stroke width, etcvisible- visibility of shapeReturns:
-
public boolean drawLine(java.lang.String id, float startX, float startY, float endX, float endY, Paint paint, boolean visible)Parameters:
id- unique shape identifierstartX- line starting x position valuestartY- line starting y position valueendX- line ending x valueendY- line ending y valuepaint- describe color, stroke width, etcvisible- visibility of shapeReturns:
-
public boolean drawPoint(java.lang.String id, float x, float y, Paint paint, boolean visible)Parameters:
id- unique shape identifierx- position of pointy- position of pointpaint- describe color, stroke width, etcvisible- visibility of shapeReturns:
-
public boolean drawRect(java.lang.String id, float left, float top, float right, float bottom, Paint paint, boolean visible)Parameters:
id- unique shape identifierleft- position valuetop- position valueright- position valuebottom- position valuepaint- describe color, stroke width, etcvisible- visibility of shapeReturns:
-
public boolean hide(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : false if id does not exist, true if operation completed. -
public boolean show(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : false if id does not exist, true if operation completed. -
public boolean isVisible(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : true if shape is visible -
public boolean remove(java.lang.String id)Parameters: :
id- unique shape identifier Returns: : false if id does not exist, true if operation completed. -
public Paint getDefaultPaint()Returns: : default paint that will be used if null is passed for a shape
-
public void setDefaultPaint(Paint paint)Parameters: :
paint- new default paint -
public void setAutoRedraw(boolean st)Parameters: :
st- set the state of auto redraw -
public boolean getAutoRedraw()Returns: : true if auto redraw is enabled
-
public void redraw()user invoked to force redraw
-
-
Source code can be found on github.
Developed by Mases Krikorian
