protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); var page = this.Element as HomeTabbedPage; if (e.PropertyName == nameof(page.HasFloatingActionButton)) { if (page.HasFloatingActionButton) { floating.Visibility = ViewStates.Visible; } else { floating.Visibility = ViewStates.Gone; } } else if (e.PropertyName == nameof(page.CurrentPage)) { if (page.CurrentPage is StatusesTopTabbedPage) { page.HasFloatingActionButton = true; page.ToggleFloatingActionButton = false; } else if (page.CurrentPage is QuestionsTopTabbedPage) { page.HasFloatingActionButton = true; page.ToggleFloatingActionButton = false; } else { page.HasFloatingActionButton = false; } } else if (e.PropertyName == nameof(page.ToggleFloatingActionButton)) { if (page.ToggleFloatingActionButton) { if (floating != null) { var animator = ViewCompat.Animate(floating) .SetDuration(500) .ScaleX(0) .ScaleY(0); animator.Start(); } } else { if (floating != null) { var animator = ViewCompat.Animate(floating) .SetDuration(500) .ScaleX(1) .ScaleY(1); animator.Start(); } } } }
protected override void ShowNegativeFeedback(ValidationInfo info) { base.ShowNegativeFeedback(info); this.editorView = this.Editor.RootLayout(); ViewCompat.Animate(editorView).Alpha(0).SetDuration(50).WithEndAction(this); }
/// <summary> /// Hides the badge with a neat little scale animation. /// </summary> public void Hide() { IsVisible = false; ViewCompat.Animate(this) .SetDuration(_animationDuration) .ScaleX(0) .ScaleY(0) .Start(); }
/// <summary> /// Shows the badge with a neat little scale animation. /// </summary> public void Show() { IsVisible = true; ViewCompat.Animate(this) .SetDuration(_animationDuration) .ScaleX(1) .ScaleY(1) .Start(); }
/// <summary> /// Hides the badge with a neat little scale animation. /// </summary> public void Hide(bool animated = true) { IsVisible = false; ViewCompat.Animate(this) .SetDuration(animated ? AnimationDuration : 0) .ScaleX(0) .ScaleY(0) .Start(); }
private void Show(FloatingActionButton button) { _isShow = true; ViewCompat.Animate(button).ScaleX(1.0F).ScaleY(1.0F).Alpha(1.0F) .SetInterpolator(new FastOutLinearInInterpolator()).WithLayer().SetListener(null) .WithStartAction(new Runnable(() => { button.Visibility = ViewStates.Visible; })); }
private void Hide(FloatingActionButton button) { _isShow = false; ViewCompat.Animate(button).ScaleX(0F).ScaleY(0F).Alpha(1.0F) .SetInterpolator(new FastOutSlowInInterpolator()).WithLayer().SetListener(null) .WithStartAction(new AnimationDrawable()) .WithEndAction(new Runnable(() => { button.Visibility = ViewStates.Invisible; })); }
private void EnsureOrCancelAnimator(View child) { if (translationAnimator == null) { translationAnimator = ViewCompat.Animate(child); translationAnimator.SetDuration(300); translationAnimator.SetInterpolator(InInterpolator); } else { translationAnimator.Cancel(); } }
private void EnsureOrCancelAnimator(V child) { if (_mTranslationAnimator == null) { _mTranslationAnimator = ViewCompat.Animate(child); _mTranslationAnimator.SetDuration(300); _mTranslationAnimator.SetInterpolator(INTERPOLATOR); } else { _mTranslationAnimator.Cancel(); } }
public static void AlphaAnimate(this View view, float alpha, int duration = 300, Action endAction = null, int startDelay = 0) { var animator = ViewCompat.Animate(view); animator .SetDuration(duration) .SetStartDelay(startDelay) .Alpha(alpha); if (endAction != null) { animator.WithEndAction(new Runnable(endAction)); } animator.Start(); }
public override void OnDependentViewRemoved(CoordinatorLayout parent, Java.Lang.Object child, View dependency) { View _child = child as View; if (dependency is Snackbar.SnackbarLayout) { animation = ViewCompat.Animate(_child) .TranslationY(0f) .SetInterpolator(HIDE_INTERPOLATOR) .SetDuration(HIDE_DURATION); animation.Start(); } base.OnDependentViewRemoved(parent, child, dependency); }
private void animateRemoveImpl(RecyclerView.ViewHolder holder) { View view = holder.ItemView; ViewCompat.Animate(view).Cancel(); ViewCompat.Animate(view).SetDuration(RemoveDuration). TranslationX(-mRecyclerView.Width).WithEndAction(() => { ViewCompat.SetTranslationX(view, -mRecyclerView.getWidth()); dispatchRemoveFinished(holder); mRemoveAnimations.remove(holder); dispatchFinishedWhenDone(); } ).Start(); mRemoveAnimations.Add(holder); }
/// <summary> /// Shows the badge with a neat little scale animation. /// </summary> public void Show(bool animated = true) { if (_needUpdateLayout) { OnLayoutUpdated = () => Show(false); return; } IsVisible = true; ViewCompat.Animate(this) .SetDuration(animated ? AnimationDuration : 0) .ScaleX(1) .ScaleY(1) .Start(); }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { var fab = Control; if (e.PropertyName == nameof(Element.ButtonColor)) { ViewCompat.SetBackgroundTintList(fab, ColorStateList.ValueOf(Element.ButtonColor.ToAndroid())); } if (e.PropertyName == nameof(Element.Image)) { var elementImage = Element.Image; var imageFile = elementImage?.File; if (imageFile != null) { fab.SetImageDrawable(Context.Resources.GetDrawable(imageFile)); } } if (e.PropertyName == nameof(Element.ToggleFloatingView)) { if (Element.ToggleFloatingView) { if (fab != null) { var animator = ViewCompat.Animate(fab) .SetDuration(500) .ScaleX(0) .ScaleY(0); animator.SetListener(this); animator.Start(); } } else { if (fab != null) { var animator = ViewCompat.Animate(fab) .SetDuration(500) .ScaleX(1) .ScaleY(1); animator.SetListener(this); animator.Start(); } } } base.OnElementPropertyChanged(sender, e); }
public static void TranslationYAnimate(this View view, int translation, int duration = 300, IInterpolator interpolator = null, Action endAction = null) { var animator = ViewCompat.Animate(view); animator .SetDuration(duration) .TranslationY(translation); if (endAction != null) { animator.WithEndAction(new Runnable(endAction)); } if (interpolator != null) { animator.SetInterpolator(interpolator); } animator.Start(); }
public override bool OnOptionsItemSelected(Android.Views.IMenuItem item) { if (item.ItemId == Resource.Id.action_notification) { notificationFrame.Visibility = ViewStates.Visible; float initialX = -(notificationFrame.Left + notificationFrame.Width + notificationFrame.PaddingLeft); notificationFrame.TranslationX = initialX; ViewCompat.Animate(notificationFrame) .TranslationX(0) .SetDuration(600) .SetStartDelay(100) .SetInterpolator(new Android.Support.V4.View.Animation.LinearOutSlowInInterpolator()) .Start(); return(true); } return(base.OnOptionsItemSelected(item)); }
public override void EndAnimation(RecyclerView.ViewHolder item) { View view = item.itemView; ViewCompat.Animate(view).Cancel(); if (mPendingMoves.Contains(item)) { ViewCompat.SetTranslationY(view, 0); ViewCompat.SetTranslationX(view, 0); dispatchMoveFinished(item); mPendingMoves.remove(item); } if (mPendingRemovals.contains(item)) { dispatchRemoveFinished(item); mPendingRemovals.remove(item); } if (mPendingAdditions.contains(item)) { ViewCompat.setAlpha(view, 1); dispatchAddFinished(item); mPendingAdditions.remove(item); } if (mMoveAnimations.contains(item)) { ViewCompat.setTranslationY(view, 0); ViewCompat.setTranslationX(view, 0); dispatchMoveFinished(item); mMoveAnimations.remove(item); } if (mRemoveAnimations.contains(item)) { ViewCompat.setAlpha(view, 1); dispatchRemoveFinished(item); mRemoveAnimations.remove(item); } if (mAddAnimations.contains(item)) { ViewCompat.setAlpha(view, 1); dispatchAddFinished(item); mAddAnimations.remove(item); } dispatchFinishedWhenDone(); }
public static void AnimateBgColorChange(View clickedView, View backgroundView, View bgOverlay, int newColor) { var centerX = (int)(ViewCompat.GetX(clickedView) + (int)(clickedView.MeasuredWidth / 2)); var centerY = clickedView.MeasuredHeight / 2; var finalRadius = backgroundView.Width; backgroundView.ClearAnimation(); bgOverlay.ClearAnimation(); object animator; if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { if (!bgOverlay.IsAttachedToWindow) { return; } animator = ViewAnimationUtils.CreateCircularReveal(bgOverlay, centerX, centerY, 0, finalRadius); } else { ViewCompat.SetAlpha(bgOverlay, 0); animator = ViewCompat.Animate(bgOverlay).Alpha(1); } var compat = animator as ViewPropertyAnimatorCompat; if (compat != null) { compat .SetListener(new CustomViewPropertyAnimatorListenerAdapter(backgroundView, newColor, bgOverlay)) .Start(); } else if (animator != null) { ((Animator)animator).AddListener(new CustomAnimatorListenerAdapter(backgroundView, newColor, bgOverlay)); ((Animator)animator).Start(); } bgOverlay.SetBackgroundColor(new Color(newColor)); bgOverlay.Visibility = ViewStates.Visible; }
private void OnActiveCardChange(int pos) { var animH = new[] { R.Animation.slide_in_right, R.Animation.slide_out_left }; var animV = new[] { R.Animation.slide_in_top, R.Animation.slide_out_bottom }; var left2Right = pos < _currentPosition; if (left2Right) { animH[0] = R.Animation.slide_in_left; animH[1] = R.Animation.slide_out_right; animV[0] = R.Animation.slide_in_bottom; animV[1] = R.Animation.slide_out_top; } SetCountryText(_countries[pos % _countries.Length], left2Right); _temperatureSwitcher.SetInAnimation(this, animH[0]); _temperatureSwitcher.SetOutAnimation(this, animH[1]); _temperatureSwitcher.SetText(_temperatures[pos % _temperatures.Length]); _placeSwitcher.SetInAnimation(this, animV[0]); _placeSwitcher.SetOutAnimation(this, animV[1]); _placeSwitcher.SetText(_places[pos % _places.Length]); _clockSwitcher.SetInAnimation(this, animV[0]); _clockSwitcher.SetOutAnimation(this, animV[1]); _clockSwitcher.SetText(_times[pos % _times.Length]); _descriptionsSwitcher.SetText(GetString(_descriptions[pos % _descriptions.Length])); ShowMap(_maps[pos % _maps.Length]); ViewCompat.Animate(_greenDot) .TranslationX(_dotCoords[pos % _dotCoords.GetLength(0), 0]) .TranslationY(_dotCoords[pos % _dotCoords.GetLength(0), 1]) .Start(); _currentPosition = pos; }
//public override bool LayoutDependsOn(CoordinatorLayout parent, Java.Lang.Object child, View dependency) //{ // var s = dependency is AppBarLayout; // return base.LayoutDependsOn(parent, child, dependency); //} //public override bool OnDependentViewChanged(CoordinatorLayout parent, Java.Lang.Object child, View dependency) //{ // //float scaleY = System.Math.Abs(dependency.GetY()); // //View _child = child as View; // ////child.TranslationY // //AnimateOffset(_child); // return true; // // return base.OnDependentViewChanged(parent, child, dependency); //} void AnimateOffset(View child, ScrollDirection scrollDirection) { if (translationAnimator == null) { translationAnimator = ViewCompat.Animate(child); translationAnimator.SetDuration(300); translationAnimator.SetInterpolator(InInterpolator); } else { translationAnimator.Cancel(); } if (scrollDirection == ScrollDirection.Up) { translationAnimator.TranslationY(child.Height).Start(); } else if (scrollDirection == ScrollDirection.Down) { translationAnimator.TranslationY(0).Start(); } }
/** * Manage animation for Android >= KITKAT * * @param child */ private void ensureOrCancelAnimator(T child, bool withAnimation) { if (translationAnimator == null) { translationAnimator = ViewCompat.Animate(child); translationAnimator.SetDuration(withAnimation ? ANIM_DURATION : 0); translationAnimator.SetUpdateListener( new CustomViewPropertyAnimatorUpdateListener((view) => { // Animate snackbar if (snackbarLayout != null && snackbarLayout.LayoutParameters is ViewGroup.MarginLayoutParams) { targetOffset = view.MeasuredHeight - view.TranslationY; ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams)snackbarLayout.LayoutParameters; p.SetMargins(p.LeftMargin, p.TopMargin, p.RightMargin, (int)targetOffset); snackbarLayout.RequestLayout(); } // Animate Floating Action Button if (floatingActionButton != null && floatingActionButton.LayoutParameters is ViewGroup.MarginLayoutParams) { ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams)floatingActionButton.LayoutParameters; fabTargetOffset = fabDefaultBottomMargin - view.TranslationY + snackBarY; p.SetMargins(p.LeftMargin, p.TopMargin, p.RightMargin, (int)fabTargetOffset); floatingActionButton.RequestLayout(); } // Pass navigation height to listener if (navigationPositionListener != null) { navigationPositionListener.onPositionChange((int)(view.MeasuredHeight - view.TranslationY + snackBarY)); } }) ); translationAnimator.SetInterpolator(INTERPOLATOR); } else { translationAnimator.SetDuration(withAnimation ? ANIM_DURATION : 0); translationAnimator.Cancel(); } }
public void Reduce() { if (expanded) { heightInitial = Context.Resources.GetDimensionPixelOffset(Resource.Dimension.mtf_cardHeight_final); ViewCompat.Animate(label) .Alpha(1) .ScaleX(1) .ScaleY(1) .TranslationY(0) .SetDuration(ANIMATION_DURATION); ViewCompat.Animate(image) .Alpha(0) .ScaleX(0.4f) .ScaleY(0.4f) .SetDuration(ANIMATION_DURATION); ViewCompat.Animate(editText) .Alpha(1f) .SetUpdateListener(this) .SetDuration(ANIMATION_DURATION) .SetListener(this); ViewCompat.Animate(card) .ScaleY(reducedScale) .SetDuration(ANIMATION_DURATION); if (editText.HasFocus) { // HideSoftInputFromInputMethod is depreciated in api29 so replaced with below. //inputMethodManager.C(editText.WindowToken, 0); inputMethodManager.HideSoftInputFromWindow(editText.WindowToken, HideSoftInputFlags.None); editText.ClearFocus(); } expanded = false; } }
private void animateMoveImpl(RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY) { final View view = holder.itemView; final int deltaX = toX - fromX; final int deltaY = toY - fromY; ViewCompat.Animate(view).cancel(); if (deltaX != 0) { ViewCompat.Animate(view).translationX(0); } if (deltaY != 0) { ViewCompat.Animate(view).translationY(0); } // TODO: make EndActions end listeners instead, since end actions aren't called when // vpas are canceled (and can't end them. why?) // need listener functionality in VPACompat for this. Ick. ViewCompat.Animate(view).SetDuration(MoveDuration).WithEndAction(() = { // .setListener(new VpaListenerAdapter() { // @Override // public void onAnimationCancel(View view) { // if (deltaX != 0) { // ViewCompat.setTranslationX(view, 0); // } // if (deltaY != 0) { // ViewCompat.setTranslationY(view, 0); // } // } // @Override // public void onAnimationEnd(View view) { dispatchMoveFinished(holder); mMoveAnimations.remove(holder); dispatchFinishedWhenDone(); } ).Start(); mMoveAnimations.add(holder); }
private void UpdateTranslation(CoordinatorLayout parent, Android.Views.View child, Android.Views.View dependency) { var translationY = GetTranslationY(parent, child); if (Math.Abs(translationY - _mTranslationY) > double.Epsilon) { ViewCompat.Animate(child).Cancel(); if (Math.Abs(Math.Abs(translationY - _mTranslationY) - dependency.Height) < double.Epsilon) { ViewCompat.Animate(child) .TranslationY(translationY) .SetListener(null); } else { ViewCompat.SetTranslationY(child, translationY); } _mTranslationY = translationY; } }
private void UpdateTranslation(CoordinatorLayout parent, View child, View dependency) { float translationY = this.GetTranslationY(parent, child); if (translationY != this.mTranslationY) { ViewCompat.Animate(child).Cancel(); if (Math.Abs(translationY - this.mTranslationY) == (float)dependency.Height) { ViewCompat.Animate(child) .TranslationY(translationY) .SetListener((IViewPropertyAnimatorListener)null); } else { ViewCompat.SetTranslationY(child, translationY); } this.mTranslationY = translationY; } }
private void animateAddImpl(RecyclerView.ViewHolder holder) { View view = holder.ItemView; ViewCompat.Animate(view).Cancel(); ViewCompat.Animate(view).TranslationX(0) .SetDuration(AddDuration).WithEndAction(() => { // SetListener(new VpaListenerAdapter() { // @Override // public void onAnimationCancel(View view) { // ViewCompat.setTranslationX(view, 0); // } // // @Override // public void onAnimationEnd(View view) { dispatchAddFinished(holder); mAddAnimations.remove(holder); dispatchFinishedWhenDone(); } ).Start(); mAddAnimations.add(holder); }
public void Expand() { if (!expanded) { ViewCompat.Animate(editText) .Alpha(1f) .SetDuration(ANIMATION_DURATION); ViewCompat.Animate(card) .ScaleY(1f) .SetDuration(ANIMATION_DURATION); ViewCompat.Animate(label) .Alpha(0.4f) .ScaleX(0.7f) .ScaleY(0.7f) .TranslationY(-labelTopMargin) .SetDuration(ANIMATION_DURATION); ViewCompat.Animate(image) .Alpha(1f) .ScaleX(1f) .ScaleY(1f) .SetDuration(ANIMATION_DURATION); if (editText != null) { editText.RequestFocus(); } if (OPEN_KEYBOARD_ON_FOCUS) { inputMethodManager.ShowSoftInput(editText, ShowFlags.Implicit); } expanded = true; } }
public void Run() { if (stage1) { ViewCompat.Animate(editorView).Alpha(1).SetDuration(50).WithEndAction(this); stage1 = false; return; } if (stage2) { ViewCompat.Animate(editorView).Alpha(0).SetDuration(50).WithEndAction(this); stage2 = false; return; } if (stage3) { ViewCompat.Animate(editorView).Alpha(1).SetDuration(50); } stage1 = true; stage2 = true; }
public override void OnDependentViewRemoved(CoordinatorLayout parent, Object child, View dependency) { ViewCompat.Animate((View)child).TranslationY(0).Start(); }