1 /* 2 * Copyright (C) 2010 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.android.test.hwui; 18 19 import android.app.Activity; 20 import android.content.Context; 21 import android.graphics.Canvas; 22 import android.graphics.Paint; 23 import android.graphics.Path; 24 import android.os.Bundle; 25 import android.view.View; 26 import android.widget.LinearLayout; 27 28 @SuppressWarnings({"UnusedDeclaration"}) 29 public class SmallCircleActivity extends Activity { 30 @Override onCreate(Bundle savedInstanceState)31 protected void onCreate(Bundle savedInstanceState) { 32 super.onCreate(savedInstanceState); 33 34 final LinearLayout layout = new LinearLayout(this); 35 layout.setOrientation(LinearLayout.VERTICAL); 36 37 View view = new PathView(this); 38 layout.addView(view, new LinearLayout.LayoutParams(PathView.SIZE, PathView.SIZE)); 39 view = new PathView(this); 40 view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 41 layout.addView(view, new LinearLayout.LayoutParams(PathView.SIZE, PathView.SIZE)); 42 43 setContentView(layout); 44 } 45 46 static class PathView extends View { 47 private static final int SIZE = 37; 48 private final Paint mPaint; 49 private final Path mPath; 50 PathView(Context c)51 PathView(Context c) { 52 super(c); 53 54 mPath = new Path(); 55 mPath.addCircle(SIZE * 0.5f, SIZE * 0.5f, SIZE * 0.275f, Path.Direction.CW); 56 mPath.addCircle(SIZE * 0.5f, SIZE * 0.5f, SIZE * 0.225f, Path.Direction.CCW); 57 58 mPaint = new Paint(); 59 mPaint.setAntiAlias(true); 60 mPaint.setColor(0xff00ffff); 61 } 62 63 @Override onDraw(Canvas canvas)64 protected void onDraw(Canvas canvas) { 65 super.onDraw(canvas); 66 67 canvas.drawPath(mPath, mPaint); 68 } 69 } 70 } 71