public static void FadeOutView(Android.Views.View view, int length, bool overrideAnim = false, Action callback = null) { if (overrideAnim) { view.Animation?.Cancel(); view.ClearAnimation(); view.Visibility = ViewStates.Visible; } else if (view.Visibility != ViewStates.Visible) { callback?.Invoke(); return; } var anim = new AlphaAnimation(1f, 0f) { Duration = length }; anim.AnimationEnd += delegate { view.Visibility = ViewStates.Invisible; callback?.Invoke(); }; view.StartAnimation(anim); }
public static void FadeOut(Android.Views.View view) { Device.BeginInvokeOnMainThread(() => { var alphaFadeout = new AlphaAnimation(1.0f, 0.0f); alphaFadeout.StartOffset = 10000; alphaFadeout.Duration = 3000; alphaFadeout.FillAfter = true; view.StartAnimation(alphaFadeout); }); return; }
/* * This method was used to create the circle view with animation. * */ private View GetCircleView(FrameLayout.LayoutParams rParams, RandomData randomData) { var circleView = new View(this); circleView.SetBackgroundResource(Resource.Drawable.circle); circleView.Clickable = true; circleView.Focusable = true; circleView.FocusableInTouchMode = true; circleView.SetOnTouchListener(this); _rootLayout.AddView(circleView, rParams); circleView.StartAnimation(GetAnimationForNewViews()); if (randomData != null) { ChangeTitle(randomData.Title); } return(circleView); }
public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (Math.Abs(velocityX) < 500) return false; _lastView = _parentActivity.LastView; var animationSet = new AnimationSet(true) { Interpolator = new AccelerateDecelerateInterpolator(), Duration = 300, FillAfter = true }; var animationRotate = new RotateAnimation(0, Math.Sign(velocityX)*15); var animationTranslate = new TranslateAnimation(0, Math.Sign(velocityX)*400, 0, 10); var animationAlpha = new AlphaAnimation(1, 0); animationSet.AddAnimation(animationRotate); animationSet.AddAnimation(animationTranslate); animationSet.AddAnimation(animationAlpha); animationSet.AnimationEnd += AnimationSet_AnimationEnd; _lastView.StartAnimation(animationSet); return true; }
/* * * This is a callback method for Touch view. This method will be called when user move the view or click on the screen or doubleTap on the screen. * */ public bool OnTouch(View v, MotionEvent e) { // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags var action = e.Action & MotionEventActions.Mask; switch (action) { // Called when user click on screen. case MotionEventActions.Down: if (v.Id == Resource.Id.root_layout && !_childScrolling) { AddView((int)e.GetX(), (int)e.GetY()); } else { long clickTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; if (clickTime - _lastClickTime < DoubleClickTimeDelta) // Called when user doubleTap the view. { if (v is ImageView) { ImageView imageView = (ImageView)v; if (GlobalMethods.IsOnline(this)) { var progressDialog = GlobalMethods.CreateProgressDialog(this, "Changing"); new Thread(() => { var randomData = ReadXml.Instance.ReadImageUrl(); var bitmap = DownloadAndCache(randomData.Data); RunOnUiThread(() => { imageView.SetImageBitmap(bitmap); imageView.StartAnimation(GetAnimationForExistingViews()); progressDialog.Hide(); ChangeTitle(randomData.Title); }); }).Start(); } else { imageView.SetBackgroundColor(GlobalMethods.GetRandomColor()); imageView.StartAnimation(GetAnimationForExistingViews()); } } else { if (GlobalMethods.IsOnline(this)) { new Thread(() => { var randomData = ReadXml.Instance.ReadHexColor(); RunOnUiThread(() => { var bgShape = (GradientDrawable)v.Background; bgShape.SetColor(Color.ParseColor(randomData.Data)); v.StartAnimation(GetAnimationForExistingViews()); ChangeTitle(randomData.Title); }); }).Start(); } else { var bgShape = (GradientDrawable)v.Background; bgShape.SetColor(GlobalMethods.GetRandomColor()); v.StartAnimation(GetAnimationForExistingViews()); } } } _lastClickTime = clickTime; } break; // Called when user moves the view. case MotionEventActions.Move: if (v.Id != Resource.Id.root_layout) { _childScrolling = true; FrameLayout.LayoutParams rParams = new FrameLayout.LayoutParams(v.Width, v.Height) { LeftMargin = (int)e.RawX - v.Width, TopMargin = (int)e.RawY - v.Height }; v.LayoutParameters = rParams; } break; // Called when user ended the moving the view. case MotionEventActions.Up: if (v.Id != Resource.Id.root_layout && _childScrolling) { FrameLayout.LayoutParams rParams = new FrameLayout.LayoutParams(v.Width, v.Height) { LeftMargin = (int)e.RawX - v.Width, TopMargin = (int)e.RawY - v.Height }; v.LayoutParameters = rParams; } _childScrolling = false; break; } return(true); }
private void CallOnGlobalLayout(Crouton crouton, View croutonView) { var layoutListener = new GlobalLayoutListener(); layoutListener.OnGlobalLayout(delegate { if (Build.VERSION.SdkInt < Build.VERSION_CODES.JellyBean) { croutonView.ViewTreeObserver.RemoveGlobalOnLayoutListener(layoutListener); } else { croutonView.ViewTreeObserver.RemoveOnGlobalLayoutListener(layoutListener); } if (crouton.GetInAnimation() != null) { croutonView.StartAnimation(crouton.GetInAnimation()); AnnounceForAccessibilityCompat(crouton.GetActivity(), crouton.DataContext == null ? "NULL" : crouton.DataContext.ToString()); SendMessageDelayed(crouton, REMOVE_CROUTON, crouton.DurationInMilliseconds + crouton.GetInAnimation().Duration); } }); }
public void StartAnimation(View v) { if (anim is Animation) { v.StartAnimation((Animation)anim); } else { if (anim is Animator) { var animator = (Animator)anim; animator.SetTarget(v); animator.Start(); } else { Log.Error("CompatibilityAnimation", "Animation is neither of type Animator nor Animation"); } } }
private void animateAlphaTranslate(View view, float alphaFrom, float alphaTo, float xFrom, float xTo, bool requestFocus) { AnimationSet animationSet = new AnimationSet(true); AlphaAnimation fade = new AlphaAnimation(alphaFrom, alphaTo); fade.Duration = 350; TranslateAnimation slide = new TranslateAnimation(Dimension.RelativeToSelf, xFrom, Dimension.RelativeToSelf, xTo, Dimension.RelativeToSelf, 0, Dimension.RelativeToSelf, 0); slide.Duration = 350; animationSet.AddAnimation(fade); animationSet.AddAnimation(slide); view.StartAnimation(animationSet); if (requestFocus) { animationSet.AnimationEnd += (obj, args) => view.RequestFocus(); } }
private void MaximizeView(View view) { var animationSet = new AnimationSet(true) { Interpolator = new AccelerateDecelerateInterpolator(), Duration = 500, FillAfter = true }; var scaleAnimation = new ScaleAnimation(1f, 1.25f, 1f, 1.25f, Dimension.RelativeToSelf, 0f, Dimension.RelativeToSelf, 0f); _selectedViewTop = view.Top; _selectedViewLeft = view.Left; var translateAnimation = new TranslateAnimation(Dimension.RelativeToSelf, 0, Dimension.Absolute, -view.Left, Dimension.RelativeToSelf, 0, Dimension.Absolute, -view.Top + _addButton.Height); animationSet.AddAnimation(scaleAnimation); animationSet.AddAnimation(translateAnimation); view.StartAnimation(animationSet); }
void Fade_In_Txt(View view) { var fadeIn = AnimationUtils.LoadAnimation (this, Resource.Animation.fade_in_text); view.Visibility = ViewStates.Visible ; RunOnUiThread (() => { view.StartAnimation (fadeIn); }); }
/** * Fades the view out. Animation starts right away. * @param v the view to be faded out */ public static void FadeIn(View v) { if (v == null) return; v.StartAnimation(FadeInAnimation(500, v)); }
public void OnTouchUp(View view, MotionEvent evt, int position) { if (ExpandCollapseEnabled && _swipeView == null) { PerformClick (view, position); } else if (SwipeToDeleteEnabled) { Animation swipeEnd = SwipeEndAnimation (); if (ShouldDeleteSwipeView ()) { swipeEnd.AnimationEnd += delegate(object sender, Animation.AnimationEndEventArgs e) { PerformDelete (_swipeView, position); }; } else { _swipeView = null; } view.StartAnimation (swipeEnd); } }