diff options
author | John Reck <jreck@google.com> | 2014-05-01 21:27:37 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2014-05-02 13:43:46 -0700 |
commit | 52244fff29042926e21fa897ef5ab11148e35299 (patch) | |
tree | 2cc7b2f6dd47fe7863c6bc2b6a806e275c149ba9 /tests | |
parent | abc975f539b4ea06c05b11ec56b0abe7c6fd95aa (diff) | |
download | frameworks_base-52244fff29042926e21fa897ef5ab11148e35299.zip frameworks_base-52244fff29042926e21fa897ef5ab11148e35299.tar.gz frameworks_base-52244fff29042926e21fa897ef5ab11148e35299.tar.bz2 |
Add CanvasProperty for drawCircle
Change-Id: Icbcc030f5033d2094e567d7c519b9d672f2aac1c
Diffstat (limited to 'tests')
4 files changed, 148 insertions, 4 deletions
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml index 5c2583b..af0d0ad 100644 --- a/tests/HwAccelerationTest/AndroidManifest.xml +++ b/tests/HwAccelerationTest/AndroidManifest.xml @@ -288,6 +288,15 @@ </activity> <activity + android:name="CirclePropActivity" + android:label="Draw/Circle Props"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.android.test.hwui.TEST" /> + </intent-filter> + </activity> + + <activity android:name="ClearActivity" android:label="Window/Clear"> <intent-filter> diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/CirclePropActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/CirclePropActivity.java new file mode 100644 index 0000000..f060bc8 --- /dev/null +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/CirclePropActivity.java @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.test.hwui; + +import android.app.Activity; +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.CanvasProperty; +import android.graphics.Paint; +import android.graphics.Paint.Style; +import android.os.Bundle; +import android.os.Trace; +import android.view.HardwareCanvas; +import android.view.RenderNodeAnimator; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.LinearLayout.LayoutParams; +import android.widget.ProgressBar; + +import java.util.ArrayList; + +public class CirclePropActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + final LinearLayout layout = new LinearLayout(this); + layout.setOrientation(LinearLayout.VERTICAL); + + ProgressBar spinner = new ProgressBar(this, null, android.R.attr.progressBarStyleLarge); + layout.addView(spinner, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); + + layout.addView(new CircleView(this), + new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + + setContentView(layout); + } + + static class CircleView extends View { + static final int DURATION = 500; + + private boolean mToggle = false; + ArrayList<RenderNodeAnimator> mRunningAnimations = new ArrayList<RenderNodeAnimator>(); + + CanvasProperty<Float> mX; + CanvasProperty<Float> mY; + CanvasProperty<Float> mRadius; + CanvasProperty<Paint> mPaint; + + CircleView(Context c) { + super(c); + setClickable(true); + + mX = CanvasProperty.createFloat(200.0f); + mY = CanvasProperty.createFloat(200.0f); + mRadius = CanvasProperty.createFloat(150.0f); + + Paint p = new Paint(); + p.setAntiAlias(true); + p.setColor(0xFFFF0000); + p.setStyle(Style.STROKE); + p.setStrokeWidth(60.0f); + mPaint = CanvasProperty.createPaint(p); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + + if (canvas.isHardwareAccelerated()) { + HardwareCanvas hwcanvas = (HardwareCanvas) canvas; + hwcanvas.drawCircle(mX, mY, mRadius, mPaint); + } + } + + @Override + public boolean performClick() { + for (int i = 0; i < mRunningAnimations.size(); i++) { + mRunningAnimations.get(i).cancel(); + } + mRunningAnimations.clear(); + + mToggle = !mToggle; + + mRunningAnimations.add(new RenderNodeAnimator( + mX, RenderNodeAnimator.DELTA_TYPE_ABSOLUTE, mToggle ? 400.0f : 200.0f)); + + mRunningAnimations.add(new RenderNodeAnimator( + mY, RenderNodeAnimator.DELTA_TYPE_ABSOLUTE, mToggle ? 600.0f : 200.0f)); + + mRunningAnimations.add(new RenderNodeAnimator( + mRadius, RenderNodeAnimator.DELTA_TYPE_ABSOLUTE, mToggle ? 250.0f : 150.0f)); + + mRunningAnimations.add(new RenderNodeAnimator( + mPaint, RenderNodeAnimator.PAINT_ALPHA, + RenderNodeAnimator.DELTA_TYPE_ABSOLUTE, mToggle ? 64.0f : 255.0f)); + + mRunningAnimations.add(new RenderNodeAnimator( + mPaint, RenderNodeAnimator.PAINT_STROKE_WIDTH, + RenderNodeAnimator.DELTA_TYPE_ABSOLUTE, mToggle ? 5.0f : 60.0f)); + + for (int i = 0; i < mRunningAnimations.size(); i++) { + mRunningAnimations.get(i).start(this); + } + + if (mToggle) { + post(new Runnable() { + @Override + public void run() { + Trace.traceBegin(Trace.TRACE_TAG_VIEW, "pretendBusy"); + try { + Thread.sleep(DURATION); + } catch (InterruptedException e) { + } + Trace.traceEnd(Trace.TRACE_TAG_VIEW); + } + }); + } + + return true; + } + } +} diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/SmallCircleActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/SmallCircleActivity.java index 8c02539..a3f4ddc 100644 --- a/tests/HwAccelerationTest/src/com/android/test/hwui/SmallCircleActivity.java +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/SmallCircleActivity.java @@ -57,7 +57,7 @@ public class SmallCircleActivity extends Activity { mPaint = new Paint(); mPaint.setAntiAlias(true); - mPaint.setColor(0xffffffff); + mPaint.setColor(0xff00ffff); } @Override diff --git a/tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java b/tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java index 1d209dd..8f9cf58 100644 --- a/tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java +++ b/tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java @@ -19,8 +19,6 @@ import java.util.Map; public class MainActivity extends Activity implements OnItemClickListener { - static final int TRANSLATION_Y = 1; - static final int DELTA_TYPE_DELTA = 1; static final int DURATION = 400; static final String KEY_NAME = "name"; @@ -75,7 +73,7 @@ public class MainActivity extends Activity implements OnItemClickListener { float delta = (pos - clickedPosition) * 1.1f; if (delta == 0) delta = -1; RenderNodeAnimator animator = new RenderNodeAnimator( - TRANSLATION_Y, DELTA_TYPE_DELTA, dy * delta); + RenderNodeAnimator.TRANSLATION_Y, RenderNodeAnimator.DELTA_TYPE_DELTA, dy * delta); animator.setDuration(DURATION); animator.start(child); } |