// Configures the necessary {@link android.graphics.Matrix}
        // transformation to `mTextureView`.
        // This method should be called after the camera preview size is determined in
        // setUpCameraOutputs and also the size of `mTextureView` is fixed.

        public void ConfigureTransform(int viewWidth, int viewHeight)
        {
            Activity activity = Activity;

            if (null == mTextureView || null == mPreviewSize || null == activity)
            {
                return;
            }
            var    rotation   = (int)activity.WindowManager.DefaultDisplay.Rotation;
            Matrix matrix     = new Matrix();
            RectF  viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            RectF  bufferRect = new RectF(0, 0, mPreviewSize.Height, mPreviewSize.Width);
            float  centreX    = viewRect.CenterX();
            float  centreY    = viewRect.CenterY();

            switch (rotation)
            {
            case (int)SurfaceOrientation.Rotation90:
            case (int)SurfaceOrientation.Rotation270:
            {
                bufferRect.Offset(centreX - bufferRect.CenterX(), centreY - bufferRect.CenterY());
                matrix.SetRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.Fill);
                float scale = Math.Max((float)viewHeight / mPreviewSize.Height, (float)viewWidth / mPreviewSize.Width);
                matrix.PostScale(scale, scale, centreX, centreY);
                matrix.PostRotate(90 * (rotation - 2), centreX, centreY);
                break;
            }

            case (int)SurfaceOrientation.Rotation180:
                matrix.PostRotate(180, centreX, centreY);
                break;
            }
            mTextureView.SetTransform(matrix);
        }
Exemple #2
0
        // Configures the necessary {@link android.graphics.Matrix}
        // transformation to `mTextureView`.
        // This method should be called after the camera preview size is determined in
        // setUpCameraOutputs and also the size of `mTextureView` is fixed.

        public void ConfigureTransform(int viewWidth, int viewHeight)
        {
            var activity = MainActivity.context;

            if (null == mTextureView || null == mPreviewSize || null == activity)
            {
                return;
            }
            var rotation   = (int)activity.WindowManager.DefaultDisplay.Rotation;
            var matrix     = new Matrix();
            var viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            var bufferRect = new RectF(0, 0, mPreviewSize.Height, mPreviewSize.Width);
            var centerX    = viewRect.CenterX();
            var centerY    = viewRect.CenterY();

            if ((int)SurfaceOrientation.Rotation90 == rotation || (int)SurfaceOrientation.Rotation270 == rotation)
            {
                bufferRect.Offset(centerX - bufferRect.CenterX(), centerY - bufferRect.CenterY());
                matrix.SetRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.Fill);
                var scale = Math.Max((float)viewHeight / mPreviewSize.Height, (float)viewWidth / mPreviewSize.Width);
                matrix.PostScale(scale, scale, centerX, centerY);
                matrix.PostRotate(90 * (rotation - 2), centerX, centerY);
            }
            else if ((int)SurfaceOrientation.Rotation180 == rotation)
            {
                matrix.PostRotate(180, centerX, centerY);
            }
            mTextureView.SetTransform(matrix);
        }
Exemple #3
0
        static void CropAndRescaleBitmap(Bitmap src, Bitmap dst,
                                         int sensorOrientation)
        {
            System.Diagnostics.Debug.Assert(dst.Width == dst.Height);

            float minDim = Math.Min(src.Width, src.Height);

            Matrix matrix = new Matrix();

            // We only want the center square out of the original rectangle.
            float translateX = -Math.Max(0, (src.Width - minDim) / 2);
            float translateY = -Math.Max(0, (src.Height - minDim) / 2);

            matrix.PreTranslate(translateX, translateY);

            float scaleFactor = dst.Height / minDim;

            //int RESIZE_SIZE = 256;
            //float scaleFactor = RESIZE_SIZE / minDim;
            matrix.PostScale(scaleFactor, scaleFactor);

            // Rotate around the center if necessary.
            if (sensorOrientation != 0)
            {
                matrix.PostTranslate(-dst.Width / 2.0f, -dst.Height / 2.0f);
                matrix.PostRotate(sensorOrientation);
                matrix.PostTranslate(dst.Width / 2.0f, dst.Height / 2.0f);
            }

            Canvas canvas = new Canvas(dst);

            canvas.DrawBitmap(src, matrix, null);
        }
