• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 NewLayersActivity extends Activity {
28     @Override
onCreate(Bundle savedInstanceState)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 
LayersView(Context c)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
onDraw(Canvas canvas)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 
drawStuff(Canvas canvas, int saveFlags)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 }
78