// 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); }
// 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); }
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 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); }
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); }
// 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); }
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); }
/** * Scrolls to the given screen. */ public void SetCurrentScreen(int screenIndex) { SnapToScreen(Math.Max(0, Math.Min(GetScreenCount() - 1, screenIndex))); }
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); }
public void SetCurrentScreenNow(int screenIndex, bool notify) { SnapToScreen(Math.Max(0, Math.Min(GetScreenCount() - 1, screenIndex)), true, notify); }
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(); }