private void init(Context context, IAttributeSet attrs)
        {
            CoreUtility.ExecuteMethod("init", delegate()
            {
                mGestureListener    = new CustomGestureListener(this);
                mDragHelperCallback = new CustomViewDragHelper(this);

                if (attrs != null && context != null)
                {
                    TypedArray a = context.Theme.ObtainStyledAttributes(
                        attrs,
                        Resource.Styleable.SwipeRevealLayout,
                        0, 0
                        );

                    mDragEdge         = a.GetInteger(Resource.Styleable.SwipeRevealLayout_dragEdge, DRAG_EDGE_LEFT);
                    mMinFlingVelocity = a.GetInteger(Resource.Styleable.SwipeRevealLayout_flingVelocity, DEFAULT_MIN_FLING_VELOCITY);
                    mMode             = a.GetInteger(Resource.Styleable.SwipeRevealLayout_mode, MODE_NORMAL);

                    mMinDistRequestDisallowParent = a.GetDimensionPixelSize(
                        Resource.Styleable.SwipeRevealLayout_minDistRequestDisallowParent,
                        dpToPx(DEFAULT_MIN_DIST_REQUEST_DISALLOW_PARENT)
                        );
                }

                mDragHelper = ViewDragHelper.Create(this, 1.0f, mDragHelperCallback);
                mDragHelper.SetEdgeTrackingEnabled(ViewDragHelper.EdgeAll);

                mGestureDetector = new GestureDetectorCompat(context, mGestureListener);
            });
        }
        public SlidingUpPanelLayout(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            if (attrs != null)
            {
                var defAttrs = context.ObtainStyledAttributes(attrs, DefaultAttrs);

                if (defAttrs.Length() > 0)
                {
                    var gravity     = defAttrs.GetInt(0, (int)GravityFlags.NoGravity);
                    var gravityFlag = (GravityFlags)gravity;
                    if (gravityFlag != GravityFlags.Top && gravityFlag != GravityFlags.Bottom)
                    {
                        throw new ArgumentException("layout_gravity must be set to either top or bottom");
                    }
                    _isSlidingUp = gravityFlag == GravityFlags.Bottom;
                }

                defAttrs.Recycle();

                var ta = context.ObtainStyledAttributes(attrs, Resource.Styleable.SlidingUpPanelLayout);

                if (ta.Length() > 0)
                {
                    _panelHeight  = ta.GetDimensionPixelSize(Resource.Styleable.SlidingUpPanelLayout_collapsedHeight, -1);
                    _shadowHeight = ta.GetDimensionPixelSize(Resource.Styleable.SlidingUpPanelLayout_shadowHeight, -1);

                    _minFlingVelocity = ta.GetInt(Resource.Styleable.SlidingUpPanelLayout_flingVelocity,
                                                  DefaultMinFlingVelocity);
                    _coveredFadeColor = ta.GetColor(Resource.Styleable.SlidingUpPanelLayout_fadeColor, DefaultFadeColor);

                    _dragViewResId = ta.GetResourceId(Resource.Styleable.SlidingUpPanelLayout_dragView, -1);
                }

                ta.Recycle();
            }

            var density = context.Resources.DisplayMetrics.Density;

            if (_panelHeight == -1)
            {
                _panelHeight = (int)(DefaultPanelHeight * density + 0.5f);
            }
            if (_shadowHeight == -1)
            {
                _shadowHeight = (int)(DefaultShadowHeight * density + 0.5f);
            }

            SetWillNotDraw(false);

            _dragHelper             = ViewDragHelper.Create(this, 0.5f, new DragHelperCallback(this));
            _dragHelper.MinVelocity = _minFlingVelocity * density;

            _canSlide      = true;
            SlidingEnabled = true;

            var vc = ViewConfiguration.Get(context);

            _scrollTouchSlop = vc.ScaledTouchSlop;
        }
示例#3
0
 private void setUpViewDragHelper()
 {
     if (viewDragHelper != null)
     {
         return;
     }
     viewDragHelper = ViewDragHelper.Create(this, sensitivity, new ViewDragHelperCallback(this));
 }
示例#4
0
        void Initialize()
        {
            mDragViews = new List <View> ();

            /**
             * Create the {@link ViewDragHelper} and set its callback.
             */
            mDragHelper = ViewDragHelper.Create(this, 1.0f, new Callbacks(this));
        }
