Ejemplo n.º 1
0
            public bool CheckIsCar(byte[] data, int max_data_count)
            {
                bool is3E = data[64] == '3' && data[65] == 'E';

                Trace.WriteLine("Checking...");
                if (is3E)
                {
                    m_ct.Cancel();
                    Task.Factory.StartNew(async() =>
                    {
                        await Task.Delay(25, m_ct.Token);
                        Trace.WriteLine("After delay...");
                        if (!m_ct.Token.IsCancellationRequested)
                        {
                            this.number_of_3E = 0;
                            Trace.WriteLine("NofE Reset to zero...");
                        }
                    }, m_ct.Token).Start();
                    number_of_3E++;
                    Trace.WriteLine("NofE: {0}", number_of_3E);
                    Trace.WriteLineIf(data[64] == '3' && data[65] == 'E' && number_of_3E == max_data_count, "Condition fulfilled...");
                    return(is3E && number_of_3E == max_data_count);
                }
                return(false);
            }
Ejemplo n.º 2
0
        /**
         * Sets the state of the bottom sheet. The bottom sheet will transition to that state with
         * animation.
         *
         * @param state One of {@link #STATE_COLLAPSED}, {@link #STATE_EXPANDED}, or
         *              {@link #STATE_HIDDEN}.
         */
        public void setState(int state)
        {
            Debug.WriteLineIf(DebugTrace, $"setState {(AnchorBottomSheetState)state}");
            if (state == mState)
            {
                return;
            }

            if (mViewRef == null)
            {
                // The view is not laid out yet; modify mState and let onLayoutChild handle it later
                if (state == STATE_COLLAPSED || state == STATE_EXPANDED || state == STATE_ANCHOR ||
                    (mHideable && state == STATE_HIDDEN))
                {
                    mState = state;
                }
                return;
            }

            View child;

            if (!mViewRef.TryGetTarget(out child))
            {
                return;
            }

            int top;

            if (state == STATE_COLLAPSED)
            {
                top = mMaxOffset;
                View scroll;
                if (mNestedScrollingChildRef.TryGetTarget(out scroll) && ViewCompat.CanScrollVertically(scroll, -1))
                {
                    scroll.ScrollTo(0, 0);
                }
            }
            else if (state == STATE_EXPANDED)
            {
                top = mMinOffset;
            }
            else if (state == STATE_ANCHOR)
            {
                top = mAnchorOffset;
            }
            else if (mHideable && state == STATE_HIDDEN)
            {
                top = mParentHeight;
            }
            else
            {
                throw new ArgumentException("Illegal state argument: " + state, nameof(state));
            }
            setStateInternal(STATE_SETTLING);
            if (mViewDragHelper.SmoothSlideViewTo(child, child.Left, top))
            {
                ViewCompat.PostOnAnimation(child, this.CreateSettleRunnable(child, state));
            }
        }
Ejemplo n.º 3
0
        public override bool OnStartNestedScroll(
            CoordinatorLayout coordinatorLayout,
            Java.Lang.Object childObject,
            View directTargetChild, View target,
            int nestedScrollAxes)
        {
            mLastNestedScrollDy = 0;
            mNestedScrolled     = false;
            var result = (nestedScrollAxes & ViewCompat.ScrollAxisVertical) != 0;

            Debug.WriteLineIf(DebugTrace, $"OnStartNestedScroll: return {result}");
            return(result);
        }
