Skip to content

Commit

Permalink
add option in xml paint color and stork size
Browse files Browse the repository at this point in the history
update android studio version
  • Loading branch information
KishanViramgama committed Nov 14, 2019
1 parent cc25a91 commit 2ba7a5e
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 7 deletions.
14 changes: 12 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

<com.app.drawing.Util.CanvasView
android:id="@+id/canvas_drawing"
app:paintColor="@color/colorPrimary"
app:paintStork="10"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'

classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
13 changes: 13 additions & 0 deletions library/src/main/java/com/app/drawing/Util/CanvasView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
Expand All @@ -11,7 +12,10 @@
import android.view.MotionEvent;
import android.view.View;

import com.app.kids.mylibrary.R;

public class CanvasView extends View {

private Bitmap bitmap;
private Canvas canvas;
private Path path;
Expand All @@ -21,6 +25,11 @@ public class CanvasView extends View {
public CanvasView(Context context, AttributeSet attrs) {
super(context, attrs);

TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.CanvasView,
0, 0);

path = new Path();
bitmapPaint = new Paint(Paint.DITHER_FLAG);

Expand All @@ -33,6 +42,9 @@ public CanvasView(Context context, AttributeSet attrs) {
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeWidth(9);

paint.setColor(a.getColor(R.styleable.CanvasView_paintColor, 0));
paint.setStrokeWidth(a.getColor(R.styleable.CanvasView_paintStork, 0));

}

@Override
Expand Down Expand Up @@ -125,6 +137,7 @@ public void paintColor(int color) {
paint.setColor(color);
}

//stork size
public void paintStork(int width) {
paint.setStrokeWidth(width);
}
Expand Down
9 changes: 9 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CanvasView">

<attr name="paintColor" format="color" />
<attr name="paintStork" format="integer"/>

</declare-styleable>
</resources>

0 comments on commit 2ba7a5e

Please sign in to comment.