Code example for Matrix

Methods: mapRect, postConcat, set

0
	public Matrix getDisplayMatrix() {
		return new Matrix(mSuppMatrix);
	} 
 
	public Matrix getImageViewMatrix() {
		mDisplayMatrix.set(mBaseMatrix);
		mDisplayMatrix.postConcat(mSuppMatrix);
		return mDisplayMatrix;
	} 
 
	public float getMaxZoom() { 
		return mMaxZoom;
	} 
 
	@Override 
	public float getRotation() { 
		return 0; 
	} 
 
	public float getScale() { 
		return getScale(mSuppMatrix);
	} 
 
	public void scrollBy(final float x, final float y) {
		panBy(x, y);
	} 
 
	public void setFitToScreen(final boolean value) {
		if (value != mFitToScreen) {
			mFitToScreen = value;
			requestLayout();
		} 
	} 
 
	@Override 
	public void setImageBitmap(final Bitmap bm) {
		setImageBitmap(bm, true);
	} 
 
	/** 
	 * Set the new image to display and reset the internal matrix. 
	 *  
	 * @param bitmap - the {@link Bitmap} to display 
	 * @param reset - if true the image bounds will be recreated, otherwise the 
	 *            old {@link Matrix} is used to display the new bitmap 
	 * @see #setImageBitmap(Bitmap) 
	 */ 
	public void setImageBitmap(final Bitmap bitmap, final boolean reset) {
		setImageBitmap(bitmap, reset, null);
	} 
 
	/** 
	 * Similar to {@link #setImageBitmap(Bitmap, boolean)} but an optional view 
	 * {@link Matrix} can be passed to determine the new bitmap view matrix.<br /> 
	 * This method is useful if you need to restore a Bitmap with the same 
	 * zoom/pan values from a previous state 
	 *  
	 * @param bitmap - the {@link Bitmap} to display 
	 * @param reset 
	 * @param matrix - the {@link Matrix} to be used to display the new bitmap 
	 *  
	 * @see #setImageBitmap(Bitmap, boolean) 
	 * @see #setImageBitmap(Bitmap) 
	 * @see #getImageViewMatrix() 
	 * @see #getDisplayMatrix() 
	 */ 
	public void setImageBitmap(final Bitmap bitmap, final boolean reset, final Matrix matrix) {
		setImageBitmap(bitmap, reset, matrix, -1);
	} 
 
	/** 
	 *  
	 * @param bitmap 
	 * @param reset 
	 * @param matrix 
	 * @param maxZoom - maximum zoom allowd during zoom gestures 
	 *  
	 * @see #setImageBitmap(Bitmap, boolean, Matrix) 
	 */ 
	public void setImageBitmap(final Bitmap bitmap, final boolean reset, final Matrix matrix, final float maxZoom) {
 
		Log.i(LOG_TAG, "setImageBitmap: " + bitmap);
 
		if (bitmap != null) {
			setImageDrawable(new FastBitmapDrawable(bitmap), reset, matrix, maxZoom);
		} else { 
			setImageDrawable(null, reset, matrix, maxZoom);
		} 
	} 
 
	@Override 
	public void setImageDrawable(final Drawable drawable) {
		setImageDrawable(drawable, true, null, -1);
	} 
 
	public void setImageDrawable(final Drawable drawable, final boolean reset, final Matrix initial_matrix,
			final float maxZoom) {
 
		final int viewWidth = getWidth();
 
		if (viewWidth <= 0) {
			mOnLayoutRunnable = new Runnable() {
 
				@Override 
				public void run() { 
					setImageDrawable(drawable, reset, initial_matrix, maxZoom);
				} 
			}; 
			return; 
		} 
 
		_setImageDrawable(drawable, reset, initial_matrix, maxZoom);
	} 
 
	@Override 
	public void setImageResource(final int resId) {
		setImageDrawable(getContext().getResources().getDrawable(resId));
	} 
 
	public void setOnBitmapChangedListener(final OnBitmapChangedListener listener) {
		mListener = listener;
	} 
 
	public void zoomTo(final float scale, final float durationMs) {
		final float cx = getWidth() / 2F;
		final float cy = getHeight() / 2F;
		zoomTo(scale, cx, cy, durationMs);
	} 
 
	protected void _setImageDrawable(final Drawable drawable, final boolean reset, final Matrix initial_matrix,
			final float maxZoom) {
 
		if (drawable != null) {
			if (mFitToScreen) {
				getProperBaseMatrix2(drawable, mBaseMatrix);
			} else { 
				getProperBaseMatrix(drawable, mBaseMatrix);
			} 
			super.setImageDrawable(drawable);
		} else { 
			mBaseMatrix.reset();
			super.setImageDrawable(null); 
		} 
 
		if (reset) {
			mSuppMatrix.reset();
			if (initial_matrix != null) {
				mSuppMatrix = new Matrix(initial_matrix);
			} 
		} 
 
		setImageMatrix(getImageViewMatrix());
 
		if (maxZoom < 1) {
			mMaxZoom = maxZoom();
		} else { 
			mMaxZoom = maxZoom;
		} 
 
		onBitmapChanged(drawable);
	} 
 
	protected void center(final boolean horizontal, final boolean vertical) {
		// Log.i(LOG_TAG, "center"); 
		final Drawable drawable = getDrawable();
 
		if (drawable == null) return;
		final RectF rect = getCenter(horizontal, vertical);
		if (rect.left != 0 || rect.top != 0) {
			postTranslate(rect.left, rect.top);
		} 
	} 
 
	protected RectF getBitmapRect() {
		final Drawable drawable = getDrawable();
 
		if (drawable == null) return null;
		final Matrix m = getImageViewMatrix();
		mBitmapRect.set(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
		m.mapRect(mBitmapRect);
		return mBitmapRect;
	} 
 
	protected RectF getCenter(final boolean horizontal, final boolean vertical) {
		final Drawable drawable = getDrawable();