示例#5
0
 /// <summary>
 /// Initializes ViewDragHelper.
 /// </summary>
 private void InitViewDragHelper()
 {
     try
     {
         DragHelper = ViewDragHelper.Create(this, DragSensitivity, new DragHelperCallback(this, DraggableContainer));
     }
     catch (Exception e)
     {
         Methods.DisplayReportResultTrack(e);
     }
 }
        public override bool OnLayoutChild(CoordinatorLayout parent, Java.Lang.Object cChild, int layoutDirection)
        {
            //           return base.OnLayoutChild(parent, child, layoutDirection);
            var child = cChild.JavaCast <View>();

            // First let the parent lay it out
            if (_state != StateDragging && _state != StateSettling)
            {
                if (parent.FitsSystemWindows && !child.FitsSystemWindows)
                {
                    child.SetFitsSystemWindows(true);
                }
                parent.OnLayoutChild(child, layoutDirection);
            }
            // Offset the bottom sheet
            _parentHeight = parent.Height;
            _minOffset    = System.Math.Max(0, _parentHeight - child.Height);
            _maxOffset    = System.Math.Max(_parentHeight - _peekHeight, _minOffset);

            /**
             * New behavior
             */
            switch (_state)
            {
            case StateAnchorPoint:
                ViewCompat.OffsetTopAndBottom(child, AnchorPoint);
                break;

            case StateExpanded:
                ViewCompat.OffsetTopAndBottom(child, _minOffset);
                break;

            case StateHidden:
                if (Hideable)
                {
                    ViewCompat.OffsetTopAndBottom(child, _parentHeight);
                }
                break;

            case StateCollapsed:
                ViewCompat.OffsetTopAndBottom(child, _maxOffset);
                break;
            }
            ;

            if (_viewDragHelper == null)
            {
                _viewDragHelper = ViewDragHelper.Create(parent, _dragCallback);
            }
            _viewRef = new WeakReference <View>(child);
            _nestedScrollingChildRef = new WeakReference <View>(FindScrollingChild(child));
            return(true);
        }
示例#7
0
        public override bool OnLayoutChild(
            CoordinatorLayout parent, Java.Lang.Object childObject, int layoutDirection)
        {
            Debug.WriteLineIf(DebugTrace, $"OnLayoutChild");
            View child = Android.Runtime.Extensions.JavaCast <View>(childObject);

            if (ViewCompat.GetFitsSystemWindows(parent) && !ViewCompat.GetFitsSystemWindows(child))
            {
                ViewCompat.SetFitsSystemWindows(child, true);
            }
            int savedTop = child.Top;

            // First let the parent lay it out
            parent.OnLayoutChild(child, layoutDirection);
            // Offset the bottom sheet
            mParentHeight = parent.Height;
            mMinOffset    = Math.Max(0, mParentHeight - child.Height);
            mMaxOffset    = Math.Max(mParentHeight - mPeekHeight, mMinOffset);
            mAnchorOffset = (int)Math.Max(mParentHeight * mAnchorThreshold, mMinOffset);

            Debug.WriteLineIf(DebugTrace, $"offset computed => savedTop:{savedTop} mMinOffset:{mMinOffset} mMaxOffset:{mMaxOffset} mAnchorOffset:{mAnchorOffset} ");
            if (mState == STATE_EXPANDED)
            {
                ViewCompat.OffsetTopAndBottom(child, mMinOffset);
            }
            else if (mState == STATE_ANCHOR)
            {
                ViewCompat.OffsetTopAndBottom(child, mAnchorOffset);
            }
            else if (mHideable && mState == STATE_HIDDEN)
            {
                ViewCompat.OffsetTopAndBottom(child, mParentHeight);
            }
            else if (mState == STATE_COLLAPSED)
            {
                ViewCompat.OffsetTopAndBottom(child, mMaxOffset);
            }
            else if (mState == STATE_DRAGGING || mState == STATE_SETTLING)
            {
                ViewCompat.OffsetTopAndBottom(child, savedTop - child.Top);
            }
            if (mViewDragHelper == null || mViewDragHelper.Handle == IntPtr.Zero)
            {
                mViewDragHelper = ViewDragHelper.Create(parent, mDragCallback);
            }
            mViewRef = new WeakReference <View>(child);
            mNestedScrollingChildRef = new WeakReference <View>(findScrollingChild(child));
            return(true);
        }
        public override bool OnTouchEvent(CoordinatorLayout parent, Java.Lang.Object cChild, MotionEvent ev)
        {
            var child = cChild.JavaCast <View>();

            if (!child.IsShown)
            {
                return(false);
            }

            var action = ev.ActionMasked;

            if (_state == StateDragging && action == MotionEventActions.Down)
            {
                return(true);
            }

            // Detect scroll direction for ignoring collapsible
            if (_lastStableState == StateAnchorPoint && action == MotionEventActions.Move)
            {
                if (ev.GetY() > _initialY && !Collapsible)
                {
                    Reset();
                    return(false);
                }
            }

            if (_viewDragHelper == null)
            {
                _viewDragHelper = ViewDragHelper.Create(parent, _dragCallback);
            }

            _viewDragHelper.ProcessTouchEvent(ev);

            if (action == MotionEventActions.Down)
            {
                Reset();
            }

            // The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it
            // to capture the bottom sheet in case it is not captured and the touch slop is passed.
            if (action == MotionEventActions.Move && !_ignoreEvents && System.Math.Abs(_initialY - ev.GetY()) > _viewDragHelper.TouchSlop)
            {
                _viewDragHelper.CaptureChildView(child, ev.GetPointerId(ev.ActionIndex));
            }


            return(!_ignoreEvents);
        }