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