Пример #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <ShimmerView> e)
        {
            if (shimmer == null)
            {
                shimmer = new ShimmerFrameLayout(Context);
            }

            var text = new TextView(Context)
            {
                Text = "Xamarin Library"
            };

            text.SetTextColor(Android.Graphics.Color.White);

            text.SetTextSize(Android.Util.ComplexUnitType.Px, 100);

            var builder = new Shimmer.AlphaHighlightBuilder();

            builder.SetDuration(2500);
            builder.SetBaseAlpha(0.1f);
            builder.SetDropoff(0.1f);
            builder.SetTilt(0f);

            shimmer.SetShimmer(builder.Build());
            shimmer.AddView(text);
            shimmer.StartShimmer();

            SetNativeControl(shimmer);
        }
        private void SelectPreset(int preset, bool showToast)
        {
            if (currentPreset == preset)
            {
                return;
            }

            if (currentPreset >= 0)
            {
                presetButtons[currentPreset].SetBackgroundResource(Resource.Color.preset_button_background);
            }

            currentPreset = preset;
            presetButtons[currentPreset].SetBackgroundResource(Resource.Color.preset_button_background_selected);

            // If a toast is already showing, hide it
            toast?.Cancel();

            var shimmerBuilder = new Shimmer.AlphaHighlightBuilder();

            switch (preset)
            {
            case 1:
                // Slow and reverse
                toast = Toast.MakeText(this, "Slow and reverse", ToastLength.Short);
                shimmerBuilder.SetDuration(5000L);
                shimmerBuilder.SetRepeatMode((int)ValueAnimatorRepeatMode.Reverse);
                break;

            case 2:
                // Thin, straight and transparent
                shimmerBuilder.SetBaseAlpha(0.1f);
                shimmerBuilder.SetDropoff(0.1f);
                shimmerBuilder.SetTilt(0f);
                toast = Toast.MakeText(this, "Thin, straight and transparent", ToastLength.Short);
                break;

            case 3:
                // Sweep angle 90
                shimmerBuilder.SetDirection(Shimmer.Direction.TopToBottom);
                shimmerBuilder.SetTilt(0f);
                toast = Toast.MakeText(this, "Sweep angle 90", ToastLength.Short);
                break;

            case 4:
                // Spotlight
                shimmerBuilder.SetBaseAlpha(0f);
                shimmerBuilder.SetDuration(2000L);
                shimmerBuilder.SetDropoff(0.1f);
                shimmerBuilder.SetIntensity(0.35f);
                shimmerBuilder.SetShape(Shimmer.Shape.Radial);
                toast = Toast.MakeText(this, "Spotlight", ToastLength.Short);
                break;

            case 5:
                // Off
                toast          = Toast.MakeText(this, "Off", ToastLength.Short);
                shimmerBuilder = null;
                break;

            default:
                toast          = Toast.MakeText(this, "Default", ToastLength.Short);
                shimmerBuilder = default(Shimmer.AlphaHighlightBuilder);
                break;
            }
            shimmerViewContainer.SetShimmer(shimmerBuilder?.Build());

            // Show toast describing the chosen preset, if necessary
            toast?.Show();
        }