Beispiel #1
0
 /// <summary>
 /// Slides down a view.
 /// </summary>
 /// <param name="view"></param>
 /// <param name="left"></param>
 /// <param name="top"></param>
 private void SlideViewTo(View view, int left, int top)
 {
     try
     {
         DragHelper.SmoothSlideViewTo(view, left, top);
         Invalidate();
     }
     catch (Exception e)
     {
         Methods.DisplayReportResultTrack(e);
     }
 }
        /**
         * Open the panel to show the secondary view
         * @param animation true to animate the open motion. {@link SwipeListener} won't be
         *                  called if is animation is false.
         */
        public void open(bool animation)
        {
            CoreUtility.ExecuteMethod("open", delegate()
            {
                mIsOpenBeforeInit = true;
                mAborted          = false;

                if (animation)
                {
                    mState = STATE_OPENING;
                    mDragHelper.SmoothSlideViewTo(mMainView, mRectMainOpen.Left, mRectMainOpen.Top);

                    if (mDragStateChangeListener != null)
                    {
                        mDragStateChangeListener.onDragStateChanged(mState);
                    }
                }
                else
                {
                    mState = STATE_OPEN;
                    mDragHelper.Abort();

                    mMainView.Layout(
                        mRectMainOpen.Left,
                        mRectMainOpen.Top,
                        mRectMainOpen.Right,
                        mRectMainOpen.Bottom
                        );

                    mSecondaryView.Layout(
                        mRectSecOpen.Left,
                        mRectSecOpen.Top,
                        mRectSecOpen.Right,
                        mRectSecOpen.Bottom
                        );
                }

                ViewCompat.PostInvalidateOnAnimation(this);
            });
        }
Beispiel #3
0
        private bool SmoothSlideTo(float slideOffset)
        {
            if (!_canSlide)
            {
                return(false);
            }

            var y = _isSlidingUp
                ? (int)(SlidingTop + slideOffset * _slideRange)
                : (int)(SlidingTop - slideOffset * _slideRange);

            if (!_dragHelper.SmoothSlideViewTo(_slideableView, _slideableView.Left, y))
            {
                return(false);
            }

            SetAllChildrenVisible();
            ViewCompat.PostInvalidateOnAnimation(this);
            return(true);
        }
        public override void OnStopNestedScroll(CoordinatorLayout coordinatorLayout, Java.Lang.Object cChild, View target, int type)
        {
            var child = cChild.JavaCast <View>();

            if (child.Top == _minOffset)
            {
                SetStateInternal(StateExpanded);
                _lastStableState = StateExpanded;
                return;
            }

            _nestedScrollingChildRef.TryGetTarget(out View nestedChildRedTarget);
            if (target != nestedChildRedTarget || !_nestedScrolled)
            {
                return;
            }

            int top;
            int targetState;

            // Are we flinging up?
            float scrollVelocity = _scrollVelocityTracker.ScrollVelocity;

            if (scrollVelocity > _minimumVelocity)
            {
                if (_lastStableState == StateCollapsed)
                {
                    // Fling from collapsed to anchor
                    top         = AnchorPoint;
                    targetState = StateAnchorPoint;
                }
                else if (_lastStableState == StateAnchorPoint)
                {
                    // Fling from anchor to expanded
                    top         = _minOffset;
                    targetState = StateExpanded;
                }
                else
                {
                    // We are already expanded
                    top         = _minOffset;
                    targetState = StateExpanded;
                }
            }
            else
            // Are we flinging down?
            if (scrollVelocity < -_minimumVelocity)
            {
                if (_lastStableState == StateExpanded)
                {
                    // Fling to from expanded to anchor
                    top         = AnchorPoint;
                    targetState = StateAnchorPoint;
                }
                else if (Collapsible == true)
                {
                    if (_lastStableState == StateAnchorPoint)
                    {
                        // Fling from anchor to collapsed
                        top         = _maxOffset;
                        targetState = StateCollapsed;
                    }
                    else
                    {
                        // We are already collapsed
                        top         = _maxOffset;
                        targetState = StateCollapsed;
                    }
                }
                else
                {
                    top         = AnchorPoint;
                    targetState = StateAnchorPoint;
                }
            }
            // Not flinging, just settle to the nearest state
            else
            {
                // Collapse?
                int currentTop = child.Top;
                if (currentTop > AnchorPoint * 1.25 && Collapsible == true)
                { // Multiply by 1.25 to account for parallax. The currentTop needs to be pulled down 50% of the anchor point before collapsing.
                    top         = _maxOffset;
                    targetState = StateCollapsed;
                }
                // Expand?
                else
                if (currentTop < AnchorPoint * 0.5)
                {
                    top         = _minOffset;
                    targetState = StateExpanded;
                }
                // Snap back to the anchor
                else
                {
                    top         = AnchorPoint;
                    targetState = StateAnchorPoint;
                }
            }

            _lastStableState = targetState;
            if (_viewDragHelper.SmoothSlideViewTo(child, child.Left, top))
            {
                SetStateInternal(StateSettling);
                ViewCompat.PostOnAnimation(child, new SettleRunnable(this, child, targetState));
            }
            else
            {
                SetStateInternal(targetState);
            }
            _nestedScrolled = false;
        }