Java Code Examples for android.graphics.Matrix#MTRANS_Y

The following examples show how to use android.graphics.Matrix#MTRANS_Y . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TouchImageView.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This function will transform the coordinates in the touch event to the coordinate
 * system of the drawable that the imageview contain
 *
 * @param x            x-coordinate of touch event
 * @param y            y-coordinate of touch event
 * @param clipToBitmap Touch event may occur within view, but outside image content. True, to clip return value
 *                     to the bounds of the bitmap size.
 * @return Coordinates of the point touched, in the coordinate system of the original drawable.
 */
private PointF transformCoordTouchToBitmap(float x, float y, boolean clipToBitmap) {
    matrix.getValues(m);
    float origW = getDrawable().getIntrinsicWidth();
    float origH = getDrawable().getIntrinsicHeight();
    float transX = m[Matrix.MTRANS_X];
    float transY = m[Matrix.MTRANS_Y];
    float finalX = ((x - transX) * origW) / getImageWidth();
    float finalY = ((y - transY) * origH) / getImageHeight();

    if (clipToBitmap) {
        finalX = Math.min(Math.max(finalX, 0), origW);
        finalY = Math.min(Math.max(finalY, 0), origH);
    }

    return new PointF(finalX, finalY);
}
 
Example 2
Source File: TouchImageView.java    From Ecommerce-Morningmist-Android with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
/**
 * Set zoom to the specified scale. Image will be centered around the point
 * (focusX, focusY). These floats range from 0 to 1 and denote the focus point
 * as a fraction from the left and top of the view. For example, the top left 
 * corner of the image would be (0, 0). And the bottom right corner would be (1, 1).
 * @param scale
 * @param focusX
 * @param focusY
 * @param scaleType
 */
public void setZoom(float scale, float focusX, float focusY, ScaleType scaleType) {
	//
	// setZoom can be called before the image is on the screen, but at this point, 
	// image and view sizes have not yet been calculated in onMeasure. Thus, we should
	// delay calling setZoom until the view has been measured.
	//
	if (!onDrawReady) {
		delayedZoomVariables = new ZoomVariables(scale, focusX, focusY, scaleType);
		return;
	}
	
	if (scaleType != mScaleType) {
		setScaleType(scaleType);
	}
	resetZoom();
	scaleImage(scale, viewWidth / 2, viewHeight / 2, true);
	matrix.getValues(m);
	m[Matrix.MTRANS_X] = -((focusX * getImageWidth()) - (viewWidth * 0.5f));
	m[Matrix.MTRANS_Y] = -((focusY * getImageHeight()) - (viewHeight * 0.5f));
	matrix.setValues(m);
	fixTrans();
	setImageMatrix(matrix);
}
 
Example 3
Source File: ViewPortHandler.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example 4
Source File: BarLineChartTouchListener.java    From WaveHeartRate with Apache License 2.0 6 votes vote down vote up
private PointF calcImagePosition(PointF klick) {
    PointF point = new PointF();
    Matrix inverse = new Matrix();
    matrix.invert(inverse);
    float[] pts = new float[2];
    float[] values = new float[9];
    pts[0] = klick.x;
    pts[1] = klick.y;
    inverse.mapPoints(pts);
    matrix.getValues(values);
    Log.d("TouchListener","Pts 0: " + pts[0] + ", Pts 1: " + pts[1]);
    point.x = (klick.x - values[Matrix.MTRANS_X]) / values[Matrix.MSCALE_X];
    point.y = (klick.y - values[Matrix.MTRANS_Y]) / values[Matrix.MSCALE_Y];
    Log.d("TouchListener","Pts X: " + point.x + ", Pts 1: " + point.y);
    return point;
}
 
Example 5
Source File: TouchImageView.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: ViewPortHandler.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
/**
 * limits the maximum scale and X translation of the given matrix
 *
 * @param matrix
 */
