public void UpdateSnackbar(CoordinatorLayout parent, View dependency, View child) { if (!_isTablet && _isShy && dependency is Snackbar.SnackbarLayout) { if (_snackbarHeight == -1) { _snackbarHeight = dependency.Height; } if (Math.Abs(ViewCompat.GetTranslationY(child)) > double.Epsilon) { return; } var targetPadding = _bottomNavHeight + _snackbarHeight - _defaultOffset; var layoutParams = (ViewGroup.MarginLayoutParams)dependency.LayoutParameters; layoutParams.BottomMargin = targetPadding; child.BringToFront(); child.Parent.RequestLayout(); if (Build.VERSION.SdkInt < BuildVersionCodes.Kitkat) { ((View)child.Parent).Invalidate(); } } }
private View FindViewUnder() { int count = this.GetAdapter().ItemCount; for (int i = count - 1; i >= 0; i--) { View child = GetChildAt(i); if (child == null) { continue; } Region r = null; if (((LinearLayoutManager)GetLayoutManager()).Orientation == LinearLayoutManager.Horizontal) { float translationX = ViewCompat.GetTranslationX(child); r = new Region( new Rect( (int)(child.Left + translationX), hoverCellCurrentBounds.Top, (int)(child.Right + translationX), hoverCellCurrentBounds.Bottom)); } else { float translationY = ViewCompat.GetTranslationY(child); r = new Region( new Rect( hoverCellCurrentBounds.Left, (int)(child.Top + translationY), hoverCellCurrentBounds.Right, (int)(child.Bottom + translationY))); } r.InvokeOp(hoverCellCurrentBounds, Region.Op.Intersect); if (!r.IsEmpty) { var ratio = (float)(r.Bounds.Width() * r.Bounds.Height()) / (float)(hoverCellCurrentBounds.Width() * hoverCellCurrentBounds.Height()); LogHelper.Debug(TAG, string.Format("#{0}# is overlapped, ratio = {1}", (char)GetChildItemId(child), ratio)); if (ratio > 0.5) { if (GetChildItemId(child) == mobileItemId) { return(null); } LogHelper.Debug(TAG, string.Format("Swap with: {0}", (char)GetChildItemId(child))); return(child); } } } return(null); }
public static bool HitTest(this View v, int x, int y) { var tx = (int)(ViewCompat.GetTranslationX(v) + 0.5f); var ty = (int)(ViewCompat.GetTranslationY(v) + 0.5f); var left = v.Left + tx; var right = v.Right + tx; var top = v.Top + ty; var bottom = v.Bottom + ty; return(x >= left && x <= right && y >= top && y <= bottom); }
private float GetTranslationY(CoordinatorLayout parent, View child) { float minOffset = 0.0F; var dependencies = parent.GetDependencies(child); int i = 0; for (int z = dependencies.Count; i < z; ++i) { View view = (View)dependencies[i]; if (IsInstanceOf <Snackbar.SnackbarLayout>(view) && parent.DoViewsOverlap(child, view)) { minOffset = Math.Min(minOffset, ViewCompat.GetTranslationY(view) - (float)view.Height); } } return(minOffset); }
private static float GetTranslationY(CoordinatorLayout parent, Android.Views.View child) { var minOffset = 0.0F; var dependencies = parent.GetDependencies(child); var i = 0; for (var z = dependencies.Count; i < z; ++i) { var view = dependencies[i]; if (IsInstanceOf <Snackbar.SnackbarLayout>(view) && parent.DoViewsOverlap(child, view)) { minOffset = Math.Min(minOffset, ViewCompat.GetTranslationY(view) - view.Height); } } return(minOffset); }
public override bool OnDependentViewChanged(CoordinatorLayout parent, Java.Lang.Object child, View dependency) { // Move the fab vertically to place correctly wrt the info pane var fab = child.JavaCast <SwitchableFab> (); var currentInfoPaneY = ViewCompat.GetTranslationY(dependency); var newTransY = (int)Math.Max(0, dependency.Height - currentInfoPaneY - minMarginBottom - fab.Height / 2); ViewCompat.SetTranslationY(fab, -newTransY); // If alternating between open/closed state, change the FAB face if (wasOpened ^ ((InfoPane)dependency).Opened) { fab.Switch(); wasOpened = !wasOpened; } return(true); }
// Long Press public override void OnLongPress(MotionEvent e) { container.downX = (int)e.GetX(); container.downY = (int)e.GetY(); container.activePointerId = e.GetPointerId(0); container.totalOffsetY = 0; container.totalOffsetX = 0; View selectedView = container.FindChildViewUnder(container.downX, container.downY); if (selectedView == null) { return; } var vh = container.GetChildViewHolder(selectedView) as DraggableViewHolder; if (vh == null) { return; } float translationX = ViewCompat.GetTranslationX(selectedView); float translationY = ViewCompat.GetTranslationY(selectedView); var selectedViewRect = new Rect( (int)(selectedView.Left + translationX), (int)(selectedView.Top + translationY), (int)(selectedView.Right + translationX), (int)(selectedView.Bottom + translationY)); if (!vh.CanDrag(selectedViewRect, container.downX, container.downY)) { return; } container.mobileItemId = container.GetChildItemId(selectedView); container.hoverCell = container.GetAndAddHoverView(selectedView); selectedView.Visibility = ViewStates.Invisible; container.cellIsMobile = true; }
public void UpdateSnackbar(CoordinatorLayout parent, View dependency, View child) { if (!_isTablet && _isShy && dependency is Snackbar.SnackbarLayout) { if (_snackbarHeight == -1) { _snackbarHeight = dependency.Height; } if (Math.Abs(ViewCompat.GetTranslationY(child)) > double.Epsilon) { return; } var targetPadding = _snackbarHeight + _bottomNavHeight - _defaultOffset; dependency.SetPadding( dependency.PaddingLeft, dependency.PaddingTop, dependency.PaddingRight, targetPadding ); } }