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.os.Bundle; 26 import android.util.Log; 27 import android.view.View; 28 29 @SuppressWarnings({"UnusedDeclaration"}) 30 public class QuickRejectActivity extends Activity { 31 @Override onCreate(Bundle savedInstanceState)32 protected void onCreate(Bundle savedInstanceState) { 33 super.onCreate(savedInstanceState); 34 final QuickRejectView view = new QuickRejectView(this); 35 setContentView(view); 36 } 37 38 static class QuickRejectView extends View { 39 private Paint mBitmapPaint; 40 private final Bitmap mBitmap1; 41 QuickRejectView(Context c)42 QuickRejectView(Context c) { 43 super(c); 44 45 mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1); 46 47 mBitmapPaint = new Paint(); 48 mBitmapPaint.setFilterBitmap(true); 49 } 50 51 @Override onDraw(Canvas canvas)52 protected void onDraw(Canvas canvas) { 53 super.onDraw(canvas); 54 55 int count = canvas.getSaveCount(); 56 Log.d("OpenGLRenderer", "count=" + count); 57 count = canvas.save(); 58 Log.d("OpenGLRenderer", "count after save=" + count); 59 count = canvas.getSaveCount(); 60 Log.d("OpenGLRenderer", "getSaveCount after save=" + count); 61 canvas.restore(); 62 count = canvas.getSaveCount(); 63 Log.d("OpenGLRenderer", "count after restore=" + count); 64 canvas.save(); 65 Log.d("OpenGLRenderer", "count after save=" + canvas.getSaveCount()); 66 canvas.save(); 67 Log.d("OpenGLRenderer", "count after save=" + canvas.getSaveCount()); 68 canvas.save(); 69 Log.d("OpenGLRenderer", "count after save=" + canvas.getSaveCount()); 70 canvas.restoreToCount(count); 71 count = canvas.getSaveCount(); 72 Log.d("OpenGLRenderer", "count after restoreToCount=" + count); 73 count = canvas.saveLayer(0, 0, 10, 10, mBitmapPaint, Canvas.ALL_SAVE_FLAG); 74 Log.d("OpenGLRenderer", "count after saveLayer=" + count); 75 count = canvas.getSaveCount(); 76 Log.d("OpenGLRenderer", "getSaveCount after saveLayer=" + count); 77 canvas.restore(); 78 count = canvas.getSaveCount(); 79 Log.d("OpenGLRenderer", "count after restore=" + count); 80 81 canvas.save(); 82 canvas.clipRect(0.0f, 0.0f, 40.0f, 40.0f); 83 canvas.drawBitmap(mBitmap1, 0.0f, 0.0f, mBitmapPaint); 84 canvas.drawBitmap(mBitmap1, -mBitmap1.getWidth(), 0.0f, mBitmapPaint); 85 canvas.drawBitmap(mBitmap1, 50.0f, 0.0f, mBitmapPaint); 86 canvas.restore(); 87 } 88 } 89 }