Exemplo n.º 1
0
        public void OnStopNestedScrollOriginal(
            CoordinatorLayout coordinatorLayout, Java.Lang.Object childObject, View target)
        {
            View child = Android.Runtime.Extensions.JavaCast <View>(childObject);

            if (child.Top == mMinOffset)
            {
                setStateInternal(STATE_EXPANDED);
                return;
            }
            View nestedScrollingChild;

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

            if (mLastNestedScrollDy > 0)
            {
                top         = mMinOffset;
                targetState = STATE_EXPANDED;
            }
            else if (mHideable && shouldHide(child, getYVelocity()))
            {
                top         = mParentHeight;
                targetState = STATE_HIDDEN;
            }
            else if (mLastNestedScrollDy == 0)
            {
                int currentTop = child.Top;
                if (Math.Abs(currentTop - mMinOffset) < Math.Abs(currentTop - mMaxOffset))
                {
                    top         = mMinOffset;
                    targetState = STATE_EXPANDED;
                }
                else
                {
                    top         = mMaxOffset;
                    targetState = STATE_COLLAPSED;
                }
            }
            else
            {
                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;
        }
Exemplo n.º 2
0
        public static ICharSequence Parse(
            Context context,
            List <IconFontDescriptorWrapper> iconFontDescriptors,
            string text,
            TextView target)
        {
            context = context.ApplicationContext;

            // Analyse the text and replace {} blocks with the appropriate character
            // Retain all transformations in the accumulator
            SpannableStringBuilder spannableBuilder = new SpannableStringBuilder(text);

            RecursivePrepareSpannableIndexes(context,
                                             text, spannableBuilder,
                                             iconFontDescriptors, 0);
            bool isAnimated = HasAnimatedSpans(spannableBuilder);

            if (isAnimated)
            {
                if (target == null)
                {
                    throw new IllegalArgumentException("You can't use \"spin\" without providing the target TextView.");
                }
                if (!(target is IHasOnViewAttachListener))
                {
                    throw new IllegalArgumentException(target.GetType().Name + " does not implement " +
                                                       "HasOnViewAttachListener. Please use IconTextView, IconButton or IconToggleButton.");
                }

                bool isAttached = false;
                var  listener   = new OnViewAttachListener();
                listener.Attach += (s, e) =>
                {
                    isAttached = true;

                    Runnable runnable = null;
                    runnable = new Runnable(() =>
                    {
                        if (isAttached)
                        {
                            target.Invalidate();
                            ViewCompat.PostOnAnimation(target, runnable);
                        }
                    });

                    ViewCompat.PostOnAnimation(target, runnable);
                };

                listener.Detach += (s, e) => isAttached = false;

                ((IHasOnViewAttachListener)target).SetOnViewAttachListener(listener);
            }
            else
            {
                (target as IHasOnViewAttachListener)?.SetOnViewAttachListener(null);
            }

            return(spannableBuilder);
        }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Starts executing the active part of the class' code.
 /// </summary>
 /// <remarks>
 /// <para tool="javadoc-to-mdoc">Starts executing the active part of the class' code. This method is
 /// called when a thread is started that has been created with a class which
 /// implements <c>Runnable</c>.
 /// </para>
 /// <para tool="javadoc-to-mdoc">
 ///   <format type="text/html">
 ///     <a href="http://developer.android.com/reference/java/lang/Runnable.html#run()" target="_blank">[Android Documentation]</a>
 ///   </format>
 /// </para>
 /// </remarks>
 /// <since version="Added in API level 1" />
 public void Run()
 {
     if (_isAttached)
     {
         _view.Invalidate();
         ViewCompat.PostOnAnimation(_view, this);
     }
 }
        /**
         * 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_ANCHOR_POINT}, {@link #STATE_EXPANDED} or {@link #STATE_HIDDEN}.
         */
        public void SetState(int state)
        {
            if (state == _state)
            {
                return;
            }

            /**
             * New behavior (added: state == STATE_ANCHOR_POINT ||)
             */
            if (state == StateCollapsed || state == StateExpanded || state == StateAnchorPoint || (Hideable && state == StateHidden))
            {
                _state           = state;
                _lastStableState = state;
            }

            View child = null;

            if (_viewRef == null)
            {
                _viewRef.TryGetTarget(out child);
            }
            if (child == null)
            {
                return;
            }

            int top;

            if (state == StateCollapsed)
            {
                top = _maxOffset;
            }
            else if (state == StateAnchorPoint)
            {
                top = AnchorPoint;
            }
            else if (state == StateExpanded)
            {
                top = _minOffset;
            }
            else if (Hideable && state == StateHidden)
            {
                top = _parentHeight;
            }
            else
            {
                throw new IllegalArgumentException("Illegal state argument: " + state);
            }

            SetStateInternal(StateSettling);
            if (_viewDragHelper.SmoothSlideViewTo(child, child.Left, top))
            {
                ViewCompat.PostOnAnimation(child, new SettleRunnable(this, child, state));
            }
        }
 public void Run()
 {
     if (_behavior._viewDragHelper != null && _behavior._viewDragHelper.ContinueSettling(true))
     {
         ViewCompat.PostOnAnimation(_view, this);
     }
     else
     {
         _behavior.SetStateInternal(_targetState);
     }
 }
            public override void OnViewReleased(View releasedChild, float xvel, float yvel)
            {
                int top;
                int targetState;

                if (yvel < 0)
                { // Moving up
                    top         = _behavior._minOffset;
                    targetState = StateExpanded;
                }
                else
                if (_behavior.Hideable && _behavior.ShouldHide(releasedChild, yvel))
                {
                    top         = _behavior._parentHeight;
                    targetState = StateHidden;
                }
                else
                if (yvel == 0)
                {
                    int currentTop = releasedChild.Top;
                    if (System.Math.Abs(currentTop - _behavior._minOffset) < System.Math.Abs(currentTop - _behavior._maxOffset))
                    {
                        top         = _behavior._minOffset;
                        targetState = StateExpanded;
                    }
                    else
                    {
                        top         = _behavior._maxOffset;
                        targetState = StateCollapsed;
                    }
                }
                else
                {
                    top         = _behavior._maxOffset;
                    targetState = StateCollapsed;
                }

                // Restrict Collapsed view (optional)
                if (!_behavior.Collapsible && targetState == StateCollapsed)
                {
                    top         = _behavior.AnchorPoint;
                    targetState = StateAnchorPoint;
                }

                if (_behavior._viewDragHelper.SettleCapturedViewAt(releasedChild.Left, top))
                {
                    _behavior.SetStateInternal(StateSettling);
                    ViewCompat.PostOnAnimation(releasedChild, new SettleRunnable(_behavior, releasedChild, targetState));
                }
                else
                {
                    _behavior.SetStateInternal(targetState);
                }
            }
Exemplo n.º 8
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);
                }
            }