public void limitTransAndScale(Matrix matrix, RectF content) {

    matrix.getValues(matrixBuffer);

    float curTransX = matrixBuffer[Matrix.MTRANS_X];
    float curScaleX = matrixBuffer[Matrix.MSCALE_X];

    float curTransY = matrixBuffer[Matrix.MTRANS_Y];
    float curScaleY = matrixBuffer[Matrix.MSCALE_Y];

    // min scale-x is 1f
    mScaleX = Math.min(Math.max(mMinScaleX, curScaleX), mMaxScaleX);

    // min scale-y is 1f
    mScaleY = Math.min(Math.max(mMinScaleY, curScaleY), mMaxScaleY);

    float width = 0f;
    float height = 0f;

    if (content != null) {
        width = content.width();
        height = content.height();
    }

    float maxTransX = -width * (mScaleX - 1f);
    mTransX = Math.min(Math.max(curTransX, maxTransX - mTransOffsetX), mTransOffsetX);

    float maxTransY = height * (mScaleY - 1f);
    mTransY = Math.max(Math.min(curTransY, maxTransY + mTransOffsetY), -mTransOffsetY);

    matrixBuffer[Matrix.MTRANS_X] = mTransX;
    matrixBuffer[Matrix.MSCALE_X] = mScaleX;

    matrixBuffer[Matrix.MTRANS_Y] = mTransY;
    matrixBuffer[Matrix.MSCALE_Y] = mScaleY;

    matrix.setValues(matrixBuffer);
}
 
Example 7
Source File: TouchImageView.java    From GankApp with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Inverse of transformCoordTouchToBitmap. This function will transform the coordinates in the
 * drawable's coordinate system to the view's coordinate system.
 *
 * @param bx x-coordinate in original bitmap coordinate system
 * @param by y-coordinate in original bitmap coordinate system
 * @return Coordinates of the point in the view's coordinate system.
 */
private PointF transformCoordBitmapToTouch(float bx, float by) {
    matrix.getValues(m);
    float origW = getDrawable().getIntrinsicWidth();
    float origH = getDrawable().getIntrinsicHeight();
    float px = bx / origW;
    float py = by / origH;
    float finalX = m[Matrix.MTRANS_X] + getImageWidth() * px;
    float finalY = m[Matrix.MTRANS_Y] + getImageHeight() * py;
    return new PointF(finalX, finalY);
}
 
Example 8
Source File: TouchImageView.java    From ploggy with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Inverse of transformCoordTouchToBitmap. This function will transform the coordinates in the
 * drawable's coordinate system to the view's coordinate system.
 * @param bx x-coordinate in original bitmap coordinate system
 * @param by y-coordinate in original bitmap coordinate system
 * @return Coordinates of the point in the view's coordinate system.
 */
private PointF transformCoordBitmapToTouch(float bx, float by) {
    matrix.getValues(m);
    float origW = getDrawable().getIntrinsicWidth();
    float origH = getDrawable().getIntrinsicHeight();
    float px = bx / origW;
    float py = by / origH;
    float finalX = m[Matrix.MTRANS_X] + getImageWidth() * px;
    float finalY = m[Matrix.MTRANS_Y] + getImageHeight() * py;
    return new PointF(finalX , finalY);
}
 
Example 9
Source File: CropImageView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取图片ImageView周围的边界组成的RectF对象
 */
private RectF getBitmapRect() {

    final Drawable drawable = getDrawable();
    if (drawable == null) {
        return new RectF();
    }

    final float[] matrixValues = new float[9];
    getImageMatrix().getValues(matrixValues);

    final float scaleX = matrixValues[Matrix.MSCALE_X];
    final float scaleY = matrixValues[Matrix.MSCALE_Y];
    final float transX = matrixValues[Matrix.MTRANS_X];
    final float transY = matrixValues[Matrix.MTRANS_Y];

    final int drawableIntrinsicWidth = drawable.getIntrinsicWidth();
    final int drawableIntrinsicHeight = drawable.getIntrinsicHeight();

    final int drawableDisplayWidth = Math.round(drawableIntrinsicWidth * scaleX);
    final int drawableDisplayHeight = Math.round(drawableIntrinsicHeight * scaleY);

    final float left = Math.max(transX, 0);
    final float top = Math.max(transY, 0);
    final float right = Math.min(left + drawableDisplayWidth, getWidth());
    final float bottom = Math.min(top + drawableDisplayHeight, getHeight());

    return new RectF(left, top, right, bottom);
}
 
