diff options
author | John Reck <jreck@google.com> | 2014-04-15 09:50:16 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2014-04-29 10:42:11 -0700 |
commit | e45b1fd03b524d2b57cc6c222d89076a31a08bea (patch) | |
tree | 31ad10387f2b59b3ee9d4396be44fce67228ca75 /tests | |
parent | 627aad9c200cb19aa505504dcd232a3710e96a25 (diff) | |
download | frameworks_base-e45b1fd03b524d2b57cc6c222d89076a31a08bea.zip frameworks_base-e45b1fd03b524d2b57cc6c222d89076a31a08bea.tar.gz frameworks_base-e45b1fd03b524d2b57cc6c222d89076a31a08bea.tar.bz2 |
RenderThread animator support
Change-Id: Icf29098edfdaf7ed550bbe9d49e9eaefb4167084
Diffstat (limited to 'tests')
-rw-r--r-- | tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java | 77 |
1 files changed, 7 insertions, 70 deletions
diff --git a/tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java b/tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java index 09531fd..1d209dd 100644 --- a/tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java +++ b/tests/RenderThreadTest/src/com/example/renderthread/MainActivity.java @@ -1,17 +1,13 @@ package com.example.renderthread; -import android.animation.TimeInterpolator; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; -import android.os.SystemClock; -import android.view.RenderNode; import android.view.HardwareRenderer; -import android.view.ThreadedRenderer; +import android.view.RenderNodeAnimator; import android.view.View; -import android.view.animation.AccelerateDecelerateInterpolator; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; @@ -23,6 +19,8 @@ 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"; @@ -66,82 +64,21 @@ public class MainActivity extends Activity implements OnItemClickListener { } } - private static class DisplayListAnimator { - private static final TimeInterpolator sDefaultInterpolator = - new AccelerateDecelerateInterpolator(); - - RenderNode mDisplayList; - float mFromValue; - float mDelta; - long mDuration = DURATION * 2; - long mStartTime; - - DisplayListAnimator(View view, float translateXBy) { - mDelta = translateXBy; - mFromValue = view.getTranslationY(); - mDisplayList = view.getDisplayList(); - } - - boolean animate(long currentTime) { - if (mStartTime == 0) mStartTime = currentTime; - - float fraction = (float)(currentTime - mStartTime) / mDuration; - if (fraction > 1) { - return false; - } - fraction = sDefaultInterpolator.getInterpolation(fraction); - float translation = mFromValue + (mDelta * fraction); - mDisplayList.setTranslationY(translation); - return fraction < 1f; - } - } - - private static class AnimationExecutor implements Runnable { - DisplayListAnimator[] mAnimations; - ThreadedRenderer mRenderer; - - AnimationExecutor(ThreadedRenderer renderer, DisplayListAnimator[] animations) { - mRenderer = renderer; - mAnimations = animations; - ThreadedRenderer.postToRenderThread(this); - } - - @Override - public void run() { - boolean hasMore = false; - long now = SystemClock.uptimeMillis(); - for (DisplayListAnimator animator : mAnimations) { - hasMore |= animator.animate(now); - } - mRenderer.repeatLastDraw(); - if (hasMore) { - ThreadedRenderer.postToRenderThread(this); - } - } - - } - @Override public void onItemClick(final AdapterView<?> adapterView, View clickedView, int clickedPosition, long clickedId) { int topPosition = adapterView.getFirstVisiblePosition(); int dy = adapterView.getHeight(); - final DisplayListAnimator[] animators = new DisplayListAnimator[adapterView.getChildCount()]; for (int i = 0; i < adapterView.getChildCount(); i++) { int pos = topPosition + i; View child = adapterView.getChildAt(i); float delta = (pos - clickedPosition) * 1.1f; if (delta == 0) delta = -1; - animators[i] = new DisplayListAnimator(child, dy * delta); + RenderNodeAnimator animator = new RenderNodeAnimator( + TRANSLATION_Y, DELTA_TYPE_DELTA, dy * delta); + animator.setDuration(DURATION); + animator.start(child); } - adapterView.invalidate(); - adapterView.post(new Runnable() { - - @Override - public void run() { - new AnimationExecutor((ThreadedRenderer) adapterView.getHardwareRenderer(), animators); - } - }); //mHandler.postDelayed(mLaunchActivity, (long) (DURATION * .4)); mLaunchActivity.run(); } |