2011-12-12 21:48:38 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2012 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-05 22:57:57 -04:00
|
|
|
package com.android.launcher3;
|
2011-12-12 21:48:38 -08:00
|
|
|
|
|
|
|
|
import android.animation.Animator;
|
|
|
|
|
import android.animation.Animator.AnimatorListener;
|
|
|
|
|
import android.animation.TimeInterpolator;
|
|
|
|
|
import android.view.View;
|
2013-04-22 15:08:42 +02:00
|
|
|
import android.view.ViewPropertyAnimator;
|
2011-12-12 21:48:38 -08:00
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
|
|
public class LauncherViewPropertyAnimator extends Animator implements AnimatorListener {
|
|
|
|
|
enum Properties {
|
|
|
|
|
TRANSLATION_X,
|
|
|
|
|
TRANSLATION_Y,
|
|
|
|
|
SCALE_X,
|
|
|
|
|
SCALE_Y,
|
|
|
|
|
ROTATION_Y,
|
|
|
|
|
ALPHA,
|
|
|
|
|
START_DELAY,
|
|
|
|
|
DURATION,
|
2013-09-26 15:29:57 -07:00
|
|
|
INTERPOLATOR,
|
|
|
|
|
WITH_LAYER
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
EnumSet<Properties> mPropertiesToSet = EnumSet.noneOf(Properties.class);
|
|
|
|
|
ViewPropertyAnimator mViewPropertyAnimator;
|
|
|
|
|
View mTarget;
|
|
|
|
|
|
|
|
|
|
float mTranslationX;
|
|
|
|
|
float mTranslationY;
|
|
|
|
|
float mScaleX;
|
|
|
|
|
float mScaleY;
|
|
|
|
|
float mRotationY;
|
|
|
|
|
float mAlpha;
|
|
|
|
|
long mStartDelay;
|
|
|
|
|
long mDuration;
|
|
|
|
|
TimeInterpolator mInterpolator;
|
2012-01-17 03:00:35 -08:00
|
|
|
ArrayList<Animator.AnimatorListener> mListeners;
|
2011-12-12 21:48:38 -08:00
|
|
|
boolean mRunning = false;
|
2013-04-08 18:28:15 -07:00
|
|
|
FirstFrameAnimatorHelper mFirstFrameHelper;
|
2011-12-12 21:48:38 -08:00
|
|
|
|
|
|
|
|
public LauncherViewPropertyAnimator(View target) {
|
|
|
|
|
mTarget = target;
|
2012-01-17 03:00:35 -08:00
|
|
|
mListeners = new ArrayList<Animator.AnimatorListener>();
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addListener(Animator.AnimatorListener listener) {
|
2012-01-17 03:00:35 -08:00
|
|
|
mListeners.add(listener);
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void cancel() {
|
2012-01-12 06:06:59 -08:00
|
|
|
if (mViewPropertyAnimator != null) {
|
|
|
|
|
mViewPropertyAnimator.cancel();
|
|
|
|
|
}
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Animator clone() {
|
|
|
|
|
throw new RuntimeException("Not implemented");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void end() {
|
|
|
|
|
throw new RuntimeException("Not implemented");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public long getDuration() {
|
2012-01-12 06:06:59 -08:00
|
|
|
return mDuration;
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ArrayList<Animator.AnimatorListener> getListeners() {
|
2012-01-17 03:00:35 -08:00
|
|
|
return mListeners;
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public long getStartDelay() {
|
2012-01-12 06:06:59 -08:00
|
|
|
return mStartDelay;
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
2012-01-17 03:00:35 -08:00
|
|
|
for (int i = 0; i < mListeners.size(); i++) {
|
|
|
|
|
Animator.AnimatorListener listener = mListeners.get(i);
|
|
|
|
|
listener.onAnimationCancel(this);
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
mRunning = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
2012-01-17 03:00:35 -08:00
|
|
|
for (int i = 0; i < mListeners.size(); i++) {
|
|
|
|
|
Animator.AnimatorListener listener = mListeners.get(i);
|
|
|
|
|
listener.onAnimationEnd(this);
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
mRunning = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationRepeat(Animator animation) {
|
2012-01-17 03:00:35 -08:00
|
|
|
for (int i = 0; i < mListeners.size(); i++) {
|
|
|
|
|
Animator.AnimatorListener listener = mListeners.get(i);
|
|
|
|
|
listener.onAnimationRepeat(this);
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animator animation) {
|
2013-04-08 18:28:15 -07:00
|
|
|
// This is the first time we get a handle to the internal ValueAnimator
|
|
|
|
|
// used by the ViewPropertyAnimator.
|
|
|
|
|
mFirstFrameHelper.onAnimationStart(animation);
|
|
|
|
|
|
2012-01-17 03:00:35 -08:00
|
|
|
for (int i = 0; i < mListeners.size(); i++) {
|
|
|
|
|
Animator.AnimatorListener listener = mListeners.get(i);
|
|
|
|
|
listener.onAnimationStart(this);
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
mRunning = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isRunning() {
|
|
|
|
|
return mRunning;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isStarted() {
|
|
|
|
|
return mViewPropertyAnimator != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void removeAllListeners() {
|
2012-01-17 03:00:35 -08:00
|
|
|
mListeners.clear();
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void removeListener(Animator.AnimatorListener listener) {
|
2012-01-17 03:00:35 -08:00
|
|
|
mListeners.remove(listener);
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Animator setDuration(long duration) {
|
|
|
|
|
mPropertiesToSet.add(Properties.DURATION);
|
|
|
|
|
mDuration = duration;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setInterpolator(TimeInterpolator value) {
|
|
|
|
|
mPropertiesToSet.add(Properties.INTERPOLATOR);
|
|
|
|
|
mInterpolator = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setStartDelay(long startDelay) {
|
|
|
|
|
mPropertiesToSet.add(Properties.START_DELAY);
|
|
|
|
|
mStartDelay = startDelay;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setTarget(Object target) {
|
|
|
|
|
throw new RuntimeException("Not implemented");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setupEndValues() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setupStartValues() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void start() {
|
|
|
|
|
mViewPropertyAnimator = mTarget.animate();
|
2013-04-08 18:28:15 -07:00
|
|
|
|
|
|
|
|
// FirstFrameAnimatorHelper hooks itself up to the updates on the animator,
|
|
|
|
|
// and then adjusts the play time to keep the first two frames jank-free
|
|
|
|
|
mFirstFrameHelper = new FirstFrameAnimatorHelper(mViewPropertyAnimator, mTarget);
|
|
|
|
|
|
2011-12-12 21:48:38 -08:00
|
|
|
if (mPropertiesToSet.contains(Properties.TRANSLATION_X)) {
|
|
|
|
|
mViewPropertyAnimator.translationX(mTranslationX);
|
|
|
|
|
}
|
|
|
|
|
if (mPropertiesToSet.contains(Properties.TRANSLATION_Y)) {
|
|
|
|
|
mViewPropertyAnimator.translationY(mTranslationY);
|
|
|
|
|
}
|
|
|
|
|
if (mPropertiesToSet.contains(Properties.SCALE_X)) {
|
|
|
|
|
mViewPropertyAnimator.scaleX(mScaleX);
|
|
|
|
|
}
|
|
|
|
|
if (mPropertiesToSet.contains(Properties.ROTATION_Y)) {
|
|
|
|
|
mViewPropertyAnimator.rotationY(mRotationY);
|
|
|
|
|
}
|
|
|
|
|
if (mPropertiesToSet.contains(Properties.SCALE_Y)) {
|
|
|
|
|
mViewPropertyAnimator.scaleY(mScaleY);
|
|
|
|
|
}
|
|
|
|
|
if (mPropertiesToSet.contains(Properties.ALPHA)) {
|
|
|
|
|
mViewPropertyAnimator.alpha(mAlpha);
|
|
|
|
|
}
|
|
|
|
|
if (mPropertiesToSet.contains(Properties.START_DELAY)) {
|
|
|
|
|
mViewPropertyAnimator.setStartDelay(mStartDelay);
|
|
|
|
|
}
|
|
|
|
|
if (mPropertiesToSet.contains(Properties.DURATION)) {
|
|
|
|
|
mViewPropertyAnimator.setDuration(mDuration);
|
|
|
|
|
}
|
|
|
|
|
if (mPropertiesToSet.contains(Properties.INTERPOLATOR)) {
|
|
|
|
|
mViewPropertyAnimator.setInterpolator(mInterpolator);
|
|
|
|
|
}
|
2013-09-26 15:29:57 -07:00
|
|
|
if (mPropertiesToSet.contains(Properties.WITH_LAYER)) {
|
|
|
|
|
mViewPropertyAnimator.withLayer();
|
|
|
|
|
}
|
2011-12-12 21:48:38 -08:00
|
|
|
mViewPropertyAnimator.setListener(this);
|
|
|
|
|
mViewPropertyAnimator.start();
|
2012-06-18 12:52:28 -07:00
|
|
|
LauncherAnimUtils.cancelOnDestroyActivity(this);
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LauncherViewPropertyAnimator translationX(float value) {
|
|
|
|
|
mPropertiesToSet.add(Properties.TRANSLATION_X);
|
|
|
|
|
mTranslationX = value;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LauncherViewPropertyAnimator translationY(float value) {
|
|
|
|
|
mPropertiesToSet.add(Properties.TRANSLATION_Y);
|
|
|
|
|
mTranslationY = value;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LauncherViewPropertyAnimator scaleX(float value) {
|
|
|
|
|
mPropertiesToSet.add(Properties.SCALE_X);
|
|
|
|
|
mScaleX = value;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LauncherViewPropertyAnimator scaleY(float value) {
|
|
|
|
|
mPropertiesToSet.add(Properties.SCALE_Y);
|
|
|
|
|
mScaleY = value;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LauncherViewPropertyAnimator rotationY(float value) {
|
|
|
|
|
mPropertiesToSet.add(Properties.ROTATION_Y);
|
|
|
|
|
mRotationY = value;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LauncherViewPropertyAnimator alpha(float value) {
|
|
|
|
|
mPropertiesToSet.add(Properties.ALPHA);
|
|
|
|
|
mAlpha = value;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2013-09-26 15:29:57 -07:00
|
|
|
|
|
|
|
|
public LauncherViewPropertyAnimator withLayer() {
|
|
|
|
|
mPropertiesToSet.add(Properties.WITH_LAYER);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2011-12-12 21:48:38 -08:00
|
|
|
}
|