private static int CalculateMaxPointCountToDisplay() { const int oneMlnPointsRequirement = 8 + 16 + 4 + 8; var memorySize = GetMaxMemorySize() - 40; var maxPointCount = memorySize / oneMlnPointsRequirement * 1000000; return((int)Math.Round(maxPointCount / 3)); }
void SnapScroll() { var roughIndex = (float)_scrollView.ScrollX / _scrollView.Width; var targetIndex = _deltaX < 0 ? Math.Floor(roughIndex) : _deltaX > 0 ? Math.Ceil(roughIndex) : Math.Round(roughIndex); ScrollToIndex((int)targetIndex); }
private Color ShadeColor(Color color, double percent) { var hex = $"#{(0xFFFFFF & color):6x}"; var f = Long.ParseLong(hex.Substring(1), 16); double t = percent < 0 ? 0 : 255; var p = percent < 0 ? percent * -1 : percent; var r = f >> 16; var g = f >> 8 & 0x00FF; var b = f & 0x0000FF; var alpha = Color.GetAlphaComponent(color); var red = (int)(Math.Round((t - r) * p) + r); var green = (int)(Math.Round((t - g) * p) + g); var blue = (int)(Math.Round((t - b) * p) + b); return(Color.Argb(alpha, red, green, blue)); }
void SnapScroll() { try { var roughIndex = (float)_scrollView.ScrollX / _scrollView.Width; var targetIndex = _deltaX < 0 ? System.Math.Floor(roughIndex) : _deltaX > 0 ? Math.Ceil(roughIndex) : Math.Round(roughIndex); ScrollToIndex((int)targetIndex); } catch (System.Exception ex) { } }
public override bool OnTouchEvent(MotionEvent ev) { if (mIsVerbose) { Log.Verbose(TAG, "onTouchEvent: " + ((int)ev.Action & MotionEventCompat.ActionMask)); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.Obtain(); } mVelocityTracker.AddMovement(ev); var action = ev.Action; switch ((int)action & MotionEventCompat.ActionMask) { case (int)MotionEventActions.Down: // If being flinged and user touches, stop the fling. isFinished // will be false if being flinged. if (!mScroller.IsFinished) { mScroller.AbortAnimation(); } // Remember where the motion event started mDownMotionX = ev.GetX(); mDownMotionY = ev.GetY(); mDownScrollX = ScrollX; mActivePointerId = MotionEventCompat.GetPointerId(ev, 0); break; case (int)MotionEventActions.Move: if (mIsVerbose) { Log.Verbose(TAG, "mTouchState=" + mTouchState); } if (mTouchState == TOUCH_STATE_SCROLLING) { // Scroll to follow the motion event int pointerIndex = MotionEventCompat.FindPointerIndex(ev, mActivePointerId); float x = MotionEventCompat.GetX(ev, pointerIndex); View lastChild = GetChildAt(ChildCount - 1); int maxScrollX = lastChild.Right - Width; ScrollTo(Math.Max(0, Math.Min(maxScrollX, (int)(mDownScrollX + mDownMotionX - x ))), 0); if (mOnScrollListener != null) { mOnScrollListener.OnScroll(GetCurrentScreenFraction()); } } else if (mTouchState == TOUCH_STATE_REST) { if (mLocked) { // we're locked on the current screen, don't allow moving break; } /* * Locally do absolute value. mLastMotionX is set to the y value * of the down event. */ int pointerIndex = MotionEventCompat.FindPointerIndex(ev, mActivePointerId); float x = MotionEventCompat.GetX(ev, pointerIndex); float y = MotionEventCompat.GetY(ev, pointerIndex); int xDiff = (int)Math.Abs(x - mDownMotionX); int yDiff = (int)Math.Abs(y - mDownMotionY); bool xPaged = xDiff > mPagingTouchSlop; bool xMoved = xDiff > mTouchSlop; bool yMoved = yDiff > mTouchSlop; if (xMoved || yMoved) { if (xPaged) { // Scroll if the user moved far enough along the X axis mTouchState = TOUCH_STATE_SCROLLING; } // Either way, cancel any pending longpress if (mAllowLongPress) { mAllowLongPress = false; // Try canceling the long press. It could also have been scheduled // by a distant descendant, so use the mAllowLongPress flag to block // everything View currentScreen = GetScreenAt(mCurrentScreen); if (currentScreen != null) { currentScreen.CancelLongPress(); } } } } break; case (int)MotionEventActions.Up: if (mTouchState == TOUCH_STATE_SCROLLING) { int activePointerId = mActivePointerId; int pointerIndex = MotionEventCompat.FindPointerIndex(ev, activePointerId); float x = MotionEventCompat.GetX(ev, pointerIndex); VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.ComputeCurrentVelocity(1000, mMaximumVelocity); //TODO(minsdk8): int velocityX = (int) MotionEventUtils.getXVelocity(velocityTracker, activePointerId); int velocityX = (int)velocityTracker.XVelocity; bool isFling = Math.Abs(mDownMotionX - x) > MIN_LENGTH_FOR_FLING; float scrolledPos = GetCurrentScreenFraction(); int whichScreen = Math.Round(scrolledPos); if (isFling && mIsVerbose) { Log.Verbose(TAG, "isFling, whichScreen=" + whichScreen + " scrolledPos=" + scrolledPos + " mCurrentScreen=" + mCurrentScreen + " velocityX=" + velocityX); } if (isFling && velocityX > SNAP_VELOCITY && mCurrentScreen > 0) { // Fling hard enough to move left // Don't fling across more than one screen at a time. int bound = scrolledPos <= whichScreen ? mCurrentScreen - 1 : mCurrentScreen; SnapToScreen(Math.Min(whichScreen, bound)); } else if (isFling && velocityX < -SNAP_VELOCITY && mCurrentScreen < ChildCount - 1) { // Fling hard enough to move right // Don't fling across more than one screen at a time. int bound = scrolledPos >= whichScreen ? mCurrentScreen + 1 : mCurrentScreen; SnapToScreen(Math.Max(whichScreen, bound)); } else { SnapToDestination(); } } else { PerformClick(); } mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; // Can't do this -> // Intentially fall through to cancel mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.Recycle(); mVelocityTracker = null; } break; case (int)MotionEventActions.Cancel: mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.Recycle(); mVelocityTracker = null; } break; case (int)MotionEventCompat.ActionPointerUp: OnSecondaryPointerUp(ev); break; } return(true); }