Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 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.google.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 |
| 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; |
Romain Guy | a674ab7 | 2010-08-10 17:26:42 -0700 | [diff] [blame] | 38 | private final Paint mStrikePaint; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 39 | |
| 40 | CustomTextView(Context c) { |
| 41 | super(c); |
| 42 | |
| 43 | mMediumPaint = new Paint(); |
| 44 | mMediumPaint.setAntiAlias(true); |
| 45 | mMediumPaint.setColor(0xffff0000); |
| 46 | mLargePaint = new Paint(); |
| 47 | mLargePaint.setAntiAlias(true); |
| 48 | mLargePaint.setTextSize(36.0f); |
Romain Guy | a674ab7 | 2010-08-10 17:26:42 -0700 | [diff] [blame] | 49 | mStrikePaint = new Paint(); |
| 50 | mStrikePaint.setAntiAlias(true); |
| 51 | mStrikePaint.setTextSize(16.0f); |
| 52 | mStrikePaint.setUnderlineText(true); |
| 53 | |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Override |
| 57 | protected void onDraw(Canvas canvas) { |
| 58 | super.onDraw(canvas); |
| 59 | canvas.drawRGB(255, 255, 255); |
Romain Guy | e8e62a4 | 2010-07-23 18:55:21 -0700 | [diff] [blame] | 60 | |
| 61 | canvas.drawText("Hello OpenGL renderer!", 100, 20, mMediumPaint); |
| 62 | mMediumPaint.setTextAlign(Paint.Align.CENTER); |
| 63 | canvas.drawText("Hello OpenGL renderer!", 100, 40, mMediumPaint); |
| 64 | mMediumPaint.setTextAlign(Paint.Align.RIGHT); |
| 65 | canvas.drawText("Hello OpenGL renderer!", 100, 60, mMediumPaint); |
| 66 | mMediumPaint.setTextAlign(Paint.Align.LEFT); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 67 | canvas.drawText("Hello OpenGL renderer!", 100, 100, mMediumPaint); |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 68 | mMediumPaint.setShadowLayer(2.5f, 0.0f, 0.0f, 0xff000000); |
| 69 | canvas.drawText("Hello OpenGL renderer!", 100, 150, mMediumPaint); |
| 70 | mMediumPaint.clearShadowLayer(); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 71 | canvas.drawText("Hello OpenGL renderer!", 100, 200, mLargePaint); |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 72 | |
| 73 | mLargePaint.setShadowLayer(2.5f, 3.0f, 3.0f, 0xff000000); |
| 74 | canvas.drawText("Hello OpenGL renderer!", 100, 400, mLargePaint); |
| 75 | mLargePaint.setShadowLayer(3.0f, 3.0f, 3.0f, 0xff00ff00); |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame^] | 76 | mLargePaint.setAlpha(100); |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 77 | canvas.drawText("Hello OpenGL renderer!", 100, 500, mLargePaint); |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame^] | 78 | mLargePaint.setAlpha(255); |
Romain Guy | 1e45aae | 2010-08-13 19:39:53 -0700 | [diff] [blame] | 79 | mLargePaint.clearShadowLayer(); |
Romain Guy | a674ab7 | 2010-08-10 17:26:42 -0700 | [diff] [blame] | 80 | |
| 81 | canvas.drawText("Hello OpenGL renderer!", 500, 40, mStrikePaint); |
| 82 | mStrikePaint.setStrikeThruText(true); |
| 83 | canvas.drawText("Hello OpenGL renderer!", 500, 70, mStrikePaint); |
| 84 | mStrikePaint.setUnderlineText(false); |
| 85 | canvas.drawText("Hello OpenGL renderer!", 500, 100, mStrikePaint); |
| 86 | mStrikePaint.setStrikeThruText(false); |
| 87 | mStrikePaint.setUnderlineText(true); |
| 88 | |
Romain Guy | 09147fb | 2010-07-22 13:08:20 -0700 | [diff] [blame] | 89 | canvas.save(); |
| 90 | canvas.clipRect(150.0f, 220.0f, 450.0f, 320.0f); |
| 91 | canvas.drawText("Hello OpenGL renderer!", 100, 300, mLargePaint); |
| 92 | canvas.restore(); |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | } |