use of android.graphics.Matrix in project android-app-common-tasks by multidots.
the class HighlightView method setup.
public void setup(Matrix m, Rect imageRect, RectF cropRect, boolean circle, boolean maintainAspectRatio) {
if (circle) {
maintainAspectRatio = true;
}
mMatrix = new Matrix(m);
mCropRect = cropRect;
mImageRect = new RectF(imageRect);
mMaintainAspectRatio = maintainAspectRatio;
mCircle = circle;
mInitialAspectRatio = mCropRect.width() / mCropRect.height();
mDrawRect = computeLayout();
mFocusPaint.setARGB(125, 50, 50, 50);
mNoFocusPaint.setARGB(125, 50, 50, 50);
mOutlinePaint.setStrokeWidth(3F);
mOutlinePaint.setStyle(Paint.Style.STROKE);
mOutlinePaint.setAntiAlias(true);
mMode = ModifyMode.None;
init();
}
use of android.graphics.Matrix in project android-app-common-tasks by multidots.
the class ImageViewTouchBase method center.
// Center as much as possible in one or both axis. Centering is
// defined as follows: if the image is scaled down below the
// view's dimensions then center it (literally). If the image
// is scaled larger than the view and is translated out of view
// then translate it back into view (i.e. eliminate black bars).
void center(@SuppressWarnings("SameParameterValue") boolean horizontal, @SuppressWarnings("SameParameterValue") boolean vertical) {
if (mBitmapDisplayed.getBitmap() == null) {
return;
}
Matrix m = getImageViewMatrix();
RectF rect = new RectF(0, 0, mBitmapDisplayed.getBitmap().getWidth(), mBitmapDisplayed.getBitmap().getHeight());
m.mapRect(rect);
float height = rect.height();
float width = rect.width();
float deltaX = 0, deltaY = 0;
if (vertical) {
int viewHeight = getHeight();
if (height < viewHeight) {
deltaY = (viewHeight - height) / 2 - rect.top;
} else if (rect.top > 0) {
deltaY = -rect.top;
} else if (rect.bottom < viewHeight) {
deltaY = getHeight() - rect.bottom;
}
}
if (horizontal) {
int viewWidth = getWidth();
if (width < viewWidth) {
deltaX = (viewWidth - width) / 2 - rect.left;
} else if (rect.left > 0) {
deltaX = -rect.left;
} else if (rect.right < viewWidth) {
deltaX = viewWidth - rect.right;
}
}
postTranslate(deltaX, deltaY);
setImageMatrix(getImageViewMatrix());
}
use of android.graphics.Matrix in project android_frameworks_base by ResurrectionRemix.
the class ChangeTransform method createTransformAnimator.
private ObjectAnimator createTransformAnimator(TransitionValues startValues, TransitionValues endValues, final boolean handleParentChange) {
Matrix startMatrix = (Matrix) startValues.values.get(PROPNAME_MATRIX);
Matrix endMatrix = (Matrix) endValues.values.get(PROPNAME_MATRIX);
if (startMatrix == null) {
startMatrix = Matrix.IDENTITY_MATRIX;
}
if (endMatrix == null) {
endMatrix = Matrix.IDENTITY_MATRIX;
}
if (startMatrix.equals(endMatrix)) {
return null;
}
final Transforms transforms = (Transforms) endValues.values.get(PROPNAME_TRANSFORMS);
// clear the transform properties so that we can use the animation matrix instead
final View view = endValues.view;
setIdentityTransforms(view);
final float[] startMatrixValues = new float[9];
startMatrix.getValues(startMatrixValues);
final float[] endMatrixValues = new float[9];
endMatrix.getValues(endMatrixValues);
final PathAnimatorMatrix pathAnimatorMatrix = new PathAnimatorMatrix(view, startMatrixValues);
PropertyValuesHolder valuesProperty = PropertyValuesHolder.ofObject(NON_TRANSLATIONS_PROPERTY, new FloatArrayEvaluator(new float[9]), startMatrixValues, endMatrixValues);
Path path = getPathMotion().getPath(startMatrixValues[Matrix.MTRANS_X], startMatrixValues[Matrix.MTRANS_Y], endMatrixValues[Matrix.MTRANS_X], endMatrixValues[Matrix.MTRANS_Y]);
PropertyValuesHolder translationProperty = PropertyValuesHolder.ofObject(TRANSLATIONS_PROPERTY, null, path);
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(pathAnimatorMatrix, valuesProperty, translationProperty);
final Matrix finalEndMatrix = endMatrix;
AnimatorListenerAdapter listener = new AnimatorListenerAdapter() {
private boolean mIsCanceled;
private Matrix mTempMatrix = new Matrix();
@Override
public void onAnimationCancel(Animator animation) {
mIsCanceled = true;
}
@Override
public void onAnimationEnd(Animator animation) {
if (!mIsCanceled) {
if (handleParentChange && mUseOverlay) {
setCurrentMatrix(finalEndMatrix);
} else {
view.setTagInternal(R.id.transitionTransform, null);
view.setTagInternal(R.id.parentMatrix, null);
}
}
view.setAnimationMatrix(null);
transforms.restore(view);
}
@Override
public void onAnimationPause(Animator animation) {
Matrix currentMatrix = pathAnimatorMatrix.getMatrix();
setCurrentMatrix(currentMatrix);
}
@Override
public void onAnimationResume(Animator animation) {
setIdentityTransforms(view);
}
private void setCurrentMatrix(Matrix currentMatrix) {
mTempMatrix.set(currentMatrix);
view.setTagInternal(R.id.transitionTransform, mTempMatrix);
transforms.restore(view);
}
};
animator.addListener(listener);
animator.addPauseListener(listener);
return animator;
}
use of android.graphics.Matrix in project android_frameworks_base by ResurrectionRemix.
the class ImageView method animateTransform.
/** @hide */
public void animateTransform(Matrix matrix) {
if (mDrawable == null) {
return;
}
if (matrix == null) {
mDrawable.setBounds(0, 0, getWidth(), getHeight());
} else {
mDrawable.setBounds(0, 0, mDrawableWidth, mDrawableHeight);
if (mDrawMatrix == null) {
mDrawMatrix = new Matrix();
}
mDrawMatrix.set(matrix);
}
invalidate();
}
use of android.graphics.Matrix in project android_frameworks_base by ResurrectionRemix.
the class BitmapDrawable method updateShaderMatrix.
/**
* Updates the {@code paint}'s shader matrix to be consistent with the
* destination size and layout direction.
*
* @param bitmap the bitmap to be drawn
* @param paint the paint used to draw the bitmap
* @param shader the shader to set on the paint
* @param needMirroring whether the bitmap should be mirrored
*/
private void updateShaderMatrix(@NonNull Bitmap bitmap, @NonNull Paint paint, @NonNull Shader shader, boolean needMirroring) {
final int sourceDensity = bitmap.getDensity();
final int targetDensity = mTargetDensity;
final boolean needScaling = sourceDensity != 0 && sourceDensity != targetDensity;
if (needScaling || needMirroring) {
final Matrix matrix = getOrCreateMirrorMatrix();
matrix.reset();
if (needMirroring) {
final int dx = mDstRect.right - mDstRect.left;
matrix.setTranslate(dx, 0);
matrix.setScale(-1, 1);
}
if (needScaling) {
final float densityScale = targetDensity / (float) sourceDensity;
matrix.postScale(densityScale, densityScale);
}
shader.setLocalMatrix(matrix);
} else {
mMirrorMatrix = null;
shader.setLocalMatrix(Matrix.IDENTITY_MATRIX);
}
paint.setShader(shader);
}
Aggregations