Code example for Matrix

Methods: postConcat, postRotate, reset

0
				baseMatrix.postRotate(orientation);
				if (orientation == 90 || orientation == 270) {
					dwidth = intrinsicHeight;
					dheight = intrinsicWidth;
				} 
			} 
 
			float vwidth = getWidth() - getPaddingLeft() - getPaddingRight();
			float vheight = getHeight() - getPaddingTop() - getPaddingBottom();
 
			RectF dRectF = null;
			RectF vRectF = new RectF(0, 0, vwidth, vheight);
			if (orientation == 0) {
				dRectF = new RectF(0, 0, dwidth, dheight);
			} else if (orientation == 90) {
				dRectF = new RectF(-dwidth, 0, 0, dheight);
			} else if (orientation == 180) {
				dRectF = new RectF(-dwidth, -dheight, 0, 0);
			} else if (orientation == 270) {
				dRectF = new RectF(0, -dheight, dwidth, 0);
			} else { 
				Log.e(TAG, "Invalid value for orientation. Cannot compute the base matrix for the image.");
				return; 
			} 
 
			Matrix m = new Matrix();
			Matrix.ScaleToFit scaleType;
			if (viewWidthDefined && viewHeightDefined) {
				scaleType = Matrix.ScaleToFit.FILL;
			} else { 
				scaleType = Matrix.ScaleToFit.CENTER;
			} 
			m.setRectToRect(dRectF, vRectF, scaleType);
			baseMatrix.postConcat(m);
		} 
	} 
 
	private void updateChangeMatrix(float dscale)
	{ 
		changeMatrix.reset();
		scaleFactor += dscale;
		scaleFactor = Math.max(scaleFactor, scaleMin);
		scaleFactor = Math.min(scaleFactor, scaleMax);
		changeMatrix.postScale(scaleFactor, scaleFactor, getWidth() / 2, getHeight() / 2);
	} 
 
	private Matrix getViewMatrix()
	{ 
		Matrix m = new Matrix(baseMatrix);
		m.postConcat(changeMatrix);
		return m;
	} 
 
	private void scheduleControlTimeout() 
	{ 
		handler.removeMessages(MSG_HIDE_CONTROLS);
		handler.sendEmptyMessageDelayed(MSG_HIDE_CONTROLS, CONTROL_TIMEOUT);
	}