ClearActivity.java revision f09ef51889f75289b041f9e9f949b7b82ed5b686
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.Bitmap;
22import android.graphics.BitmapFactory;
23import android.graphics.BitmapShader;
24import android.graphics.Canvas;
25import android.graphics.Paint;
26import android.graphics.Path;
27import android.graphics.PorterDuff;
28import android.graphics.PorterDuffXfermode;
29import android.os.Bundle;
30import android.view.View;
31
32@SuppressWarnings({"UnusedDeclaration"})
33public class ClearActivity extends Activity {
34    @Override
35    protected void onCreate(Bundle savedInstanceState) {
36        super.onCreate(savedInstanceState);
37        final PathsView view = new PathsView(this);
38        setContentView(view);
39    }
40
41    public static class PathsView extends View {
42        private final Bitmap mBitmap1;
43        private final Paint mClearPaint;
44        private final Path mPath;
45
46        public PathsView(Context c) {
47            super(c);
48
49            mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset2);
50
51            mClearPaint = new Paint();
52            mClearPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
53            mClearPaint.setAntiAlias(true);
54            mClearPaint.setColor(0x0000ff00);
55            mClearPaint.setStrokeWidth(15.0f);
56            mClearPaint.setStyle(Paint.Style.FILL);
57            mClearPaint.setTextSize(32.0f);
58
59            mPath = new Path();
60            mPath.moveTo(0.0f, 0.0f);
61            mPath.cubicTo(0.0f, 0.0f, 100.0f, 150.0f, 100.0f, 200.0f);
62            mPath.cubicTo(100.0f, 200.0f, 50.0f, 300.0f, -80.0f, 200.0f);
63            mPath.cubicTo(-80.0f, 200.0f, 100.0f, 200.0f, 200.0f, 0.0f);
64
65        }
66
67        @Override
68        protected void onDraw(Canvas canvas) {
69            super.onDraw(canvas);
70
71            canvas.save(); {
72                canvas.drawARGB(255, 255, 255, 255);
73                canvas.drawRect(100.0f, 100.0f, 200.0f, 200.0f, mClearPaint);
74                canvas.drawCircle(150.0f, 400.0f, 100.0f, mClearPaint);
75                canvas.drawBitmap(mBitmap1, 400.0f, 100.0f, mClearPaint);
76                canvas.save(); {
77                    canvas.translate(400.0f, 400.0f);
78                    canvas.drawPath(mPath, mClearPaint);
79                }
80                canvas.restore();
81                canvas.drawText("OpenGLRenderer", 50.0f, 50.0f, mClearPaint);
82            }
83            canvas.restore();
84        }
85    }
86}
87