| 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.graphics.Path; |
| 24 |
import android.os.Bundle; |
| 25 |
import android.view.View; |
| 26 |
import android.widget.ScrollView; |
| 27 |
|
| 28 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 29 |
public class TextPathActivity extends Activity { |
| 30 |
@Override |
| 31 |
protected void onCreate(Bundle savedInstanceState) { |
| 32 |
super.onCreate(savedInstanceState); |
| 33 |
|
| 34 |
ScrollView scroller = new ScrollView(this); |
| 35 |
scroller.addView(new CustomTextView(this)); |
| 36 |
setContentView(scroller); |
| 37 |
} |
| 38 |
|
| 39 |
static class CustomTextView extends View { |
| 40 |
private final Paint mHugePaint; |
| 41 |
|
| 42 |
CustomTextView(Context c) { |
| 43 |
super(c); |
| 44 |
|
| 45 |
mHugePaint = new Paint(); |
| 46 |
mHugePaint.setAntiAlias(true); |
| 47 |
mHugePaint.setColor(0xff000000); |
| 48 |
mHugePaint.setTextSize(300f); |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 53 |
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), 3000); |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
protected void onDraw(Canvas canvas) { |
| 58 |
super.onDraw(canvas); |
| 59 |
canvas.drawRGB(255, 255, 255); |
| 60 |
|
| 61 |
Path path = new Path(); |
| 62 |
|
| 63 |
canvas.translate(100.0f, 300.0f); |
| 64 |
drawTextAsPath(canvas, "Hello", path); |
| 65 |
|
| 66 |
canvas.translate(0.0f, 400.0f); |
| 67 |
drawTextAsPath(canvas, "OpenGL", path); |
| 68 |
} |
| 69 |
|
| 70 |
private void drawTextAsPath(Canvas canvas, String text, Path path) { |
| 71 |
int count = text.length(); |
| 72 |
mHugePaint.getTextPath(text, 0, count, 0, 0, path); |
| 73 |
path.close(); |
| 74 |
canvas.drawPath(path, mHugePaint); |
| 75 |
} |
| 76 |
} |
| 77 |
} |