Example usage for android.graphics Matrix MSCALE_X

List of usage examples for android.graphics Matrix MSCALE_X

Introduction

In this page you can find the example usage for android.graphics Matrix MSCALE_X.

Prototype

int MSCALE_X

To view the source code for android.graphics Matrix MSCALE_X.

Click Source Link

Usage

From source file:com.diegocarloslima.byakugallery.TouchImageView.java

private void loadMatrixValues() {
    mMatrix.getValues(mMatrixValues);/*from w ww .  j a  va2 s . c o m*/
    mScale = mMatrixValues[Matrix.MSCALE_X];
    mTranslationX = mMatrixValues[Matrix.MTRANS_X];
    mTranslationY = mMatrixValues[Matrix.MTRANS_Y];
}

From source file:com.jsibbold.zoomage.ZoomageView.java

/**
 * Animate the matrix back to its original position after the user stopped interacting with it.
 *///from   w  w w .j  a v a2s. c  o m
private void animateToStartMatrix() {

    final Matrix beginMatrix = new Matrix(getImageMatrix());
    beginMatrix.getValues(mValues);

    //difference in current and original values
    final float xsdiff = startValues[Matrix.MSCALE_X] - mValues[Matrix.MSCALE_X];
    final float ysdiff = startValues[Matrix.MSCALE_Y] - mValues[Matrix.MSCALE_Y];
    final float xtdiff = startValues[Matrix.MTRANS_X] - mValues[Matrix.MTRANS_X];
    final float ytdiff = startValues[Matrix.MTRANS_Y] - mValues[Matrix.MTRANS_Y];

    ValueAnimator anim = ValueAnimator.ofFloat(0, 1f);
    anim.addUpdateListener(new AnimatorUpdateListener() {

        final Matrix activeMatrix = new Matrix(getImageMatrix());
        final float[] values = new float[9];

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float val = (Float) animation.getAnimatedValue();
            activeMatrix.set(beginMatrix);
            activeMatrix.getValues(values);
            values[Matrix.MTRANS_X] = values[Matrix.MTRANS_X] + xtdiff * val;
            values[Matrix.MTRANS_Y] = values[Matrix.MTRANS_Y] + ytdiff * val;
            values[Matrix.MSCALE_X] = values[Matrix.MSCALE_X] + xsdiff * val;
            values[Matrix.MSCALE_Y] = values[Matrix.MSCALE_Y] + ysdiff * val;
            activeMatrix.setValues(values);
            setImageMatrix(activeMatrix);
        }
    });
    anim.setDuration(RESET_DURATION);
    anim.start();
}

From source file:it.mb.whatshare.Utils.java

/**
 * Applies the transformations stored in the array of float values to the
 * argument list of points./*  www.  j  a va2 s. co m*/
 * 
 * <p>
 * The float array can be obtained starting from a {@link Matrix} object by
 * calling <blockquote>
 * 
 * <pre>
 * Matrix myMatrix;
 * float[] matrixValues = new float[9];
 * myMatrix.getValues(matrixValues);
 * </pre>
 * 
 * </blockquote>
 * 
 * @param matrixValues
 *            the values to apply to all points in the list
 * @param points
 *            a list of points to which the transformations in the array
 *            will be applied
 */
public static void applyMatrix(float[] matrixValues, List<PointF> points) {
    // variable names are the same used by Skia library
    final float tx = matrixValues[Matrix.MTRANS_X];
    final float ty = matrixValues[Matrix.MTRANS_Y];
    final float mx = matrixValues[Matrix.MSCALE_X];
    final float my = matrixValues[Matrix.MSCALE_Y];
    final float kx = matrixValues[Matrix.MSKEW_X];
    final float ky = matrixValues[Matrix.MSKEW_Y];
    /*
     * if rotation: skia messes up with the matrix, so sx and sy actually
     * store cosV, rx and ry store -sinV and sinV
     */
    for (PointF point : points) {
        final float originalY = point.y;
        point.y = point.x * ky + (point.y * my) + ty;
        point.x = point.x * mx + (originalY * kx) + tx;
    }
}

From source file:com.goka.flickableview.ImageViewTouchBase.java

public void printMatrix(Matrix matrix) {
    float scaleX = getValue(matrix, Matrix.MSCALE_X);
    float scaleY = getValue(matrix, Matrix.MSCALE_Y);
    float tx = getValue(matrix, Matrix.MTRANS_X);
    float ty = getValue(matrix, Matrix.MTRANS_Y);
    LogUtil.D(TAG, "matrix: { x: " + tx + ", y: " + ty + ", scaleX: " + scaleX + ", scaleY: " + scaleY + " }");
}

From source file:com.goka.flickableview.ImageViewTouchBase.java

protected float getScale(Matrix matrix) {
    return getValue(matrix, Matrix.MSCALE_X);
}

From source file:com.github.colorchief.colorchief.MainActivity.java