Exemple #4
0
        private float getFingerSpacing(MotionEvent e)
        {
            float x = e.GetX(0) - e.GetX(1);
            float y = e.GetY(0) - e.GetY(1);

            return((float)Math.Sqrt(x * x + y * y));
        }
        // Configures the necessary {@link android.graphics.Matrix}
        // transformation to `mTextureView`.
        // This method should be called after the camera preview size is determined in
        // setUpCameraOutputs and also the size of `mTextureView` is fixed.

        public void ConfigureTransform(int viewWidth, int viewHeight)
        {
            Activity activity = Activity;

            if (null == _textureView || null == _previewSize || null == activity)
            {
                return;
            }

            var    rotation   = (int)activity.WindowManager.DefaultDisplay.Rotation;
            Matrix matrix     = new Matrix();
            RectF  viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            RectF  bufferRect = new RectF(0, 0, _previewSize.Height, _previewSize.Width);
            float  centerX    = viewRect.CenterX();
            float  centerY    = viewRect.CenterY();

            if (rotation == (int)SurfaceOrientation.Rotation90 || rotation == (int)SurfaceOrientation.Rotation270)
            {
                bufferRect.Offset(centerX - bufferRect.CenterX(), centerY - bufferRect.CenterY());
                matrix.SetRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.Fill);
                float scale = JMath.Max((float)viewHeight / _previewSize.Height, (float)viewWidth / _previewSize.Width);
                matrix.PostScale(scale, scale, centerX, centerY);
                matrix.PostRotate(90 * (rotation - 2), centerX, centerY);
            }
            else if (rotation == (int)SurfaceOrientation.Rotation180)
            {
                matrix.PostRotate(180, centerX, centerY);
            }
            _textureView.SetTransform(matrix);
        }
Exemple #6
0
        private void DrawScale(Canvas canvas)
        {
            canvas.Save(SaveFlags.Matrix);
            // On canvas, North is 0 degrees, East is 90 degrees, South is 180 etc.
            // We start the scale somewhere South-West so we need to first rotate the canvas.
            canvas.Rotate(mScaleRotation, 0.5f, 0.5f);

            int totalTicks = mDivisions * mSubdivisions + 1;

            for (int i = 0; i < totalTicks; i++)
            {
                float y1 = mScaleRect.Top;
                float y2 = y1 + 0.015f; // height of division
                float y3 = y1 + 0.045f; // height of subdivision

                float value = GetValueForTick(i);
                Paint paint = GetRangePaint(value);
                float mod   = value % mDivisionValue;

                if ((Math.Abs(mod - 0) < 0.001) || (Math.Abs(mod - mDivisionValue) < 0.001))
                {
                    // Draw a division tick
                    canvas.DrawLine(0.5f, y1, 0.5f, y3, paint);
                    // Draw the text 0.15 away from the division tick
                    DrawTextOnCanvasWithMagnifier(canvas, ValueString(value), 0.5f, y3 + 0.045f, paint);
                }
                else
                {
                    // Draw a subdivision tick
                    canvas.DrawLine(0.5f, y1, 0.5f, y2, paint);
                }
                canvas.Rotate(mSubdivisionAngle, 0.5f, 0.5f);
            }
            canvas.Restore();
        }
