File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 11
11
public class SampleView extends View {
12
12
13
13
private Paint paint = new Paint ();
14
+ private int color = Color .RED ;
15
+ private int bx = 100 ;
16
+ private int by = 100 ;
17
+ private int R = 50 ;
14
18
public SampleView (Context context ) {
15
19
super (context );
16
20
setBackgroundColor (Color .WHITE );
17
21
}
18
22
19
23
@ Override
20
24
public void onDraw (Canvas canvas ){
21
- canvas .drawCircle (100 , 100 , 20 , paint );
25
+ paint .setColor (color );
26
+ canvas .drawCircle (100 , 100 , R , paint );
22
27
}
23
28
24
29
@ Override
25
30
public boolean onTouchEvent (MotionEvent event ){
26
- Toast .makeText (getContext (), "Touch" , Toast .LENGTH_SHORT ).show ();
31
+ int action = event .getAction ();
32
+ if ((action & MotionEvent .ACTION_MASK ) == MotionEvent .ACTION_DOWN ){
33
+ int ex = (int )event .getX ();
34
+ int ey = (int )event .getY ();
35
+ if ((bx - ex )*(bx - ex )+(by - ey )*(by - ey ) <= R *R ){
36
+ Toast .makeText (getContext (),"Touch‚³‚ê‚Ü‚µ‚½" , Toast .LENGTH_SHORT ).show ();
37
+ if (color == Color .BLUE ){
38
+ color = Color .RED ;
39
+ } else {
40
+ color = Color .BLUE ;
41
+ }
42
+ invalidate (); // Ä•`‰æ
43
+ }
44
+ }
27
45
return true ;
28
46
}
29
47
}
You can’t perform that action at this time.
0 commit comments