ShapesActivity.java revision 01d58e43ede5ca98cbebdd166f9b0c545032c01b
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
17package com.android.test.hwui;
18
19import android.app.Activity;
20import android.content.Context;
21import android.graphics.Canvas;
22import android.graphics.Paint;
23import android.graphics.RectF;
24import android.os.Bundle;
25import android.view.View;
26
27@SuppressWarnings({"UnusedDeclaration"})
28public class ShapesActivity extends Activity {
29    @Override
30    protected void onCreate(Bundle savedInstanceState) {
31        super.onCreate(savedInstanceState);
32
33        setContentView(new ShapesView(this));
34    }
35
36    static class ShapesView extends View {
37        private Paint mNormalPaint;
38        private Paint mStrokePaint;
39        private Paint mFillPaint;
40        private RectF mRect;
41
42        ShapesView(Context c) {
43            super(c);
44
45            mRect = new RectF(0.0f, 0.0f, 160.0f, 90.0f);
46
47            mNormalPaint = new Paint();
48            mNormalPaint.setAntiAlias(true);
49            mNormalPaint.setColor(0xff0000ff);
50            mNormalPaint.setStrokeWidth(6.0f);
51            mNormalPaint.setStyle(Paint.Style.FILL_AND_STROKE);
52
53            mStrokePaint = new Paint();
54            mStrokePaint.setAntiAlias(true);
55            mStrokePaint.setColor(0xff0000ff);
56            mStrokePaint.setStrokeWidth(6.0f);
57            mStrokePaint.setStyle(Paint.Style.STROKE);
58
59            mFillPaint = new Paint();
60            mFillPaint.setAntiAlias(true);
61            mFillPaint.setColor(0xff0000ff);
62            mFillPaint.setStyle(Paint.Style.FILL);
63        }
64
65        @Override
66        protected void onDraw(Canvas canvas) {
67            super.onDraw(canvas);
68
69            canvas.save();
70            canvas.translate(50.0f, 50.0f);
71            canvas.drawRoundRect(mRect, 6.0f, 6.0f, mNormalPaint);
72
73            canvas.translate(0.0f, 110.0f);
74            canvas.drawRoundRect(mRect, 6.0f, 6.0f, mStrokePaint);
75
76            canvas.translate(0.0f, 110.0f);
77            canvas.drawRoundRect(mRect, 6.0f, 6.0f, mFillPaint);
78            canvas.restore();
79
80            canvas.save();
81            canvas.translate(250.0f, 50.0f);
82            canvas.drawCircle(80.0f, 45.0f, 45.0f, mNormalPaint);
83
84            canvas.translate(0.0f, 110.0f);
85            canvas.drawCircle(80.0f, 45.0f, 45.0f, mStrokePaint);
86
87            canvas.translate(0.0f, 110.0f);
88            canvas.drawCircle(80.0f, 45.0f, 45.0f, mFillPaint);
89            canvas.restore();
90        }
91    }
92}
93