void DoAnimation2 (bool really, Action changePic) { if (!really) changePic (); else { var fdIn = ObjectAnimator.OfFloat (this, "alpha", new float[] { 0, 1 }); var fdOut = ObjectAnimator.OfFloat (this, "alpha", new float[] { 1, 0 }); fdOut.AnimationEnd += (sender, e) => changePic (); var animator = new AnimatorSet (); animator.SetInterpolator (new LinearInterpolator ()); //animator.PlaySequentially (fdOut, fdIn); animator.Play (fdOut); animator.Play (fdIn).After (fdOut).After (2000); animator.Start (); } }
private void Switch (Drawable src, ColorStateList tint, bool withAnimation = false) { if (!withAnimation) { SetImageDrawable (src); BackgroundTintList = tint; return; } const int ScaleDuration = 200; const int InitialDelay = 100; if (switchAnimation != null) { switchAnimation.Cancel (); switchAnimation = null; } var currentSrc = Drawable; // Scaling down animation var circleAnimOutX = ObjectAnimator.OfFloat (this, "scaleX", 1, 0.1f); var circleAnimOutY = ObjectAnimator.OfFloat (this, "scaleY", 1, 0.1f); circleAnimOutX.SetDuration (ScaleDuration); circleAnimOutY.SetDuration (ScaleDuration); // Alpha out of the icon //var iconAnimOut = ObjectAnimator.OfInt (currentSrc, "alpha", 255, 0); //iconAnimOut.SetDuration (AlphaDuration); var outSet = new AnimatorSet (); outSet.PlayTogether (circleAnimOutX, circleAnimOutY); outSet.SetInterpolator (AnimationUtils.LoadInterpolator (Context, Android.Resource.Animation.AccelerateInterpolator)); outSet.StartDelay = InitialDelay; outSet.AnimationEnd += (sender, e) => { BackgroundTintList = tint; SetImageDrawable (src); JumpDrawablesToCurrentState (); ((Animator)sender).RemoveAllListeners (); }; // Scaling up animation var circleAnimInX = ObjectAnimator.OfFloat (this, "scaleX", 0.1f, 1); var circleAnimInY = ObjectAnimator.OfFloat (this, "scaleY", 0.1f, 1); circleAnimInX.SetDuration (ScaleDuration); circleAnimInY.SetDuration (ScaleDuration); var inSet = new AnimatorSet (); inSet.PlayTogether (circleAnimInX, circleAnimInY); inSet.SetInterpolator (AnimationUtils.LoadInterpolator (Context, Android.Resource.Animation.DecelerateInterpolator)); switchAnimation = new AnimatorSet (); switchAnimation.PlaySequentially (outSet, inSet); switchAnimation.Start (); }
public void shift(View view) { if (!mShifted) { foreach (ImageView imageView in mImageViews) { ObjectAnimator tx = ObjectAnimator.OfFloat(imageView, View.X, (mRandom.NextFloat() - 0.5f) * 500); tx.AddUpdateListener(new AnimListener(mBlurringView)); ObjectAnimator ty = ObjectAnimator.OfFloat(imageView, View.Y, (mRandom.NextFloat() - 0.5f) * 500); ty.AddUpdateListener(new AnimListener(mBlurringView)); AnimatorSet set = new AnimatorSet(); set.PlayTogether(tx, ty); set.SetDuration(3000); set.SetInterpolator(new OvershootInterpolator()); set.AddListener(new AnimationEndListener(imageView)); set.Start(); }; mShifted = true; } else { foreach (ImageView imageView in mImageViews) { ObjectAnimator tx = ObjectAnimator.OfFloat(imageView, View.X, 0); tx.AddUpdateListener(new AnimListener(mBlurringView)); ObjectAnimator ty = ObjectAnimator.OfFloat(imageView, View.Y, 0); ty.AddUpdateListener(new AnimListener(mBlurringView)); AnimatorSet set = new AnimatorSet(); set.PlayTogether(tx, ty); set.SetDuration(3000); set.SetInterpolator(new OvershootInterpolator()); set.AddListener(new AnimationEndListener(imageView)); set.Start(); }; mShifted = false; } }
private void PlayAnimation() { var animator = ObjectAnimator.OfFloat (this, "animationSeek", 0.0f, 1.0f); var animatorSet = new AnimatorSet (); animatorSet.SetDuration (AnimationDuration); animatorSet.SetInterpolator (new DecelerateInterpolator ()); animatorSet.SetTarget (this); animatorSet.Play(animator); animatorSet.Start(); }
private AnimatorSet GetAnimatorSet(int idx, bool expand) { AnimatorSet set = null; var avgRadians = this.ToRadians(360 / (this.ChildCount - 1)); var w = Math.Min(this.MeasuredWidth, this.MeasuredHeight) / 2; var cx = this.MeasuredWidth / 2; var cy = this.MeasuredHeight / 2; var c = this.GetChildAt(idx); var radians = idx * avgRadians; var hw = c.MeasuredWidth / 2; var hy = c.MeasuredHeight / 2; var tmp = (w - hw); var l = w + (int)Math.Round(tmp * Math.Cos(radians) - hw); var t = w + (int)Math.Round(tmp * Math.Sin(radians) - hw); var duration = new Random(1000).Next(200, 1000); set = new AnimatorSet(); set.SetInterpolator(new Android.Views.Animations.BounceInterpolator()); set.SetTarget(c); set.SetDuration(200 * idx + duration); //set.SetDuration(200); float[] xs = new float[] { cx - hw, l }; float[] ys = new float[] { cy - hy, t }; float[] ss = new float[] { 0.1f, 1 }; if (!expand) { Array.Reverse(xs); Array.Reverse(ys); Array.Reverse(ss); } var aniX = ObjectAnimator.OfFloat(c, "X", xs); var aniY = ObjectAnimator.OfFloat(c, "Y", ys); var aniSX = ObjectAnimator.OfFloat(c, "ScaleX", ss); var aniSY = ObjectAnimator.OfFloat(c, "ScaleY", ss); aniX.SetAutoCancel(true); aniY.SetAutoCancel(true); aniSX.SetAutoCancel(true); aniSY.SetAutoCancel(true); set.PlayTogether(aniX, aniY, aniSX, aniSY); set.AnimationEnd += Set_AnimationEnd; return set; }
private Animator.IAnimatorListener animationListener;//=new AnimationListenerClass(this); //private Animator.AnimatorListener animationListener = new Animator.AnimatorListener() { // @Override // public void onAnimationStart(Animator animation) { // if (isOpened()){ // showScrollViewMenu(scrollViewMenu); // if (menuListener != null) // menuListener.openMenu(); // } // } // @Override // public void onAnimationEnd(Animator animation) { // // reset the view; // if(isOpened()){ // viewActivity.setTouchDisable(true); // viewActivity.setOnClickListener(viewActivityOnClickListener); // }else{ // viewActivity.setTouchDisable(false); // viewActivity.setOnClickListener(null); // hideScrollViewMenu(scrollViewLeftMenu); // hideScrollViewMenu(scrollViewRightMenu); // if (menuListener != null) // menuListener.closeMenu(); // } // } // @Override // public void onAnimationCancel(Animator animation) { // } // @Override // public void onAnimationRepeat(Animator animation) { // } //}; /** * A helper method to build scale down animation; * * @param target * @param targetScaleX * @param targetScaleY * @return */ private AnimatorSet buildScaleDownAnimation(View target, float targetScaleX, float targetScaleY) { AnimatorSet scaleDown = new AnimatorSet(); scaleDown.PlayTogether( ObjectAnimator.OfFloat(target, "scaleX", targetScaleX), ObjectAnimator.OfFloat(target, "scaleY", targetScaleY) ); if (mUse3D) { int angle = scaleDirection == DIRECTION_LEFT ? -ROTATE_Y_ANGLE : ROTATE_Y_ANGLE; scaleDown.PlayTogether(ObjectAnimator.OfFloat(target, "rotationY", angle)); } scaleDown.SetInterpolator(AnimationUtils.LoadInterpolator(activity, Android.Resource.Animation.DecelerateInterpolator)); scaleDown.SetDuration(250); return scaleDown; }
/// <summary> /// Builds the AnimatorSet that will create the expanding animation - the user will perceive the thumbnail getting bigger. /// </summary> /// <param name="expandedView">This is the ImageView that the thumbnail will scale up to.</param> /// <param name="startBounds">The visible rectangle of the thumbnail (global coordinates).</param> /// <param name="finalBounds">The visible rectangle of the full sized image (global coordinates).</param> /// <param name="startScale"></param> /// <returns></returns> private AnimatorSet BuildExpandingAnimatorSet(ImageView expandedView, Rect startBounds, Rect finalBounds, float startScale) { // Each expanding animator is unique to the start location - we'll cache the AnimatorSet // instance based on the starting location. int key = startBounds.GetHashCode (); if (_expandingAnimators.ContainsKey(key)) { return _expandingAnimators[key]; } AnimatorSet expandSet = new AnimatorSet(); expandSet.Play(ObjectAnimator.OfFloat(expandedView, View.X, startBounds.Left, finalBounds.Left)) .With(ObjectAnimator.OfFloat(expandedView, View.Y, startBounds.Top, finalBounds.Top)) .With(ObjectAnimator.OfFloat(expandedView, "ScaleX", startScale, 1f)) .With(ObjectAnimator.OfFloat(expandedView, "ScaleY", startScale, 1f)); expandSet.SetDuration(_shortAnimationDuration); expandSet.SetInterpolator(new DecelerateInterpolator()); expandSet.AnimationEnd += NullOutCurrentAnimator; expandSet.AnimationCancel += NullOutCurrentAnimator; _expandingAnimators.Add(key, expandSet); return expandSet; }
/// <summary> /// Builds the AnimatorSet to shrink the full sized image back to the thumbnail. /// </summary> /// <param name="bigView">The full sized view.</param> /// <param name="thumbView">The thumbnail view.</param> /// <param name="startBounds">The visible rectangle of the thumbnail when it is visible.</param> /// <param name="scale">Scale ratio.</param> /// <returns></returns> private AnimatorSet BuildShrinkingAnimatorSet(View bigView, View thumbView, Rect startBounds, float scale) { if (_shrinkingAnimators.ContainsKey(thumbView.Id)) { return _shrinkingAnimators[thumbView.Id]; } AnimatorSet shrinkSet = new AnimatorSet(); shrinkSet.Play(ObjectAnimator.OfFloat(bigView, View.X, startBounds.Left)) .With(ObjectAnimator.OfFloat(bigView, View.Y, startBounds.Top)) .With(ObjectAnimator.OfFloat(bigView, "ScaleX", scale)) .With(ObjectAnimator.OfFloat(bigView, "ScaleY", scale)); shrinkSet.SetDuration(_shortAnimationDuration); shrinkSet.SetInterpolator(new DecelerateInterpolator()); shrinkSet.AnimationEnd += (sender1, args1) =>{ thumbView.Alpha = 1.0f; bigView.Visibility = ViewStates.Gone; NullOutCurrentAnimator(sender1, args1); }; shrinkSet.AnimationCancel += (sender1, args1) =>{ thumbView.Alpha = 1.0f; bigView.Visibility = ViewStates.Gone; NullOutCurrentAnimator(sender1, args1); }; _shrinkingAnimators.Add(thumbView.Id, shrinkSet); return shrinkSet; }
public override void OnViewCreated(View view, Bundle savedInstanceState) { base.OnViewCreated (view, savedInstanceState); var interpolator = new Android.Views.Animations.AccelerateDecelerateInterpolator (); var xDelta = 12.ToPixels (); var yDelta = 8.ToPixels (); var transX = ObjectAnimator.OfFloat (logoImage, "translationX", -xDelta, xDelta); var transY = ObjectAnimator.OfFloat (logoImage, "translationY", -yDelta, 0, -yDelta); var rot = ObjectAnimator.OfFloat (logoImage, "rotation", -1.2f, 1.2f); // Ad infinitam transX.RepeatCount = transY.RepeatCount = rot.RepeatCount = -1; transX.RepeatMode = transY.RepeatMode = rot.RepeatMode = ValueAnimatorRepeatMode.Reverse; logoAnimation = new AnimatorSet (); logoAnimation.PlayTogether (transX, transY, rot); logoAnimation.SetDuration (800); logoAnimation.SetInterpolator (interpolator); logoAnimation.Start (); }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); mBlurringView = FindViewById<BlurringView> (Resource.Id.blurring_view); View blurredView = FindViewById(Resource.Id.blurred_view); mBlurringView.SetBlurredView (blurredView); mImageViews [0] = FindViewById<ImageView> (Resource.Id.image0); mImageViews [1] = FindViewById<ImageView> (Resource.Id.image1); mImageViews [2] = FindViewById<ImageView> (Resource.Id.image2); mImageViews [3] = FindViewById<ImageView> (Resource.Id.image3); mImageViews [4] = FindViewById<ImageView> (Resource.Id.image4); mImageViews [5] = FindViewById<ImageView> (Resource.Id.image5); mImageViews [6] = FindViewById<ImageView> (Resource.Id.image6); mImageViews [7] = FindViewById<ImageView> (Resource.Id.image7); mImageViews [8] = FindViewById<ImageView> (Resource.Id.image8); // Get our button from the layout resource, // and attach an event to it Button shuffleButton = FindViewById<Button> (Resource.Id.shuffle_button); Button shiftButton = FindViewById<Button> (Resource.Id.shift_button); shiftButton.Click += (sender, e) => { if (!mShifted) { foreach (ImageView imageView in mImageViews) { ObjectAnimator tx = ObjectAnimator.OfFloat (imageView, "translationX", (float)((mRandom.NextDouble () - 0.5f) * 500)); tx.Update += (s, ea) => mBlurringView.Invalidate(); ObjectAnimator ty = ObjectAnimator.OfFloat (imageView, "translationY", (float)((mRandom.NextDouble () - 0.5f) * 500)); tx.Update += (s, ea) => mBlurringView.Invalidate(); AnimatorSet set = new AnimatorSet(); set.PlayTogether(tx, ty); set.SetDuration(3000); set.SetInterpolator(new OvershootInterpolator()); set.AnimationStart += (s, ea) => imageView.SetLayerType(LayerType.Hardware, null); set.AnimationEnd += (s, ea) => imageView.SetLayerType(LayerType.None, null); set.AnimationCancel += (s, ea) => imageView.SetLayerType (LayerType.None, null); set.Start(); } mShifted = true; } else { foreach (ImageView imageView in mImageViews) { ObjectAnimator tx = ObjectAnimator.OfFloat (imageView, "translationX", 0); tx.Update += (s, ea) => mBlurringView.Invalidate(); ObjectAnimator ty = ObjectAnimator.OfFloat (imageView, "translationY", 0); tx.Update += (s, ea) => mBlurringView.Invalidate(); AnimatorSet set = new AnimatorSet(); set.PlayTogether(tx, ty); set.SetDuration(3000); set.SetInterpolator(new OvershootInterpolator()); // set.AddListener(new AnimationEndListener(imageView)); set.AnimationStart += (s, ea) => imageView.SetLayerType(LayerType.Hardware, null); set.AnimationEnd += (s, ea) => imageView.SetLayerType(LayerType.None, null); set.AnimationCancel += (s, ea) => imageView.SetLayerType (LayerType.None, null); set.Start(); } mShifted = false; } }; shuffleButton.Click += (sender, e) => { int newStartIndex; do { newStartIndex = mImageIds[mRandom.Next(mImageIds.Length)]; } while (newStartIndex == mStartIndex); mStartIndex = newStartIndex; for (int i = 0; i < mImageViews.Length; i++) { int drawableId = mImageIds[(mStartIndex +i) % mImageIds.Length]; mImageViews[i].SetImageDrawable(ApplicationContext.Resources.GetDrawable(drawableId)); } mBlurringView.Invalidate(); }; }
private void CreateCustomAnimation() { FloatingActionMenu menu3 = FindViewById<FloatingActionMenu>(Resource.Id.menu3); AnimatorSet set = new AnimatorSet(); ObjectAnimator scaleOutX = ObjectAnimator.OfFloat(menu3.MenuIconView, "scaleX", 1.0f, 0.2f); ObjectAnimator scaleOutY = ObjectAnimator.OfFloat(menu3.MenuIconView, "scaleY", 1.0f, 0.2f); ObjectAnimator scaleInX = ObjectAnimator.OfFloat(menu3.MenuIconView, "scaleX", 0.2f, 1.0f); ObjectAnimator scaleInY = ObjectAnimator.OfFloat(menu3.MenuIconView, "scaleY", 0.2f, 1.0f); scaleOutX.SetDuration(50); scaleOutY.SetDuration(50); scaleInX.SetDuration(150); scaleInY.SetDuration(150); scaleInX.AnimationStart += (object sender, EventArgs e) => { menu3.MenuIconView.SetImageResource(menu3.IsOpened ? Resource.Drawable.ic_close : Resource.Drawable.ic_star); }; set.Play(scaleOutX).With(scaleOutY); set.Play(scaleInX).With(scaleInY).After(scaleOutX); set.SetInterpolator(new OvershootInterpolator(2)); menu3.IconToggleAnimatorSet = set; }