Skip to content

Commit

Permalink
Merge pull request #10 from infotech-group/travis
Browse files Browse the repository at this point in the history
problem: need CI

Conflicts:
	README.md
  • Loading branch information
meoyawn authored and Korilakkuma committed Aug 6, 2017
1 parent 34c94d6 commit 7e46eac
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 31 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: android
jdk: oraclejdk8

android:
components:
- tools
- platform-tools
- build-tools-25.0.2
- android-25
102 changes: 71 additions & 31 deletions CanvasView/app/src/main/java/com/android/graphics/CanvasView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@

package com.android.graphics;

import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.PorterDuffXfermode;
import android.graphics.PorterDuff;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.view.View;
import android.view.MotionEvent;
// import android.util.Log;
// import android.widget.Toast;
import android.view.View;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;

/**
* This class defines fields and methods for drawing.
Expand All @@ -52,13 +51,14 @@ public enum Drawer {
QUBIC_BEZIER;
}

private Context context = null;
private Canvas canvas = null;
private Bitmap bitmap = null;

private List<Path> pathLists = new ArrayList<Path>();
private List<Paint> paintLists = new ArrayList<Paint>();

private final Paint emptyPaint = new Paint();

// for Eraser
private int baseColor = Color.WHITE;

Expand All @@ -71,13 +71,14 @@ public enum Drawer {
private boolean isDown = false;

// for Paint
private Paint.Style paintStyle = Paint.Style.STROKE;
private int paintStrokeColor = Color.BLACK;
private int paintFillColor = Color.BLACK;
private float paintStrokeWidth = 3F;
private int opacity = 255;
private float blur = 0F;
private Paint.Cap lineCap = Paint.Cap.ROUND;
private Paint.Style paintStyle = Paint.Style.STROKE;
private int paintStrokeColor = Color.BLACK;
private int paintFillColor = Color.BLACK;
private float paintStrokeWidth = 3F;
private int opacity = 255;
private float blur = 0F;
private Paint.Cap lineCap = Paint.Cap.ROUND;
private PathEffect drawPathEffect = null;

// for Text
private String text = "";
Expand All @@ -103,7 +104,7 @@ public enum Drawer {
*/
public CanvasView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.setup(context);
this.setup();
}

/**
Expand All @@ -114,7 +115,7 @@ public CanvasView(Context context, AttributeSet attrs, int defStyle) {
*/
public CanvasView(Context context, AttributeSet attrs) {
super(context, attrs);
this.setup(context);
this.setup();
}

/**
Expand All @@ -124,16 +125,14 @@ public CanvasView(Context context, AttributeSet attrs) {
*/
public CanvasView(Context context) {
super(context);
this.setup(context);
this.setup();
}

/**
* Common initialization.
*
* @param context
*/
private void setup(Context context) {
this.context = context;
private void setup() {

this.pathLists.add(new Path());
this.paintLists.add(this.createPaint());
Expand Down Expand Up @@ -177,6 +176,7 @@ private Paint createPaint() {
paint.setColor(this.paintStrokeColor);
paint.setShadowLayer(this.blur, 0F, 0F, this.paintStrokeColor);
paint.setAlpha(this.opacity);
paint.setPathEffect(this.drawPathEffect);
}

return paint;
Expand Down Expand Up @@ -207,7 +207,6 @@ private Path createPath(MotionEvent event) {
* "Undo" and "Redo" are enabled by this method.
*
* @param path the instance of Path
* @param paint the instance of Paint
*/
private void updateHistory(Path path) {
if (this.historyPointer == this.pathLists.size()) {
Expand Down Expand Up @@ -350,7 +349,13 @@ private void onActionMove(MotionEvent event) {
break;
case RECTANGLE :
path.reset();
path.addRect(this.startX, this.startY, x, y, Path.Direction.CCW);

float left = Math.min(this.startX, x);
float right = Math.max(this.startX, x);
float top = Math.min(this.startY, y);
float bottom = Math.max(this.startY, y);

path.addRect(left, top, right, bottom, Path.Direction.CCW);
break;
case CIRCLE :
double distanceX = Math.abs((double)(this.startX - x));
Expand Down Expand Up @@ -418,7 +423,7 @@ protected void onDraw(Canvas canvas) {
canvas.drawColor(this.baseColor);

if (this.bitmap != null) {
canvas.drawBitmap(this.bitmap, 0F, 0F, new Paint());
canvas.drawBitmap(this.bitmap, 0F, 0F, emptyPaint);
}

for (int i = 0; i < this.historyPointer; i++) {
Expand Down Expand Up @@ -497,13 +502,31 @@ public void setDrawer(Drawer drawer) {
this.drawer = drawer;
}

/**
* This method checks if Undo is available
*
* @return If Undo is available, this is returned as true. Otherwise, this is returned as false.
*/
public boolean canUndo() {
return this.historyPointer > 1;
}

/**
* This method checks if Redo is available
*
* @return If Redo is available, this is returned as true. Otherwise, this is returned as false.
*/
public boolean canRedo() {
return this.historyPointer < this.pathLists.size();
}

/**
* This method draws canvas again for Undo.
*
* @return If Undo is enabled, this is returned as true. Otherwise, this is returned as false.
*/
public boolean undo() {
if (this.historyPointer > 1) {
if (canUndo()) {
this.historyPointer--;
this.invalidate();

Expand All @@ -519,7 +542,7 @@ public boolean undo() {
* @return If Redo is enabled, this is returned as true. Otherwise, this is returned as false.
*/
public boolean redo() {
if (this.historyPointer < this.pathLists.size()) {
if (canRedo()) {
this.historyPointer++;
this.invalidate();

Expand Down Expand Up @@ -744,6 +767,23 @@ public void setLineCap(Paint.Cap cap) {
this.lineCap = cap;
}

/**
* This method is getter for path effect of drawing.
*
* @return drawPathEffect
*/
public PathEffect getDrawPathEffect() {
return drawPathEffect;
}

/**
* This method is setter for path effect of drawing.
*
* @param drawPathEffect
*/
public void setDrawPathEffect(PathEffect drawPathEffect) {
this.drawPathEffect = drawPathEffect;
}
/**
* This method is getter for font size,
*
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![](https://jitpack.io/v/infotech-group/CanvasView.svg)](https://jitpack.io/#infotech-group/CanvasView)
[![Build Status](https://travis-ci.org/infotech-group/CanvasView.svg?branch=master)](https://travis-ci.org/infotech-group/CanvasView)

CanvasView
=========

Expand Down

0 comments on commit 7e46eac

Please sign in to comment.