Example 10
Source File: TouchImageView.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
void fixTrans() {
	matrix.getValues(m);
	float transX = m[Matrix.MTRANS_X];
	float transY = m[Matrix.MTRANS_Y];

	float fixTransX = getFixTrans(transX, viewWidth, origWidth * saveScale);
	float fixTransY = getFixTrans(transY, viewHeight, origHeight
			* saveScale);
	if (BuildConfig.DEBUG)
		Log.d("fixTrans", "fixTransX " + fixTransX + " fixTransY : "
				+ fixTransY);
	if (fixTransX != 0 || fixTransY != 0)
		matrix.postTranslate(fixTransX, fixTransY);
}
 
Example 11
Source File: TouchImageView.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Inverse of transformCoordTouchToBitmap. This function will transform the coordinates in the
 * drawable's coordinate system to the view's coordinate system.
 *
 * @param bx x-coordinate in original bitmap coordinate system
 * @param by y-coordinate in original bitmap coordinate system
 * @return Coordinates of the point in the view's coordinate system.
 */
private PointF transformCoordBitmapToTouch(float bx, float by) {
    matrix.getValues(m);
    float origW = getDrawable().getIntrinsicWidth();
    float origH = getDrawable().getIntrinsicHeight();
    float px = bx / origW;
    float py = by / origH;
    float finalX = m[Matrix.MTRANS_X] + getImageWidth() * px;
    float finalY = m[Matrix.MTRANS_Y] + getImageHeight() * py;
    return new PointF(finalX, finalY);
}
 
Example 12
Source File: TouchImageView.java    From ImageGallery with Apache License 2.0 5 votes vote down vote up
/**
 * Inverse of transformCoordTouchToBitmap. This function will transform the coordinates in the
 * drawable's coordinate system to the view's coordinate system.
 *
 * @param bx x-coordinate in original bitmap coordinate system
 * @param by y-coordinate in original bitmap coordinate system
 * @return Coordinates of the point in the view's coordinate system.
 */
private PointF transformCoordBitmapToTouch(float bx, float by) {
    matrix.getValues(m);
    float origW = getDrawable().getIntrinsicWidth();
    float origH = getDrawable().getIntrinsicHeight();
    float px = bx / origW;
    float py = by / origH;
    float finalX = m[Matrix.MTRANS_X] + getImageWidth() * px;
    float finalY = m[Matrix.MTRANS_Y] + getImageHeight() * py;
    return new PointF(finalX, finalY);
}
 
Example 13
Source File: TouchImageView.java    From TouchNews with Apache License 2.0 5 votes vote down vote up
/**
 * Inverse of transformCoordTouchToBitmap. This function will transform the coordinates in the
 * drawable's coordinate system to the view's coordinate system.
 *
 * @param bx x-coordinate in original bitmap coordinate system
 * @param by y-coordinate in original bitmap coordinate system
 * @return Coordinates of the point in the view's coordinate system.
 */
private PointF transformCoordBitmapToTouch(float bx, float by) {
    matrix.getValues(m);
    float origW = getDrawable().getIntrinsicWidth();
    float origH = getDrawable().getIntrinsicHeight();
    float px = bx / origW;
    float py = by / origH;
    float finalX = m[Matrix.MTRANS_X] + getImageWidth() * px;
    float finalY = m[Matrix.MTRANS_Y] + getImageHeight() * py;
    return new PointF(finalX, finalY);
}
 
