Romain Guy | 0bbae08 | 2010-06-15 18:03:40 -0700 | [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.google.android.test.hwui; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.content.Context; |
Romain Guy | 0bbae08 | 2010-06-15 18:03:40 -0700 | [diff] [blame] | 21 | import android.graphics.Canvas; |
| 22 | import android.graphics.Paint; |
| 23 | import android.os.Bundle; |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 24 | import android.util.Log; |
Romain Guy | 0bbae08 | 2010-06-15 18:03:40 -0700 | [diff] [blame] | 25 | import android.view.View; |
| 26 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 27 | @SuppressWarnings({"UnusedDeclaration"}) |
Romain Guy | 0bbae08 | 2010-06-15 18:03:40 -0700 | [diff] [blame] | 28 | public class HwUiActivity extends Activity { |
| 29 | private static final String LOG_TAG = "HwUi"; |
| 30 | |
| 31 | @Override |
| 32 | protected void onCreate(Bundle savedInstanceState) { |
| 33 | super.onCreate(savedInstanceState); |
| 34 | |
| 35 | setContentView(new DirtyBitmapView(this)); |
| 36 | } |
| 37 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 38 | @SuppressWarnings({"UnusedDeclaration"}) |
Romain Guy | 0bbae08 | 2010-06-15 18:03:40 -0700 | [diff] [blame] | 39 | static int dipToPx(Context c, int dip) { |
| 40 | return (int) (c.getResources().getDisplayMetrics().density * dip + 0.5f); |
| 41 | } |
| 42 | |
| 43 | static class DirtyBitmapView extends View { |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 44 | private final Paint mPaint; |
| 45 | |
Romain Guy | 0bbae08 | 2010-06-15 18:03:40 -0700 | [diff] [blame] | 46 | DirtyBitmapView(Context c) { |
| 47 | super(c); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 48 | mPaint = new Paint(); |
Romain Guy | 0bbae08 | 2010-06-15 18:03:40 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Override |
| 52 | protected void onDraw(Canvas canvas) { |
| 53 | super.onDraw(canvas); |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 54 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 55 | canvas.drawRGB(255, 255, 255); |
| 56 | |
| 57 | mPaint.setColor(0xffff0000); |
| 58 | canvas.drawRect(200.0f, 0.0f, 220.0f, 20.0f, mPaint); |
| 59 | |
| 60 | canvas.save(); |
| 61 | canvas.clipRect(20.0f, 0.0f, 40.0f, 20.0f); |
| 62 | Log.d(LOG_TAG, "clipRect = " + canvas.getClipBounds()); |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame^] | 63 | Log.d(LOG_TAG, "rejected = " + canvas.quickReject(100.0f, 100.0f, 110.0f, 110.0f, |
| 64 | Canvas.EdgeType.BW)); |
| 65 | Log.d(LOG_TAG, "rejected = " + canvas.quickReject(25.0f, 5.0f, 30.0f, 10.0f, |
| 66 | Canvas.EdgeType.BW)); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 67 | canvas.restore(); |
| 68 | |
| 69 | canvas.save(); |
| 70 | canvas.scale(2.0f, 2.0f); |
| 71 | canvas.clipRect(20.0f, 0.0f, 40.0f, 20.0f); |
| 72 | Log.d(LOG_TAG, "clipRect = " + canvas.getClipBounds()); |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame^] | 73 | Log.d(LOG_TAG, "rejected = " + canvas.quickReject(50.0f, 50.0f, 60.0f, 60.0f, |
| 74 | Canvas.EdgeType.BW)); |
| 75 | Log.d(LOG_TAG, "rejected = " + canvas.quickReject(25.0f, 5.0f, 30.0f, 10.0f, |
| 76 | Canvas.EdgeType.BW)); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 77 | canvas.restore(); |
| 78 | |
| 79 | canvas.save(); |
| 80 | canvas.translate(20.0f, 20.0f); |
| 81 | canvas.clipRect(20.0f, 0.0f, 40.0f, 20.0f); |
| 82 | Log.d(LOG_TAG, "clipRect = " + canvas.getClipBounds()); |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame^] | 83 | Log.d(LOG_TAG, "rejected = " + canvas.quickReject(80.0f, 80.0f, 90.0f, 90.0f, |
| 84 | Canvas.EdgeType.BW)); |
| 85 | Log.d(LOG_TAG, "rejected = " + canvas.quickReject(25.0f, 5.0f, 30.0f, 10.0f, |
| 86 | Canvas.EdgeType.BW)); |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 87 | canvas.restore(); |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame^] | 88 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 89 | canvas.scale(2.0f, 2.0f); |
| 90 | canvas.clipRect(20.0f, 0.0f, 40.0f, 20.0f); |
| 91 | |
| 92 | mPaint.setColor(0xff00ff00); |
| 93 | canvas.drawRect(0.0f, 0.0f, 20.0f, 20.0f, mPaint); |
| 94 | |
| 95 | mPaint.setColor(0xff0000ff); |
| 96 | canvas.drawRect(20.0f, 0.0f, 40.0f, 20.0f, mPaint); |
Romain Guy | 0bbae08 | 2010-06-15 18:03:40 -0700 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | } |