Several animation calls cleanup

> Using View property instead of strings to avoid extra reflection step
> Using ViewPropertyAnimator when several properties are being animated

Change-Id: I41625643b38b70bac11e2c81d18058ec878d73bd
This commit is contained in:
Sunny Goyal
2015-07-06 22:52:49 -07:00
parent c1729a4d15
commit 5d2fc32e6d
13 changed files with 64 additions and 118 deletions

View File

@@ -441,10 +441,10 @@ public class AppWidgetResizeFrame extends FrameLayout {
PropertyValuesHolder y = PropertyValuesHolder.ofInt("y", lp.y, newY);
ObjectAnimator oa =
LauncherAnimUtils.ofPropertyValuesHolder(lp, this, width, height, x, y);
ObjectAnimator leftOa = LauncherAnimUtils.ofFloat(mLeftHandle, "alpha", 1.0f);
ObjectAnimator rightOa = LauncherAnimUtils.ofFloat(mRightHandle, "alpha", 1.0f);
ObjectAnimator topOa = LauncherAnimUtils.ofFloat(mTopHandle, "alpha", 1.0f);
ObjectAnimator bottomOa = LauncherAnimUtils.ofFloat(mBottomHandle, "alpha", 1.0f);
ObjectAnimator leftOa = LauncherAnimUtils.ofFloat(mLeftHandle, ALPHA, 1.0f);
ObjectAnimator rightOa = LauncherAnimUtils.ofFloat(mRightHandle, ALPHA, 1.0f);
ObjectAnimator topOa = LauncherAnimUtils.ofFloat(mTopHandle, ALPHA, 1.0f);
ObjectAnimator bottomOa = LauncherAnimUtils.ofFloat(mBottomHandle, ALPHA, 1.0f);
oa.addUpdateListener(new AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
requestLayout();

View File

@@ -18,7 +18,6 @@ package com.android.launcher3;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
@@ -2156,17 +2155,14 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
a.cancel();
}
AnimatorSet s = LauncherAnimUtils.createAnimatorSet();
a = s;
s.playTogether(
LauncherAnimUtils.ofFloat(child, "scaleX", getChildrenScale()),
LauncherAnimUtils.ofFloat(child, "scaleY", getChildrenScale()),
LauncherAnimUtils.ofFloat(child, "translationX", 0f),
LauncherAnimUtils.ofFloat(child, "translationY", 0f)
);
s.setDuration(REORDER_ANIMATION_DURATION);
s.setInterpolator(new android.view.animation.DecelerateInterpolator(1.5f));
s.start();
a = new LauncherViewPropertyAnimator(child)
.scaleX(getChildrenScale())
.scaleY(getChildrenScale())
.translationX(0)
.translationY(0)
.setDuration(REORDER_ANIMATION_DURATION);
a.setInterpolator(new android.view.animation.DecelerateInterpolator(1.5f));
a.start();
}
}

View File