Exemplo n.º 9
0
 public void Run()
 {
     if (dragHelper != null && dragHelper.continueSettling(true))
     {
         ViewCompat.PostOnAnimation(this.mView, this);
     }
     else
     {
         Log.d(TAG, "ONSWIPE clamp: " + moveToClamp + " ; moveToRight: " + moveToRight);
         if (moveToClamp && swipeListener != null)
         {
             swipeListener.onSwipeClampReached(SwipeLayout.this, moveToRight);
         }
     }
 }
Exemplo n.º 10
0
        private Java.Lang.IRunnable CreateSettleRunnable(View view, int targetState)
        {
            Java.Lang.IRunnable settleRunnable = null;
            settleRunnable = new Java.Lang.Runnable(() =>
            {
                if (mViewDragHelper != null && mViewDragHelper.ContinueSettling(true))
                {
                    ViewCompat.PostOnAnimation(view, settleRunnable);
                }
                else
                {
                    setStateInternal(targetState);
                }
            });

            return(settleRunnable);
        }
Exemplo n.º 11
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);
                }
            }
Exemplo n.º 12
0
 /// <summary>
 /// Called when [attach].
 /// </summary>
 public void OnAttach()
 {
     _isAttached = true;
     ViewCompat.PostOnAnimation(_view, this);
 }
Exemplo n.º 13
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;
        }
        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;
        }