Exemple #7
0
        public void ConfigureTransform(int viewWidth, int viewHeight)
        {
            //var activity = (Activity)_context;
            if (null == _surfaceView || null == _previewSize || null == _context)
            {
                return;
            }

            var windowManager = _context
                                .GetSystemService(Context.WindowService).JavaCast <IWindowManager>();

            ;
            var rotation   = (int)windowManager.DefaultDisplay.Rotation;
            var matrix     = new Matrix();
            var viewRect   = new RectF(0, 0, viewWidth, viewHeight);
            var bufferRect = new RectF(0, 0, _previewSize.Height, _previewSize.Width);
            var centerX    = viewRect.CenterX();
            var centerY    = viewRect.CenterY();

            if ((int)SurfaceOrientation.Rotation90 == rotation || (int)SurfaceOrientation.Rotation270 == rotation)
            {
                bufferRect.Offset(centerX - bufferRect.CenterX(), centerY - bufferRect.CenterY());
                matrix.SetRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.Fill);
                var scale = Math.Max((float)viewHeight / _previewSize.Height, (float)viewWidth / _previewSize.Width);
                matrix.PostScale(scale, scale, centerX, centerY);
                matrix.PostRotate(90 * (rotation - 2), centerX, centerY);
            }
            else if ((int)SurfaceOrientation.Rotation180 == rotation)
            {
                matrix.PostRotate(180, centerX, centerY);
            }

            _surfaceView.SetTransform(matrix);
        }
Exemple #8
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            mCountdownRunnable = new Runnable(() => {
                int remainingSec       = (int)Math.Max(0, (UIUtils.CONFERENCE_START_MILLIS - JavaSystem.CurrentTimeMillis()) / 1000);
                bool conferenceStarted = remainingSec == 0;

                if (conferenceStarted)
                {
                    // Conference started while in countdown mode, switch modes and
                    // bail on future countdown updates.
                    messageHandler.PostDelayed(() => {
                        Refresh();
                    }, 100);
                    return;
                }

                int secs   = remainingSec % 86400;
                int days   = remainingSec / 86400;
                string str = Resources.GetQuantityString(
                    Resource.Plurals.whats_on_countdown_title, days, days,
                    DateUtils.FormatElapsedTime(secs));
                countdownTextView.Text = str;

                // Repost ourselves to keep updating countdown
                messageHandler.PostDelayed(mCountdownRunnable, 1000);
            });

            rootView = (ViewGroup)inflater.Inflate(Resource.Layout.FragmentWhatsOn, container);
            Refresh();
            return(rootView);
        }
        public static void AnimateVisibility(bool show, View view)
        {
            if ((show && view.Visibility == ViewStates.Visible) || !show && view.Visibility != ViewStates.Visible)
            {
                return;
            }

            int   cx     = view.Width / 2;
            int   cy     = view.Height / 2;
            float radius = (float)Math.Hypot(cx, cy);

            if (show)
            {
                Animator anim = ViewAnimationUtils.CreateCircularReveal(view, cx, cy, 0, radius);
                view.Visibility = ViewStates.Visible;
                anim.Start();
            }
            else
            {
                try
                {
                    Animator anim =
                        ViewAnimationUtils.CreateCircularReveal(view, cx, cy, radius, 0);
                    anim.AnimationEnd += delegate { view.Visibility = ViewStates.Invisible; };
                    anim.Start();
                }
                catch (System.Exception)
                {
                    view.Visibility = ViewStates.Invisible;
                }
            }
        }
Exemple #10
0
        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));
        }