@@ -196,15 +196,6 @@ public class DragView extends View {
@Override
protected void onDraw(Canvas canvas) {
@SuppressWarnings("all") // suppress dead code warning
final boolean debug = false;
if (debug) {
Paint p = new Paint();
p.setStyle(Paint.Style.FILL);
p.setColor(0x66ffffff);
canvas.drawRect(0, 0, getWidth(), getHeight(), p);
}
mHasDrawn = true;
boolean crossFade = mCrossFadeProgress > 0 && mCrossFadeBitmap != null;
if (crossFade) {
@@ -235,6 +226,7 @@ public class DragView extends View {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mCrossFadeProgress = animation.getAnimatedFraction();
invalidate();
}
});
va.start();

View File

@@ -16,7 +16,7 @@
package com.android.launcher3;
import android.animation.ObjectAnimator;
import android.animation.Animator;
import android.animation.PropertyValuesHolder;
import android.content.Context;
import android.graphics.Canvas;
@@ -36,7 +36,7 @@ public class FocusIndicatorView extends View implements View.OnFocusChangeListen
private final int[] mIndicatorPos = new int[2];
private final int[] mTargetViewPos = new int[2];
private ObjectAnimator mCurrentAnimation;
private Animator mCurrentAnimation;
private ViewAnimState mTargetState;
private View mLastFocusedView;
@@ -98,12 +98,12 @@ public class FocusIndicatorView extends View implements View.OnFocusChangeListen
if (getAlpha() > MIN_VISIBLE_ALPHA) {
mTargetState = nextState;
mCurrentAnimation = LauncherAnimUtils.ofPropertyValuesHolder(this,
PropertyValuesHolder.ofFloat(View.ALPHA, 1),
PropertyValuesHolder.ofFloat(View.TRANSLATION_X, mTargetState.x),
PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, mTargetState.y),
PropertyValuesHolder.ofFloat(View.SCALE_X, mTargetState.scaleX),
PropertyValuesHolder.ofFloat(View.SCALE_Y, mTargetState.scaleY));
mCurrentAnimation = new LauncherViewPropertyAnimator(this)
.alpha(1)
.translationX(mTargetState.x)
.translationY(mTargetState.y)
.scaleX(mTargetState.scaleX)
.scaleY(mTargetState.scaleY);
} else {
applyState(nextState);
mCurrentAnimation = LauncherAnimUtils.ofPropertyValuesHolder(this,

View File

@@ -450,11 +450,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
positionAndSizeAsIcon();
centerAboutIcon();
PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
final ObjectAnimator oa =
LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
final ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(this, 1, 1, 1);
oa.setDuration(mExpandDuration);
openFolderAnim = oa;
@@ -477,8 +473,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
float transY = - 0.075f * (height / 2 - getPivotY());
setTranslationX(transX);
setTranslationY(transY);
PropertyValuesHolder tx = PropertyValuesHolder.ofFloat("translationX", transX, 0);
PropertyValuesHolder ty = PropertyValuesHolder.ofFloat("translationY", transY, 0);
PropertyValuesHolder tx = PropertyValuesHolder.ofFloat(TRANSLATION_X, transX, 0);
PropertyValuesHolder ty = PropertyValuesHolder.ofFloat(TRANSLATION_Y, transY, 0);
Animator drift = ObjectAnimator.ofPropertyValuesHolder(this, tx, ty);
drift.setDuration(mMaterialExpandDuration);
@@ -557,6 +553,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
final boolean updateAnimationFlag = !mDragInProgress;
openFolderAnim.addListener(new AnimatorListenerAdapter() {
@SuppressLint("InlinedApi")
@Override
public void onAnimationEnd(Animator animation) {
mFolderName.animate().setDuration(FOLDER_NAME_ANIMATION_DURATION)
@@ -623,12 +620,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
public void animateClosed() {
if (!(getParent() instanceof DragLayer)) return;
PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
final ObjectAnimator oa =
LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
final ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(this, 0, 0.9f, 0.9f);
oa.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {

View File

@@ -20,7 +20,6 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
@@ -2999,10 +2998,6 @@ public class Launcher extends Activity
private void growAndFadeOutFolderIcon(FolderIcon fi) {
if (fi == null) return;
PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
FolderInfo info = (FolderInfo) fi.getTag();
if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
CellLayout cl = (CellLayout) fi.getParent().getParent();
@@ -3014,8 +3009,8 @@ public class Launcher extends Activity
copyFolderIconToImage(fi);
fi.setVisibility(View.INVISIBLE);
ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
scaleX, scaleY);
ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(
mFolderIconImageView, 0, 1.5f, 1.5f);
if (Utilities.isLmpOrAbove()) {
oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
}
@@ -3025,17 +3020,12 @@ public class Launcher extends Activity
private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
if (fi == null) return;
PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
final CellLayout cl = (CellLayout) fi.getParent().getParent();
// We remove and re-draw the FolderIcon in-case it has changed
mDragLayer.removeView(mFolderIconImageView);
copyFolderIconToImage(fi);
ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
scaleX, scaleY);
ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(mFolderIconImageView, 1, 1, 1);
oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
oa.addListener(new AnimatorListenerAdapter() {
@Override
@@ -4061,10 +4051,7 @@ public class Launcher extends Activity
}
private ValueAnimator createNewAppBounceAnimation(View v, int i) {
ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
PropertyValuesHolder.ofFloat("alpha", 1f),
PropertyValuesHolder.ofFloat("scaleX", 1f),
PropertyValuesHolder.ofFloat("scaleY", 1f));
ValueAnimator bounceAnim = LauncherAnimUtils.ofViewAlphaAndScale(v, 1, 1, 1);
bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
bounceAnim.setInterpolator(new OvershootInterpolator(BOUNCE_ANIMATION_TENSION));

View File

@@ -21,14 +21,10 @@ import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.os.Build;
import android.util.Property;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewTreeObserver;
import com.android.launcher3.util.UiThreadCircularReveal;
import java.util.HashSet;
import java.util.WeakHashMap;
@@ -102,42 +98,32 @@ public class LauncherAnimUtils {
return anim;
}
public static ObjectAnimator ofFloat(View target, String propertyName, float... values) {
ObjectAnimator anim = new ObjectAnimator();
anim.setTarget(target);
anim.setPropertyName(propertyName);
anim.setFloatValues(values);
public static ObjectAnimator ofFloat(View target, Property<View, Float> property,
float... values) {
ObjectAnimator anim = ObjectAnimator.ofFloat(target, property, values);
cancelOnDestroyActivity(anim);
new FirstFrameAnimatorHelper(anim, target);
return anim;
}
public static ObjectAnimator ofViewAlphaAndScale(View target,
float alpha, float scaleX, float scaleY) {
return ofPropertyValuesHolder(target,
PropertyValuesHolder.ofFloat(View.ALPHA, alpha),
PropertyValuesHolder.ofFloat(View.SCALE_X, scaleX),
PropertyValuesHolder.ofFloat(View.SCALE_Y, scaleY));
}
public static ObjectAnimator ofPropertyValuesHolder(View target,
PropertyValuesHolder... values) {
ObjectAnimator anim = new ObjectAnimator();
anim.setTarget(target);
anim.setValues(values);
cancelOnDestroyActivity(anim);
new FirstFrameAnimatorHelper(anim, target);
return anim;
return ofPropertyValuesHolder(target, target, values);
}
public static ObjectAnimator ofPropertyValuesHolder(Object target,
View view, PropertyValuesHolder... values) {
ObjectAnimator anim = new ObjectAnimator();
anim.setTarget(target);
anim.setValues(values);
ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(target, values);
cancelOnDestroyActivity(anim);
new FirstFrameAnimatorHelper(anim, view);
return anim;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static ValueAnimator createCircularReveal(View view, int centerX,
int centerY, float startRadius, float endRadius) {
ValueAnimator anim = UiThreadCircularReveal.createCircularReveal(view, centerX,
centerY, startRadius, endRadius);
new FirstFrameAnimatorHelper(anim, view);
return anim;
}
}

View File

@@ -161,12 +161,12 @@ class LauncherClings implements OnClickListener {
ObjectAnimator anim;
if (TAG_CROP_TOP_AND_SIDES.equals(content.getTag())) {
content.setTranslationY(-content.getMeasuredHeight());
anim = LauncherAnimUtils.ofFloat(content, "translationY", 0);
anim = LauncherAnimUtils.ofFloat(content, View.TRANSLATION_Y, 0);
} else {
content.setScaleX(0);
content.setScaleY(0);
PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1);
PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1);
PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1);
PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1);
anim = LauncherAnimUtils.ofPropertyValuesHolder(content, scaleX, scaleY);
}

View File

@@ -30,8 +30,8 @@ import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.util.UiThreadCircularReveal;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.UiThreadCircularReveal;
import com.android.launcher3.widget.WidgetsContainerView;
import java.util.HashMap;
@@ -259,11 +259,11 @@ public class LauncherStateTransitionAnimation {
// Create the animators
PropertyValuesHolder panelAlpha =
PropertyValuesHolder.ofFloat("alpha", revealViewToAlpha, 1f);
PropertyValuesHolder.ofFloat(View.ALPHA, revealViewToAlpha, 1f);
PropertyValuesHolder panelDriftY =
PropertyValuesHolder.ofFloat("translationY", revealViewToYDrift, 0);
PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, revealViewToYDrift, 0);
PropertyValuesHolder panelDriftX =
PropertyValuesHolder.ofFloat("translationX", revealViewToXDrift, 0);
PropertyValuesHolder.ofFloat(View.TRANSLATION_X, revealViewToXDrift, 0);
ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView,
panelAlpha, panelDriftY, panelDriftX);
panelAlphaAndDrift.setDuration(revealDuration);

View File

@@ -18,7 +18,6 @@ package com.android.launcher3;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.LayoutTransition;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
@@ -1681,16 +1680,14 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
// Animate the view translation from its old position to its new
// position
AnimatorSet anim = (AnimatorSet) v.getTag(ANIM_TAG_KEY);
ObjectAnimator anim = (ObjectAnimator) v.getTag();
if (anim != null) {
anim.cancel();
}
v.setTranslationX(oldX - newX);
anim = new AnimatorSet();
anim = LauncherAnimUtils.ofFloat(v, View.TRANSLATION_X, 0);
anim.setDuration(REORDERING_REORDER_REPOSITION_DURATION);
anim.playTogether(
ObjectAnimator.ofFloat(v, "translationX", 0f));
anim.start();
v.setTag(anim);
}
@@ -2140,13 +2137,12 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
// Animate the drag view back to the original position
private void animateDragViewToOriginalPosition() {
if (mDragView != null) {
AnimatorSet anim = new AnimatorSet();
anim.setDuration(REORDERING_DROP_REPOSITION_DURATION);
anim.playTogether(
ObjectAnimator.ofFloat(mDragView, "translationX", 0f),
ObjectAnimator.ofFloat(mDragView, "translationY", 0f),
ObjectAnimator.ofFloat(mDragView, "scaleX", 1f),
ObjectAnimator.ofFloat(mDragView, "scaleY", 1f));
Animator anim = new LauncherViewPropertyAnimator(mDragView)
.translationX(0)
.translationY(0)
.scaleX(1)
.scaleY(1)
.setDuration(REORDERING_DROP_REPOSITION_DURATION);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
@@ -2243,8 +2239,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
animateDragViewToOriginalPosition();
}
private static final int ANIM_TAG_KEY = 100;
/* Accessibility */
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)

View File

@@ -78,7 +78,7 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D
public void setQsbSearchBar(View qsb) {
mQSBSearchBar = qsb;
if (mQSBSearchBar != null) {
mHideSearchBarAnim = LauncherAnimUtils.ofFloat(mQSBSearchBar, "alpha", 1f, 0f);
mHideSearchBarAnim = LauncherAnimUtils.ofFloat(mQSBSearchBar, ALPHA, 1f, 0f);
setupAnimation(mHideSearchBarAnim, mQSBSearchBar);
} else {
// Create a no-op animation of the search bar is null
@@ -124,7 +124,7 @@ public class SearchDropTargetBar extends FrameLayout implements DragController.D
// Create the various fade animations
mDropTargetBar.setAlpha(0f);
mShowDropTargetBarAnim = LauncherAnimUtils.ofFloat(mDropTargetBar, "alpha", 0f, 1f);
mShowDropTargetBarAnim = LauncherAnimUtils.ofFloat(mDropTargetBar, ALPHA, 0f, 1f);
setupAnimation(mShowDropTargetBarAnim, mDropTargetBar);
}

View File

@@ -379,7 +379,6 @@ public class WorkspaceStateTransitionAnimation {
mNewBackgroundAlphas[i] != 0) {
ValueAnimator bgAnim = ObjectAnimator.ofFloat(cl, "backgroundAlpha",
mOldBackgroundAlphas[i], mNewBackgroundAlphas[i]);
LauncherAnimUtils.ofFloat(cl, 0f, 1f);
bgAnim.setInterpolator(mZoomInInterpolator);
bgAnim.setDuration(duration);
mStateAnimator.play(bgAnim);
@@ -554,8 +553,7 @@ public class WorkspaceStateTransitionAnimation {
if (animated) {
// These properties refer to the background protection gradient used for AllApps
// and Widget tray.
ValueAnimator bgFadeOutAnimation =
LauncherAnimUtils.ofFloat(mWorkspace, startAlpha, finalAlpha);
ValueAnimator bgFadeOutAnimation = ValueAnimator.ofFloat(startAlpha, finalAlpha);
bgFadeOutAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {

View File

@@ -330,7 +330,8 @@ public class LauncherExtension extends Launcher {
@Override
public void onScrollInteractionEnd() {
if (mProgress > 25 && mLauncherOverlayCallbacks.enterFullImmersion()) {
ObjectAnimator oa = LauncherAnimUtils.ofFloat(mSearchOverlay, "translationX", 0);
ObjectAnimator oa = LauncherAnimUtils.ofFloat(
mSearchOverlay, View.TRANSLATION_X, 0);
oa.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator arg0) {