The key for release to market has been expired. Needs new key and package name.
[0xbench:0xbench.git] / src / org / zeroxlab / graphics / DrawCircle.java
1 /*
2  * Copyright (C) 2010 0xlab - http://0xlab.org/
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 org.zeroxlab.graphics;
18
19 import org.zeroxlab.zeroxbenchmark.Tester;
20
21 import android.app.Activity;
22 import android.content.Context;
23 import android.graphics.Canvas;
24 import android.graphics.Color;
25 import android.graphics.Paint;
26
27 import android.os.Bundle;
28 import android.view.View;
29
30 public class DrawCircle extends Tester {
31     /** Called when the activity is first created. */
32
33     SampleView mView;
34
35     public String getTag() {
36         return "DrawCircle";
37     }
38
39     public int sleepBeforeStart() {
40         return 1000;
41     }
42
43     public int sleepBetweenRound() {
44         return 0;
45     }
46
47     public void oneRound() {
48         mView.postInvalidate();
49     }
50
51     @Override
52     public void onCreate(Bundle savedInstanceState) {
53         super.onCreate(savedInstanceState);
54         mView = new SampleView(this);
55         setContentView(mView);
56     }
57
58     private class SampleView extends View {
59         private Paint[] mPaints;
60         private Paint mFramePaint;
61
62         private float mSweep;
63         private int mBigIndex;
64
65         private final float SWEEP_INC = 2;
66         private int counter = 0;
67         int i, row;
68         long current;
69         long last;
70
71         public SampleView(Context context) {
72             super(context);
73
74             mPaints = new Paint[4];
75
76             mPaints[0] = new Paint();
77             mPaints[0].setAntiAlias(true);
78             mPaints[0].setStyle(Paint.Style.FILL);
79             mPaints[0].setColor(0x88FF0000);
80
81             mPaints[1] = new Paint(mPaints[0]);
82             mPaints[1].setColor(0x8800FF00);
83
84             mPaints[2] = new Paint(mPaints[0]);
85             mPaints[2].setStyle(Paint.Style.STROKE);
86             mPaints[2].setStrokeWidth(4);
87             mPaints[2].setColor(0x880000FF);
88
89             mPaints[3] = new Paint(mPaints[2]);
90             mPaints[3].setColor(0x88888888);
91
92             mFramePaint = new Paint();
93             mFramePaint.setAntiAlias(true);
94             mFramePaint.setTextSize(40);
95             mFramePaint.setStyle(Paint.Style.STROKE);
96             mFramePaint.setStrokeWidth(0);
97         }
98
99         @Override
100         protected void onWindowVisibilityChanged(int visibility) {
101             super.onWindowVisibilityChanged(visibility);
102             if (visibility != View.VISIBLE) {
103                 return;
104             }
105
106             startTester();
107         }
108
109         @Override
110         protected void onDraw(Canvas canvas) {
111             canvas.drawColor(Color.WHITE);
112
113             canvas.drawCircle(160f, 150f, 120f, mPaints[mBigIndex]);
114             canvas.drawText(counter + "th time", 30, 160, mFramePaint);
115             canvas.drawText((current - last) + "ms", 30, 200, mFramePaint);
116
117             for (row = 0; row < 8; row++) {
118                 for (i = 0; i < 4; i++) {
119                     canvas.drawCircle(40.0f + i * 80, 40.0f + row * 60, mSweep,
120                             mPaints[i]);
121                 }
122             }
123
124             mSweep += SWEEP_INC;
125             if (mSweep > 80) {
126                 mSweep -= 80;
127                 mBigIndex = (mBigIndex + 1) % 4;
128                 counter++;
129                 last = current;
130                 current = System.currentTimeMillis();
131
132             }
133
134             invalidate();
135             decreaseCounter();
136         }
137     }
138 }