Example 14
Source File: TouchImageView.java    From CodePolitan with Apache License 2.0 5 votes vote down vote up
/**
 * Performs boundary checking and fixes the image matrix if it is out of
 * bounds.
 */
private void fixTrans()
{
    matrix.getValues(m);
    float transX = m[Matrix.MTRANS_X];
    float transY = m[Matrix.MTRANS_Y];

    float fixTransX = getFixTrans(transX, viewWidth, getImageWidth());
    float fixTransY = getFixTrans(transY, viewHeight, getImageHeight());

    if (fixTransX != 0 || fixTransY != 0)
    {
        matrix.postTranslate(fixTransX, fixTransY);
    }
}
 
Example 15
Source File: CoupleChartGestureListener.java    From shinny-futures-android with GNU General Public License v3.0 5 votes vote down vote up
private void syncCharts() {
    Matrix srcMatrix;
    float[] srcVals = new float[9];
    Matrix dstMatrix;
    float[] dstVals = new float[9];
    // get src chart translation matrix:
    srcMatrix = srcChart.getViewPortHandler().getMatrixTouch();
    srcMatrix.getValues(srcVals);
    // apply X axis scaling and position to dst charts:
    for (Chart dstChart : dstCharts) {
        dstMatrix = dstChart.getViewPortHandler().getMatrixTouch();
        dstMatrix.getValues(dstVals);

        dstVals[Matrix.MSCALE_X] = srcVals[Matrix.MSCALE_X];
        dstVals[Matrix.MSKEW_X] = srcVals[Matrix.MSKEW_X];
        dstVals[Matrix.MTRANS_X] = srcVals[Matrix.MTRANS_X];
        dstVals[Matrix.MSKEW_Y] = srcVals[Matrix.MSKEW_Y];
        dstVals[Matrix.MSCALE_Y] = srcVals[Matrix.MSCALE_Y];
        dstVals[Matrix.MTRANS_Y] = srcVals[Matrix.MTRANS_Y];
        dstVals[Matrix.MPERSP_0] = srcVals[Matrix.MPERSP_0];
        dstVals[Matrix.MPERSP_1] = srcVals[Matrix.MPERSP_1];
        dstVals[Matrix.MPERSP_2] = srcVals[Matrix.MPERSP_2];

        dstMatrix.setValues(dstVals);
        dstChart.getViewPortHandler().refresh(dstMatrix, dstChart, true);
    }
}
 
Example 16
Source File: ViewPortHandler.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * limits the maximum scale and X translation of the given matrix
 *
 * @param matrix
 */
public void limitTransAndScale(Matrix matrix, RectF content) {

    matrix.getValues(matrixBuffer);

    float curTransX = matrixBuffer[Matrix.MTRANS_X];
    float curScaleX = matrixBuffer[Matrix.MSCALE_X];

    float curTransY = matrixBuffer[Matrix.MTRANS_Y];
    float curScaleY = matrixBuffer[Matrix.MSCALE_Y];

    // min scale-x is 1f
    mScaleX = Math.min(Math.max(mMinScaleX, curScaleX), mMaxScaleX);

    // min scale-y is 1f
    mScaleY = Math.min(Math.max(mMinScaleY, curScaleY), mMaxScaleY);

    float width = 0f;
    float height = 0f;

    if (content != null) {
        width = content.width();
        height = content.height();
    }

    float maxTransX = -width * (mScaleX - 1f);
    mTransX = Math.min(Math.max(curTransX, maxTransX - mTransOffsetX), mTransOffsetX);

    float maxTransY = height * (mScaleY - 1f);
    mTransY = Math.max(Math.min(curTransY, maxTransY + mTransOffsetY), -mTransOffsetY);

    matrixBuffer[Matrix.MTRANS_X] = mTransX;
    matrixBuffer[Matrix.MSCALE_X] = mScaleX;

    matrixBuffer[Matrix.MTRANS_Y] = mTransY;
    matrixBuffer[Matrix.MSCALE_Y] = mScaleY;

    matrix.setValues(matrixBuffer);
}
 
