• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.example.android.apis.graphics;
18 
19 // Need the following import to get access to the app resources, since this
20 // class is in a sub-package.
21 //import com.example.android.apis.R;
22 
23 import android.app.Activity;
24 import android.content.Context;
25 import android.graphics.*;
26 import android.os.Bundle;
27 import android.view.KeyEvent;
28 import android.view.View;
29 
30 public class PathFillTypes extends GraphicsActivity {
31 
32     @Override
onCreate(Bundle savedInstanceState)33     protected void onCreate(Bundle savedInstanceState) {
34         super.onCreate(savedInstanceState);
35         setContentView(new SampleView(this));
36     }
37 
38     private static class SampleView extends View {
39         private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
40         private Path mPath;
41 
SampleView(Context context)42         public SampleView(Context context) {
43             super(context);
44             setFocusable(true);
45             setFocusableInTouchMode(true);
46 
47             mPath = new Path();
48             mPath.addCircle(40, 40, 45, Path.Direction.CCW);
49             mPath.addCircle(80, 80, 45, Path.Direction.CCW);
50         }
51 
showPath(Canvas canvas, int x, int y, Path.FillType ft, Paint paint)52         private void showPath(Canvas canvas, int x, int y, Path.FillType ft,
53                               Paint paint) {
54             canvas.save();
55             canvas.translate(x, y);
56             canvas.clipRect(0, 0, 120, 120);
57             canvas.drawColor(Color.WHITE);
58             mPath.setFillType(ft);
59             canvas.drawPath(mPath, paint);
60             canvas.restore();
61         }
62 
onDraw(Canvas canvas)63         @Override protected void onDraw(Canvas canvas) {
64             Paint paint = mPaint;
65 
66             canvas.drawColor(0xFFCCCCCC);
67 
68             canvas.translate(20, 20);
69 
70             paint.setAntiAlias(true);
71 
72             showPath(canvas, 0, 0, Path.FillType.WINDING, paint);
73             showPath(canvas, 160, 0, Path.FillType.EVEN_ODD, paint);
74             showPath(canvas, 0, 160, Path.FillType.INVERSE_WINDING, paint);
75             showPath(canvas, 160, 160, Path.FillType.INVERSE_EVEN_ODD, paint);
76         }
77     }
78 }
79 
80