Exemple #1
0
        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);
        }
Exemple #3
0
            // 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;
            }