| 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 NewLayersActivity extends Activity { |
| 28 |
@Override |
| 29 |
protected void onCreate(Bundle savedInstanceState) { |
| 30 |
super.onCreate(savedInstanceState); |
| 31 |
setContentView(new LayersView(this)); |
| 32 |
} |
| 33 |
|
| 34 |
public static class LayersView extends View { |
| 35 |
private Paint mLayerPaint; |
| 36 |
private final Paint mRectPaint; |
| 37 |
|
| 38 |
public LayersView(Context c) { |
| 39 |
super(c); |
| 40 |
|
| 41 |
mLayerPaint = new Paint(); |
| 42 |
mLayerPaint.setAlpha(127); |
| 43 |
mRectPaint = new Paint(); |
| 44 |
mRectPaint.setAntiAlias(true); |
| 45 |
mRectPaint.setTextSize(24.0f); |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
protected void onDraw(Canvas canvas) { |
| 50 |
super.onDraw(canvas); |
| 51 |
canvas.drawRGB(128, 255, 128); |
| 52 |
|
| 53 |
canvas.save(); |
| 54 |
|
| 55 |
canvas.translate(140.0f, 100.0f); |
| 56 |
drawStuff(canvas, Canvas.ALL_SAVE_FLAG); |
| 57 |
|
| 58 |
canvas.translate(0.0f, 200.0f); |
| 59 |
drawStuff(canvas, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG); |
| 60 |
|
| 61 |
canvas.restore(); |
| 62 |
} |
| 63 |
|
| 64 |
private void drawStuff(Canvas canvas, int saveFlags) { |
| 65 |
int count = canvas.saveLayer(0.0f, 0.0f, 200.0f, 100.0f, mLayerPaint, saveFlags); |
| 66 |
|
| 67 |
mRectPaint.setColor(0x7fff0000); |
| 68 |
canvas.drawRect(-20.0f, -20.0f, 220.0f, 120.0f, mRectPaint); |
| 69 |
|
| 70 |
mRectPaint.setColor(0xff000000); |
| 71 |
canvas.drawText("This is a very long string to overlap between layers and framebuffer", |
| 72 |
-100.0f, 50.0f, mRectPaint); |
| 73 |
|
| 74 |
canvas.restoreToCount(count); |
| 75 |
} |
| 76 |
} |
| 77 |
} |