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