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 PosTextActivity 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 mLargePaint; 37 private final String mText; 38 private final float[] mPos; 39 CustomTextView(Context c)40 CustomTextView(Context c) { 41 super(c); 42 43 mText = c.getResources().getString(R.string.complex_string); 44 mPos = new float[mText.length() * 2]; 45 for (int i = 0; i < mPos.length; i += 2) { 46 mPos[i] = i * 30.0f; 47 mPos[i + 1] = i * 10.0f; 48 } 49 50 mLargePaint = new Paint(); 51 mLargePaint.setAntiAlias(true); 52 mLargePaint.setTextSize(36.0f); 53 } 54 55 @Override onDraw(Canvas canvas)56 protected void onDraw(Canvas canvas) { 57 super.onDraw(canvas); 58 canvas.drawRGB(255, 255, 255); 59 60 canvas.save(); 61 62 canvas.drawLine(100.0f, 0.0f, 100.0f, getHeight(), mLargePaint); 63 64 canvas.translate(100.0f, 100.0f); 65 mLargePaint.setTextAlign(Paint.Align.LEFT); 66 canvas.drawPosText(mText, mPos, mLargePaint); 67 68 canvas.translate(0.0f, 50.0f); 69 mLargePaint.setTextAlign(Paint.Align.CENTER); 70 canvas.drawPosText(mText, mPos, mLargePaint); 71 72 canvas.translate(0.0f, 50.0f); 73 mLargePaint.setTextAlign(Paint.Align.RIGHT); 74 canvas.drawPosText(mText, mPos, mLargePaint); 75 76 canvas.restore(); 77 } 78 } 79 } 80