Example 17
Source File: TouchImageView.java    From Travel-Mate with MIT License 5 votes vote down vote up
Fling(int velocityX, int velocityY) {
    setState(State.FLING);
    scroller = new CompatScroller(mContext);
    mMatrix.getValues(mFloat);

    int startX = (int) mFloat[Matrix.MTRANS_X];
    int startY = (int) mFloat[Matrix.MTRANS_Y];
    int minX, maxX, minY, maxY;

    if (getImageWidth() > mViewWidth) {
        minX = mViewWidth - (int) getImageWidth();
        maxX = 0;

    } else {
        minX = maxX = startX;
    }

    if (getImageHeight() > mViewHeight) {
        minY = mViewHeight - (int) getImageHeight();
        maxY = 0;

    } else {
        minY = maxY = startY;
    }

    scroller.fling(startX, startY, velocityX, velocityY, minX,
            maxX, minY, maxY);
    currX = startX;
    currY = startY;
}
 
Example 18
Source File: QGallery.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
	gestureScanner.onTouchEvent(event);
	switch (event.getAction()) {
	case MotionEvent.ACTION_UP:
		// 判断上下边界是否越界
		View view = QGallery.this.getSelectedView();
		if (view instanceof QImageView) {
			imageView = (QImageView) view;
			float width = imageView.getScale() * imageView.getImageWidth();
			float height = imageView.getScale() * imageView.getImageHeight();
			if ((int) width <= GalleryActivity.screenWidth && (int) height <= GalleryActivity.screenHeight)// 如果图片当前大小<屏幕大小,判断边界
			{
				break;
			}
			float v[] = new float[9];
			Matrix m = imageView.getImageMatrix();
			m.getValues(v);
			float top = v[Matrix.MTRANS_Y];
			float bottom = top + height;
			if (top > 0) {
				imageView.postTranslateDur(-top, 200f);
			}
			if (bottom < GalleryActivity.screenHeight) {
				imageView.postTranslateDur(GalleryActivity.screenHeight - bottom, 200f);
			}
		}
		break;
	}
	return super.onTouchEvent(event);
}
 
Example 19
Source File: TouchImageView.java    From PhotoPicker with Apache License 2.0 5 votes vote down vote up
/**
 * Performs boundary checking and fixes the image matrix if it
 * is out of bounds.
 */
private void fixTrans() {
  matrix.getValues(m);
  float transX = m[Matrix.MTRANS_X];
  float transY = m[Matrix.MTRANS_Y];

  float fixTransX = getFixTrans(transX, viewWidth, getImageWidth());
  float fixTransY = getFixTrans(transY, viewHeight, getImageHeight());

  if (fixTransX != 0 || fixTransY != 0) {
    matrix.postTranslate(fixTransX, fixTransY);
  }
}
 
Example 20
Source File: PhotoImageView.java    From MoeQuest with Apache License 2.0 5 votes vote down vote up
/**
 * Inverse of transformCoordTouchToBitmap. This function will transform the coordinates in the
 * drawable's coordinate system to the view's coordinate system.
 *
 * @param bx x-coordinate in original bitmap coordinate system
 * @param by y-coordinate in original bitmap coordinate system
 * @return Coordinates of the point in the view's coordinate system.
 */
private PointF transformCoordBitmapToTouch(float bx, float by) {

  matrix.getValues(m);
  float origW = getDrawable().getIntrinsicWidth();
  float origH = getDrawable().getIntrinsicHeight();
  float px = bx / origW;
  float py = by / origH;
  float finalX = m[Matrix.MTRANS_X] + getImageWidth() * px;
  float finalY = m[Matrix.MTRANS_Y] + getImageHeight() * py;
  return new PointF(finalX, finalY);
}