use of android.animation.AnimatorSet in project Conductor by bluelinelabs.
the class FlipChangeHandler method getAnimator.
@Override
@NonNull
protected Animator getAnimator(@NonNull ViewGroup container, View from, View to, boolean isPush, boolean toAddedToContainer) {
AnimatorSet animatorSet = new AnimatorSet();
if (to != null) {
to.setAlpha(0);
ObjectAnimator rotation = ObjectAnimator.ofFloat(to, flipDirection.property, flipDirection.inStartRotation, 0).setDuration(animationDuration);
rotation.setInterpolator(new AccelerateDecelerateInterpolator());
animatorSet.play(rotation);
Animator alpha = ObjectAnimator.ofFloat(to, View.ALPHA, 1).setDuration(animationDuration / 2);
alpha.setStartDelay(animationDuration / 3);
animatorSet.play(alpha);
}
if (from != null) {
ObjectAnimator rotation = ObjectAnimator.ofFloat(from, flipDirection.property, 0, flipDirection.outEndRotation).setDuration(animationDuration);
rotation.setInterpolator(new AccelerateDecelerateInterpolator());
animatorSet.play(rotation);
Animator alpha = ObjectAnimator.ofFloat(from, View.ALPHA, 0).setDuration(animationDuration / 2);
alpha.setStartDelay(animationDuration / 3);
animatorSet.play(alpha);
}
return animatorSet;
}
use of android.animation.AnimatorSet in project Conductor by bluelinelabs.
the class FabTransform method createAnimator.
@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) {
if (startValues == null || endValues == null)
return null;
final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);
final boolean fromFab = endBounds.width() > startBounds.width();
final View view = endValues.view;
final Rect dialogBounds = fromFab ? endBounds : startBounds;
final Interpolator fastOutSlowInInterpolator = AnimUtils.getFastOutSlowInInterpolator();
final long duration = getDuration();
final long halfDuration = duration / 2;
final long twoThirdsDuration = duration * 2 / 3;
if (!fromFab) {
// Force measure / layout the dialog back to it's original bounds
view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
}
final int translationX = startBounds.centerX() - endBounds.centerX();
final int translationY = startBounds.centerY() - endBounds.centerY();
if (fromFab) {
view.setTranslationX(translationX);
view.setTranslationY(translationY);
}
// Add a color overlay to fake appearance of the FAB
final ColorDrawable fabColor = new ColorDrawable(color);
fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
if (!fromFab)
fabColor.setAlpha(0);
view.getOverlay().add(fabColor);
// Add an icon overlay again to fake the appearance of the FAB
final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(), iconTop + fabIcon.getIntrinsicHeight());
if (!fromFab)
fabIcon.setAlpha(0);
view.getOverlay().add(fabIcon);
// Since the view that's being transition to always seems to be on the top (z-order), we have
// to make a copy of the "from" view and put it in the "to" view's overlay, then fade it out.
// There has to be another way to do this, right?
Drawable dialogView = null;
if (!fromFab) {
startValues.view.setDrawingCacheEnabled(true);
startValues.view.buildDrawingCache();
Bitmap viewBitmap = startValues.view.getDrawingCache();
dialogView = new BitmapDrawable(view.getResources(), viewBitmap);
dialogView.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
view.getOverlay().add(dialogView);
}
// Circular clip from/to the FAB size
final Animator circularReveal;
if (fromFab) {
circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startBounds.width() / 2, (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2));
circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator());
} else {
circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2), endBounds.width() / 2);
circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator());
// Persist the end clip i.e. stay at FAB size after the reveal has run
circularReveal.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
final ViewOutlineProvider fabOutlineProvider = view.getOutlineProvider();
view.setOutlineProvider(new ViewOutlineProvider() {
boolean hasRun = false;
@Override
public void getOutline(final View view, Outline outline) {
final int left = (view.getWidth() - endBounds.width()) / 2;
final int top = (view.getHeight() - endBounds.height()) / 2;
outline.setOval(left, top, left + endBounds.width(), top + endBounds.height());
if (!hasRun) {
hasRun = true;
view.setClipToOutline(true);
// We have to remove this as soon as it's laid out so we can get the shadow back
view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (view.getWidth() == endBounds.width() && view.getHeight() == endBounds.height()) {
view.setOutlineProvider(fabOutlineProvider);
view.setClipToOutline(false);
view.getViewTreeObserver().removeOnPreDrawListener(this);
return true;
}
return true;
}
});
}
}
});
}
});
}
circularReveal.setDuration(duration);
// Translate to end position along an arc
final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0) : getPathMotion().getPath(0, 0, -translationX, -translationY));
translate.setDuration(duration);
translate.setInterpolator(fastOutSlowInInterpolator);
// Fade contents of non-FAB view in/out
List<Animator> fadeContents = null;
if (view instanceof ViewGroup) {
final ViewGroup vg = ((ViewGroup) view);
fadeContents = new ArrayList<>(vg.getChildCount());
for (int i = vg.getChildCount() - 1; i >= 0; i--) {
final View child = vg.getChildAt(i);
final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
if (fromFab) {
child.setAlpha(0f);
}
fade.setDuration(twoThirdsDuration);
fade.setInterpolator(fastOutSlowInInterpolator);
fadeContents.add(fade);
}
}
// Fade in/out the fab color & icon overlays
final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
if (!fromFab) {
colorFade.setStartDelay(halfDuration);
iconFade.setStartDelay(halfDuration);
}
colorFade.setDuration(halfDuration);
iconFade.setDuration(halfDuration);
colorFade.setInterpolator(fastOutSlowInInterpolator);
iconFade.setInterpolator(fastOutSlowInInterpolator);
// Run all animations together
final AnimatorSet transition = new AnimatorSet();
transition.playTogether(circularReveal, translate, colorFade, iconFade);
transition.playTogether(fadeContents);
if (dialogView != null) {
final Animator dialogViewFade = ObjectAnimator.ofInt(dialogView, "alpha", 0).setDuration(twoThirdsDuration);
dialogViewFade.setInterpolator(fastOutSlowInInterpolator);
transition.playTogether(dialogViewFade);
}
transition.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
// Clean up
view.getOverlay().clear();
if (!fromFab) {
view.setTranslationX(0);
view.setTranslationY(0);
view.setTranslationZ(0);
view.measure(makeMeasureSpec(endBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(endBounds.height(), View.MeasureSpec.EXACTLY));
view.layout(endBounds.left, endBounds.top, endBounds.right, endBounds.bottom);
}
}
});
return new AnimUtils.NoPauseAnimator(transition);
}
use of android.animation.AnimatorSet in project floatingsearchview by arimorty.
the class FloatingSearchView method transitionOutLeftSection.
private void transitionOutLeftSection(boolean withAnim) {
switch(mLeftActionMode) {
case LEFT_ACTION_MODE_SHOW_HAMBURGER:
closeMenuDrawable(mMenuBtnDrawable, withAnim);
break;
case LEFT_ACTION_MODE_SHOW_SEARCH:
changeIcon(mLeftAction, mIconSearch, withAnim);
break;
case LEFT_ACTION_MODE_SHOW_HOME:
//do nothing
break;
case LEFT_ACTION_MODE_NO_LEFT_ACTION:
mLeftAction.setImageDrawable(mIconBackArrow);
if (withAnim) {
ObjectAnimator searchInputTransXAnim = ViewPropertyObjectAnimator.animate(mSearchInputParent).translationX(-Util.dpToPx(LEFT_MENU_WIDTH_AND_MARGIN_START)).get();
ObjectAnimator scaleXArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).scaleX(0.5f).get();
ObjectAnimator scaleYArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).scaleY(0.5f).get();
ObjectAnimator fadeArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).alpha(0.5f).get();
scaleXArrowAnim.setDuration(300);
scaleYArrowAnim.setDuration(300);
fadeArrowAnim.setDuration(300);
scaleXArrowAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
//restore normal state
mLeftAction.setScaleX(1.0f);
mLeftAction.setScaleY(1.0f);
mLeftAction.setAlpha(1.0f);
mLeftAction.setVisibility(View.INVISIBLE);
}
});
AnimatorSet animSet = new AnimatorSet();
animSet.setDuration(350);
animSet.playTogether(scaleXArrowAnim, scaleYArrowAnim, fadeArrowAnim, searchInputTransXAnim);
animSet.start();
} else {
mLeftAction.setVisibility(View.INVISIBLE);
}
break;
}
}
use of android.animation.AnimatorSet in project floatingsearchview by arimorty.
the class FloatingSearchView method transitionInLeftSection.
private void transitionInLeftSection(boolean withAnim) {
if (mSearchProgress.getVisibility() != View.VISIBLE) {
mLeftAction.setVisibility(View.VISIBLE);
} else {
mLeftAction.setVisibility(View.INVISIBLE);
}
switch(mLeftActionMode) {
case LEFT_ACTION_MODE_SHOW_HAMBURGER:
openMenuDrawable(mMenuBtnDrawable, withAnim);
if (!mMenuOpen) {
break;
}
break;
case LEFT_ACTION_MODE_SHOW_SEARCH:
mLeftAction.setImageDrawable(mIconBackArrow);
if (withAnim) {
mLeftAction.setRotation(45);
mLeftAction.setAlpha(0.0f);
ObjectAnimator rotateAnim = ViewPropertyObjectAnimator.animate(mLeftAction).rotation(0).get();
ObjectAnimator fadeAnim = ViewPropertyObjectAnimator.animate(mLeftAction).alpha(1.0f).get();
AnimatorSet animSet = new AnimatorSet();
animSet.setDuration(500);
animSet.playTogether(rotateAnim, fadeAnim);
animSet.start();
}
break;
case LEFT_ACTION_MODE_SHOW_HOME:
//do nothing
break;
case LEFT_ACTION_MODE_NO_LEFT_ACTION:
mLeftAction.setImageDrawable(mIconBackArrow);
if (withAnim) {
ObjectAnimator searchInputTransXAnim = ViewPropertyObjectAnimator.animate(mSearchInputParent).translationX(0).get();
mLeftAction.setScaleX(0.5f);
mLeftAction.setScaleY(0.5f);
mLeftAction.setAlpha(0.0f);
mLeftAction.setTranslationX(Util.dpToPx(8));
ObjectAnimator transXArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).translationX(1.0f).get();
ObjectAnimator scaleXArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).scaleX(1.0f).get();
ObjectAnimator scaleYArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).scaleY(1.0f).get();
ObjectAnimator fadeArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).alpha(1.0f).get();
transXArrowAnim.setStartDelay(150);
scaleXArrowAnim.setStartDelay(150);
scaleYArrowAnim.setStartDelay(150);
fadeArrowAnim.setStartDelay(150);
AnimatorSet animSet = new AnimatorSet();
animSet.setDuration(500);
animSet.playTogether(searchInputTransXAnim, transXArrowAnim, scaleXArrowAnim, scaleYArrowAnim, fadeArrowAnim);
animSet.start();
} else {
mSearchInputParent.setTranslationX(0);
}
break;
}
}
use of android.animation.AnimatorSet in project floatingsearchview by arimorty.
the class MenuView method showIfRoomItems.
/**
* Shows all the menu items that were hidden by hideIfRoomItems(boolean withAnim)
*
* @param withAnim
*/
public void showIfRoomItems(boolean withAnim) {
if (mMenu == -1) {
return;
}
cancelChildAnimListAndClear();
if (mMenuItems.isEmpty()) {
return;
}
anims = new ArrayList<>();
for (int i = 0; i < getChildCount(); i++) {
final View currentView = getChildAt(i);
//reset all the action item views
if (i < mActionItems.size()) {
ImageView action = (ImageView) currentView;
final MenuItem actionItem = mActionItems.get(i);
action.setImageDrawable(actionItem.getIcon());
Util.setIconColor(action, mActionIconColor);
action.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mMenuCallback != null) {
mMenuCallback.onMenuItemSelected(mMenuBuilder, actionItem);
}
}
});
}
Interpolator interpolator = new DecelerateInterpolator();
if (i > (mActionShowAlwaysItems.size() - 1)) {
interpolator = new LinearInterpolator();
}
currentView.setClickable(true);
//simply animate all properties of all action item views back to their default/visible state
anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
currentView.setTranslationX(0);
}
}).setInterpolator(interpolator).translationX(0).get());
anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
currentView.setScaleX(1.0f);
}
}).setInterpolator(interpolator).scaleX(1.0f).get());
anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
currentView.setScaleY(1.0f);
}
}).setInterpolator(interpolator).scaleY(1.0f).get());
anims.add(ViewPropertyObjectAnimator.animate(currentView).addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
currentView.setAlpha(1.0f);
}
}).setInterpolator(interpolator).alpha(1.0f).get());
}
if (anims.isEmpty()) {
return;
}
AnimatorSet animSet = new AnimatorSet();
if (!withAnim) {
//temporary, from laziness
animSet.setDuration(0);
}
animSet.playTogether(anims.toArray(new ObjectAnimator[anims.size()]));
animSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (mOnVisibleWidthChangedListener != null) {
mVisibleWidth = (getChildCount() * (int) ACTION_DIMENSION_PX) - (mHasOverflow ? Util.dpToPx(8) : 0);
mOnVisibleWidthChangedListener.onItemsMenuVisibleWidthChanged(mVisibleWidth);
}
}
});
animSet.start();
}
Aggregations