コード例 #1
0
        public override Animator?CreateAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues)
        {
            if (startValues == null || endValues == null)
            {
                return(null);
            }

            var   view  = endValues.View;
            float start = (float)startValues.Values[PropertyName],
                  end   = (float)endValues.Values[PropertyName];

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (start == end)
            {
                return(null);
            }

            var anim = ValueAnimator.OfFloat(start, end);

            anim.Update += (_, args) =>
            {
                if (view.IsDisposed())
                {
                    return;
                }
                view.Alpha = (float)args.Animation.AnimatedValue;
            };

            return(anim);
        }
コード例 #2
0
 public override void CaptureEndValues(TransitionValues transitionValues)
 {
     if (transitionValues is null)
     {
         throw new ArgumentNullException(nameof(transitionValues));
     }
     CaptureValues(transitionValues);
 }
コード例 #3
0
        public override void CaptureEndValues(TransitionValues transitionValues)
        {
            var view = transitionValues.View;

            if (view.Width <= 0 || view.Height <= 0)
            {
                return;
            }
            CaptureValues(transitionValues);
        }
コード例 #4
0
        private void CaptureValues(TransitionValues transitionValues)
        {
            var view = transitionValues.View;

            transitionValues.Values.Add(PROPERTY_BOUNDS, new Rect(view.Left, view.Top, view.Right, view.Bottom));
            var position = new int[2];

            transitionValues.View.GetLocationInWindow(position);
            transitionValues.Values.Add(PROPERTY_POSITION, position);
        }
コード例 #5
0
        public override Animator?CreateAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues)
        {
            if (startValues == null || endValues == null)
            {
                return(null);
            }

            var view = endValues.View;

            var props = CreatePropertyValues(startValues, endValues).ToArray();

            return(!props.Any() ? default : ObjectAnimator.OfPropertyValuesHolder(view, props));
        }
コード例 #6
0
        private static void CaptureValues(TransitionValues values)
        {
            var view = values.View;
            var vals = values.Values;

            Capture(vals, PivotX, view.PivotX);
            Capture(vals, PivotY, view.PivotY);
            Capture(vals, Rotation, view.Rotation);
            Capture(vals, RotationX, view.RotationX);
            Capture(vals, RotationY, view.RotationY);
            Capture(vals, ScaleX, view.ScaleX);
            Capture(vals, ScaleY, view.ScaleY);
            Capture(vals, TranslationX, view.TranslationX);
            Capture(vals, TranslationY, view.TranslationY);
        }
コード例 #7
0
        public override void CaptureStartValues(TransitionValues transitionValues)
        {
            var view = transitionValues.View;

            if (view.Width <= 0 || view.Height <= 0)
            {
                return;
            }
            CaptureValues(transitionValues);
            var bitmap = Bitmap.CreateBitmap(view.Width, view.Height,
                                             Bitmap.Config.Argb8888);
            var canvas = new Canvas(bitmap);

            view.Draw(canvas);
            transitionValues.Values.Add(PROPERTY_IMAGE, bitmap);
        }
コード例 #8
0
        private static IEnumerable <PropertyValuesHolder> CreatePropertyValues(TransitionValues startValues, TransitionValues endValues)
        {
            foreach (var propertyName in AnimateProperties())
            {
                var   fullName = $"{Prefix}:{propertyName}";
                float start    = (float)startValues.Values[fullName],
                      end      = (float)endValues.Values[fullName];

                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (start == end)
                {
                    continue;
                }

                yield return(PropertyValuesHolder.OfFloat(propertyName, start, end));
            }
        }
