android.graphics.Matrix#MTRANS_X源码实例Demo

下面列出了android.graphics.Matrix#MTRANS_X 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AndroidAnimationExercise   文件: TouchImageView.java
/**
 * 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);
}
 
源代码2 项目: MoeQuest   文件: PhotoImageView.java
@Override
public boolean canScrollHorizontally(int direction) {

  matrix.getValues(m);
  float x = m[Matrix.MTRANS_X];

  if (getImageWidth() < viewWidth) {
    return false;
  } else if (x >= -1 && direction < 0) {
    return false;
  } else if (Math.abs(x) + viewWidth + 1 >= getImageWidth() && direction > 0) {
    return false;
  }

  return true;
}
 
源代码3 项目: iGap-Android   文件: TouchImageView.java
/**
 * 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).
 */
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);
}
 
源代码4 项目: ploggy   文件: TouchImageView.java
/**
 * 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(x, 0), origW);
         finalY = Math.min(Math.max(y, 0), origH);
     }

     return new PointF(finalX , finalY);
}
 
/**
 * 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);
}
 
源代码6 项目: PowerFileExplorer   文件: TouchImageView.java
@Override
public boolean canScrollHorizontally(int direction) {
    matrix.getValues(m);
    float x = m[Matrix.MTRANS_X];

    if (getImageWidth() < viewWidth) {
        return false;

    } else if (x >= -1 && direction < 0) {
        return false;

    } else if (Math.abs(x) + viewWidth + 1 >= getImageWidth() && direction > 0) {
        return false;
    }

    return true;
}
 
源代码7 项目: social-app-android   文件: TouchImageView.java
@Override
public boolean canScrollHorizontally(int direction) {
    matrix.getValues(m);
    float x = m[Matrix.MTRANS_X];

    if (getImageWidth() < viewWidth) {
        return false;

    } else if (x >= -1 && direction < 0) {
        return false;

    } else if (Math.abs(x) + viewWidth + 1 >= getImageWidth() && direction > 0) {
        return false;
    }

    return true;
}
 
源代码8 项目: flow-android   文件: TouchImageView.java
/**
 * 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);
}
 
源代码9 项目: social-app-android   文件: TouchImageView.java
Fling(int velocityX, int velocityY) {
    setState(State.FLING);
    scroller = new CompatScroller(context);
    matrix.getValues(m);

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

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

    } else {
        minX = maxX = startX;
    }

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

    } else {
        minY = maxY = startY;
    }

    scroller.fling(startX, startY, (int) velocityX, (int) velocityY, minX,
            maxX, minY, maxY);
    currX = startX;
    currY = startY;
}
 
源代码10 项目: sealrtc-android   文件: ContainerLayout.java
private PointF getChildTranslateValue() {
    float[] matrixValues = new float[9];
    videoChild.getMatrix().getValues(matrixValues);
    //        Log.d("VideoContainerGesture",
    //            "onTranslate: x " + +", y "
    //                +);
    return new PointF(matrixValues[Matrix.MTRANS_X], matrixValues[Matrix.MTRANS_Y]);
}
 
源代码11 项目: PowerFileExplorer   文件: TouchImageView.java
/**
 * 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 (userSpecifiedMinScale == AUTOMATIC_MIN_ZOOM) {
        setMinZoom(AUTOMATIC_MIN_ZOOM);
        if (normalizedScale < minScale) {
            normalizedScale = minScale;
        }
    }

    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);
}
 
源代码12 项目: JNChartDemo   文件: ViewPortHandler.java
/**
 * 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);
}
 
源代码13 项目: Overchan-Android   文件: TouchGifView.java
private void fixTrans() {
    matrix.getValues(m);
    float transX = m[Matrix.MTRANS_X];
    float transY = m[Matrix.MTRANS_Y];
    float fixTransX = getFixTrans(transX, width, bmWidth*saveScale/realScale);
    float fixTransY = getFixTrans(transY, height, bmHeight*saveScale/realScale);
    if (fixTransX != 0 || fixTransY != 0) {
        matrix.postTranslate(fixTransX, fixTransY);
    }
}
 
源代码14 项目: GankApp   文件: TouchImageView.java
/**
 * 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);
}
 
源代码15 项目: CodePolitan   文件: TouchImageView.java
/**
 * 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);
}
 
源代码16 项目: PicturePicker   文件: ZoomImageView.java
/**
 * 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);
}
 
源代码17 项目: GankApp   文件: TouchImageView.java
Fling(int velocityX, int velocityY) {
    setState(State.FLING);
    scroller = new CompatScroller(context);
    matrix.getValues(m);

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

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

    } else {
        minX = maxX = startX;
    }

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

    } else {
        minY = maxY = startY;
    }

    scroller.fling(startX, startY, (int) velocityX, (int) velocityY, minX,
            maxX, minY, maxY);
    currX = startX;
    currY = startY;
}
 
源代码18 项目: catnut   文件: TouchImageView.java
Fling(int velocityX, int velocityY) {
	setState(FLING);
	scroller = new CompatScroller(context);
	matrix.getValues(m);

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

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

	} else {
		minX = maxX = startX;
	}

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

	} else {
		minY = maxY = startY;
	}

	scroller.fling(startX, startY, (int) velocityX, (int) velocityY, minX,
			maxX, minY, maxY);
	currX = startX;
	currY = startY;
}
 
源代码19 项目: ploggy   文件: TouchImageView.java
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    Drawable drawable = getDrawable();
    if (drawable == null || drawable.getIntrinsicWidth() == 0 || drawable.getIntrinsicHeight() == 0) {
        return;
    }

    int drawableWidth = drawable.getIntrinsicWidth();
    int drawableHeight = drawable.getIntrinsicHeight();
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    viewWidth = setViewSize(widthMode, widthSize, drawableWidth);
    viewHeight = setViewSize(heightMode, heightSize, drawableHeight);

    //
    // Set view dimensions
    //
    setMeasuredDimension(viewWidth, viewHeight);

    //
    // Scale image for view
    //
    float scaleX = (float) viewWidth / drawableWidth;
    float scaleY = (float) viewHeight / drawableHeight;
    float scale = Math.min(scaleX, scaleY);

    //
    // Center the image
    //
    float redundantYSpace = viewHeight - (scale * drawableHeight);
    float redundantXSpace = viewWidth - (scale * drawableWidth);
    matchViewWidth = viewWidth - redundantXSpace;
    matchViewHeight = viewHeight - redundantYSpace;

    if (normalizedScale == 1) {
        //
        // Stretch and center image to fit view
        //
        matrix.setScale(scale, scale);
        matrix.postTranslate(redundantXSpace / 2, redundantYSpace / 2);

    } else {
        prevMatrix.getValues(m);

        //
        // Rescale Matrix after rotation
        //
        m[Matrix.MSCALE_X] = matchViewWidth / drawableWidth * normalizedScale;
        m[Matrix.MSCALE_Y] = matchViewHeight / drawableHeight * normalizedScale;

        //
        // TransX and TransY from previous matrix
        //
        float transX = m[Matrix.MTRANS_X];
        float transY = m[Matrix.MTRANS_Y];

        //
        // Width
        //
        float prevActualWidth = prevMatchViewWidth * normalizedScale;
        float actualWidth = getImageWidth();
        translateMatrixAfterRotate(Matrix.MTRANS_X, transX, prevActualWidth, actualWidth, prevViewWidth, viewWidth, drawableWidth);

        //
        // Height
        //
        float prevActualHeight = prevMatchViewHeight * normalizedScale;
        float actualHeight = getImageHeight();
        translateMatrixAfterRotate(Matrix.MTRANS_Y, transY, prevActualHeight, actualHeight, prevViewHeight, viewHeight, drawableHeight);

        //
        // Set the matrix to the adjusted scale and translate values.
        //
        matrix.setValues(m);
    }
    fixTrans();
    setImageMatrix(matrix);
}
 
源代码20 项目: mobile-manager-tool   文件: QGallery.java
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
	View view = QGallery.this.getSelectedView();
	if (view instanceof QImageView) {
		imageView = (QImageView) view;

		float v[] = new float[9];
		Matrix m = imageView.getImageMatrix();
		m.getValues(v);
		// 图片实时的上下左右坐标
		float left, right;
		// 图片的实时宽,高
		float width, height;
		width = imageView.getScale() * imageView.getImageWidth();
		height = imageView.getScale() * imageView.getImageHeight();
		// 下面逻辑为移动图片和滑动gallery换屏的逻辑。
		if ((int) width <= GalleryActivity.screenWidth && (int) height <= GalleryActivity.screenHeight)// 如果图片当前大小<屏幕大小,直接处理滑屏事件
		{
			if(isScroll)
				super.onScroll(e1, e2, distanceX, distanceY);
		} else {
			left = v[Matrix.MTRANS_X];
			right = left + width;	
			
			if (distanceX > 0)// 手势向左滑动,下一张图
			{
				if (right <= GalleryActivity.screenWidth) {
					super.onScroll(e1, e2, distanceX, distanceY);
				}else {
					imageView.postTranslate(-distanceX, -distanceY);
				}
			} else if (distanceX < 0)// 手势向右滑动,上一张图
			{
				if (left >= 0) {
					super.onScroll(e1, e2, distanceX, distanceY);
				} else {
					imageView.postTranslate(-distanceX, -distanceY);
				}
			}
		}

	} else {
		super.onScroll(e1, e2, distanceX, distanceY);
	}
	return false;
}