List of usage examples for android.animation ObjectAnimator addUpdateListener
public void addUpdateListener(AnimatorUpdateListener listener)
From source file:com.taobao.weex.ui.animation.WXAnimationModule.java
private static @Nullable ObjectAnimator createAnimator(@NonNull WXAnimationBean animation, final View target, final int viewPortWidth) { if (target == null) { return null; }/*from www.java 2s . c o m*/ WXAnimationBean.Style style = animation.styles; if (style != null) { ObjectAnimator animator; List<PropertyValuesHolder> holders = style.getHolders(); if (!TextUtils.isEmpty(style.backgroundColor)) { BorderDrawable borderDrawable; if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) { holders.add(PropertyValuesHolder.ofObject(WXAnimationBean.Style.BACKGROUND_COLOR, new ArgbEvaluator(), borderDrawable.getColor(), WXResourceUtils.getColor(style.backgroundColor))); } else if (target.getBackground() instanceof ColorDrawable) { holders.add(PropertyValuesHolder.ofObject(WXAnimationBean.Style.BACKGROUND_COLOR, new ArgbEvaluator(), ((ColorDrawable) target.getBackground()).getColor(), WXResourceUtils.getColor(style.backgroundColor))); } } if (style.getPivot() != null) { Pair<Float, Float> pair = style.getPivot(); target.setPivotX(pair.first); target.setPivotY(pair.second); } animator = ObjectAnimator.ofPropertyValuesHolder(target, holders.toArray(new PropertyValuesHolder[holders.size()])); animator.setStartDelay(animation.delay); if (target.getLayoutParams() != null && (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) { DimensionUpdateListener listener = new DimensionUpdateListener(target); ViewGroup.LayoutParams layoutParams = target.getLayoutParams(); if (!TextUtils.isEmpty(style.width)) { listener.setWidth(layoutParams.width, (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth)); } if (!TextUtils.isEmpty(style.height)) { listener.setHeight(layoutParams.height, (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth)); } animator.addUpdateListener(listener); } return animator; } else { return null; } }
From source file:com.klinker.android.sliding.MultiShrinkScroller.java
/** * Scroll the activity up as the entrace animation. * @param scrollToCurrentPosition if true, will scroll from the bottom of the screen to the * current position. Otherwise, will scroll from the bottom of the screen to the top of the * screen./* w w w . j av a2s . c o m*/ */ public void performEntranceAnimation(OpenAnimation animation, boolean scrollToCurrentPosition) { final int currentPosition = getScroll(); final int bottomScrollPosition = currentPosition - (getHeight() - getTransparentViewHeight()) + 1; final int desiredValue = currentPosition + (scrollToCurrentPosition ? currentPosition : getTransparentViewHeight()); if (animation == OpenAnimation.EXPAND_FROM_VIEW) { scrollTo(0, desiredValue); runExpansionAnimation(); openAnimation = animation; } else { final Interpolator interpolator; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { interpolator = AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.linear_out_slow_in); } else { interpolator = new DecelerateInterpolator(); } final ObjectAnimator animator = ObjectAnimator.ofInt(this, "scroll", bottomScrollPosition, desiredValue); animator.setInterpolator(interpolator); animator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { if (animation.getAnimatedValue().equals(desiredValue) && listener != null) { listener.onEntranceAnimationDone(); } } }); animator.start(); } }
From source file:com.github.shareme.gwsmaterialdrawer.library.DrawerView.java
private void animateToProfile(DrawerProfile profile) { Log.d(TAG, "animateToProfile(*" + profile.getId() + ")"); if (mProfileAdapter.getCount() > 1) { List<Animator> animators = new ArrayList<>(); List<Animator.AnimatorListener> listeners = new ArrayList<>(); final DrawerProfile oldProfile = mProfileAdapter.getItem(0); final DrawerProfile newProfile = profile; /* Background animation */ AlphaSatColorMatrixEvaluator evaluator = new AlphaSatColorMatrixEvaluator(); final AnimatableColorMatrixColorFilter filter = new AnimatableColorMatrixColorFilter( evaluator.getColorMatrix()); ObjectAnimator backgroundAnimator = ObjectAnimator.ofObject(filter, "colorMatrix", evaluator, evaluator.getColorMatrix()); backgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override// w w w . j a va 2 s .c o m public void onAnimationUpdate(ValueAnimator animation) { imageViewProfileBackgroundOverlay.setColorFilter(filter.getColorFilter()); } }); animators.add(backgroundAnimator); listeners.add(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { imageViewProfileBackground.setImageDrawable(oldProfile.getBackground()); imageViewProfileBackgroundOverlay.setImageDrawable(newProfile.getBackground()); imageViewProfileBackgroundOverlay.setColorFilter(filter.getColorFilter()); imageViewProfileBackgroundOverlay.setVisibility(VISIBLE); imageViewProfileAvatarSecondary.setClickable(false); } @Override public void onAnimationEnd(Animator animation) { imageViewProfileBackground.setImageDrawable(newProfile.getBackground()); if (newProfile.getBackground() instanceof BitmapDrawable) { new Palette.Builder(((BitmapDrawable) newProfile.getBackground()).getBitmap()) .resizeBitmapSize(500).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { Palette.Swatch vibrantSwatch = palette.getVibrantSwatch(); if (vibrantSwatch != null) { textViewProfileAvatarCount .setTextColor(vibrantSwatch.getTitleTextColor()); textViewProfileAvatarCount.getBackground() .setColorFilter(vibrantSwatch.getRgb(), PorterDuff.Mode.SRC_IN); } } }); } imageViewProfileBackgroundOverlay.setVisibility(GONE); if (hasOnProfileSwitchListener()) { onProfileSwitchListener.onSwitch(oldProfile, oldProfile.getId(), newProfile, newProfile.getId()); } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); /* Text animation */ AnimatorSet textSet = new AnimatorSet(); AnimatorSet textOutSet = new AnimatorSet(); textOutSet.playTogether(ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "alpha", 1, 0), ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "translationX", 0, getWidth() / 4)); textOutSet.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { updateProfileTheme(); if (newProfile.hasName()) { textViewProfileName.setText(newProfile.getName()); textViewProfileName.setVisibility(VISIBLE); } else { textViewProfileName.setVisibility(GONE); } if (newProfile.hasDescription()) { textViewProfileDescription.setText(newProfile.getDescription()); textViewProfileDescription.setVisibility(VISIBLE); } else { textViewProfileDescription.setVisibility(GONE); } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); AnimatorSet textInSet = new AnimatorSet(); textInSet.playTogether(ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "alpha", 0, 1), ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "translationX", -getWidth() / 4, 0)); textSet.playSequentially(textOutSet, textInSet); animators.add(textSet); AnimatorSet profileSet = new AnimatorSet(); if (mProfileAdapter.getCount() == 2) { /* Avatar animation */ int translation = imageViewProfileAvatarSecondary.getLeft() - getResources().getDimensionPixelSize(R.dimen.md_baseline); float scale = getResources().getDimension(R.dimen.md_avatar_size) / getResources().getDimension(R.dimen.md_big_avatar_size); float translationCorrect = (getResources().getDimension(R.dimen.md_avatar_size) - getResources().getDimension(R.dimen.md_big_avatar_size)) / 2; listeners.add(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { imageViewProfileAvatarSecondary.setPivotX(0); imageViewProfileAvatarSecondary.setPivotY(0); } @Override public void onAnimationEnd(Animator animation) { imageViewProfileAvatar.setTranslationX(0); imageViewProfileAvatar.setTranslationY(0); imageViewProfileAvatar.setScaleX(1); imageViewProfileAvatar.setScaleY(1); imageViewProfileAvatarSecondary.setTranslationX(0); imageViewProfileAvatarSecondary.setScaleX(1); imageViewProfileAvatarSecondary.setScaleY(1); if (oldProfile.hasAvatar()) { imageViewProfileAvatarSecondary.setImageDrawable(oldProfile.getAvatar()); imageViewProfileAvatarSecondary.setVisibility(VISIBLE); } else { imageViewProfileAvatarSecondary.setVisibility(INVISIBLE); } if (newProfile.hasAvatar()) { imageViewProfileAvatar.setImageDrawable(newProfile.getAvatar()); imageViewProfileAvatar.setVisibility(VISIBLE); imageViewProfileAvatarSecondary.setClickable(true); } else { imageViewProfileAvatar.setVisibility(INVISIBLE); imageViewProfileAvatarSecondary.setClickable(false); } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); if (oldProfile.hasAvatar()) { ObjectAnimator stepTranslateXAnimator = ObjectAnimator.ofFloat(imageViewProfileAvatar, "translationX", 0, translation + translationCorrect); stepTranslateXAnimator.setInterpolator(new StepInterpolator()); animators.add(stepTranslateXAnimator); ObjectAnimator stepTranslateYAnimator = ObjectAnimator.ofFloat(imageViewProfileAvatar, "translationY", 0, translationCorrect); stepTranslateYAnimator.setInterpolator(new StepInterpolator()); animators.add(stepTranslateYAnimator); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 1, 0, 1)); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 1, 0.5f, scale)); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 1, 0.5f, scale)); } if (newProfile.hasAvatar()) { animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "translationX", 0, -translation)); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "scaleX", 1, 1 / scale)); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "scaleY", 1, 1 / scale)); } } else { AnimatorSet profileOutSet = new AnimatorSet(); profileOutSet.playTogether(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 1, 0), ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 1, 0.5f), ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 1, 0.5f)); profileOutSet.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { linearListViewProfileList.setOnItemClickListener(new LinearListView.OnItemClickListener() { @Override public void onItemClick(LinearListView parent, View view, int position, long id) { } }); } @Override public void onAnimationEnd(Animator animation) { imageViewProfileAvatar.setImageDrawable(newProfile.getAvatar()); linearListViewProfileList.setOnItemClickListener(new LinearListView.OnItemClickListener() { @Override public void onItemClick(LinearListView parent, View view, int position, long id) { if (position != 0) { selectProfile(mProfileAdapter.getItem(position)); } } }); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); AnimatorSet profileInSet = new AnimatorSet(); profileInSet.playTogether(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 0, 1), ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 0.5f, 1), ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 0.5f, 1)); profileSet.playSequentially(profileOutSet, profileInSet); animators.add(profileSet); } if (animators.size() > 0) { /* Play animation */ AnimatorSet set = new AnimatorSet(); set.playTogether(animators); set.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time)); textSet.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time) / 2); profileSet.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time) / 2); for (Animator.AnimatorListener listener : listeners) { set.addListener(listener); } set.start(); } } }
From source file:trendoidtechnologies.com.navigationdrawerlibrary.DrawerView.java
private void animateToProfile(DrawerProfile profile) { if (loggingEnabled) Log.d(TAG, "animateToProfile(*" + profile.getId() + ")"); if (mProfileAdapter.getCount() > 1) { List<Animator> animators = new ArrayList<>(); List<Animator.AnimatorListener> listeners = new ArrayList<>(); final DrawerProfile oldProfile = mProfileAdapter.getItem(0); final DrawerProfile newProfile = profile; boolean isRtl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == LAYOUT_DIRECTION_RTL; int rtlSign = isRtl ? -1 : 1; /* Background animation */ AlphaSatColorMatrixEvaluator evaluator = new AlphaSatColorMatrixEvaluator(); final AnimatableColorMatrixColorFilter filter = new AnimatableColorMatrixColorFilter( evaluator.getColorMatrix()); ObjectAnimator backgroundAnimator = ObjectAnimator.ofObject(filter, "colorMatrix", evaluator, evaluator.getColorMatrix()); backgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from ww w.j a v a2 s . com public void onAnimationUpdate(ValueAnimator animation) { imageViewProfileBackgroundOverlay.setColorFilter(filter.getColorFilter()); } }); animators.add(backgroundAnimator); listeners.add(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { imageViewProfileBackground.setImageDrawable(oldProfile.getBackground()); imageViewProfileBackgroundOverlay.setImageDrawable(newProfile.getBackground()); imageViewProfileBackgroundOverlay.setColorFilter(filter.getColorFilter()); imageViewProfileBackgroundOverlay.setVisibility(VISIBLE); imageViewProfileAvatarSecondary.setClickable(false); } @Override public void onAnimationEnd(Animator animation) { imageViewProfileBackground.setImageDrawable(newProfile.getBackground()); if (newProfile.getBackground() instanceof BitmapDrawable) { new Palette.Builder(((BitmapDrawable) newProfile.getBackground()).getBitmap()) .resizeBitmapSize(500).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { Palette.Swatch vibrantSwatch = palette.getVibrantSwatch(); if (vibrantSwatch != null) { textViewProfileAvatarCount .setTextColor(vibrantSwatch.getTitleTextColor()); textViewProfileAvatarCount.getBackground() .setColorFilter(vibrantSwatch.getRgb(), PorterDuff.Mode.SRC_IN); } } }); } imageViewProfileBackgroundOverlay.setVisibility(GONE); if (hasOnProfileSwitchListener()) { onProfileSwitchListener.onSwitch(oldProfile, oldProfile.getId(), newProfile, newProfile.getId()); } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); /* Text animation */ AnimatorSet textSet = new AnimatorSet(); AnimatorSet textOutSet = new AnimatorSet(); textOutSet.playTogether(ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "alpha", 1, 0), ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "translationX", 0, getWidth() / 4 * rtlSign)); textOutSet.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { updateProfileTheme(); if (newProfile.hasName()) { textViewProfileName.setText(newProfile.getName()); textViewProfileName.setVisibility(VISIBLE); } else { textViewProfileName.setVisibility(GONE); } if (newProfile.hasDescription()) { textViewProfileDescription.setText(newProfile.getDescription()); textViewProfileDescription.setVisibility(VISIBLE); } else { textViewProfileDescription.setVisibility(GONE); } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); AnimatorSet textInSet = new AnimatorSet(); textInSet.playTogether(ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "alpha", 0, 1), ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "translationX", -getWidth() / 4 * rtlSign, 0)); textSet.playSequentially(textOutSet, textInSet); animators.add(textSet); AnimatorSet profileSet = new AnimatorSet(); if (mProfileAdapter.getCount() == 2) { /* Avatar animation */ int translation = isRtl ? (relativeLayoutProfileContent.getWidth() - getResources().getDimensionPixelSize(R.dimen.md_big_avatar_size) - 2 * getResources().getDimensionPixelSize(R.dimen.md_baseline)) : (imageViewProfileAvatarSecondary.getLeft() - getResources().getDimensionPixelSize(R.dimen.md_baseline)); float scale = getResources().getDimension(R.dimen.md_avatar_size) / getResources().getDimension(R.dimen.md_big_avatar_size); float translationCorrect = (getResources().getDimension(R.dimen.md_avatar_size) - getResources().getDimension(R.dimen.md_big_avatar_size)) / 2; listeners.add(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { imageViewProfileAvatarSecondary.setPivotX(0); imageViewProfileAvatarSecondary.setPivotY(0); } @Override public void onAnimationEnd(Animator animation) { imageViewProfileAvatar.setTranslationX(0); imageViewProfileAvatar.setTranslationY(0); imageViewProfileAvatar.setScaleX(1); imageViewProfileAvatar.setScaleY(1); imageViewProfileAvatarSecondary.setTranslationX(0); imageViewProfileAvatarSecondary.setScaleX(1); imageViewProfileAvatarSecondary.setScaleY(1); if (oldProfile.hasAvatar()) { imageViewProfileAvatarSecondary.setImageDrawable(oldProfile.getAvatar()); imageViewProfileAvatarSecondary.setVisibility(VISIBLE); } else { imageViewProfileAvatarSecondary.setVisibility(INVISIBLE); } if (newProfile.hasAvatar()) { imageViewProfileAvatar.setImageDrawable(newProfile.getAvatar()); imageViewProfileAvatar.setVisibility(VISIBLE); imageViewProfileAvatarSecondary.setClickable(true); } else { imageViewProfileAvatar.setVisibility(INVISIBLE); imageViewProfileAvatarSecondary.setClickable(false); } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); if (oldProfile.hasAvatar()) { ObjectAnimator stepTranslateXAnimator = ObjectAnimator.ofFloat(imageViewProfileAvatar, "translationX", 0, translation * rtlSign + translationCorrect); stepTranslateXAnimator.setInterpolator(new StepInterpolator()); animators.add(stepTranslateXAnimator); ObjectAnimator stepTranslateYAnimator = ObjectAnimator.ofFloat(imageViewProfileAvatar, "translationY", 0, translationCorrect); stepTranslateYAnimator.setInterpolator(new StepInterpolator()); animators.add(stepTranslateYAnimator); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 1, 0, 1)); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 1, 0.5f, scale)); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 1, 0.5f, scale)); } if (newProfile.hasAvatar()) { animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "translationX", 0, -translation * rtlSign)); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "scaleX", 1, 1 / scale)); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "scaleY", 1, 1 / scale)); } } else { AnimatorSet profileOutSet = new AnimatorSet(); profileOutSet.playTogether(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 1, 0), ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 1, 0.5f), ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 1, 0.5f)); profileOutSet.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { linearListViewProfileList.setOnItemClickListener(new LinearListView.OnItemClickListener() { @Override public void onItemClick(LinearListView parent, View view, int position, long id) { } }); } @Override public void onAnimationEnd(Animator animation) { imageViewProfileAvatar.setImageDrawable(newProfile.getAvatar()); linearListViewProfileList.setOnItemClickListener(new LinearListView.OnItemClickListener() { @Override public void onItemClick(LinearListView parent, View view, int position, long id) { if (position != 0) { selectProfile(mProfileAdapter.getItem(position)); } } }); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); AnimatorSet profileInSet = new AnimatorSet(); profileInSet.playTogether(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 0, 1), ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 0.5f, 1), ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 0.5f, 1)); profileSet.playSequentially(profileOutSet, profileInSet); animators.add(profileSet); } if (animators.size() > 0) { /* Play animation */ AnimatorSet set = new AnimatorSet(); set.playTogether(animators); set.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time)); textSet.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time) / 2); profileSet.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time) / 2); for (Animator.AnimatorListener listener : listeners) { set.addListener(listener); } set.start(); } } }
From source file:com.taobao.weex.dom.action.AnimationAction.java
private @Nullable ObjectAnimator createAnimator(final View target, final int viewPortWidth) { if (target == null) { return null; }//from w w w . j a v a 2s . c o m WXAnimationBean.Style style = mAnimationBean.styles; if (style != null) { ObjectAnimator animator; List<PropertyValuesHolder> holders = style.getHolders(); if (!TextUtils.isEmpty(style.backgroundColor)) { BorderDrawable borderDrawable; if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) { holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(), borderDrawable.getColor(), WXResourceUtils.getColor(style.backgroundColor))); } else if (target.getBackground() instanceof ColorDrawable) { holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(), ((ColorDrawable) target.getBackground()).getColor(), WXResourceUtils.getColor(style.backgroundColor))); } } if (style.getPivot() != null) { Pair<Float, Float> pair = style.getPivot(); target.setPivotX(pair.first); target.setPivotY(pair.second); } animator = ObjectAnimator.ofPropertyValuesHolder(target, holders.toArray(new PropertyValuesHolder[holders.size()])); animator.setStartDelay(mAnimationBean.delay); if (target.getLayoutParams() != null && (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) { DimensionUpdateListener listener = new DimensionUpdateListener(target); ViewGroup.LayoutParams layoutParams = target.getLayoutParams(); if (!TextUtils.isEmpty(style.width)) { listener.setWidth(layoutParams.width, (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth)); } if (!TextUtils.isEmpty(style.height)) { listener.setHeight(layoutParams.height, (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth)); } animator.addUpdateListener(listener); } return animator; } else { return null; } }
From source file:com.bartoszlipinski.viewpropertyobjectanimator.ViewPropertyObjectAnimator.java
@SuppressLint("NewApi") public ObjectAnimator get() { if (hasView()) { Collection<PropertyValuesHolder> holders = mPropertyHoldersMap.values(); ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(mView.get(), holders.toArray(new PropertyValuesHolder[holders.size()])); if (mWithLayer) { animator.addListener(new AnimatorListenerAdapter() { int mCurrentLayerType = View.LAYER_TYPE_NONE; @Override// w w w .ja v a 2s . co m public void onAnimationStart(Animator animation) { if (hasView()) { View view = mView.get(); mCurrentLayerType = view.getLayerType(); view.setLayerType(View.LAYER_TYPE_HARDWARE, null); if (ViewCompat.isAttachedToWindow(view)) { view.buildLayer(); } } } @Override public void onAnimationEnd(Animator animation) { if (hasView()) { mView.get().setLayerType(mCurrentLayerType, null); } } }); } if (mStartDelay != -1) { animator.setStartDelay(mStartDelay); } if (mDuration != -1) { animator.setDuration(mDuration); } if (mInterpolator != null) { animator.setInterpolator(mInterpolator); } for (Animator.AnimatorListener listener : mListeners) { animator.addListener(listener); } if (mMarginListener != null) { animator.addUpdateListener(mMarginListener); } if (mDimensionListener != null) { animator.addUpdateListener(mDimensionListener); } if (mPaddingListener != null) { animator.addUpdateListener(mPaddingListener); } if (mScrollListener != null) { animator.addUpdateListener(mScrollListener); } if (mPercentListener != null) { animator.addUpdateListener(mPercentListener); } for (ValueAnimator.AnimatorUpdateListener listener : mUpdateListeners) { animator.addUpdateListener(listener); } if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { for (Animator.AnimatorPauseListener listener : mPauseListeners) { animator.addPauseListener(listener); } } return animator; } return ObjectAnimator.ofFloat(null, View.ALPHA, 1, 1); }
From source file:com.android.launcher2.Launcher.java
/** * Zoom the camera back into the workspace, hiding 'fromView'. * This is the opposite of showAppsCustomizeHelper. * @param animated If true, the transition will be animated. *//*from w ww .ja v a 2 s . c o m*/ private void hideAppsCustomizeHelper(State toState, final boolean animated, final boolean springLoaded, final Runnable onCompleteRunnable) { if (mStateAnimation != null) { mStateAnimation.cancel(); mStateAnimation = null; } Resources res = getResources(); final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime); final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime); final float scaleFactor = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); final View fromView = mAppsCustomizeTabHost; final View toView = mWorkspace; Animator workspaceAnim = null; if (toState == State.WORKSPACE) { int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger); workspaceAnim = mWorkspace.getChangeStateAnimation(Workspace.State.NORMAL, animated, stagger); } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) { workspaceAnim = mWorkspace.getChangeStateAnimation(Workspace.State.SPRING_LOADED, animated); } setPivotsForZoom(fromView, scaleFactor); updateWallpaperVisibility(true); showHotseat(animated); if (animated) { final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(fromView); scaleAnim.scaleX(scaleFactor).scaleY(scaleFactor).setDuration(duration) .setInterpolator(new Workspace.ZoomInInterpolator()); final ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(fromView, "alpha", 1f, 0f) .setDuration(fadeOutDuration); alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator()); alphaAnim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float t = 1f - (Float) animation.getAnimatedValue(); dispatchOnLauncherTransitionStep(fromView, t); dispatchOnLauncherTransitionStep(toView, t); } }); mStateAnimation = LauncherAnimUtils.createAnimatorSet(); dispatchOnLauncherTransitionPrepare(fromView, animated, true); dispatchOnLauncherTransitionPrepare(toView, animated, true); mAppsCustomizeContent.pauseScrolling(); mStateAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { updateWallpaperVisibility(true); fromView.setVisibility(View.GONE); dispatchOnLauncherTransitionEnd(fromView, animated, true); dispatchOnLauncherTransitionEnd(toView, animated, true); if (mWorkspace != null) { mWorkspace.hideScrollingIndicator(false); } if (onCompleteRunnable != null) { onCompleteRunnable.run(); } mAppsCustomizeContent.updateCurrentPageScroll(); mAppsCustomizeContent.resumeScrolling(); } }); mStateAnimation.playTogether(scaleAnim, alphaAnim); if (workspaceAnim != null) { mStateAnimation.play(workspaceAnim); } dispatchOnLauncherTransitionStart(fromView, animated, true); dispatchOnLauncherTransitionStart(toView, animated, true); final Animator stateAnimation = mStateAnimation; mWorkspace.post(new Runnable() { public void run() { if (stateAnimation != mStateAnimation) return; mStateAnimation.start(); } }); } else { fromView.setVisibility(View.GONE); dispatchOnLauncherTransitionPrepare(fromView, animated, true); dispatchOnLauncherTransitionStart(fromView, animated, true); dispatchOnLauncherTransitionEnd(fromView, animated, true); dispatchOnLauncherTransitionPrepare(toView, animated, true); dispatchOnLauncherTransitionStart(toView, animated, true); dispatchOnLauncherTransitionEnd(toView, animated, true); mWorkspace.hideScrollingIndicator(false); } }
From source file:com.android.launcher2.Launcher.java
/** * Zoom the camera out from the workspace to reveal 'toView'. * Assumes that the view to show is anchored at either the very top or very bottom * of the screen./*from www. j ava 2 s.co m*/ */ private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) { if (mStateAnimation != null) { mStateAnimation.cancel(); mStateAnimation = null; } final Resources res = getResources(); final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime); final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime); final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); final View fromView = mWorkspace; final AppsCustomizeTabHost toView = mAppsCustomizeTabHost; final int startDelay = res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger); setPivotsForZoom(toView, scale); // Shrink workspaces away if going to AppsCustomize from workspace Animator workspaceAnim = mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated); if (animated) { toView.setScaleX(scale); toView.setScaleY(scale); final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView); scaleAnim.scaleX(1f).scaleY(1f).setDuration(duration) .setInterpolator(new Workspace.ZoomOutInterpolator()); toView.setVisibility(View.VISIBLE); toView.setAlpha(0f); final ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(toView, "alpha", 0f, 1f) .setDuration(fadeDuration); alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f)); alphaAnim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { if (animation == null) { throw new RuntimeException("animation is null"); } float t = (Float) animation.getAnimatedValue(); dispatchOnLauncherTransitionStep(fromView, t); dispatchOnLauncherTransitionStep(toView, t); } }); // toView should appear right at the end of the workspace shrink // animation mStateAnimation = LauncherAnimUtils.createAnimatorSet(); mStateAnimation.play(scaleAnim).after(startDelay); mStateAnimation.play(alphaAnim).after(startDelay); mStateAnimation.addListener(new AnimatorListenerAdapter() { boolean animationCancelled = false; @Override public void onAnimationStart(Animator animation) { updateWallpaperVisibility(true); // Prepare the position toView.setTranslationX(0.0f); toView.setTranslationY(0.0f); toView.setVisibility(View.VISIBLE); toView.bringToFront(); } @Override public void onAnimationEnd(Animator animation) { dispatchOnLauncherTransitionEnd(fromView, animated, false); dispatchOnLauncherTransitionEnd(toView, animated, false); if (mWorkspace != null && !springLoaded && !LauncherApplication.isScreenLarge()) { // Hide the workspace scrollbar mWorkspace.hideScrollingIndicator(true); hideDockDivider(); } if (!animationCancelled) { updateWallpaperVisibility(false); } // Hide the search bar if (mSearchDropTargetBar != null) { mSearchDropTargetBar.hideSearchBar(false); } } @Override public void onAnimationCancel(Animator animation) { animationCancelled = true; } }); if (workspaceAnim != null) { mStateAnimation.play(workspaceAnim); } boolean delayAnim = false; final ViewTreeObserver observer; dispatchOnLauncherTransitionPrepare(fromView, animated, false); dispatchOnLauncherTransitionPrepare(toView, animated, false); // If any of the objects being animated haven't been measured/laid out // yet, delay the animation until we get a layout pass if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) || (mWorkspace.getMeasuredWidth() == 0) || (toView.getMeasuredWidth() == 0)) { observer = mWorkspace.getViewTreeObserver(); delayAnim = true; } else { observer = null; } final AnimatorSet stateAnimation = mStateAnimation; final Runnable startAnimRunnable = new Runnable() { public void run() { // Check that mStateAnimation hasn't changed while // we waited for a layout/draw pass if (mStateAnimation != stateAnimation) return; setPivotsForZoom(toView, scale); dispatchOnLauncherTransitionStart(fromView, animated, false); dispatchOnLauncherTransitionStart(toView, animated, false); toView.post(new Runnable() { public void run() { // Check that mStateAnimation hasn't changed while // we waited for a layout/draw pass if (mStateAnimation != stateAnimation) return; mStateAnimation.start(); } }); } }; if (delayAnim) { final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() { public void onGlobalLayout() { toView.post(startAnimRunnable); ViewTreeObserverCompat.removeOnGlobalLayoutListener(observer, this); } }; observer.addOnGlobalLayoutListener(delayedStart); } else { startAnimRunnable.run(); } } else { toView.setTranslationX(0.0f); toView.setTranslationY(0.0f); toView.setScaleX(1.0f); toView.setScaleY(1.0f); toView.setVisibility(View.VISIBLE); toView.bringToFront(); if (!springLoaded && !LauncherApplication.isScreenLarge()) { // Hide the workspace scrollbar mWorkspace.hideScrollingIndicator(true); hideDockDivider(); // Hide the search bar if (mSearchDropTargetBar != null) { mSearchDropTargetBar.hideSearchBar(false); } } dispatchOnLauncherTransitionPrepare(fromView, animated, false); dispatchOnLauncherTransitionStart(fromView, animated, false); dispatchOnLauncherTransitionEnd(fromView, animated, false); dispatchOnLauncherTransitionPrepare(toView, animated, false); dispatchOnLauncherTransitionStart(toView, animated, false); dispatchOnLauncherTransitionEnd(toView, animated, false); updateWallpaperVisibility(false); } }
From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java
/** * Zoom the camera out from the workspace to reveal 'toView'. * Assumes that the view to show is anchored at either the very top or very bottom * of the screen./*from www.ja v a 2 s . c o m*/ */ private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) { if (mStateAnimation != null) { mStateAnimation.cancel(); mStateAnimation = null; } final Resources res = getResources(); final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime); final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime); final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); final View fromView = mWorkspace; final AppsCustomizeTabHost toView = mAppsCustomizeTabHost; final int startDelay = res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger); setPivotsForZoom(toView, scale); // Shrink workspaces away if going to AppsCustomize from workspace Animator workspaceAnim = mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated); if (animated) { toView.setScaleX(scale); toView.setScaleY(scale); final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView); scaleAnim.scaleX(1f).scaleY(1f).setDuration(duration) .setInterpolator(new Workspace.ZoomOutInterpolator()); toView.setVisibility(View.VISIBLE); toView.setAlpha(0f); final ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(toView, "alpha", 0f, 1f) .setDuration(fadeDuration); alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f)); alphaAnim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { if (animation == null) { throw new RuntimeException("animation is null"); } float t = (Float) animation.getAnimatedValue(); dispatchOnLauncherTransitionStep(fromView, t); dispatchOnLauncherTransitionStep(toView, t); } }); // toView should appear right at the end of the workspace shrink // animation mStateAnimation = LauncherAnimUtils.createAnimatorSet(); mStateAnimation.play(scaleAnim).after(startDelay); mStateAnimation.play(alphaAnim).after(startDelay); mStateAnimation.addListener(new AnimatorListenerAdapter() { boolean animationCancelled = false; @Override public void onAnimationStart(Animator animation) { updateWallpaperVisibility(true); // Prepare the position toView.setTranslationX(0.0f); toView.setTranslationY(0.0f); toView.setVisibility(View.VISIBLE); toView.bringToFront(); } @Override public void onAnimationEnd(Animator animation) { dispatchOnLauncherTransitionEnd(fromView, animated, false); dispatchOnLauncherTransitionEnd(toView, animated, false); if (mWorkspace != null && !springLoaded && !LauncherApplication.isScreenLarge()) { // Hide the workspace scrollbar mWorkspace.hideScrollingIndicator(true); hideDockDivider(); } if (!animationCancelled) { updateWallpaperVisibility(false); } // Hide the search bar if (mSearchDropTargetBar != null) { mSearchDropTargetBar.hideSearchBar(false); } } @Override public void onAnimationCancel(Animator animation) { animationCancelled = true; } }); if (workspaceAnim != null) { mStateAnimation.play(workspaceAnim); } boolean delayAnim = false; final ViewTreeObserver observer; dispatchOnLauncherTransitionPrepare(fromView, animated, false); dispatchOnLauncherTransitionPrepare(toView, animated, false); // If any of the objects being animated haven't been measured/laid out // yet, delay the animation until we get a layout pass if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) || (mWorkspace.getMeasuredWidth() == 0) || (toView.getMeasuredWidth() == 0)) { observer = mWorkspace.getViewTreeObserver(); delayAnim = true; } else { observer = null; } final AnimatorSet stateAnimation = mStateAnimation; final Runnable startAnimRunnable = new Runnable() { public void run() { // Check that mStateAnimation hasn't changed while // we waited for a layout/draw pass if (mStateAnimation != stateAnimation) return; setPivotsForZoom(toView, scale); dispatchOnLauncherTransitionStart(fromView, animated, false); dispatchOnLauncherTransitionStart(toView, animated, false); toView.post(new Runnable() { public void run() { // Check that mStateAnimation hasn't changed while // we waited for a layout/draw pass if (mStateAnimation != stateAnimation) return; mStateAnimation.start(); } }); } }; if (delayAnim) { final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() { public void onGlobalLayout() { toView.post(startAnimRunnable); observer.removeOnGlobalLayoutListener(this); } }; observer.addOnGlobalLayoutListener(delayedStart); } else { startAnimRunnable.run(); } } else { toView.setTranslationX(0.0f); toView.setTranslationY(0.0f); toView.setScaleX(1.0f); toView.setScaleY(1.0f); toView.setVisibility(View.VISIBLE); toView.bringToFront(); if (!springLoaded && !LauncherApplication.isScreenLarge()) { // Hide the workspace scrollbar mWorkspace.hideScrollingIndicator(true); hideDockDivider(); // Hide the search bar if (mSearchDropTargetBar != null) { mSearchDropTargetBar.hideSearchBar(false); } } dispatchOnLauncherTransitionPrepare(fromView, animated, false); dispatchOnLauncherTransitionStart(fromView, animated, false); dispatchOnLauncherTransitionEnd(fromView, animated, false); dispatchOnLauncherTransitionPrepare(toView, animated, false); dispatchOnLauncherTransitionStart(toView, animated, false); dispatchOnLauncherTransitionEnd(toView, animated, false); updateWallpaperVisibility(false); } }
From source file:com.android.soma.Launcher.java
/** * Zoom the camera back into the workspace, hiding 'fromView'. * This is the opposite of showAppsCustomizeHelper. * @param animated If true, the transition will be animated. *///from w ww. jav a2s . c om private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated, final boolean springLoaded, final Runnable onCompleteRunnable) { if (mStateAnimation != null) { mStateAnimation.setDuration(0); mStateAnimation.cancel(); mStateAnimation = null; } Resources res = getResources(); final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime); final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime); final float scaleFactor = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); final View fromView = mAppsCustomizeTabHost; final View toView = mWorkspace; Animator workspaceAnim = null; if (toState == Workspace.State.NORMAL) { int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger); workspaceAnim = mWorkspace.getChangeStateAnimation(toState, animated, stagger, -1); } else if (toState == Workspace.State.SPRING_LOADED || toState == Workspace.State.OVERVIEW) { workspaceAnim = mWorkspace.getChangeStateAnimation(toState, animated); } setPivotsForZoom(fromView, scaleFactor); showHotseat(animated); if (animated) { final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(fromView); scaleAnim.scaleX(scaleFactor).scaleY(scaleFactor).setDuration(duration) .setInterpolator(new Workspace.ZoomInInterpolator()); final ObjectAnimator alphaAnim = LauncherAnimUtils.ofFloat(fromView, "alpha", 1f, 0f) .setDuration(fadeOutDuration); alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator()); alphaAnim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float t = 1f - (Float) animation.getAnimatedValue(); dispatchOnLauncherTransitionStep(fromView, t); dispatchOnLauncherTransitionStep(toView, t); } }); mStateAnimation = LauncherAnimUtils.createAnimatorSet(); dispatchOnLauncherTransitionPrepare(fromView, animated, true); dispatchOnLauncherTransitionPrepare(toView, animated, true); mAppsCustomizeContent.pauseScrolling(); mStateAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { fromView.setVisibility(View.GONE); dispatchOnLauncherTransitionEnd(fromView, animated, true); dispatchOnLauncherTransitionEnd(toView, animated, true); if (onCompleteRunnable != null) { onCompleteRunnable.run(); } mAppsCustomizeContent.updateCurrentPageScroll(); mAppsCustomizeContent.resumeScrolling(); } }); mStateAnimation.playTogether(scaleAnim, alphaAnim); if (workspaceAnim != null) { mStateAnimation.play(workspaceAnim); } dispatchOnLauncherTransitionStart(fromView, animated, true); dispatchOnLauncherTransitionStart(toView, animated, true); LauncherAnimUtils.startAnimationAfterNextDraw(mStateAnimation, toView); } else { fromView.setVisibility(View.GONE); dispatchOnLauncherTransitionPrepare(fromView, animated, true); dispatchOnLauncherTransitionStart(fromView, animated, true); dispatchOnLauncherTransitionEnd(fromView, animated, true); dispatchOnLauncherTransitionPrepare(toView, animated, true); dispatchOnLauncherTransitionStart(toView, animated, true); dispatchOnLauncherTransitionEnd(toView, animated, true); } }