/** * Resets all zooming and dragging and makes the chart fit exactly it's * bounds. Output Matrix is available for those who wish to cache the object. */ public void fitScreen(Matrix outputMatrix) { mMinScaleX = 1f; mMinScaleY = 1f; outputMatrix.set(mMatrixTouch); float[] vals = valsBufferForFitScreen; for (int i = 0; i < 9; i++) { vals[i] = 0; } outputMatrix.getValues(vals); // reset all translations and scaling vals[Matrix.MTRANS_X] = 0f; vals[Matrix.MTRANS_Y] = 0f; vals[Matrix.MSCALE_X] = 1f; vals[Matrix.MSCALE_Y] = 1f; outputMatrix.setValues(vals); }
matrixBuffer[Matrix.MSCALE_Y] = mScaleY; matrix.setValues(matrixBuffer);
/** * Save the current matrix and view dimensions * in the prevMatrix and prevView variables. */ public void savePreviousImageValues() { if (matrix != null && viewHeight != 0 && viewWidth != 0) { matrix.getValues(m); prevMatrix.setValues(m); prevMatchViewHeight = matchViewHeight; prevMatchViewWidth = matchViewWidth; prevViewHeight = viewHeight; prevViewWidth = viewWidth; } }
@Override @Nullable public Matrix evaluate(float fraction, @NonNull Matrix startValue, @NonNull Matrix endValue) { startValue.getValues(mTempStartValues); endValue.getValues(mTempEndValues); for (int i = 0; i < 9; i++) { float diff = mTempEndValues[i] - mTempStartValues[i]; mTempEndValues[i] = mTempStartValues[i] + (fraction * diff); } mTempMatrix.setValues(mTempEndValues); return mTempMatrix; } }
mMatrixArray[4] = 1 - 2 * f8 * f8; mMatrix.reset(); mMatrix.setValues(mMatrixArray); mMatrix.preTranslate(-mBezierControl1.x, -mBezierControl1.y); mMatrix.postTranslate(mBezierControl1.x, mBezierControl1.y);
@Override public void onRestoreInstanceState(Parcelable state) { if (state instanceof Bundle) { Bundle bundle = (Bundle) state; normalizedScale = bundle.getFloat("saveScale"); m = bundle.getFloatArray("matrix"); prevMatrix.setValues(m); prevMatchViewHeight = bundle.getFloat("matchViewHeight"); prevMatchViewWidth = bundle.getFloat("matchViewWidth"); prevViewHeight = bundle.getInt("viewHeight"); prevViewWidth = bundle.getInt("viewWidth"); imageRenderedAtLeastOnce = bundle.getBoolean("imageRendered"); viewSizeChangeFixedPixel = (FixedPixel) bundle.getSerializable("viewSizeChangeFixedPixel"); orientationChangeFixedPixel = (FixedPixel) bundle.getSerializable("orientationChangeFixedPixel"); int oldOrientation = bundle.getInt("orientation"); if (orientation != oldOrientation) { orientationJustChanged = true; } super.onRestoreInstanceState(bundle.getParcelable("instanceState")); return; } super.onRestoreInstanceState(state); }
if (np.numbers.size() == 6) { Matrix mat = new Matrix(); mat.setValues(new float[] {
@Test public void testGetSetValues() { final Matrix matrix = new Matrix(); final float[] values = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; matrix.setValues(values); final float[] matrixValues = new float[9]; matrix.getValues(matrixValues); assertThat(matrixValues) .isEqualTo(values); }
@Override protected void applyTransformation(float interpolatedTime, Transformation t) { mAnimRect.left = mStartCropWindowRect.left + (mEndCropWindowRect.left - mStartCropWindowRect.left) * interpolatedTime; mAnimRect.top = mStartCropWindowRect.top + (mEndCropWindowRect.top - mStartCropWindowRect.top) * interpolatedTime; mAnimRect.right = mStartCropWindowRect.right + (mEndCropWindowRect.right - mStartCropWindowRect.right) * interpolatedTime; mAnimRect.bottom = mStartCropWindowRect.bottom + (mEndCropWindowRect.bottom - mStartCropWindowRect.bottom) * interpolatedTime; mCropOverlayView.setCropWindowRect(mAnimRect); for (int i = 0; i < mAnimPoints.length; i++) { mAnimPoints[i] = mStartBoundPoints[i] + (mEndBoundPoints[i] - mStartBoundPoints[i]) * interpolatedTime; } mCropOverlayView.setBounds(mAnimPoints, mImageView.getWidth(), mImageView.getHeight()); for (int i = 0; i < mAnimMatrix.length; i++) { mAnimMatrix[i] = mStartImageMatrix[i] + (mEndImageMatrix[i] - mStartImageMatrix[i]) * interpolatedTime; } Matrix m = mImageView.getImageMatrix(); m.setValues(mAnimMatrix); mImageView.setImageMatrix(m); mImageView.invalidate(); mCropOverlayView.invalidate(); }
matrix.setValues(m);
@Test @Config(sdk = { Build.VERSION_CODES.LOLLIPOP, Build.VERSION_CODES.LOLLIPOP_MR1, Build.VERSION_CODES.M }) public void testIsAffine() { final Matrix matrix = new Matrix(); assertThat(matrix.isAffine()) .isTrue(); matrix.postScale(2.0f, 2.0f); assertThat(matrix.isAffine()) .isTrue(); matrix.postTranslate(1.0f, 2.0f); assertThat(matrix.isAffine()) .isTrue(); matrix.postRotate(45.0f); assertThat(matrix.isAffine()) .isTrue(); matrix.setValues(new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 2.0f }); assertThat(matrix.isAffine()) .isFalse(); }
/** * When transitioning from zooming from focus to zoom from center (or vice versa) * the image can become unaligned within the view. This is apparent when zooming * quickly. When the content size is less than the view size, the content will often * be centered incorrectly within the view. fixScaleTrans first calls fixTrans() and * then makes sure the image is centered correctly within the view. */ private void fixScaleTrans() { fixTrans(); matrix.getValues(m); if (getImageWidth() < viewWidth) { m[Matrix.MTRANS_X] = (viewWidth - getImageWidth()) / 2; } if (getImageHeight() < viewHeight) { m[Matrix.MTRANS_Y] = (viewHeight - getImageHeight()) / 2; } matrix.setValues(m); }
protected void calculateInterpolation(Matrix outMatrix, float fraction) { for (int i = 0; i < 9; i++) { mCurrentValues[i] = (1 - fraction) * mStartValues[i] + fraction * mStopValues[i]; } outMatrix.setValues(mCurrentValues); }
m[Matrix.MTRANS_X] = -((focusX * getImageWidth()) - (viewWidth * 0.5f)); m[Matrix.MTRANS_Y] = -((focusY * getImageHeight()) - (viewHeight * 0.5f)); matrix.setValues(m); fixTrans(); setImageMatrix(matrix);
/** * Save the current matrix and view dimensions * in the prevMatrix and prevView variables. */ private void savePreviousImageValues() { if (matrix != null && viewHeight != 0 && viewWidth != 0) { matrix.getValues(m); prevMatrix.setValues(m); prevMatchViewHeight = matchViewHeight; prevMatchViewWidth = matchViewWidth; prevViewHeight = viewHeight; prevViewWidth = viewWidth; } }
/** * Save the current matrix and view dimensions * in the prevMatrix and prevView variables. */ private void savePreviousImageValues() { if (matrix != null && viewHeight != 0 && viewWidth != 0) { matrix.getValues(m); prevMatrix.setValues(m); prevMatchViewHeight = matchViewHeight; prevMatchViewWidth = matchViewWidth; prevViewHeight = viewHeight; prevViewWidth = viewWidth; } }
@Override public void onRestoreInstanceState(Parcelable state) { if (state instanceof Bundle) { Bundle bundle = (Bundle) state; normalizedScale = bundle.getFloat("saveScale"); m = bundle.getFloatArray("matrix"); prevMatrix.setValues(m); prevMatchViewHeight = bundle.getFloat("matchViewHeight"); prevMatchViewWidth = bundle.getFloat("matchViewWidth"); prevViewHeight = bundle.getInt("viewHeight"); prevViewWidth = bundle.getInt("viewWidth"); imageRenderedAtLeastOnce = bundle.getBoolean("imageRendered"); super.onRestoreInstanceState(bundle.getParcelable("instanceState")); return; } super.onRestoreInstanceState(state); }
@Override public void onRestoreInstanceState(Parcelable state) { if (state instanceof Bundle) { Bundle bundle = (Bundle) state; normalizedScale = bundle.getFloat("saveScale"); m = bundle.getFloatArray("matrix"); prevMatrix.setValues(m); prevMatchViewHeight = bundle.getFloat("matchViewHeight"); prevMatchViewWidth = bundle.getFloat("matchViewWidth"); prevViewHeight = bundle.getInt("viewHeight"); prevViewWidth = bundle.getInt("viewWidth"); imageRenderedAtLeastOnce = bundle.getBoolean("imageRendered"); super.onRestoreInstanceState(bundle.getParcelable("instanceState")); return; } super.onRestoreInstanceState(state); }
/** * When transitioning from zooming from focus to zoom from center (or vice versa) * the image can become unaligned within the view. This is apparent when zooming * quickly. When the content size is less than the view size, the content will often * be centered incorrectly within the view. fixScaleTrans first calls fixTrans() and * then makes sure the image is centered correctly within the view. */ private void fixScaleTrans() { fixTrans(); matrix.getValues(m); if (getImageWidth() < viewWidth) { m[Matrix.MTRANS_X] = (viewWidth - getImageWidth()) / 2; } if (getImageHeight() < viewHeight) { m[Matrix.MTRANS_Y] = (viewHeight - getImageHeight()) / 2; } matrix.setValues(m); }
/** * When transitioning from zooming from focus to zoom from center (or vice versa) * the image can become unaligned within the view. This is apparent when zooming * quickly. When the content size is less than the view size, the content will often * be centered incorrectly within the view. fixScaleTrans first calls fixTrans() and * then makes sure the image is centered correctly within the view. */ private void fixScaleTrans() { fixTrans(); matrix.getValues(m); if (getImageWidth() < viewWidth) { m[Matrix.MTRANS_X] = (viewWidth - getImageWidth()) / 2; } if (getImageHeight() < viewHeight) { m[Matrix.MTRANS_Y] = (viewHeight - getImageHeight()) / 2; } matrix.setValues(m); }