public SwipeLayout(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            IsSwipeEnabled = true;
            gestureDetector = new GestureDetector (Context, new SwipeDetector (this));
            mDragHelperCallback = new SwipeLayoutDragHelperCallback (this);

            mDragHelper = ViewDragHelper.Create(this, mDragHelperCallback);
            mTouchSlop = ViewConfiguration.Get(context).ScaledTouchSlop;

            TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.SwipeLayout);
            int dragEdgeChoices = a.GetInt(Resource.Styleable.SwipeLayout_drag_edge, DRAG_RIGHT);
            mEdgeSwipesOffset[(int)DragEdge.Left] = a.GetDimension(Resource.Styleable.SwipeLayout_leftEdgeSwipeOffset, 0);
            mEdgeSwipesOffset[(int)DragEdge.Right] = a.GetDimension(Resource.Styleable.SwipeLayout_rightEdgeSwipeOffset, 0);
            mEdgeSwipesOffset[(int)DragEdge.Top] = a.GetDimension(Resource.Styleable.SwipeLayout_topEdgeSwipeOffset, 0);
            mEdgeSwipesOffset[(int)DragEdge.Bottom] = a.GetDimension(Resource.Styleable.SwipeLayout_bottomEdgeSwipeOffset, 0);
            ClickToClose = a.GetBoolean(Resource.Styleable.SwipeLayout_clickToClose, ClickToClose);

            if ((dragEdgeChoices & DRAG_LEFT) == DRAG_LEFT) {
                mDragEdges.Add(DragEdge.Left, null);
            }
            if ((dragEdgeChoices & DRAG_TOP) == DRAG_TOP) {
                mDragEdges.Add(DragEdge.Top, null);
            }
            if ((dragEdgeChoices & DRAG_RIGHT) == DRAG_RIGHT) {
                mDragEdges.Add(DragEdge.Right, null);
            }
            if ((dragEdgeChoices & DRAG_BOTTOM) == DRAG_BOTTOM) {
                mDragEdges.Add(DragEdge.Bottom, null);
            }
            int ordinal = a.GetInt(Resource.Styleable.SwipeLayout_show_mode, (int)ShowMode.PullOut);
            mShowMode = (ShowMode)System.Enum.ToObject(typeof(ShowMode), ordinal);
            a.Recycle();
        }
Example #2
0
 private void setUpViewDragHelper()
 {
     if (viewDragHelper != null)
     {
         return;
     }
     viewDragHelper = ViewDragHelper.Create(this, sensitivity, new ViewDragHelperCallback(this));
 }
		void Initialize ()
		{
			mDragViews = new List<View> ();

			/**
	         * Create the {@link ViewDragHelper} and set its callback.
	         */
			mDragHelper = ViewDragHelper.Create (this, 1.0f, new Callbacks (this));
		}
Example #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));
        }
Example #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);
        }
Example #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);
        }
Example #9
0
        public SlidingUpPanelLayout(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            // not really relevan in Xamarin.Android but keeping for a possible
            // future update which will render layouts in the Designer.
            if (IsInEditMode)
            {
                return;
            }

            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("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);

                    OverlayContent = ta.GetBoolean(Resource.Styleable.SlidingUpPanelLayout_overlay, DefaultOverlayFlag);
                }

                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;
        }
        public SlidingUpPanelLayout(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            // not really relevan in Xamarin.Android but keeping for a possible
            // future update which will render layouts in the Designer.
            if (IsInEditMode) return; 

            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("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);

                    OverlayContent = ta.GetBoolean(Resource.Styleable.SlidingUpPanelLayout_overlay, DefaultOverlayFlag);
                }

                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;
        }