2 * Copyright (C) 2014 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
.CanvasProperty
;
23 import android
.graphics
.Paint
;
24 import android
.graphics
.Paint
.Style
;
25 import android
.os
.Bundle
;
26 import android
.os
.Trace
;
27 import android
.view
.DisplayListCanvas
;
28 import android
.view
.RenderNodeAnimator
;
29 import android
.view
.View
;
30 import android
.widget
.LinearLayout
;
31 import android
.widget
.LinearLayout
.LayoutParams
;
32 import android
.widget
.ProgressBar
;
34 import java
.util
.ArrayList
;
36 public class CirclePropActivity
extends Activity
{
38 protected void onCreate(Bundle savedInstanceState
) {
39 super.onCreate(savedInstanceState
);
41 final LinearLayout layout
= new LinearLayout(this);
42 layout
.setOrientation(LinearLayout
.VERTICAL
);
44 ProgressBar spinner
= new ProgressBar(this, null, android
.R
.attr
.progressBarStyleLarge
);
45 layout
.addView(spinner
, new LayoutParams(LayoutParams
.WRAP_CONTENT
, LayoutParams
.WRAP_CONTENT
));
46 // For testing with a functor in the tree
47 // WebView wv = new WebView(this);
48 // wv.setWebViewClient(new WebViewClient());
49 // wv.setWebChromeClient(new WebChromeClient());
50 // wv.loadUrl("http://theverge.com");
51 // layout.addView(wv, new LayoutParams(LayoutParams.MATCH_PARENT, 100));
53 layout
.addView(new CircleView(this),
54 new LayoutParams(LayoutParams
.MATCH_PARENT
, LayoutParams
.MATCH_PARENT
));
56 setContentView(layout
);
59 static class CircleView
extends View
{
60 static final int DURATION
= 500;
62 private boolean mToggle
= false;
63 ArrayList
<RenderNodeAnimator
> mRunningAnimations
= new ArrayList
<RenderNodeAnimator
>();
65 CanvasProperty
<Float
> mX
;
66 CanvasProperty
<Float
> mY
;
67 CanvasProperty
<Float
> mRadius
;
68 CanvasProperty
<Paint
> mPaint
;
70 CircleView(Context c
) {
74 mX
= CanvasProperty
.createFloat(200.0f
);
75 mY
= CanvasProperty
.createFloat(200.0f
);
76 mRadius
= CanvasProperty
.createFloat(150.0f
);
78 Paint p
= new Paint();
80 p
.setColor(0xFFFF0000);
81 p
.setStyle(Style
.STROKE
);
82 p
.setStrokeWidth(60.0f
);
83 mPaint
= CanvasProperty
.createPaint(p
);
87 protected void onDraw(Canvas canvas
) {
90 if (canvas
.isHardwareAccelerated()) {
91 DisplayListCanvas displayListCanvas
= (DisplayListCanvas
) canvas
;
92 displayListCanvas
.drawCircle(mX
, mY
, mRadius
, mPaint
);
97 public boolean performClick() {
98 for (int i
= 0; i
< mRunningAnimations
.size(); i
++) {
99 mRunningAnimations
.get(i
).cancel();
101 mRunningAnimations
.clear();
105 mRunningAnimations
.add(new RenderNodeAnimator(
106 mX
, mToggle ?
400.0f
: 200.0f
));
108 mRunningAnimations
.add(new RenderNodeAnimator(
109 mY
, mToggle ?
600.0f
: 200.0f
));
111 mRunningAnimations
.add(new RenderNodeAnimator(
112 mRadius
, mToggle ?
250.0f
: 150.0f
));
114 mRunningAnimations
.add(new RenderNodeAnimator(
115 mPaint
, RenderNodeAnimator
.PAINT_STROKE_WIDTH
,
116 mToggle ?
5.0f
: 60.0f
));
118 mRunningAnimations
.add(new RenderNodeAnimator(
119 mPaint
, RenderNodeAnimator
.PAINT_ALPHA
, 64.0f
));
121 // Will be "chained" to run after the above
122 mRunningAnimations
.add(new RenderNodeAnimator(
123 mPaint
, RenderNodeAnimator
.PAINT_ALPHA
, 255.0f
));
125 for (int i
= 0; i
< mRunningAnimations
.size(); i
++) {
126 RenderNodeAnimator anim
= mRunningAnimations
.get(i
);
127 anim
.setDuration(1000);
128 anim
.setTarget(this);
129 if (i
== (mRunningAnimations
.size() - 1)) {
131 anim
.setStartValue(64.0f
);
132 anim
.setStartDelay(anim
.getDuration());
138 post(new Runnable() {
141 Trace
.traceBegin(Trace
.TRACE_TAG_VIEW
, "pretendBusy");
143 Thread
.sleep(DURATION
);
144 } catch (InterruptedException e
) {
146 Trace
.traceEnd(Trace
.TRACE_TAG_VIEW
);