Ejemplo n.º 4
0
            public void OnViewReleasedOriginal(View releasedChild, float xvel, float yvel)
            {
                Debug.WriteLineIf(DebugTrace, $"OnViewReleased => xvel:{xvel} yvel:{yvel}");
                int top;
                int targetState;

                if (yvel < 0)
                {                 // Moving up
                    Debug.WriteLineIf(DebugTrace, "Moving up: EXPANDED");
                    top         = mBehavior.mMinOffset;
                    targetState = STATE_EXPANDED;
                }
                else if (mBehavior.mHideable && mBehavior.shouldHide(releasedChild, yvel))
                {
                    Debug.WriteLineIf(DebugTrace, "Hideable and should hide: HIDDEN");
                    top         = mBehavior.mParentHeight;
                    targetState = STATE_HIDDEN;
                }
                else if (yvel == 0f)
                {
                    int currentTop = releasedChild.Top;
                    if (Math.Abs(currentTop - mBehavior.mMinOffset) < Math.Abs(currentTop - mBehavior.mMaxOffset))
                    {
                        Debug.WriteLineIf(DebugTrace, "Near top: EXPANDED");
                        top         = mBehavior.mMinOffset;
                        targetState = STATE_EXPANDED;
                    }
                    else
                    {
                        Debug.WriteLineIf(DebugTrace, "Else near top: COLLAPSED");
                        top         = mBehavior.mMaxOffset;
                        targetState = STATE_COLLAPSED;
                    }
                }
                else
                {
                    Debug.WriteLineIf(DebugTrace, "Else: COLLAPSED");
                    top         = mBehavior.mMaxOffset;
                    targetState = STATE_COLLAPSED;
                }
                if (mBehavior.mViewDragHelper.SettleCapturedViewAt(releasedChild.Left, top))
                {
                    mBehavior.setStateInternal(STATE_SETTLING);
                    ViewCompat.PostOnAnimation(releasedChild,
                                               mBehavior.CreateSettleRunnable(releasedChild, targetState));
                }
                else
                {
                    mBehavior.setStateInternal(targetState);
                }
            }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        private void setStateInternal(int state)
        {
            Debug.WriteLineIf(DebugTrace, $"setStateInternal {(AnchorBottomSheetState)state}");
            if (mState == state)
            {
                return;
            }

            mState = state;
            View bottomSheet;

            if (mViewRef.TryGetTarget(out bottomSheet) && mCallback != null)
            {
                mCallback.OnStateChanged(bottomSheet, state);
            }
        }
Ejemplo n.º 7
0
        public override bool OnNestedPreFling(
            CoordinatorLayout coordinatorLayout,
            Java.Lang.Object childObject,
            View target,
            float velocityX,
            float velocityY)
        {
            View nestedScrollingChild;

            mNestedScrollingChildRef.TryGetTarget(out nestedScrollingChild);
            var result = target == nestedScrollingChild && (mState != STATE_EXPANDED || base.OnNestedPreFling(
                                                                coordinatorLayout, childObject, target, velocityX, velocityY));

            Debug.WriteLineIf(DebugTrace, $"OnNestedPreFling: return {result}");
            return(result);
        }
Ejemplo n.º 8
0
            public override void OnViewReleased(View releasedChild, float xvel, float yvel)
            {
                Debug.WriteLineIf(DebugTrace, $"OnViewReleased => xvel:{xvel} yvel:{yvel}");
                int top;
                int targetState;

                if (mBehavior.mHideable && mBehavior.shouldHide(releasedChild, yvel))
                {
                    Debug.WriteLineIf(DebugTrace, "Hideable and should hide: HIDDEN");
                    top         = mBehavior.mParentHeight;
                    targetState = STATE_HIDDEN;
                }
                else if (yvel <= 0f)
                {
                    int currentTop = releasedChild.Top;
                    Debug.WriteLineIf(DebugTrace, $"yvel <= 0f: currentTop:{currentTop} mAnchorOffset:{mBehavior.mAnchorOffset} mMinOffset:{mBehavior.mMinOffset} mMaxOffset:{mBehavior.mMaxOffset}");
                    if (Math.Abs(currentTop - mBehavior.mAnchorOffset) < Math.Abs(currentTop - mBehavior.mMinOffset))
                    {
                        Debug.WriteLineIf(DebugTrace, "top close to anchor => ANCHOR");
                        top         = mBehavior.mAnchorOffset;
                        targetState = STATE_ANCHOR;
                    }
                    else if (Math.Abs(currentTop - mBehavior.mMinOffset) < Math.Abs(currentTop - mBehavior.mMaxOffset))
                    {
                        Debug.WriteLineIf(DebugTrace, "top close child height => EXPANDED");
                        top         = mBehavior.mMinOffset;
                        targetState = STATE_EXPANDED;
                    }
                    else
                    {
                        Debug.WriteLineIf(DebugTrace, "else => COLLAPSED");
                        top         = mBehavior.mMaxOffset;
                        targetState = STATE_COLLAPSED;
                    }
                }
                else
                {
                    Debug.WriteLineIf(DebugTrace, $"global else");
                    int currentTop = releasedChild.Top;
                    Debug.WriteLineIf(DebugTrace, $"yvel <= 0f: currentTop:{currentTop} mAnchorOffset:{mBehavior.mAnchorOffset} mMinOffset:{mBehavior.mMinOffset} mMaxOffset:{mBehavior.mMaxOffset}");
                    if (Math.Abs(currentTop - mBehavior.mAnchorOffset) < Math.Abs(currentTop - mBehavior.mMaxOffset))
                    {
                        Debug.WriteLineIf(DebugTrace, "top close to anchor => ANCHOR");
                        top         = mBehavior.mAnchorOffset;
                        targetState = STATE_ANCHOR;
                    }
                    else
                    {
                        Debug.WriteLineIf(DebugTrace, $"else => COLLAPSED");
                        top         = mBehavior.mMaxOffset;
                        targetState = STATE_COLLAPSED;
                    }
                }
                if (mBehavior.mViewDragHelper.SettleCapturedViewAt(releasedChild.Left, top))
                {
                    mBehavior.setStateInternal(STATE_SETTLING);
                    ViewCompat.PostOnAnimation(
                        releasedChild, mBehavior.CreateSettleRunnable(releasedChild, targetState));
                }
                else
                {
                    mBehavior.setStateInternal(targetState);
                }
            }
