List of usage examples for android.animation AnimatorSet play
public Builder play(Animator anim)
Builder
object, which is used to set up playing constraints. From source file:Main.java
public static void animateHeartButton(final View v) { AnimatorSet animatorSet = new AnimatorSet(); ObjectAnimator rotationAnim = ObjectAnimator.ofFloat(v, "rotation", 0f, 360f); rotationAnim.setDuration(300);// ww w . j a v a2 s.c o m rotationAnim.setInterpolator(ACCELERATE_INTERPOLATOR); ObjectAnimator bounceAnimX = ObjectAnimator.ofFloat(v, "scaleX", 0.2f, 1f); bounceAnimX.setDuration(300); bounceAnimX.setInterpolator(OVERSHOOT_INTERPOLATOR); ObjectAnimator bounceAnimY = ObjectAnimator.ofFloat(v, "scaleY", 0.2f, 1f); bounceAnimY.setDuration(300); bounceAnimY.setInterpolator(OVERSHOOT_INTERPOLATOR); bounceAnimY.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { } }); animatorSet.play(bounceAnimX).with(bounceAnimY).after(rotationAnim); animatorSet.start(); }
From source file:com.hippo.android.animator.AnimatorsBase.java
static Animator playSequentially(List<Animator> animators) { if (animators == null || animators.size() == 0) { return null; }/*www . j a v a 2 s . co m*/ AnimatorSet set = null; Animator previous = null; for (Animator animator : animators) { if (animator == null) { continue; } if (previous == null) { // Save first non-null animator as previous previous = animator; } else { if (set == null) { set = new AnimatorSet(); } set.play(previous).before(animator); // Update previous previous = animator; } } return set == null ? previous : set; }
From source file:com.hippo.android.animator.AnimatorsBase.java
static Animator playTogether(Collection<Animator> animators) { if (animators == null || animators.size() == 0) { return null; }/* w w w . j a va 2 s .c o m*/ Animator first = null; AnimatorSet set = null; AnimatorSet.Builder builder = null; for (Animator animator : animators) { if (animator == null) { continue; } if (first == null) { // Save first non-null animator first = animator; } else { if (builder == null) { // Get second non-null animator // It's time to create a AnimatorSet set = new AnimatorSet(); builder = set.play(first); } builder.with(animator); } } return set == null ? first : set; }
From source file:MainActivity.java
private void zoomFromThumbnail(final ImageView imageViewThumb) { if (mCurrentAnimator != null) { mCurrentAnimator.cancel();/* www .j a v a 2 s. com*/ } final Rect startBounds = new Rect(); final Rect finalBounds = new Rect(); final Point globalOffset = new Point(); imageViewThumb.getGlobalVisibleRect(startBounds); findViewById(R.id.frameLayout).getGlobalVisibleRect(finalBounds, globalOffset); mImageViewExpanded .setImageBitmap(loadSampledResource(R.drawable.image, finalBounds.height(), finalBounds.width())); startBounds.offset(-globalOffset.x, -globalOffset.y); finalBounds.offset(-globalOffset.x, -globalOffset.y); float startScale; if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width() / startBounds.height()) { startScale = (float) startBounds.height() / finalBounds.height(); float startWidth = startScale * finalBounds.width(); float deltaWidth = (startWidth - startBounds.width()) / 2; startBounds.left -= deltaWidth; startBounds.right += deltaWidth; } else { startScale = (float) startBounds.width() / finalBounds.width(); float startHeight = startScale * finalBounds.height(); float deltaHeight = (startHeight - startBounds.height()) / 2; startBounds.top -= deltaHeight; startBounds.bottom += deltaHeight; } imageViewThumb.setVisibility(View.GONE); mImageViewExpanded.setVisibility(View.VISIBLE); mImageViewExpanded.setPivotX(0f); mImageViewExpanded.setPivotY(0f); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(ObjectAnimator.ofFloat(mImageViewExpanded, View.X, startBounds.left, finalBounds.left)) .with(ObjectAnimator.ofFloat(mImageViewExpanded, View.Y, startBounds.top, finalBounds.top)) .with(ObjectAnimator.ofFloat(mImageViewExpanded, View.SCALE_X, startScale, 1f)) .with(ObjectAnimator.ofFloat(mImageViewExpanded, View.SCALE_Y, startScale, 1f)); animatorSet.setDuration(1000); animatorSet.setInterpolator(new AccelerateInterpolator()); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { mCurrentAnimator = null; } }); animatorSet.start(); mCurrentAnimator = animatorSet; }
From source file:com.google.samples.apps.ourstreets.fragment.StreetViewFragment.java
/** * Reveals the contents of this fragment using a circular reveal animation. *//*from w w w .j a v a2 s . c om*/ private void revealPanorama() { //noinspection ConstantConditions getView().setVisibility(View.VISIBLE); //noinspection ConstantConditions Animator circularReveal = ViewUtils.createCircularReveal(mRevealCenter, mRevealWidth, getView(), INTERPOLATOR); ObjectAnimator colorChange = ViewUtils.createColorChange(((FrameLayout) getView()), R.color.foreground, android.R.color.transparent, INTERPOLATOR); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(circularReveal).with(colorChange); animatorSet.start(); }
From source file:org.cyanogenmod.designertools.ui.CreditsActivity.java
private void animateContent() { View avatar1 = findViewById(R.id.avatar1); avatar1.setScaleX(0);// w w w .jav a 2s.co m avatar1.setScaleY(0); avatar1.setVisibility(View.VISIBLE); View text1 = findViewById(R.id.text1); text1.setAlpha(0); text1.setVisibility(View.VISIBLE); View avatar2 = findViewById(R.id.avatar2); avatar2.setScaleX(0); avatar2.setScaleY(0); avatar2.setVisibility(View.VISIBLE); View text2 = findViewById(R.id.text2); text2.setAlpha(0); text2.setVisibility(View.VISIBLE); View avatar3 = findViewById(R.id.avatar3); avatar3.setScaleX(0); avatar3.setScaleY(0); avatar3.setVisibility(View.VISIBLE); View text3 = findViewById(R.id.text3); text3.setAlpha(0); text3.setVisibility(View.VISIBLE); View avatar4 = findViewById(R.id.avatar4); avatar4.setScaleX(0); avatar4.setScaleY(0); avatar4.setVisibility(View.VISIBLE); View text4 = findViewById(R.id.text4); text4.setAlpha(0); text4.setVisibility(View.VISIBLE); Interpolator interpolator = new FastOutSlowInInterpolator(); long duration = 375L; long delay = duration / 3; AnimatorSet anim1 = new AnimatorSet(); anim1.play(ObjectAnimator.ofFloat(avatar1, "scaleX", 1f)) .with(ObjectAnimator.ofFloat(avatar1, "scaleY", 1f)) .with(ObjectAnimator.ofFloat(text1, "alpha", 1f)); anim1.setDuration(duration); anim1.setInterpolator(interpolator); AnimatorSet anim2 = new AnimatorSet(); anim2.play(ObjectAnimator.ofFloat(avatar2, "scaleX", 1f)) .with(ObjectAnimator.ofFloat(avatar2, "scaleY", 1f)) .with(ObjectAnimator.ofFloat(text2, "alpha", 1f)); anim2.setDuration(duration); anim2.setInterpolator(interpolator); anim2.setStartDelay(delay); AnimatorSet anim3 = new AnimatorSet(); anim3.play(ObjectAnimator.ofFloat(avatar3, "scaleX", 1f)) .with(ObjectAnimator.ofFloat(avatar3, "scaleY", 1f)) .with(ObjectAnimator.ofFloat(text3, "alpha", 1f)); anim3.setDuration(duration); anim3.setInterpolator(interpolator); anim3.setStartDelay(delay * 2); AnimatorSet anim4 = new AnimatorSet(); anim4.play(ObjectAnimator.ofFloat(avatar4, "scaleX", 1f)) .with(ObjectAnimator.ofFloat(avatar4, "scaleY", 1f)) .with(ObjectAnimator.ofFloat(text4, "alpha", 1f)); anim4.setDuration(duration); anim4.setInterpolator(interpolator); anim4.setStartDelay(delay * 3); AnimatorSet set = new AnimatorSet(); set.play(anim1).with(anim2); set.play(anim2).with(anim3); set.play(anim3).with(anim4); set.start(); }
From source file:org.muckebox.android.ui.activity.WizardActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_wizard); mExtraContainer = findViewById(R.id.wizard_extra_container); mExtraContainer.measure(SPEC, SPEC); mExtraContainerHeight = mExtraContainer.getMeasuredHeight(); LayoutParams params = mExtraContainer.getLayoutParams(); params.height = 0;/* ww w . java 2s. c om*/ mExtraContainer.setLayoutParams(params); mExpandButton = findViewById(R.id.wizard_expand_button); mExpandButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play( ValueAnimator.ofObject(new HeightEvaluator(mExtraContainer), 0, mExtraContainerHeight)); animatorSet.play( ValueAnimator.ofObject(new HeightEvaluator(mExpandButton), mExpandButton.getHeight(), 0)); animatorSet.start(); } }); mServerText = (TextView) findViewById(R.id.wizard_server_text); mPasswordText = (TextView) findViewById(R.id.wizard_server_password); mPortText = (TextView) findViewById(R.id.wizard_port_text); mSslCheckbox = (CheckBox) findViewById(R.id.wizard_ssl_enabled); mResultText = (TextView) findViewById(R.id.wizard_result_text); readFromPreferences(); }
From source file:com.myhexaville.iconanimations.gooey_fab.GooeyFab.java
void onElevationsChanged(final float elevation, final float pressedTranslationZ) { final StateListAnimator stateListAnimator = new StateListAnimator(); // Animate elevation and translationZ to our values when pressed AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(this, "elevation", elevation).setDuration(0)).with(ObjectAnimator .ofFloat(this, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(PRESSED_ENABLED_STATE_SET, set); // Same deal for when we're focused set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(this, "elevation", elevation).setDuration(0)).with(ObjectAnimator .ofFloat(this, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(FOCUSED_ENABLED_STATE_SET, set); // Animate translationZ to 0 if not pressed set = new AnimatorSet(); // Use an AnimatorSet to set a start delay since there is a bug with ValueAnimator that // prevents it from being cancelled properly when used with a StateListAnimator. AnimatorSet anim = new AnimatorSet(); anim.play(ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, 0f).setDuration(PRESSED_ANIM_DURATION)) .after(PRESSED_ANIM_DURATION); set.play(ObjectAnimator.ofFloat(this, "elevation", elevation).setDuration(0)).with(anim); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(ENABLED_STATE_SET, set); // Animate everything to 0 when disabled set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(this, "elevation", 0f).setDuration(0)) .with(ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, 0f).setDuration(0)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(EMPTY_STATE_SET, set); setStateListAnimator(stateListAnimator); }
From source file:android.support.design.widget.FloatingActionButtonLollipop.java
@Override void onElevationsChanged(final float elevation, final float pressedTranslationZ) { final int sdk = Build.VERSION.SDK_INT; if (sdk == 21) { // Animations produce NPE in version 21. Bluntly set the values instead (matching the // logic in the animations below). if (mView.isEnabled()) { mView.setElevation(elevation); if (mView.isFocused() || mView.isPressed()) { mView.setTranslationZ(pressedTranslationZ); } else { mView.setTranslationZ(0); }//from w ww . j a v a2 s . co m } else { mView.setElevation(0); mView.setTranslationZ(0); } } else { final StateListAnimator stateListAnimator = new StateListAnimator(); // Animate elevation and translationZ to our values when pressed AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator .ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(PRESSED_ENABLED_STATE_SET, set); // Same deal for when we're focused set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator .ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(FOCUSED_ENABLED_STATE_SET, set); // Animate translationZ to 0 if not pressed set = new AnimatorSet(); set.playSequentially(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0), // This is a no-op animation which exists here only for introducing the duration // because setting the delay (on the next animation) via "setDelay" or "after" // can trigger a NPE between android versions 22 and 24 (due to a framework // bug). The issue has been fixed in version 25. ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, mView.getTranslationZ()) .setDuration(PRESSED_ANIM_DELAY), ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(PRESSED_ANIM_DURATION)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(ENABLED_STATE_SET, set); // Animate everything to 0 when disabled set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(mView, "elevation", 0f).setDuration(0)) .with(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(0)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(EMPTY_STATE_SET, set); mView.setStateListAnimator(stateListAnimator); } if (mShadowViewDelegate.isCompatPaddingEnabled()) { updatePadding(); } }
From source file:com.commonsware.cwac.crossport.design.widget.FloatingActionButtonLollipop.java
@Override void onElevationsChanged(final float elevation, final float pressedTranslationZ) { if (Build.VERSION.SDK_INT == 21) { // Animations produce NPE in version 21. Bluntly set the values instead (matching the // logic in the animations below). if (mView.isEnabled()) { mView.setElevation(elevation); if (mView.isFocused() || mView.isPressed()) { mView.setTranslationZ(pressedTranslationZ); } else { mView.setTranslationZ(0); }/* w w w .jav a 2 s.c o m*/ } else { mView.setElevation(0); mView.setTranslationZ(0); } } else { final StateListAnimator stateListAnimator = new StateListAnimator(); // Animate elevation and translationZ to our values when pressed AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator .ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(PRESSED_ENABLED_STATE_SET, set); // Same deal for when we're focused set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)).with(ObjectAnimator .ofFloat(mView, View.TRANSLATION_Z, pressedTranslationZ).setDuration(PRESSED_ANIM_DURATION)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(FOCUSED_ENABLED_STATE_SET, set); // Animate translationZ to 0 if not pressed set = new AnimatorSet(); List<Animator> animators = new ArrayList<>(); animators.add(ObjectAnimator.ofFloat(mView, "elevation", elevation).setDuration(0)); if (Build.VERSION.SDK_INT >= 22 && Build.VERSION.SDK_INT <= 24) { // This is a no-op animation which exists here only for introducing the duration // because setting the delay (on the next animation) via "setDelay" or "after" // can trigger a NPE between android versions 22 and 24 (due to a framework // bug). The issue has been fixed in version 25. animators.add(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, mView.getTranslationZ()) .setDuration(PRESSED_ANIM_DELAY)); } animators.add(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(PRESSED_ANIM_DURATION)); set.playSequentially(animators.toArray(new ObjectAnimator[0])); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(ENABLED_STATE_SET, set); // Animate everything to 0 when disabled set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(mView, "elevation", 0f).setDuration(0)) .with(ObjectAnimator.ofFloat(mView, View.TRANSLATION_Z, 0f).setDuration(0)); set.setInterpolator(ANIM_INTERPOLATOR); stateListAnimator.addState(EMPTY_STATE_SET, set); mView.setStateListAnimator(stateListAnimator); } if (mShadowViewDelegate.isCompatPaddingEnabled()) { updatePadding(); } }