forked from technojam/AndroidCustomView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgress.java
More file actions
95 lines (69 loc) · 2.59 KB
/
Progress.java
File metadata and controls
95 lines (69 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.example.customviewdemoapplication.Views;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
public class Progress extends View {
float mCircleX;
float mCircleY;
float sweepAngle = 180;
public Progress(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mCircleX = getWidth()/2;
mCircleY = getWidth()/2;
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStrokeWidth(50);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.GRAY);
canvas.drawCircle(mCircleX, mCircleY, getWidth()/3, paint);
Paint paint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
paint1.setStrokeWidth(50);
paint1.setStyle(Paint.Style.STROKE);
paint1.setColor(Color.RED);
paint1.setStrokeCap(Paint.Cap.ROUND);
RectF rect = new RectF();
rect.top = mCircleX - getWidth()/3;
rect.left = mCircleX - getWidth()/3;
rect.bottom = mCircleY + getWidth()/3;
rect.right = mCircleY + getWidth()/3;
//canvas.drawRect(rect, paint1);
canvas.drawArc(rect, 270, sweepAngle, false, paint1);
int correction = 200;
Paint paint2 = new Paint();
paint2.setColor(Color.BLUE);
paint2.setTextSize(50);
paint2.setTextAlign(Paint.Align.CENTER);
canvas.drawText("75", mCircleX, mCircleY+100, paint2);
}
/*
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean value = super.onTouchEvent(event);
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
return true;
case MotionEvent.ACTION_MOVE:
Toast.makeText(getContext(), "Click", Toast.LENGTH_SHORT).show();
float x = getX();
float y = getY();
double dx = Math.pow(x - mCircleX, 2);
double dy = Math.pow(y - mCircleY, 2);
if(dy + dx < Math.pow(getWidth()/3, 2)+100 & dy + dx > Math.pow(getWidth()/3, 2)-100){
Toast.makeText(getContext(), "Click inside", Toast.LENGTH_SHORT).show();
sweepAngle += 10;
postInvalidate();
return true;
}
return value;
}
return value;
}*/
}