Ejemplo n.º 9
0
        public override void OnStopNestedScroll(
            CoordinatorLayout coordinatorLayout, Java.Lang.Object childObject, View target)
        {
            Debug.WriteLineIf(DebugTrace, "OnStopNestedScroll");

            View child = Android.Runtime.Extensions.JavaCast <View>(childObject);

            if (child.Top == mMinOffset)
            {
                Debug.WriteLineIf(DebugTrace, "top == minOffset => EXPANDED");
                setStateInternal(STATE_EXPANDED);
                return;
            }

            View nestedScrollingChild;

            mNestedScrollingChildRef.TryGetTarget(out nestedScrollingChild);
            if (target != nestedScrollingChild || !mNestedScrolled)
            {
                return;
            }

            int top;
            int targetState;

            if (mHideable && shouldHide(child, getYVelocity()))
            {
                Debug.WriteLineIf(DebugTrace, "hideable && shouldHide => HIDDEN");
                top         = mParentHeight;
                targetState = STATE_HIDDEN;
            }
            else if (mLastNestedScrollDy >= 0)
            {
                // It went Up
                int currentTop = child.Top;
                Debug.WriteLineIf(DebugTrace,
                                  $"mLastNestedScrollDy >= 0: currentTop:{currentTop} mAnchorOffset:{mAnchorOffset} mMinOffset:{mMinOffset} mMaxOffset:{mMaxOffset}");

                if (Math.Abs(currentTop - mAnchorOffset) < Math.Abs(currentTop - mMinOffset))
                {
                    Debug.WriteLineIf(DebugTrace, "top close to anchor => ANCHOR");
                    top         = mAnchorOffset;
                    targetState = STATE_ANCHOR;
                }
                else if (Math.Abs(currentTop - mMinOffset) < Math.Abs(currentTop - mMaxOffset))
                {
                    Debug.WriteLineIf(DebugTrace, "top close child height => EXPANDED");
                    top         = mMinOffset;
                    targetState = STATE_EXPANDED;
                }
                else
                {
                    Debug.WriteLineIf(DebugTrace, "else => COLLAPSED");
                    top         = mMaxOffset;
                    targetState = STATE_COLLAPSED;
                }
            }
            else
            {
                // It went down
                Debug.WriteLineIf(DebugTrace, $"global else");
                int currentTop = child.Top;
                Debug.WriteLineIf(DebugTrace, $"mLastNestedScrollDy >= 0: currentTop:{currentTop} mAnchorOffset:{mAnchorOffset} mMinOffset:{mMinOffset} mMaxOffset:{mMaxOffset}");

                if (Math.Abs(currentTop - mAnchorOffset) < Math.Abs(currentTop - mMaxOffset))
                {
                    Debug.WriteLineIf(DebugTrace, "top close to anchor => ANCHOR");
                    top         = mAnchorOffset;
                    targetState = STATE_ANCHOR;
                }
                else
                {
                    Debug.WriteLineIf(DebugTrace, $"else => COLLAPSED");
                    top         = mMaxOffset;
                    targetState = STATE_COLLAPSED;
                }
            }

            if (mViewDragHelper.SmoothSlideViewTo(child, child.Left, top))
            {
                setStateInternal(STATE_SETTLING);
                ViewCompat.PostOnAnimation(child, this.CreateSettleRunnable(child, targetState));
            }
            else
            {
                setStateInternal(targetState);
            }

            mNestedScrolled = false;
        }