コード例 #9
0
        //Create an animation for each target that is in both the starting and ending Scene that interpolates between the start and end color.
        public override Animator CreateAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues)
        {
            //Check if the targets are in both the starting and ending scenes
            if (null == startValues || null == endValues)
            {
                return(null);
            }

            View view = endValues.View;

            //store the starting and ending background properties
            Drawable startBackground = (Drawable)startValues.Values [PROPNAME_BACKGROUND];
            Drawable endBackground   = (Drawable)endValues.Values [PROPNAME_BACKGROUND];

            //Ignore a target that isn't a drawable
            if (startBackground is ColorDrawable && endBackground is ColorDrawable)
            {
                var startColor = (ColorDrawable)startBackground;
                var endColor   = (ColorDrawable)endBackground;
                int i          = Color.Rgb(startColor.Color.R, startColor.Color.G, startColor.Color.B);
                int u          = Color.Rgb(endColor.Color.R, endColor.Color.G, endColor.Color.B);

                //make an animation if the starting and ending colors are different
                if (startColor.Color != endColor.Color)
                {
                    //make an animator to apply to the targets to create the animation
                    ValueAnimator animator = ValueAnimator.OfObject(new ArgbEvaluator(), i, u);
                    animator.Update += (object sender, ValueAnimator.AnimatorUpdateEventArgs e) =>
                    {
                        var value = (int)animator.AnimatedValue;
                        if (!value.Equals(null))
                        {
                            view.SetBackgroundColor(new Color(value));
                        }
                    };

                    return(animator);
                }
            }
            return(null);
        }
コード例 #10
0
            public override Animator CreateAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues)
            {
                if (null == startValues || null == endValues)
                {
                    return(null);
                }

                var view = endValues.View;

                var startBackground = (Drawable)startValues.Values[PROPNAME_BACKGROUND];
                var endBackground   = (Drawable)endValues.Values[PROPNAME_BACKGROUND];

                if (startBackground is ColorDrawable && endBackground is ColorDrawable)
                {
                    var startColor = (ColorDrawable)startBackground;
                    var endColor   = (ColorDrawable)endBackground;
                    int colorStart = Color.Rgb(startColor.Color.R, startColor.Color.G, startColor.Color.B);
                    int colorEnd   = Color.Rgb(endColor.Color.R, endColor.Color.G, endColor.Color.B);

                    if (startColor.Color != endColor.Color)
                    {
                        var animator = ValueAnimator.OfObject(new ArgbEvaluator(), colorStart, colorEnd);
                        animator.Update += (object sender, ValueAnimator.AnimatorUpdateEventArgs e) =>
                        {
                            var value = (int)animator.AnimatedValue;
                            if (!value.Equals(null))
                            {
                                view.SetBackgroundColor(new Color(value));
                            }
                        };

                        return(animator);
                    }
                }
                return(null);
            }