Exemple #11
0
        public void getQuaternion(float[] quaternion, int offset)
        {
            if (offset + 4 > quaternion.Length)
            {
                throw new IllegalArgumentException("Not enough space to write the result");
            }

            float[] m = mHeadView;
            float   t = m[0] + m[5] + m[10];
            float   s, w, x, y, z;

            if (t >= 0.0F)
            {
                s = (float)Math.Sqrt(t + 1.0F);
                w = 0.5F * s;
                s = 0.5F / s;
                x = (m[9] - m[6]) * s;
                y = (m[2] - m[8]) * s;
                z = (m[4] - m[1]) * s;
            }
            else
            {
                if ((m[0] > m[5]) && (m[0] > m[10]))
                {
                    s = (float)Math.Sqrt(1.0F + m[0] - m[5] - m[10]);
                    x = s * 0.5F;
                    s = 0.5F / s;
                    y = (m[4] + m[1]) * s;
                    z = (m[2] + m[8]) * s;
                    w = (m[9] - m[6]) * s;
                }
                else
                {
                    if (m[5] > m[10])
                    {
                        s = (float)Math.Sqrt(1.0F + m[5] - m[0] - m[10]);
                        y = s * 0.5F;
                        s = 0.5F / s;
                        x = (m[4] + m[1]) * s;
                        z = (m[9] + m[6]) * s;
                        w = (m[2] - m[8]) * s;
                    }
                    else
                    {
                        s = (float)Math.Sqrt(1.0F + m[10] - m[0] - m[5]);
                        z = s * 0.5F;
                        s = 0.5F / s;
                        x = (m[2] + m[8]) * s;
                        y = (m[9] + m[6]) * s;
                        w = (m[4] - m[1]) * s;
                    }
                }
            }
            quaternion[(offset + 0)] = x;
            quaternion[(offset + 1)] = y;
            quaternion[(offset + 2)] = z;
            quaternion[(offset + 3)] = w;
        }
Exemple #12
0
        /// <summary>
        /// Three-dimensional data standardization method, which divides each
        /// number by the root of the sum of squares of all numbers.
        /// </summary>
        /// <param name="vector">vector.</param>
        public static void NormalizeVec3(float[] vector)
        {
            // This data has three dimensions(0,1,2)
            float length = 1.0f / (float)Math.Sqrt(vector[0] * vector[0] + vector[1] * vector[1] + vector[2] * vector[2]);

            vector[0] *= length;
            vector[1] *= length;
            vector[2] *= length;
        }
        private void ObscureDecorView(float factor)
        {
            float normalizedValue = (factor - MIN_SCALE_FACTOR) / (MAX_SCALE_FACTOR - MIN_SCALE_FACTOR);

            normalizedValue = Math.Min(0.75f, normalizedValue * 2);
            var obscure = Color.Argb((int)(normalizedValue * 255), 0, 0, 0);

            Shadow.SetBackgroundColor(obscure);
        }
Exemple #14
0
        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);
        }
 public bool OnScale(ScaleGestureDetector detector)
 {
     if (ZoomableView == null)
     {
         return(false);
     }
     ScaleFactor        *= detector.ScaleFactor;
     ScaleFactor         = Math.Max(MIN_SCALE_FACTOR, Math.Min(ScaleFactor, MAX_SCALE_FACTOR));
     ZoomableView.ScaleX = ScaleFactor;
     ZoomableView.ScaleY = ScaleFactor;
     ObscureDecorView(ScaleFactor);
     return(true);
 }
Exemple #16
0
        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)
            {
            }
        }
