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.graphics.RectF; 25 import android.os.Bundle; 26 import android.view.View; 27 28 @SuppressWarnings({"UnusedDeclaration"}) 29 public class ShapesActivity extends Activity { 30 @Override onCreate(Bundle savedInstanceState)31 protected void onCreate(Bundle savedInstanceState) { 32 super.onCreate(savedInstanceState); 33 34 setContentView(new ShapesView(this)); 35 } 36 37 static class ShapesView extends View { 38 private final Paint mNormalPaint; 39 private final Paint mStrokePaint; 40 private final Paint mFillPaint; 41 private final RectF mRect; 42 private final RectF mOval; 43 private final RectF mArc; 44 private final Path mTriangle; 45 ShapesView(Context c)46 ShapesView(Context c) { 47 super(c); 48 49 mRect = new RectF(0.0f, 0.0f, 160.0f, 90.0f); 50 51 mNormalPaint = new Paint(); 52 mNormalPaint.setAntiAlias(true); 53 mNormalPaint.setColor(0xff0000ff); 54 mNormalPaint.setStrokeWidth(6.0f); 55 mNormalPaint.setStyle(Paint.Style.FILL_AND_STROKE); 56 57 mStrokePaint = new Paint(); 58 mStrokePaint.setAntiAlias(true); 59 mStrokePaint.setColor(0xff0000ff); 60 mStrokePaint.setStrokeWidth(6.0f); 61 mStrokePaint.setStyle(Paint.Style.STROKE); 62 63 mFillPaint = new Paint(); 64 mFillPaint.setAntiAlias(true); 65 mFillPaint.setColor(0xff0000ff); 66 mFillPaint.setStyle(Paint.Style.FILL); 67 68 mOval = new RectF(0.0f, 0.0f, 80.0f, 45.0f); 69 mArc = new RectF(0.0f, 0.0f, 100.0f, 120.0f); 70 71 mTriangle = new Path(); 72 mTriangle.moveTo(0.0f, 90.0f); 73 mTriangle.lineTo(45.0f, 0.0f); 74 mTriangle.lineTo(90.0f, 90.0f); 75 mTriangle.close(); 76 } 77 78 @Override onDraw(Canvas canvas)79 protected void onDraw(Canvas canvas) { 80 super.onDraw(canvas); 81 82 canvas.save(); 83 canvas.translate(50.0f, 50.0f); 84 canvas.drawRoundRect(mRect, 6.0f, 6.0f, mNormalPaint); 85 86 canvas.translate(0.0f, 110.0f); 87 canvas.drawRoundRect(mRect, 6.0f, 6.0f, mStrokePaint); 88 89 canvas.translate(0.0f, 110.0f); 90 canvas.drawRoundRect(mRect, 6.0f, 6.0f, mFillPaint); 91 canvas.restore(); 92 93 canvas.save(); 94 canvas.translate(250.0f, 50.0f); 95 canvas.drawCircle(80.0f, 45.0f, 45.0f, mNormalPaint); 96 97 canvas.translate(0.0f, 110.0f); 98 canvas.drawCircle(80.0f, 45.0f, 45.0f, mStrokePaint); 99 100 canvas.translate(0.0f, 110.0f); 101 canvas.drawCircle(80.0f, 45.0f, 45.0f, mFillPaint); 102 canvas.restore(); 103 104 canvas.save(); 105 canvas.translate(450.0f, 50.0f); 106 canvas.drawOval(mOval, mNormalPaint); 107 108 canvas.translate(0.0f, 110.0f); 109 canvas.drawOval(mOval, mStrokePaint); 110 111 canvas.translate(0.0f, 110.0f); 112 canvas.drawOval(mOval, mFillPaint); 113 canvas.restore(); 114 115 canvas.save(); 116 canvas.translate(625.0f, 50.0f); 117 canvas.drawRect(0.0f, 0.0f, 160.0f, 90.0f, mNormalPaint); 118 119 canvas.translate(0.0f, 110.0f); 120 canvas.drawRect(0.0f, 0.0f, 160.0f, 90.0f, mStrokePaint); 121 122 canvas.translate(0.0f, 110.0f); 123 canvas.drawRect(0.0f, 0.0f, 160.0f, 90.0f, mFillPaint); 124 canvas.restore(); 125 126 canvas.save(); 127 canvas.translate(825.0f, 50.0f); 128 canvas.drawArc(mArc, -30.0f, 70.0f, true, mNormalPaint); 129 130 canvas.translate(0.0f, 110.0f); 131 canvas.drawArc(mArc, -30.0f, 70.0f, true, mStrokePaint); 132 133 canvas.translate(0.0f, 110.0f); 134 canvas.drawArc(mArc, -30.0f, 70.0f, true, mFillPaint); 135 canvas.restore(); 136 137 canvas.save(); 138 canvas.translate(950.0f, 50.0f); 139 canvas.drawArc(mArc, 30.0f, 100.0f, false, mNormalPaint); 140 141 canvas.translate(0.0f, 110.0f); 142 canvas.drawArc(mArc, 30.0f, 100.0f, false, mStrokePaint); 143 144 canvas.translate(0.0f, 110.0f); 145 canvas.drawArc(mArc, 30.0f, 100.0f, false, mFillPaint); 146 canvas.restore(); 147 148 canvas.save(); 149 canvas.translate(50.0f, 400.0f); 150 canvas.drawPath(mTriangle, mNormalPaint); 151 152 canvas.translate(110.0f, 0.0f); 153 canvas.drawPath(mTriangle, mStrokePaint); 154 155 canvas.translate(110.0f, 0.0f); 156 canvas.drawPath(mTriangle, mFillPaint); 157 canvas.restore(); 158 } 159 } 160 } 161