blob: 14154a8894f4c793bbd15a9124f7fa5b15a1b8d6 [file] [log] [blame]
Romain Guy0bbae082010-06-15 18:03:40 -07001/*
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.google.android.test.hwui;
18
19import android.app.Activity;
20import android.content.Context;
Romain Guy0bbae082010-06-15 18:03:40 -070021import android.graphics.Canvas;
22import android.graphics.Paint;
23import android.os.Bundle;
Romain Guy9d5316e2010-06-24 19:30:36 -070024import android.util.Log;
Romain Guy0bbae082010-06-15 18:03:40 -070025import android.view.View;
26
Romain Guy9d5316e2010-06-24 19:30:36 -070027@SuppressWarnings({"UnusedDeclaration"})
Romain Guy0bbae082010-06-15 18:03:40 -070028public 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 Guy85bf02f2010-06-22 13:11:24 -070038 @SuppressWarnings({"UnusedDeclaration"})
Romain Guy0bbae082010-06-15 18:03:40 -070039 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 Guy9d5316e2010-06-24 19:30:36 -070044 private final Paint mPaint;
45
Romain Guy0bbae082010-06-15 18:03:40 -070046 DirtyBitmapView(Context c) {
47 super(c);
Romain Guy9d5316e2010-06-24 19:30:36 -070048 mPaint = new Paint();
Romain Guy0bbae082010-06-15 18:03:40 -070049 }
50
51 @Override
52 protected void onDraw(Canvas canvas) {
53 super.onDraw(canvas);
Romain Guy85bf02f2010-06-22 13:11:24 -070054
Romain Guy9d5316e2010-06-24 19:30:36 -070055 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 Guyc7d53492010-06-25 13:41:57 -070063 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 Guy9d5316e2010-06-24 19:30:36 -070067 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 Guyc7d53492010-06-25 13:41:57 -070073 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 Guy9d5316e2010-06-24 19:30:36 -070077 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 Guyc7d53492010-06-25 13:41:57 -070083 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 Guy9d5316e2010-06-24 19:30:36 -070087 canvas.restore();
Romain Guyc7d53492010-06-25 13:41:57 -070088
Romain Guy9d5316e2010-06-24 19:30:36 -070089 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 Guy0bbae082010-06-15 18:03:40 -070097 }
98 }
99}