NewLayersActivity.java revision f607bdc167f66b3e7003acaa4736ae46d78c1492
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
17package com.android.test.hwui;
18
19import android.app.Activity;
20import android.content.Context;
21import android.graphics.Canvas;
22import android.graphics.Paint;
23import android.os.Bundle;
24import android.view.View;
25
26@SuppressWarnings({"UnusedDeclaration"})
27public class NewLayersActivity extends Activity {
28    @Override
29    protected void onCreate(Bundle savedInstanceState) {
30        super.onCreate(savedInstanceState);
31        setContentView(new LayersView(this));
32    }
33
34    static class LayersView extends View {
35        private Paint mLayerPaint;
36        private final Paint mRectPaint;
37
38        LayersView(Context c) {
39            super(c);
40
41            mLayerPaint = new Paint();
42            mRectPaint = new Paint();
43            mRectPaint.setAntiAlias(true);
44            mRectPaint.setTextSize(24.0f);
45        }
46
47        @Override
48        protected void onDraw(Canvas canvas) {
49            super.onDraw(canvas);
50
51            canvas.drawRGB(128, 255, 128);
52            canvas.translate(140.0f, 100.0f);
53
54            mLayerPaint.setAlpha(127);
55            int count = canvas.saveLayer(0.0f, 0.0f, 200.0f, 100.0f, mLayerPaint,
56                    Canvas.ALL_SAVE_FLAG);
57
58            mRectPaint.setColor(0x7fff0000);
59            canvas.drawRect(-20.0f, -20.0f, 220.0f, 120.0f, mRectPaint);
60
61            mRectPaint.setColor(0xff000000);
62            canvas.drawText("This is a very long string to overlap between layers and framebuffer",
63                    -100.0f, 50.0f, mRectPaint);
64
65            canvas.restoreToCount(count);
66
67            canvas.translate(0.0f, 200.0f);
68
69            mLayerPaint.setAlpha(127);
70            count = canvas.saveLayer(0.0f, 0.0f, 200.0f, 100.0f, mLayerPaint,
71                    Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
72
73            mRectPaint.setColor(0x7fff0000);
74            canvas.drawRect(-20.0f, -20.0f, 220.0f, 120.0f, mRectPaint);
75
76            mRectPaint.setColor(0xff000000);
77            canvas.drawText("This is a very long string to overlap between layers and framebuffer",
78                    -100.0f, 50.0f, mRectPaint);
79
80            canvas.restoreToCount(count);
81        }
82    }
83}
84