protected override void OnCreate (Bundle savedInstanceState) { base.OnCreate (savedInstanceState); SetContentView (Resource.Layout.activity_main); easingList = FindViewById<ListView> (Resource.Id.easing_list); adapter = new EasingAdapter (this); easingList.Adapter = adapter; target = FindViewById (Resource.Id.target); history = FindViewById<DrawView> (Resource.Id.history); easingList.ItemClick += (sender, e) => { history.Clear (); var s = (Skill)e.View.Tag; var set = new AnimatorSet (); target.TranslationX = 0; target.TranslationY = 0; set.PlayTogether ( Glider.Glide (s, 1200, ObjectAnimator.OfFloat (target, "translationY", 0, DrawView.DipToPixels (this, -(160 - 3))), args => { history.DrawPoint (args.Time, args.Duration, args.Value - DrawView.DipToPixels (this, 60)); })); set.SetDuration (1200); set.Start (); }; }
private void CreateAnimation() { if (animation == null) { var anim1 = ObjectAnimator.OfFloat(balls[0], "y", 0f, Height - balls[0].Height); anim1.SetDuration(500); var anim2 = anim1.Clone(); anim2.SetTarget(balls[1]); anim1.Update += delegate { Invalidate(); }; var ball2 = balls[2]; var animDown = ObjectAnimator.OfFloat(ball2, "y", 0f, Height - ball2.Height); animDown.SetDuration(500); animDown.SetInterpolator(new AccelerateInterpolator()); var animUp = ObjectAnimator.OfFloat(ball2, "y", Height - ball2.Height, 0f); animUp.SetDuration(500); animUp.SetInterpolator(new DecelerateInterpolator()); var s1 = new AnimatorSet(); s1.PlaySequentially(animDown, animUp); animDown.Update += delegate { Invalidate(); }; animUp.Update += delegate { Invalidate(); }; var s2 = (AnimatorSet)s1.Clone(); s2.SetTarget(balls[3]); animation = new AnimatorSet(); animation.PlayTogether(anim1, anim2, s1); animation.PlaySequentially(s1, s2); } }
private void CreateAnimation() { if (animation == null) { var yAnim = ObjectAnimator.OfFloat(ball, "y", ball.Y, Height - 50f); yAnim.SetDuration(1000); yAnim.RepeatCount = 0; yAnim.RepeatMode = ValueAnimatorRepeatMode.Reverse; yAnim.SetInterpolator(new AccelerateInterpolator(2f)); yAnim.Update += delegate { Invalidate(); }; yAnim.AnimationStart += delegate { activity.startTextAnimator.SetTextColor(On); if (endImmediately) { animation.End(); } }; yAnim.AnimationEnd += delegate { activity.endTextAnimator.SetTextColor(On); }; yAnim.AnimationCancel += delegate { activity.cancelTextAnimator.SetTextColor(On); }; yAnim.AnimationRepeat += delegate { activity.repeatTextAnimator.SetTextColor(On); }; var xAnim = ObjectAnimator.OfFloat(ball, "x", ball.X, ball.X + 300); xAnim.SetDuration(1000); xAnim.StartDelay = 0; xAnim.RepeatCount = 0; xAnim.RepeatMode = ValueAnimatorRepeatMode.Reverse; xAnim.SetInterpolator(new AccelerateInterpolator(2f)); var alphaAnim = ObjectAnimator.OfFloat(ball, "alpha", 1.0f, 0.5f); alphaAnim.SetDuration(1000); animation = new AnimatorSet(); animation.PlayTogether(yAnim, xAnim, alphaAnim); animation.AnimationStart += delegate { activity.startText.SetTextColor(On); if (endImmediately) { animation.End(); } }; animation.AnimationEnd += delegate { activity.endText.SetTextColor(On); }; animation.AnimationCancel += delegate { activity.cancelText.SetTextColor(On); }; animation.AnimationRepeat += delegate { activity.repeatText.SetTextColor(On); }; } }
protected AnimatorSet createPagerIconAnimation(int oldIndex, int newIndex) { AnimatorSet animations = new AnimatorSet(); animations.SetDuration(ANIM_PAGER_ICON_TIME); // scale down whole old element ViewGroup oldActiveItem = (ViewGroup)mPagerIconsContainer.GetChildAt(oldIndex); LinearLayout.LayoutParams oldActiveItemParams = (LinearLayout.LayoutParams)oldActiveItem.LayoutParameters; ValueAnimator oldItemScaleDown = ValueAnimator.OfInt(mPagerElementActiveSize, mPagerElementNormalSize); var updateListener = new CustomAnimatorUpdateListener(); updateListener.OnUpdateAnimaion += (valueAnimator) => { oldActiveItemParams.Height = (int)valueAnimator.AnimatedValue; oldActiveItemParams.Width = (int)valueAnimator.AnimatedValue; oldActiveItem.RequestLayout(); }; oldItemScaleDown.AddUpdateListener(updateListener); // fade out old new element icon View oldActiveIcon = oldActiveItem.GetChildAt(1); Animator oldActiveIconFadeOut = ObjectAnimator.OfFloat(oldActiveIcon, "alpha", 1, 0); // fade in old element shape ImageView oldActiveShape = (ImageView)oldActiveItem.GetChildAt(0); oldActiveShape.SetImageResource(oldIndex - newIndex > 0 ? Resource.Drawable.onboarding_pager_circle_icon : Resource.Drawable.onboarding_pager_round_icon); Animator oldActiveShapeFadeIn = ObjectAnimator.OfFloat(oldActiveShape, "alpha", 0, PAGER_ICON_SHAPE_ALPHA); // add animations animations.PlayTogether(oldItemScaleDown, oldActiveIconFadeOut, oldActiveShapeFadeIn); // scale up whole new element ViewGroup newActiveItem = (ViewGroup)mPagerIconsContainer.GetChildAt(newIndex); LinearLayout.LayoutParams newActiveItemParams = (LinearLayout.LayoutParams)newActiveItem.LayoutParameters; ValueAnimator newItemScaleUp = ValueAnimator.OfInt(mPagerElementNormalSize, mPagerElementActiveSize); var updateItemListener = new CustomAnimatorUpdateListener(); updateItemListener.OnUpdateAnimaion += (valueAnimator) => { newActiveItemParams.Height = (int)valueAnimator.AnimatedValue; newActiveItemParams.Width = (int)valueAnimator.AnimatedValue; newActiveItem.RequestLayout(); }; newItemScaleUp.AddUpdateListener(updateItemListener); // fade in new element icon View newActiveIcon = newActiveItem.GetChildAt(1); Animator newActiveIconFadeIn = ObjectAnimator.OfFloat(newActiveIcon, "alpha", 0, 1); // fade out new element shape ImageView newActiveShape = (ImageView)newActiveItem.GetChildAt(0); Animator newActiveShapeFadeOut = ObjectAnimator.OfFloat(newActiveShape, "alpha", PAGER_ICON_SHAPE_ALPHA, 0); // add animations animations.PlayTogether(newItemScaleUp, newActiveShapeFadeOut, newActiveIconFadeIn); animations.SetInterpolator(new DecelerateInterpolator()); return(animations); }
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(); }
private async void OnRequestOnboardingPage(OnboardingViewModel oVm) { _viewModel = oVm; AnimationInitUI(); BindEvents(); var mainAnimatorSet = new AnimatorSet(); var appNameLayoutFinalTopSpace = TypedValue.ApplyDimension(ComplexUnitType.Dip, 55.0f, Application.Context.Resources.DisplayMetrics); var decelerateInterpolator = new DecelerateInterpolator(1.0f); var appNameLayoutAnimator = new ValueAnimator(); appNameLayoutAnimator.SetDuration(750); appNameLayoutAnimator.SetInterpolator(decelerateInterpolator); appNameLayoutAnimator.SetFloatValues(_appNameLayout.GetY(), appNameLayoutFinalTopSpace); appNameLayoutAnimator.Update += (o, args) => { _appNameLayout.SetY((float)args.Animation.AnimatedValue); }; var whatAccountsAnimator = new ValueAnimator(); whatAccountsAnimator.SetDuration(750); whatAccountsAnimator.SetInterpolator(decelerateInterpolator); whatAccountsAnimator.SetFloatValues(0.0f, 1.0f); whatAccountsAnimator.Update += (o, args) => { _whatAccounts.Alpha = (float)args.Animation.AnimatedValue; }; var appNameAnimationSet = new AnimatorSet(); appNameAnimationSet.PlayTogether(appNameLayoutAnimator, whatAccountsAnimator); var socialButtonsAnimatorSet = new AnimatorSet(); var overshootInterpolator = new OvershootInterpolator(3f); var facebookButtonAnimator = new ValueAnimator(); facebookButtonAnimator.SetDuration(500); facebookButtonAnimator.SetInterpolator(overshootInterpolator); facebookButtonAnimator.SetFloatValues(_facebookButton.GetY() + _facebookButton.Height, _facebookButton.GetY()); facebookButtonAnimator.Update += (o, args) => { _facebookButton.SetY((float)args.Animation.AnimatedValue); _facebookButton.Alpha = args.Animation.AnimatedFraction; }; var twitterButtonAnimator = new ValueAnimator(); twitterButtonAnimator.SetDuration(500); twitterButtonAnimator.SetInterpolator(overshootInterpolator); twitterButtonAnimator.SetFloatValues(_facebookButton.GetY() + _facebookButton.Height, _facebookButton.GetY()); twitterButtonAnimator.Update += (o, args) => { _twitterButton.SetY((float)args.Animation.AnimatedValue); _twitterButton.Alpha = args.Animation.AnimatedFraction; }; socialButtonsAnimatorSet.PlaySequentially(facebookButtonAnimator, twitterButtonAnimator); socialButtonsAnimatorSet.StartDelay = 500; var letsGoButtonAnimator = new ValueAnimator(); letsGoButtonAnimator.SetDuration(500); letsGoButtonAnimator.SetInterpolator(decelerateInterpolator); letsGoButtonAnimator.SetFloatValues(0.0f, 1.0f); letsGoButtonAnimator.Update += (sender, args) => { _goButton.Alpha = (float)args.Animation.AnimatedValue; }; mainAnimatorSet.PlaySequentially(appNameAnimationSet, socialButtonsAnimatorSet, letsGoButtonAnimator); await _viewModel.DidLoad(); await Task.Delay(2000); mainAnimatorSet.Start(); await _viewModel.DidAppear(); }