Exemple #18
0
        private void ComputeCurrentValue()
        {
            if (!(Math.Abs(mCurrentValue - mTargetValue) > 0.01f))
            {
                return;
            }

            if (-1 != mNeedleLastMoved)
            {
                float time      = (JavaSystem.CurrentTimeMillis() - mNeedleLastMoved) / 1000.0f;
                float direction = Math.Signum(mNeedleVelocity);
                if (Math.Abs(mNeedleVelocity) < 90.0f)
                {
                    mNeedleAcceleration = 5.0f * (mTargetValue - mCurrentValue);
                }
                else
                {
                    mNeedleAcceleration = 0.0f;
                }

                mNeedleAcceleration = 5.0f * (mTargetValue - mCurrentValue);
                mCurrentValue      += mNeedleVelocity * time;
                mNeedleVelocity    += mNeedleAcceleration * time;

                if ((mTargetValue - mCurrentValue) * direction < 0.01f * direction)
                {
                    mCurrentValue       = mTargetValue;
                    mNeedleVelocity     = 0.0f;
                    mNeedleAcceleration = 0.0f;
                    mNeedleLastMoved    = -1L;
                }
                else
                {
                    mNeedleLastMoved = JavaSystem.CurrentTimeMillis();
                }

                Invalidate();
            }
            else
            {
                mNeedleLastMoved = JavaSystem.CurrentTimeMillis();
                ComputeCurrentValue();
            }
        }
        /// <summary>
        /// Return the previous distance between the two pointers forming the
        /// gesture in progress.
        /// </summary>
        /// <returns>Previous distance between pointers in pixels.</returns>
        public float GetPreviousSpan()
        {
            try
            {
                if (MPrevLen == -1)
                {
                    float pvx = MPrevFingerDiffX;
                    float pvy = MPrevFingerDiffY;
                    MPrevLen = (float)Math.Sqrt(pvx * pvx + pvy * pvy);
                }

                return(MPrevLen);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                return(0);
            }
        }
        public float GetCurrentSpan()
        {
            try
            {
                if (MCurrLen == -1)
                {
                    float cvx = MCurrFingerDiffX;
                    float cvy = MCurrFingerDiffY;
                    MCurrLen = (float)Math.Sqrt(cvx * cvx + cvy * cvy);
                }

                return(MCurrLen);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                return(0);
            }
        }
        protected static double calculateDistance(int txPower, double rssi)
        {
            if (rssi == 0)
            {
                return(-1.0);                // if we cannot determine distance, return -1.
            }

            double ratio = rssi * 1.0 / txPower;

            if (ratio < 1.0)
            {
                return(Math.Pow(ratio, 10));
            }
            else
            {
                double accuracy = (0.89976) * Math.Pow(ratio, 7.7095) + 0.111;
                return(accuracy);
            }
        }
        /// <summary>
        /// Return the previous distance between the two pointers forming the
        /// gesture in progress.
        /// </summary>
        /// <returns>Previous distance between pointers in pixels.</returns>
        public float GetPreviousSpan()
        {
            try
            {
                if (MPrevLen == -1)
                {
                    float pvx = MPrevFingerDiffX;
                    float pvy = MPrevFingerDiffY;
                    MPrevLen = (float)Math.Sqrt(pvx * pvx + pvy * pvy);
                }

                return(MPrevLen);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(0);
            }
        }
        public float GetCurrentSpan()
        {
            try
            {
                if (MCurrLen == -1)
                {
                    float cvx = MCurrFingerDiffX;
                    float cvy = MCurrFingerDiffY;
                    MCurrLen = (float)Math.Sqrt(cvx * cvx + cvy * cvy);
                }

                return(MCurrLen);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(0);
            }
        }
Exemple #24
0
        public void getEulerAngles(float[] eulerAngles, int offset)
        {
            if (offset + 3 > eulerAngles.Length)
            {
                throw new IllegalArgumentException("Not enough space to write the result");
            }

            float yaw, roll, pitch = (float)Math.Asin(mHeadView[6]);

            if ((float)Math.Sqrt(1.0F - mHeadView[6] * mHeadView[6]) >= GIMBAL_LOCK_EPSILON)
            {
                yaw  = (float)Math.Atan2(-mHeadView[2], mHeadView[10]);
                roll = (float)Math.Atan2(-mHeadView[4], mHeadView[5]);
            }
            else
            {
                yaw  = 0.0F;
                roll = (float)Math.Atan2(mHeadView[1], mHeadView[0]);
            }

            eulerAngles[(offset + 0)] = (-pitch);
            eulerAngles[(offset + 1)] = (-yaw);
            eulerAngles[(offset + 2)] = (-roll);
        }
 public void SetCurrentScreenNow(int screenIndex, bool notify)
 {
     SnapToScreen(Math.Max(0, Math.Min(GetScreenCount() - 1, screenIndex)), true, notify);
 }
        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);
        }
 /**
  * Scrolls to the given screen.
  */
 public void SetCurrentScreen(int screenIndex)
 {
     SnapToScreen(Math.Max(0, Math.Min(GetScreenCount() - 1, screenIndex)));
 }
