public ShineView(Context context, ShineButtonControl shineButton, ShineParams shineParams, ColourSet randomColourSet = null) : base(context) { // Populate a custom selection of random colours if provided if (randomColourSet != null && randomColourSet.ColourSelection?.Length != 0) { suppliedColorRandom = randomColourSet.ColourSelection; } InitShineParams(shineParams, shineButton); this.shineAnimator = new ShineAnimator(animDuration, shineDistanceMultiple, clickAnimDuration); ValueAnimator.FrameDelay = FRAME_REFRESH_DELAY; this.shineButton = shineButton; paint = new Paint(); paint.Color = bigShineColor; paint.StrokeWidth = 20; paint.SetStyle(Paint.Style.Stroke); paint.StrokeCap = Paint.Cap.Round; paint2 = new Paint(); paint2.Color = Color.White; paint2.StrokeWidth = 20; paint2.StrokeCap = Paint.Cap.Round; paintSmall = new Paint(); paintSmall.Color = smallShineColor; paintSmall.StrokeWidth = 10; paintSmall.SetStyle(Paint.Style.Stroke); paintSmall.StrokeCap = Paint.Cap.Round; clickAnimator = ValueAnimator.OfFloat(0f, 1.1f); ValueAnimator.FrameDelay = FRAME_REFRESH_DELAY; clickAnimator.SetDuration(clickAnimDuration); clickAnimator.SetInterpolator(new EasingInterpolator(Ease.QuartOut)); clickAnimator.Update += (s, e) => { clickValue = (float)e.Animation.AnimatedValue; Invalidate(); }; clickAnimator.AnimationEnd += (s, e) => { clickValue = 0; Invalidate(); }; shineAnimator.AnimationEnd += (s, e) => { shineButton.RemoveView(this); }; }
private void InitShineParams(ShineParams shineParams, ShineButtonControl shineButton) { shineCount = shineParams.ShineCount; turnAngle = shineParams.ShineTurnAngle; smallOffsetAngle = shineParams.SmallShineOffsetAngle; enableFlashing = shineParams.EnableFlashing; useRandomColor = shineParams.UseRandomColor; shineDistanceMultiple = shineParams.ShineDistanceMultiple; animDuration = shineParams.AnimDuration; clickAnimDuration = shineParams.ClickAnimDuration; smallShineColor = shineParams.SmallShineColor; bigShineColor = shineParams.BigShineColor; shineSize = shineParams.ShineSize; if (smallShineColor == 0) { smallShineColor = internalColorRandom[0]; } if (bigShineColor == 0) { bigShineColor = internalColorRandom[1]; } }
private void ShowAnimation(ShineButtonControl shineButton) { btnWidth = shineButton.Width; btnHeight = shineButton.Height; thirdLength = GetThirdLength(btnHeight, btnWidth); int[] location = new int[2]; shineButton.GetLocationInWindow(location); Rect visibleFrame = new Rect(); if (Utils.IsWindowsNotLimit(shineButton.activity)) { shineButton.activity.Window.DecorView.GetLocalVisibleRect(visibleFrame); } else { shineButton.activity.Window.DecorView.GetWindowVisibleDisplayFrame(visibleFrame); } centerAnimX = location[0] + btnWidth / 2 - visibleFrame.Left; // If navigation bar is not displayed on left, visibleFrame.left is 0. if (Utils.IsTranslucentNavigation(shineButton.activity)) { if (Utils.IsFullScreen(shineButton.activity)) { centerAnimY = visibleFrame.Height() - shineButton.GetBottomHeight(false) + btnHeight / 2; } else { centerAnimY = visibleFrame.Height() - shineButton.GetBottomHeight(true) + btnHeight / 2; } } else { centerAnimY = MeasuredHeight - shineButton.GetBottomHeight(false) + btnHeight / 2; } shineAnimator.Update += (s, e) => { value = (float)e.Animation.AnimatedValue; if (shineSize != 0 && shineSize > 0) { paint.StrokeWidth = (shineSize) * (shineDistanceMultiple - value); paintSmall.StrokeWidth = ((float)shineSize / 3 * 2) * (shineDistanceMultiple - value); } else { paint.StrokeWidth = (btnWidth / 2) * (shineDistanceMultiple - value); paintSmall.StrokeWidth = (btnWidth / 3) * (shineDistanceMultiple - value); } rectF.Set(centerAnimX - (btnWidth / (3 - shineDistanceMultiple) * value), centerAnimY - (btnHeight / (3 - shineDistanceMultiple) * value), centerAnimX + (btnWidth / (3 - shineDistanceMultiple) * value), centerAnimY + (btnHeight / (3 - shineDistanceMultiple) * value)); rectFSmall.Set(centerAnimX - (btnWidth / ((3 - shineDistanceMultiple) + distanceOffset) * value), centerAnimY - (btnHeight / ((3 - shineDistanceMultiple) + distanceOffset) * value), centerAnimX + (btnWidth / ((3 - shineDistanceMultiple) + distanceOffset) * value), centerAnimY + (btnHeight / ((3 - shineDistanceMultiple) + distanceOffset) * value)); Invalidate(); }; shineAnimator.StartAnim(this, centerAnimX, centerAnimY); clickAnimator.Start(); }