| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
| 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 |
|
| 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 |
| 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 |
} |