Permalink
Browse files

Changing the Brush Size

  • Loading branch information...
dragosholban committed Apr 21, 2018
1 parent 62492a1 commit 34c985fffd029b2f8f614b8dccdbde6198b98811
@@ -17,6 +17,8 @@
private ArrayList<Path> paths = new ArrayList<>();
private ArrayList<Integer> colors = new ArrayList<>();
private int currentColor = 0xFF000000;
private ArrayList<Integer> widths = new ArrayList<>();
private int currentWidth = 6;
public DrawingView(Context context) {
super(context);
@@ -38,6 +40,7 @@ public DrawingView(Context context, @Nullable AttributeSet attrs, int defStyleAt
public void addPath(Path path) {
paths.add(path);
colors.add(currentColor);
widths.add(currentWidth);
}
public Path getLastPath() {
@@ -57,7 +60,7 @@ protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(colors.get(i));
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(3f);
paint.setStrokeWidth(widths.get(i));
canvas.drawPath(path, paint);
i++;
}
@@ -66,4 +69,8 @@ protected void onDraw(Canvas canvas) {
public void setCurrentColor(int color) {
currentColor = color;
}
public void setCurrentWidth(int width) {
currentWidth = (width + 1) * 2;
}
}
@@ -4,10 +4,12 @@
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.SeekBar;
public class MainActivity extends AppCompatActivity {
DrawingView drawingView;
SeekBar seekBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -16,6 +18,24 @@ protected void onCreate(Bundle savedInstanceState) {
drawingView = findViewById(R.id.canvas);
drawingView.setOnTouchListener(new TouchListener());
seekBar = findViewById(R.id.seekBar);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
drawingView.setCurrentWidth(progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
public void setColor(View view) {
@@ -31,7 +31,7 @@
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/seekBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<View
@@ -63,4 +63,16 @@
android:background="#000000"
android:onClick="setColor"/>
</LinearLayout>
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:max="9"
android:progress="2"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>

0 comments on commit 34c985f

Please sign in to comment.