private boolean clickInImage(int x, int y, ImageView imageView) {

    //ImageView imageViewer = (ImageView) findViewById(R.id.imageView);

    if (imageView.getVisibility() != View.VISIBLE) {
        return false;
    }//from ww w .  j  a va  2 s .  co  m

    int[] imageViewCoords = new int[2];
    imageView.getLocationOnScreen(imageViewCoords);

    float[] imageViewMatrix = new float[9];
    imageView.getImageMatrix().getValues(imageViewMatrix);
    float scaleX = imageViewMatrix[Matrix.MSCALE_X];
    float scaleY = imageViewMatrix[Matrix.MSCALE_Y];

    Bitmap bitmap = null;
    int bitmapWidth = 0;
    int bitmapHeight = 0;

    try {
        bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        bitmapWidth = bitmap.getWidth();
        bitmapHeight = bitmap.getHeight();
    } catch (NullPointerException npe) {
        Log.e(TAG, "Failed to extract Bitmap from ImageView: " + npe);
    }

    //assuming Bitmap is centred in imageViewer
    int scaledBitmapWidth = Math.round(bitmapWidth * scaleX);
    int scaledBitmapHeight = Math.round(bitmapHeight * scaleY);

    int xOffsetBitmap2imageViewer = (imageView.getWidth() - scaledBitmapWidth) / 2;
    int yOffsetBitmap2imageViewer = (imageView.getHeight() - scaledBitmapHeight) / 2;

    // get total bitmap offset vs. screen origin
    int xTotalOffset = imageViewCoords[0] + xOffsetBitmap2imageViewer;
    int yTotalOffset = imageViewCoords[1] + yOffsetBitmap2imageViewer;

    if ((x >= xTotalOffset) && (x <= xTotalOffset + scaledBitmapWidth) && (y >= yTotalOffset)
            && (y <= yTotalOffset + scaledBitmapHeight)) {
        return true;
    } else {
        return false;
    }
}

From source file:com.test.xujixiao.xjx.widget.view.BaseZoomableImageView.java

protected boolean isScrollOver(float distanceX) {
    try {/*from www .ja  v a2s. c o  m*/
        if (mDisplayMatrix != null) {
            float m_x = getValue(mDisplayMatrix, Matrix.MTRANS_X); //?
            float width = getWidth() - m_x;
            //width  ?+?
            //mBitmap.getWidth() * getValue(mDisplayMatrix, Matrix.MSCALE_X)  ?
            //width == mBitmap.getWidth() * getValue(mDisplayMatrix, Matrix.MSCALE_X) ???? == 0??
            if ((m_x == 0 && distanceX <= 0) //
                    || (width == mBitmap.getWidth() //??
                            * getValue(mDisplayMatrix, Matrix.MSCALE_X) && distanceX >= 0)) {
                System.out.println("ScrollOver");
                return true;
            }
        }
    } catch (IllegalArgumentException e) {
        Log.v("Vincent", "isScrollOver");
        e.printStackTrace();
    }

    return false;
}

From source file:com.afra55.commontutils.ui.imageview.BaseZoomableImageView.java

protected boolean isScrollOver(float distanceX) {
    try {/*  ww  w.j a  v a  2  s . co m*/
        if (mDisplayMatrix != null) {
            float m_x = getValue(mDisplayMatrix, Matrix.MTRANS_X); //?
            float width = getWidth() - m_x;
            //width  ?+? 
            //mBitmap.getWidth() * getValue(mDisplayMatrix, Matrix.MSCALE_X)  ?
            //width == mBitmap.getWidth() * getValue(mDisplayMatrix, Matrix.MSCALE_X) ???? == 0??                        
            if ((m_x == 0 && distanceX <= 0) //
                    || (width == mBitmap.getWidth() //??
                            * getValue(mDisplayMatrix, Matrix.MSCALE_X) && distanceX >= 0)) {
                System.out.println("ScrollOver");
                return true;
            }
        }
    } catch (Exception e) {
        Log.v("MultiTouchZoom", "isScrollOver");
        Log.e("MultiTouchZoom", e.toString());
    }

    return false;
}

From source file:cn.jmessage.android.uikit.pickerimage.view.BaseZoomableImageView.java

protected boolean isScrollOver(float distanceX) {
    try {/* w  ww  .  j  a  v a  2 s. c  o  m*/
        if (mDisplayMatrix != null) {
            float m_x = getValue(mDisplayMatrix, Matrix.MTRANS_X); //?
            float width = getWidth() - m_x;
            //width  ?+? 
            //mBitmap.getWidth() * getValue(mDisplayMatrix, Matrix.MSCALE_X)  ?
            //width == mBitmap.getWidth() * getValue(mDisplayMatrix, Matrix.MSCALE_X) ???? == 0??                        
            if ((m_x == 0 && distanceX <= 0) //
                    || (width == mBitmap.getWidth() //??
                            * getValue(mDisplayMatrix, Matrix.MSCALE_X) && distanceX >= 0)) {
                System.out.println("ScrollOver");
                return true;
            }
        }
    } catch (IllegalArgumentException e) {
        Log.v("Vincent", "isScrollOver");
        e.printStackTrace();
    }

    return false;
}

From source file:com.jsibbold.zoomage.ZoomageView.java

@Override
public boolean onScale(ScaleGestureDetector detector) {

    //calculate value we should scale by, ultimately the scale will be startScale*scaleFactor
    scaleBy = (startScale * detector.getScaleFactor()) / mValues[Matrix.MSCALE_X];

    //what the scaling should end up at after the transformation
    final float projectedScale = scaleBy * mValues[Matrix.MSCALE_X];

    //clamp to the min/max if it's going over
    if (projectedScale < minScale) {
        scaleBy = minScale / mValues[Matrix.MSCALE_X];
    } else if (projectedScale > maxScale) {
        scaleBy = maxScale / mValues[Matrix.MSCALE_X];
    }/*w  ww  .ja va 2 s.  c o m*/

    return false;
}