Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 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; |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 23 | import android.graphics.Path; |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 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 |
| 31 | protected void onCreate(Bundle savedInstanceState) { |
| 32 | super.onCreate(savedInstanceState); |
| 33 | |
| 34 | setContentView(new ShapesView(this)); |
| 35 | } |
| 36 | |
| 37 | static class ShapesView extends View { |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 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; |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 45 | |
| 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); |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 67 | |
| 68 | mOval = new RectF(0.0f, 0.0f, 80.0f, 45.0f); |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 69 | mArc = new RectF(0.0f, 0.0f, 100.0f, 120.0f); |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 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(); |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
| 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(); |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 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(); |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 116 | canvas.translate(625.0f, 50.0f); |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 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(); |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 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(); |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 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(); |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | } |