blob: e8cdbc32178a28e44b4ce1406a0f576aad48680d [file] [log] [blame]
Chet Haase858aa932011-05-12 09:06:00 -07001/*
2 * Copyright (C) 2011 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.animation.ObjectAnimator;
20import android.app.Activity;
21import android.content.Context;
22import android.graphics.Canvas;
23import android.graphics.Color;
24import android.graphics.Paint;
25import android.graphics.drawable.ColorDrawable;
26import android.os.Bundle;
27import android.view.View;
28import android.widget.FrameLayout;
29
30@SuppressWarnings({"UnusedDeclaration"})
31public class ColoredRectsActivity extends Activity {
32 private ObjectAnimator mAnimator;
33
34 @Override
35 protected void onCreate(Bundle savedInstanceState) {
36 super.onCreate(savedInstanceState);
37 getWindow().setBackgroundDrawable(new ColorDrawable(0xff000000));
38 FrameLayout frame = new FrameLayout(this);
39 final RectsView gpuView = new RectsView(this, 0, Color.GREEN);
40 frame.addView(gpuView);
41 final RectsView swView = new RectsView(this, 400, Color.RED);
42 swView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
43 frame.addView(swView);
44 final RectsView hwBothView = new RectsView(this, 850, Color.GREEN);
45 // Don't actually need to render to a hw layer, but it's a good sanity-check that
46 // we're rendering to/from layers correctly
47 hwBothView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
48 frame.addView(hwBothView);
49 final RectsView swBothView = new RectsView(this, 854, Color.RED);
50 swBothView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
51 frame.addView(swBothView);
52 setContentView(frame);
53 }
54
55 @Override
56 protected void onDestroy() {
57 super.onDestroy();
58 }
59
60 public static class RectsView extends View {
61
62 private float mOffset;
63 private int mColor;
64
65 public RectsView(Context c, float offset, int color) {
66 super(c);
67 mOffset = offset;
68 mColor = color;
69 }
70
71 @Override
72 protected void onDraw(Canvas canvas) {
73 super.onDraw(canvas);
74 Paint p = new Paint();
75 p.setColor(mColor);
76 float yOffset = 10;
77
78 for (int i = 0; i < 2; ++i) {
79 canvas.save();
80 canvas.translate(mOffset, yOffset);
81 canvas.drawRect(0, 0, 20, 10, p);
82 canvas.drawRect(35, 0, 45, 20, p);
83 canvas.translate(0, -yOffset);
84 canvas.scale(2, 2);
85 canvas.translate(60, yOffset/2);
86 canvas.drawRect(0, 0, 20, 10, p);
87 canvas.translate(15, 0);
88 canvas.drawRect(35, 0, 45, 20, p);
89 canvas.restore();
90
91 yOffset += 100;
92
93 canvas.save();
94 canvas.save();
95 canvas.translate(mOffset + 10, yOffset);
96 canvas.rotate(45);
97 canvas.drawRect(0, 0, 20, 10, p);
98 canvas.restore();
99 canvas.save();
100 canvas.translate(mOffset + 70, yOffset);
101 canvas.rotate(5);
102 canvas.drawRect(0, 0, 20, 10, p);
103 canvas.restore();
104 canvas.save();
105 canvas.translate(mOffset + 140, yOffset);
106 canvas.scale(2, 2);
107 canvas.rotate(5);
108 canvas.drawRect(0, 0, 20, 10, p);
109 canvas.restore();
110 canvas.save();
111 canvas.translate(mOffset + 210, yOffset);
112 canvas.scale(2, 2);
113 canvas.rotate(45);
114 canvas.drawRect(0, 0, 20, 10, p);
115 canvas.restore();
116 canvas.restore();
117
118 yOffset += 100;
119
120 p.setAntiAlias(true);
121 }
122 }
123 }
124}