Ejemplo n.º 10
0
        public override void OnNestedPreScroll(
            CoordinatorLayout coordinatorLayout,
            Java.Lang.Object childObject,
            View target,
            int dx,
            int dy,
            int[] consumed)
        {
            Debug.WriteLineIf(DebugTrace, $"OnNestedPreScroll");
            View child = Android.Runtime.Extensions.JavaCast <View>(childObject);

            View scrollingChild;

            mNestedScrollingChildRef.TryGetTarget(out scrollingChild);
            if (target != scrollingChild)
            {
                return;
            }

            int currentTop = child.Top;
            int newTop     = currentTop - dy;

            Debug.WriteLineIf(DebugTrace, $"currentTop:{currentTop} newTop:{newTop}");
            if (dy > 0)
            {             // Upward
                Debug.WriteLineIf(DebugTrace, $"dy > 0: Upward");
                if (newTop < mMinOffset)
                {
                    Debug.WriteLineIf(DebugTrace, $"newTop < mMinOffset: STATE_EXPANDED");
                    consumed[1] = currentTop - mMinOffset;
                    ViewCompat.OffsetTopAndBottom(child, -consumed[1]);
                    setStateInternal(STATE_EXPANDED);
                }
                else
                {
                    Debug.WriteLineIf(DebugTrace, $"else: STATE_DRAGGING");
                    consumed[1] = dy;
                    ViewCompat.OffsetTopAndBottom(child, -dy);
                    setStateInternal(STATE_DRAGGING);
                }
            }
            else if (dy < 0)
            {
                // Downward
                Debug.WriteLineIf(DebugTrace, $"dy < 0: Downward");
                if (!ViewCompat.CanScrollVertically(target, -1))
                {
                    if (newTop <= mMaxOffset || mHideable)
                    {
                        Debug.WriteLineIf(DebugTrace, $"newTop <= mMaxOffset || mHideable: STATE_DRAGGING");
                        consumed[1] = dy;
                        ViewCompat.OffsetTopAndBottom(child, -dy);
                        setStateInternal(STATE_DRAGGING);
                    }
                    else
                    {
                        Debug.WriteLineIf(DebugTrace, $"else: STATE_COLLAPSED");
                        consumed[1] = currentTop - mMaxOffset;
                        ViewCompat.OffsetTopAndBottom(child, -consumed[1]);
                        setStateInternal(STATE_COLLAPSED);
                    }
                }
            }

            dispatchOnSlide(child.Top);
            mLastNestedScrollDy = dy;
            mNestedScrolled     = true;
        }
Ejemplo n.º 11
0
        public override bool OnInterceptTouchEvent(
            CoordinatorLayout parent, Java.Lang.Object childObject, MotionEvent @event)
        {
            View child = Android.Runtime.Extensions.JavaCast <View>(childObject);

            if (!child.IsShown)
            {
                Debug.WriteLineIf(DebugTrace, $"OnInterceptTouchEvent: return false");
                return(false);
            }

            int action = MotionEventCompat.GetActionMasked(@event);

            // Record the velocity
            if (action == (int)MotionEventActions.Down)
            {
                reset();
            }

            if (mVelocityTracker == null || mVelocityTracker.Handle == IntPtr.Zero)
            {
                mVelocityTracker = VelocityTracker.Obtain();
            }

            mVelocityTracker.AddMovement(@event);
            switch (action)
            {
            case (int)MotionEventActions.Up:
            case (int)MotionEventActions.Cancel:
                mTouchingScrollingChild = false;
                mActivePointerId        = MotionEvent.InvalidPointerId;
                // Reset the ignore flag
                if (mIgnoreEvents)
                {
                    mIgnoreEvents = false;
                    return(false);
                }
                break;

            case (int)MotionEventActions.Down:
                int initialX = (int)@event.GetX();
                mInitialY = (int)@event.GetY();
                View nestedScroll;

                if (mNestedScrollingChildRef.TryGetTarget(out nestedScroll) && parent.IsPointInChildBounds(nestedScroll, initialX, mInitialY))
                {
                    mActivePointerId = @event.GetPointerId(@event.ActionIndex);
                    //mTouchingScrollingChild = true;
                }
                mIgnoreEvents =
                    mActivePointerId == MotionEvent.InvalidPointerId &&
                    !parent.IsPointInChildBounds(child, initialX, mInitialY);
                break;
            }
            if (!mIgnoreEvents && mViewDragHelper.ShouldInterceptTouchEvent(@event))
            {
                Debug.WriteLineIf(DebugTrace, $"OnInterceptTouchEvent: return true");
                return(true);
            }
            // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because
            // it is not the top most view of its parent. This is not necessary when the touch event is
            // happening over the scrolling content as nested scrolling logic handles that case.
            View scroll;
            var  result = action == (int)MotionEventActions.Move &&
                          mNestedScrollingChildRef.TryGetTarget(out scroll) &&
                          !mIgnoreEvents && mState != STATE_DRAGGING &&
                          !parent.IsPointInChildBounds(scroll, (int)@event.GetX(), (int)@event.GetY()) &&
                          Math.Abs(mInitialY - @event.GetY()) > mViewDragHelper.TouchSlop;

            Debug.WriteLineIf(DebugTrace, $"OnInterceptTouchEvent: return {result}");
            return(result);
        }