Roll android_tools support library to 25.1.0
[android_tools.git] / sdk / sources / android-23 / com / android / test / hwui / NewLayersActivity.java
blob2509d367fe302494adedde28f174e5950f74d82b
1 /*
2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.test.hwui;
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;
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));
34 public static class LayersView extends View {
35 private Paint mLayerPaint;
36 private final Paint mRectPaint;
38 public LayersView(Context c) {
39 super(c);
41 mLayerPaint = new Paint();
42 mLayerPaint.setAlpha(127);
43 mRectPaint = new Paint();
44 mRectPaint.setAntiAlias(true);
45 mRectPaint.setTextSize(24.0f);
48 @Override
49 protected void onDraw(Canvas canvas) {
50 super.onDraw(canvas);
51 canvas.drawRGB(128, 255, 128);
53 canvas.save();
55 canvas.translate(140.0f, 100.0f);
56 drawStuff(canvas, Canvas.ALL_SAVE_FLAG);
58 canvas.translate(0.0f, 200.0f);
59 drawStuff(canvas, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
61 canvas.restore();
64 private void drawStuff(Canvas canvas, int saveFlags) {
65 int count = canvas.saveLayer(0.0f, 0.0f, 200.0f, 100.0f, mLayerPaint, saveFlags);
67 mRectPaint.setColor(0x7fff0000);
68 canvas.drawRect(-20.0f, -20.0f, 220.0f, 120.0f, mRectPaint);
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);
74 canvas.restoreToCount(count);