blob: 208c387526d20d92be4131e5b06d0faaf912f9a4 [file] [log] [blame]
Chris Craikf533e942014-01-14 22:35:37 -08001package com.android.test.hwui;
2
3import android.content.Context;
4import android.graphics.Canvas;
5import android.graphics.Paint;
6import android.graphics.RectF;
7import android.os.Bundle;
8
9import android.app.Activity;
10import android.util.AttributeSet;
11import android.view.DisplayList;
12import android.view.View;
13import android.widget.LinearLayout;
14
15public class ProjectionActivity extends Activity {
16 /**
17 * The content from this view should be projected in between the background of the
18 * ProjecteeLayout and its children, unclipped.
19 *
20 * This view doesn't clip to its bounds (because its parent has clipChildren=false) so that
21 * when it is projected onto the ProjecteeLayout, it draws outside its view bounds.
22 */
23 public static class ProjectedView extends View {
24 private final Paint mPaint = new Paint();
25 private final RectF mRectF = new RectF();
26
27 public ProjectedView(Context context) {
28 this(context, null);
29 }
30
31 public ProjectedView(Context context, AttributeSet attrs) {
32 this(context, attrs, 0);
33 }
34
35 public ProjectedView(Context context, AttributeSet attrs, int defStyleAttr) {
36 super(context, attrs, defStyleAttr);
37
38 setOnClickListener(new OnClickListener() {
39 boolean toggle = false;
40 @Override
41 public void onClick(View v) {
42 toggle = !toggle;
43 setProject(toggle);
44 }
45 });
46 }
47
48 private void setProject(boolean value) {
49 DisplayList displayList = getDisplayList();
50 if (displayList != null) {
Chris Craik6657a6c2014-01-26 11:30:58 -080051 displayList.setProjectBackwards(value);
Chris Craikf533e942014-01-14 22:35:37 -080052 }
53 // NOTE: we can't invalidate ProjectedView for the redraw because:
54 // 1) the view won't preserve displayList properties that it doesn't know about
55 // 2) the damage rect won't be big enough
56
57 // instead, twiddle properties on the container, so that enough area of the screen is
58 // redrawn without rerecording any DisplayLists.
59 container.setTranslationX(100f);
60 container.setTranslationX(0.0f);
61 }
62
63 @Override
64 protected void onDraw(Canvas canvas) {
65 // TODO: set projection flag
66 final int w = getWidth();
67 final int h = getHeight();
68 mRectF.set(0, -h, w, 2 * h);
69 mPaint.setAntiAlias(true);
70 mPaint.setColor(0x5f00ff00);
71 canvas.drawOval(mRectF, mPaint);
72 }
73 }
74
Chris Craikf533e942014-01-14 22:35:37 -080075 static View container;
76
77 @Override
78 protected void onCreate(Bundle savedInstanceState) {
79 super.onCreate(savedInstanceState);
80 setContentView(R.layout.projection);
81 container = findViewById(R.id.container);
82 }
83}