blob: c25df7c1b44e4569f47c2706860114b04b8cbef0 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 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
Neal Nguyen1a44d5d2010-01-13 10:42:43 -080017package android.widget;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
19import android.content.Context;
20import android.graphics.Bitmap;
21import android.graphics.Canvas;
22import android.graphics.Paint;
23import android.test.AndroidTestCase;
24import android.test.suitebuilder.annotation.MediumTest;
25import android.test.suitebuilder.annotation.SmallTest;
26import android.text.SpannedString;
27import android.view.View;
28import android.view.ViewGroup;
29import android.widget.TextView;
30
31public class TextViewPerformanceTest extends AndroidTestCase {
32
33 private String mString = "The quick brown fox";
34 private Canvas mCanvas;
35 private PerformanceTextView mTextView;
36 private Paint mPaint;
37 private PerformanceLabelView mLabelView;
38
39 @Override
40 protected void setUp() throws Exception {
41 super.setUp();
42
43 Bitmap mBitmap = Bitmap.createBitmap(320, 240, Bitmap.Config.RGB_565);
44 mCanvas = new Canvas(mBitmap);
45
46 ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(320, 240);
47
48 mLabelView = new PerformanceLabelView(mContext);
49 mLabelView.setText(mString);
50 mLabelView.measure(View.MeasureSpec.AT_MOST | 320, View.MeasureSpec.AT_MOST | 240);
51 mLabelView.mySetFrame(320, 240);
52 mLabelView.setLayoutParams(p);
53 mLabelView.myDraw(mCanvas);
54
55 mPaint = new Paint();
56 mCanvas.save();
57 mTextView = new PerformanceTextView(mContext);
58 mTextView.setLayoutParams(p);
59 mTextView.setText(mString);
60 mTextView.mySetFrame(320, 240);
61 mTextView.measure(View.MeasureSpec.AT_MOST | 320, View.MeasureSpec.AT_MOST | 240);
62 }
63
64 @MediumTest
65 public void testDrawTextViewLine() throws Exception {
66 mTextView.myDraw(mCanvas);
67 mTextView.myDraw(mCanvas);
68 mTextView.myDraw(mCanvas);
69 mTextView.myDraw(mCanvas);
70 mTextView.myDraw(mCanvas);
71 mTextView.myDraw(mCanvas);
72 mTextView.myDraw(mCanvas);
73 mTextView.myDraw(mCanvas);
74 mTextView.myDraw(mCanvas);
75 mTextView.myDraw(mCanvas);
76 }
77
78 @SmallTest
79 public void testSpan() throws Exception {
80 CharSequence charSeq = new SpannedString(mString);
81 mTextView.setText(charSeq);
82
83 mTextView.myDraw(mCanvas);
84 mTextView.myDraw(mCanvas);
85 mTextView.myDraw(mCanvas);
86 mTextView.myDraw(mCanvas);
87 mTextView.myDraw(mCanvas);
88 mTextView.myDraw(mCanvas);
89 mTextView.myDraw(mCanvas);
90 mTextView.myDraw(mCanvas);
91 mTextView.myDraw(mCanvas);
92 mTextView.myDraw(mCanvas);
93 }
94
95 @SmallTest
96 public void testCanvasDrawText() throws Exception {
97 mCanvas.drawText(mString, 30, 30, mPaint);
98 }
99
100 @SmallTest
101 public void testLabelViewDraw() throws Exception {
102 mLabelView.myDraw(mCanvas);
103 }
104
105 private class PerformanceTextView extends TextView {
106 public PerformanceTextView(Context context) {
107 super(context);
108 }
109
110 final void myDraw(Canvas c) {
111 super.onDraw(c);
112 }
113
114 final void mySetFrame(int w, int h) {
115 super.setFrame(0, 0, w, h);
116 }
117 }
118
119 private class PerformanceLabelView extends LabelView {
120 public PerformanceLabelView(Context context) {
121 super(context);
122 }
123
124 final void myDraw(Canvas c) {
125 super.onDraw(c);
126 }
127
128 final void mySetFrame(int w, int h) {
129 super.setFrame(0, 0, w, h);
130 }
131 }
132}