• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.android.test.hwui;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.graphics.Canvas;
22 import android.graphics.Paint;
23 import android.os.Bundle;
24 import android.view.View;
25 
26 @SuppressWarnings({"UnusedDeclaration"})
27 public class TextActivity extends Activity {
28     @Override
onCreate(Bundle savedInstanceState)29     protected void onCreate(Bundle savedInstanceState) {
30         super.onCreate(savedInstanceState);
31 
32         setContentView(new CustomTextView(this));
33     }
34 
35     static class CustomTextView extends View {
36         private final Paint mMediumPaint;
37         private final Paint mLargePaint;
38         private final Paint mStrikePaint;
39         private final Paint mScaledPaint;
40         private final Paint mSkewPaint;
41         private final Paint mHugePaint;
42 
CustomTextView(Context c)43         CustomTextView(Context c) {
44             super(c);
45 
46             mMediumPaint = new Paint();
47             mMediumPaint.setAntiAlias(true);
48             mMediumPaint.setColor(0xffff0000);
49 
50             mLargePaint = new Paint();
51             mLargePaint.setAntiAlias(true);
52             mLargePaint.setTextSize(36.0f);
53 
54             mStrikePaint = new Paint();
55             mStrikePaint.setAntiAlias(true);
56             mStrikePaint.setTextSize(16.0f);
57             mStrikePaint.setUnderlineText(true);
58 
59             mScaledPaint = new Paint();
60             mScaledPaint.setAntiAlias(true);
61             mScaledPaint.setTextSize(16.0f);
62             mScaledPaint.setShadowLayer(3.0f, 3.0f, 3.0f, 0xff00ff00);
63 
64             mSkewPaint = new Paint();
65             mSkewPaint.setAntiAlias(true);
66             mSkewPaint.setTextSize(16.0f);
67             mSkewPaint.setShadowLayer(3.0f, 3.0f, 3.0f, 0xff000000);
68 
69             mHugePaint = new Paint();
70             mHugePaint.setAntiAlias(true);
71             mHugePaint.setColor(0xff000000);
72             mHugePaint.setTextSize(300f);
73         }
74 
75         @Override
onDraw(Canvas canvas)76         protected void onDraw(Canvas canvas) {
77             super.onDraw(canvas);
78             canvas.drawRGB(255, 255, 255);
79 
80             mMediumPaint.setStyle(Paint.Style.FILL_AND_STROKE);
81             mMediumPaint.setStrokeWidth(2.0f);
82             canvas.drawText("Hello OpenGL renderer!", 100, 20, mMediumPaint);
83 
84             mMediumPaint.setStyle(Paint.Style.FILL);
85             mMediumPaint.setTextAlign(Paint.Align.CENTER);
86             canvas.drawText("Hello OpenGL renderer!", 100, 40, mMediumPaint);
87 
88             mMediumPaint.setStyle(Paint.Style.STROKE);
89             mMediumPaint.setStrokeWidth(2.0f);
90             mMediumPaint.setTextAlign(Paint.Align.RIGHT);
91             canvas.drawText("Hello OpenGL renderer!", 100, 60, mMediumPaint);
92 
93             mMediumPaint.setStyle(Paint.Style.FILL);
94             mMediumPaint.setTextAlign(Paint.Align.LEFT);
95             canvas.drawText("Hello OpenGL renderer!", 100, 100, mMediumPaint);
96 
97             mMediumPaint.setShadowLayer(2.5f, 0.0f, 0.0f, 0xff000000);
98             canvas.drawText("Hello OpenGL renderer!", 100, 150, mMediumPaint);
99             mMediumPaint.clearShadowLayer();
100             canvas.drawText("Hello OpenGL renderer!", 100, 200, mLargePaint);
101 
102             mLargePaint.setShadowLayer(2.5f, 3.0f, 3.0f, 0xff000000);
103             canvas.drawText("Hello OpenGL renderer!", 100, 400, mLargePaint);
104             mLargePaint.setShadowLayer(3.0f, 3.0f, 3.0f, 0xff00ff00);
105             mLargePaint.setAlpha(100);
106             canvas.drawText("Hello OpenGL renderer!", 100, 500, mLargePaint);
107             mLargePaint.setAlpha(255);
108             mLargePaint.setShadowLayer(3.0f, 3.0f, 3.0f, 0xd000ff00);
109             mLargePaint.setColor(0x00ffff00);
110             canvas.drawText("Hello OpenGL renderer!", 100, 600, mLargePaint);
111             mLargePaint.setShadowLayer(3.0f, 3.0f, 3.0f, 0x80000000);
112             mLargePaint.setColor(0x4dffffff);
113             canvas.drawText("Hello OpenGL renderer!", 100, 650, mLargePaint);
114             mLargePaint.setAlpha(255);
115             mLargePaint.setColor(0xff000000);
116             mLargePaint.clearShadowLayer();
117 
118             canvas.drawText("Hello!", 500, 600, mHugePaint);
119 
120             canvas.drawText("Hello OpenGL renderer!", 500, 40, mStrikePaint);
121             mStrikePaint.setStrikeThruText(true);
122             canvas.drawText("Hello OpenGL renderer!", 500, 70, mStrikePaint);
123             mStrikePaint.setUnderlineText(false);
124             canvas.drawText("Hello OpenGL renderer!", 500, 100, mStrikePaint);
125             mStrikePaint.setStrikeThruText(false);
126             mStrikePaint.setUnderlineText(true);
127 
128             mSkewPaint.setTextSkewX(-0.25f);
129             canvas.drawText("Hello OpenGL renderer!", 980, 200, mSkewPaint);
130             mSkewPaint.setTextSkewX(0.5f);
131             canvas.drawText("Hello OpenGL renderer!", 980, 230, mSkewPaint);
132             mSkewPaint.setTextSkewX(0.0f);
133             canvas.drawText("Hello OpenGL renderer!", 980, 260, mSkewPaint);
134 
135             mScaledPaint.setTextScaleX(0.5f);
136             canvas.drawText("Hello OpenGL renderer!", 500, 200, mScaledPaint);
137             mScaledPaint.setTextScaleX(1.0f);
138             canvas.drawText("Hello OpenGL renderer!", 500, 230, mScaledPaint);
139             mScaledPaint.setTextScaleX(2.0f);
140             canvas.drawText("Hello OpenGL renderer!", 500, 260, mScaledPaint);
141 
142             canvas.save();
143             canvas.clipRect(150.0f, 220.0f, 450.0f, 320.0f);
144             canvas.drawText("Hello OpenGL renderer!", 100, 300, mLargePaint);
145             canvas.restore();
146 
147         }
148     }
149 }
150