コード例 #11
0
        public override Animator CreateAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues)
        {
            if (startValues == null || endValues == null)
            {
                return(null);
            }
            var startBounds = (Rect)startValues.Values[PROPERTY_BOUNDS];
            var endBounds   = (Rect)endValues.Values[PROPERTY_BOUNDS];

            if (startBounds == null || endBounds == null || startBounds.Equals(endBounds))
            {
                return(null);
            }

            var      startImage      = (Bitmap)startValues.Values[PROPERTY_IMAGE];
            Drawable startBackground = new BitmapDrawable(sceneRoot.Context.Resources, startImage);

            _startView = AddViewToOverlay(sceneRoot, startImage.Width,
                                          startImage.Height, startBackground);
            Drawable shrinkingBackground = new ColorDrawable(new Color(_color));

            _shrinkingView = AddViewToOverlay(sceneRoot, startImage.Width,
                                              startImage.Height, shrinkingBackground);

            var sceneRootLoc = new int[2];

            sceneRoot.GetLocationInWindow(sceneRootLoc);
            var startLoc          = (int[])startValues.Values[PROPERTY_POSITION];
            var startTranslationX = startLoc[0] - sceneRootLoc[0];
            var startTranslationY = startLoc[1] - sceneRootLoc[1];

            _startView.TranslationX     = startTranslationX;
            _startView.TranslationY     = startTranslationY;
            _shrinkingView.TranslationX = startTranslationX;
            _shrinkingView.TranslationY = startTranslationY;

            _endView = endValues.View;
            var startRadius = CalculateMaxRadius(_shrinkingView);
            var minRadius   = Math.Min(CalculateMinRadius(_shrinkingView), CalculateMinRadius(_endView));

            var circleBackground = new ShapeDrawable(new OvalShape());

            circleBackground.Paint.Color = new Color(_color);
            _circleView = AddViewToOverlay(sceneRoot, minRadius * 2, minRadius * 2,
                                           circleBackground);
            float circleStartX = startLoc[0] - sceneRootLoc[0] +
                                 ((_startView.Width - _circleView.Width) / 2);
            float circleStartY = startLoc[1] - sceneRootLoc[1] +
                                 ((_startView.Height - _circleView.Height) / 2);

            _circleView.TranslationX = circleStartX;
            _circleView.TranslationY = circleStartY;

            _circleView.Visibility = ViewStates.Invisible;
            _shrinkingView.Alpha   = 0f;
            _endView.Alpha         = 0f;

            var shrinkingAnimator = CreateCircularReveal(_shrinkingView, startRadius, minRadius);

            shrinkingAnimator.AddListener(new ShrinkingAnimator());

            var startAnimator  = CreateCircularReveal(_startView, startRadius, minRadius);
            var fadeInAnimator = ObjectAnimator.OfFloat(_shrinkingView, "angle", 0, 1);  // <<<<==================

            var shrinkFadeSet = new AnimatorSet();

            shrinkFadeSet.PlayTogether(shrinkingAnimator, startAnimator, fadeInAnimator);

            var   endLoc     = (int[])endValues.Values[PROPERTY_POSITION];
            float circleEndX = endLoc[0] - sceneRootLoc[0] +
                               ((_endView.Width - _circleView.Width) / 2);
            float circleEndY = endLoc[1] - sceneRootLoc[1] +
                               ((_endView.Height - _circleView.Height) / 2);
            var      circlePath     = PathMotion.GetPath(circleStartX, circleStartY, circleEndX, circleEndY);
            Animator circleAnimator = ObjectAnimator.OfFloat(_circleView, View.X,
                                                             View.Y, circlePath);

            _growingView = AddViewToOverlay(sceneRoot, _endView.Width,
                                            _endView.Height, shrinkingBackground);
            _growingView.Visibility = ViewStates.Invisible;
            float endTranslationX = endLoc[0] - sceneRootLoc[0];
            float endTranslationY = endLoc[1] - sceneRootLoc[1];

            _growingView.TranslationX = endTranslationX;
            _growingView.TranslationY = endTranslationY;

            var endRadius = CalculateMaxRadius(_endView);

            circleAnimator.AddListener(new CircleAnimator());

            Animator fadeOutAnimator = ObjectAnimator.OfFloat(_growingView, "angle", 1, 0); //<<<============
            var      endAnimator     = CreateCircularReveal(_endView, minRadius, endRadius);
            var      growingAnimator = CreateCircularReveal(_growingView, minRadius, endRadius);

            growingAnimator.AddListener(new GrowingAnimator(sceneRoot));
            var growingFadeSet = new AnimatorSet();

            growingFadeSet.PlayTogether(fadeOutAnimator, endAnimator, growingAnimator);

            var animatorSet = new AnimatorSet();

            animatorSet.PlaySequentially(shrinkFadeSet, circleAnimator, growingFadeSet);
            return(animatorSet);
        }
コード例 #12
0
 private static void CaptureValues(TransitionValues values) => values.Values[PropertyName] = values.View.Alpha;
コード例 #13
0
 public override Android.Animation.Animator OnDisappear(Android.Views.ViewGroup sceneRoot, Android.Views.View view, TransitionValues startValues, TransitionValues endValues)
 {
     return(CreateAnimation(view, 1, 0));
 }
コード例 #14
0
 //Capture the value of the background drawable property in the ending Scene
 public override void CaptureEndValues(TransitionValues transitionValues)
 {
     CaptureValues(transitionValues);
 }
コード例 #15
0
 //Capture the property values of views for later use
 private void CaptureValues(TransitionValues values)
 {
     values.Values [PROPNAME_BACKGROUND] = values.View.Background;
 }
コード例 #16
0
 public override void CaptureStartValues(TransitionValues transitionValues) => CaptureValues(transitionValues);