@Test public void testCenterCropToFitCenter() throws Throwable { transformImage(ImageView.ScaleType.CENTER_CROP, ImageView.ScaleType.FIT_CENTER); verifyMatrixMatches(centerCropMatrix(), mStartMatrix); verifyMatrixMatches(fitCenterMatrix(), mEndMatrix); }
private static Matrix centerCropMatrix(ImageView view) { final Drawable image = view.getDrawable(); final int imageWidth = image.getIntrinsicWidth(); final int imageViewWidth = view.getWidth(); final float scaleX = ((float) imageViewWidth) / imageWidth; final int imageHeight = image.getIntrinsicHeight(); final int imageViewHeight = view.getHeight(); final float scaleY = ((float) imageViewHeight) / imageHeight; final float maxScale = Math.max(scaleX, scaleY); final float width = imageWidth * maxScale; final float height = imageHeight * maxScale; final int tx = Math.round((imageViewWidth - width) / 2f); final int ty = Math.round((imageViewHeight - height) / 2f); final Matrix matrix = new Matrix(); matrix.postScale(maxScale, maxScale); matrix.postTranslate(tx, ty); return matrix; }
ChangeImageTransform extends Transition { private static Matrix centerCropMatrix(ImageView view) { final Drawable image = view.getDrawable(); final int imageWidth = image.getIntrinsicWidth(); final int imageViewWidth = view.getWidth(); final float scaleX = ((float) imageViewWidth) / imageWidth; final int imageHeight = image.getIntrinsicHeight(); final int imageViewHeight = view.getHeight(); final float scaleY = ((float) imageViewHeight) / imageHeight; final float maxScale = Math.max(scaleX, scaleY); final float width = imageWidth * maxScale; final float height = imageHeight * maxScale; final int tx = Math.round((imageViewWidth - width) / 2f); final int ty = Math.round((imageViewHeight - height) / 2f); final Matrix matrix = new Matrix(); matrix.postScale(maxScale, maxScale); matrix.postTranslate(tx, ty); return matrix; } }
ChangeImageTransform extends Transition { private static Matrix centerCropMatrix(ImageView view) { final Drawable image = view.getDrawable(); final int imageWidth = image.getIntrinsicWidth(); final int imageViewWidth = view.getWidth(); final float scaleX = ((float) imageViewWidth) / imageWidth; final int imageHeight = image.getIntrinsicHeight(); final int imageViewHeight = view.getHeight(); final float scaleY = ((float) imageViewHeight) / imageHeight; final float maxScale = Math.max(scaleX, scaleY); final float width = imageWidth * maxScale; final float height = imageHeight * maxScale; final int tx = Math.round((imageViewWidth - width) / 2f); final int ty = Math.round((imageViewHeight - height) / 2f); final Matrix matrix = new Matrix(); matrix.postScale(maxScale, maxScale); matrix.postTranslate(tx, ty); return matrix; } ChangeImageTransform();  ChangeImageTransform(Context context, AttributeSet attrs); }
ChangeImageTransform extends Transition { private static Matrix centerCropMatrix(ImageView view) { final Drawable image = view.getDrawable(); final int imageWidth = image.getIntrinsicWidth(); final int imageViewWidth = view.getWidth(); final float scaleX = ((float) imageViewWidth) / imageWidth; final int imageHeight = image.getIntrinsicHeight(); final int imageViewHeight = view.getHeight(); final float scaleY = ((float) imageViewHeight) / imageHeight; final float maxScale = Math.max(scaleX, scaleY); final float width = imageWidth * maxScale; final float height = imageHeight * maxScale; final int tx = Math.round((imageViewWidth - width) / 2f); final int ty = Math.round((imageViewHeight - height) / 2f); final Matrix matrix = new Matrix(); matrix.postScale(maxScale, maxScale); matrix.postTranslate(tx, ty); return matrix; } ChangeImageTransform();  ChangeImageTransform(Context context, AttributeSet attrs); @Override void captureStartValues(@NonNull TransitionValues transitionValues); @Override void captureEndValues(@NonNull TransitionValues transitionValues); @Override String[] getTransitionProperties(); @Override Animator createAnimator(@NonNull ViewGroup sceneRoot, TransitionValues startValues,
            final TransitionValues endValues); }
ChangeImageTransform extends Transition { private static Matrix centerCropMatrix(ImageView view) { final Drawable image = view.getDrawable(); final int imageWidth = image.getIntrinsicWidth(); final int imageViewWidth = view.getWidth(); final float scaleX = ((float) imageViewWidth) / imageWidth; final int imageHeight = image.getIntrinsicHeight(); final int imageViewHeight = view.getHeight(); final float scaleY = ((float) imageViewHeight) / imageHeight; final float maxScale = Math.max(scaleX, scaleY); final float width = imageWidth * maxScale; final float height = imageHeight * maxScale; final int tx = Math.round((imageViewWidth - width) / 2f); final int ty = Math.round((imageViewHeight - height) / 2f); final Matrix matrix = new Matrix(); matrix.postScale(maxScale, maxScale); matrix.postTranslate(tx, ty); return matrix; } ChangeImageTransform();  ChangeImageTransform(Context context, AttributeSet attrs); @Override void captureStartValues(@NonNull TransitionValues transitionValues); @Override void captureEndValues(@NonNull TransitionValues transitionValues); @Override String[] getTransitionProperties(); @Override Animator createAnimator(@NonNull ViewGroup sceneRoot, TransitionValues startValues,
            final TransitionValues endValues);  }