Exemple #28
0
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);
            var time = (float)(DateTimeHelperClass.CurrentUnixTimeMillis() - _startTime) / _period;

            if (_isPlaying)
            {
                for (var i = 3; i >= 0; i--)
                {
                    var y = (float)-(_jumpHeight * Math.Max(0, Math.Sin(time + i / 1.5f)));
                    switch (i)
                    {
                    case 2:
                        _dotOne.TranslationY = y;
                        break;

                    case 1:
                        _dotTwo.TranslationY = y;
                        break;

                    case 0:
                        _dotThree.TranslationY = y;
                        break;
                    }
                }
            }
            else
            {
                for (var i = 3; i >= 0; i--)
                {
                    var y = (float)-(_jumpHeight * Math.Max(0, Math.Sin(time + i / 1.5f)));
                    switch (i)
                    {
                    case 2:
                        if (y == 0 || _lockDotOne)
                        {
                            _lockDotOne          = true;
                            _dotOne.TranslationY = 0;
                        }
                        else
                        {
                            _dotOne.TranslationY = y;
                        }
                        break;

                    case 1:
                        if (y == 0 || _lockDotTwo)
                        {
                            _lockDotTwo          = true;
                            _dotTwo.TranslationY = 0;
                        }
                        else
                        {
                            _dotTwo.TranslationY = y;
                        }
                        break;

                    case 0:
                        if (y == 0 || _lockDotThree)
                        {
                            _lockDotThree          = true;
                            _dotThree.TranslationY = 0;
                        }
                        else
                        {
                            _dotThree.TranslationY = y;
                        }
                        break;
                    }
                }
                if (_lockDotOne && _lockDotTwo && _lockDotThree)
                {
                    //all are in bottom position
                    SetWillNotDraw(true);
                }
            }
            Invalidate();
        }
Exemple #29
0
        public bool OnTouch(View view, MotionEvent motionEvent)
        {
            if (view != LastTouchedView)
            {
                Count           = 0;
                LastTouchedView = view;
            }

            if (motionEvent.Action == MotionEventActions.Up)
            {
                Count = 0;
                return(true);
            }

            if (Count < 2)
            {
                if (Count == 0)
                {
                    HasCloned = false;
                    FirstX    = motionEvent.GetX();
                    FirstY    = motionEvent.GetY();
                }

                Count++;
                return(true);
            }

            float dX = Math.Abs(motionEvent.GetX() - FirstX);
            float dY = Math.Abs(motionEvent.GetY() - FirstY);

            if (LastTouchedView.Parent is RecyclerView && (dX > dY) ||
                LastTouchedView.Parent is LinearLayout && dY > dX)
            {
                return(false);
            }

            if (view is RecyclerBlockView recyclerBlockView)
            {
                if (!HasCloned)
                {
                    // OnTouchListener is set in DragAction.OnDrop, and OnDragListener doesn't need to be set on the BlockView, as it's set in the ctor of ContainerBlockView !
                    LastClonedRbv = recyclerBlockView.Clone();
                    HasCloned     = true;
                }

                view = LastClonedRbv;
            }

            SaveViewPosition(view);

            ClipData clipData = new ClipData("dragged",
                                             new[] { ClipDescription.MimetypeTextPlain },
                                             new ClipData.Item("dragged"));


            if (view.StartDragAndDrop(clipData, new View.DragShadowBuilder(LastTouchedView), view, 0))
            {
                view.Visibility = ViewStates.Invisible;
            }
            else
            {
                if (LastTouchedView is RecyclerBlockView blockView)
                {
                    blockView.RemoveCloneInstance();
                }
            }

            return(true);
        }