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:org.que.activities.fragments.MapImageFragment.java

/**
 * The onTouch method which will be called if an onTouch event appears.
 * //  w w w . ja  va2s  .co  m
 * @param view the view which was touched
 * @param event the touch event
 * @return true if the touch event was handled, false otherwise
 */
public boolean onTouch(View view, MotionEvent event) {
    Boolean consumed;
    ImageView image = (ImageView) view;
    switch (event.getAction() & MotionEvent.ACTION_MASK) //bitwise and with mask
    {
    case MotionEvent.ACTION_DOWN:
        saved.set(m);
        p.set(event.getX(), event.getY());
        mode = TOUCH_MODE.DRAG;
        consumed = true;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        mode = TOUCH_MODE.NONE;
        consumed = true;
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        saved.set(m);
        mode = TOUCH_MODE.ZOOM;
        oldDis = euclideanDistance(event);
        p = calcMidPoint(p, event);
        consumed = true;
        break;
    case MotionEvent.ACTION_MOVE:
        if (mode == TOUCH_MODE.ZOOM) {
            m.set(saved);
            newDis = euclideanDistance(event);
            scale = newDis / oldDis;
            m.postScale(scale, scale, p.x, p.y);
            float[] values = new float[9];
            m.getValues(values);
            float mscale = values[Matrix.MSCALE_X];
            if (mscale < MIN_ZOOM) {
                m.setScale(MIN_ZOOM, MIN_ZOOM, p.x, p.y);
            } else if (mscale > MAX_ZOOM) {
                m.setScale(MAX_ZOOM, MAX_ZOOM, p.x, p.y);
            }
        } else if (mode == TOUCH_MODE.DRAG) {
            m.set(saved);
            m.postTranslate(event.getX() - p.x, event.getY() - p.y);
        }
        consumed = true;
        break;
    default:
        consumed = false;

    }
    image.setImageMatrix(m);
    return consumed;
}

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

/**
 * Get the width of the displayed image.
 *
 * @return the current width of the image as displayed (not the width of the {@link ImageView} itself.
 *///from  w w w  .  j  av a 2s. com
private float getCurrentDisplayedWidth() {
    if (getDrawable() != null)
        return getDrawable().getIntrinsicWidth() * mValues[Matrix.MSCALE_X];
    else
        return 0;
}

From source file:com.guodong.sun.guodong.widget.ZoomImageView.java

/**
 * ?/*from w  ww.  j a  v  a2  s  . c  om*/
 *
 * @return
 */
public float getScale() {

    float[] values = new float[9];
    mScaleMatrix.getValues(values);
    return values[Matrix.MSCALE_X];
}

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

/**
 * Remember our starting values so we can animate our image back to its original position.
 */// w  ww .j a  v a  2s  .c o m
private void setStartValues() {
    startValues = new float[9];
    startMatrix = new Matrix(getImageMatrix());
    startMatrix.getValues(startValues);
    minScale *= startValues[Matrix.MSCALE_X];
    maxScale *= startValues[Matrix.MSCALE_X];
}

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

protected float getScale(Matrix matrix) {

    // If the bitmap is set return the scale
    if (mBitmap != null)
        return getValue(matrix, Matrix.MSCALE_X);
    // Otherwise return the default value of 1
    else/* www . j  a  v  a 2s  .co  m*/
        return 1f;
}

From source file:com.frank.protean.photoview.PhotoViewAttacher.java

public float getScale() {
    return (float) Math.sqrt((float) Math.pow(getValue(mSuppMatrix, Matrix.MSCALE_X), 2)
            + (float) Math.pow(getValue(mSuppMatrix, Matrix.MSKEW_Y), 2));
}

From source file:com.hippo.vector.VectorDrawable.java

@Override
@SuppressWarnings("deprecation")
public void draw(Canvas canvas) {
    // We will offset the bounds for drawBitmap, so copyBounds() here instead
    // of getBounds().
    copyBounds(mTmpBounds);//ww  w.  ja v a 2s.  c  om
    if (mTmpBounds.width() <= 0 || mTmpBounds.height() <= 0) {
        // Nothing to draw
        return;
    }

    // Color filters always override tint filters.
    final ColorFilter colorFilter = (mColorFilter == null ? mTintFilter : mColorFilter);

    // The imageView can scale the canvas in different ways, in order to
    // avoid blurry scaling, we have to draw into a bitmap with exact pixel
    // size first. This bitmap size is determined by the bounds and the
    // canvas scale.
    canvas.getMatrix(mTmpMatrix);
    mTmpMatrix.getValues(mTmpFloats);
    float canvasScaleX = Math.abs(mTmpFloats[Matrix.MSCALE_X]);
    float canvasScaleY = Math.abs(mTmpFloats[Matrix.MSCALE_Y]);
    int scaledWidth = (int) (mTmpBounds.width() * canvasScaleX);
    int scaledHeight = (int) (mTmpBounds.height() * canvasScaleY);
    scaledWidth = Math.min(MAX_CACHED_BITMAP_SIZE, scaledWidth);
    scaledHeight = Math.min(MAX_CACHED_BITMAP_SIZE, scaledHeight);

    if (scaledWidth <= 0 || scaledHeight <= 0) {
        return;
    }

    final int saveCount = canvas.save();
    canvas.translate(mTmpBounds.left, mTmpBounds.top);

    // Handle RTL mirroring.
    final boolean needMirroring = needMirroring();
    if (needMirroring) {
        canvas.translate(mTmpBounds.width(), 0);
        canvas.scale(-1.0f, 1.0f);
    }

    // At this point, canvas has been translated to the right position.
    // And we use this bound for the destination rect for the drawBitmap, so
    // we offset to (0, 0);
    mTmpBounds.offsetTo(0, 0);

    mVectorState.createCachedBitmapIfNeeded(scaledWidth, scaledHeight);
    if (!mAllowCaching) {
        mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
    } else {
        if (!mVectorState.canReuseCache()) {
            mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
            mVectorState.updateCacheStates();
        }
    }
    mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter, mTmpBounds);
    canvas.restoreToCount(saveCount);
}

From source file:com.bettervectordrawable.lib.graphics.drawable.VectorDrawable.java

@Override
public void draw(Canvas canvas) {
    // We will offset the bounds for drawBitmap, so copyBounds() here instead
    // of getBounds().
    copyBounds(mTmpBounds);/*from w  w  w  .  ja  va2s .  c  o m*/
    if (mTmpBounds.width() <= 0 || mTmpBounds.height() <= 0) {
        // Nothing to draw
        return;
    }
    // Color filters always override tint filters.
    final ColorFilter colorFilter = (mColorFilter == null ? mTintFilter : mColorFilter);
    // The imageView can scale the canvas in different ways, in order to
    // avoid blurry scaling, we have to draw into a bitmap with exact pixel
    // size first. This bitmap size is determined by the bounds and the
    // canvas scale.
    canvas.getMatrix(mTmpMatrix);
    mTmpMatrix.getValues(mTmpFloats);
    float canvasScaleX = Math.abs(mTmpFloats[Matrix.MSCALE_X]);
    float canvasScaleY = Math.abs(mTmpFloats[Matrix.MSCALE_Y]);
    int scaledWidth = (int) (mTmpBounds.width() * canvasScaleX);
    int scaledHeight = (int) (mTmpBounds.height() * canvasScaleY);
    scaledWidth = Math.min(MAX_CACHED_BITMAP_SIZE, scaledWidth);
    scaledHeight = Math.min(MAX_CACHED_BITMAP_SIZE, scaledHeight);
    if (scaledWidth <= 0 || scaledHeight <= 0) {
        return;
    }
    final int saveCount = canvas.save();
    canvas.translate(mTmpBounds.left, mTmpBounds.top);
    // Handle RTL mirroring.
    final boolean needMirroring = needMirroring();
    if (needMirroring) {
        canvas.translate(mTmpBounds.width(), 0);
        canvas.scale(-1.0f, 1.0f);
    }
    // At this point, canvas has been translated to the right position.
    // And we use this bound for the destination rect for the drawBitmap, so
    // we offset to (0, 0);
    mTmpBounds.offsetTo(0, 0);
    mVectorState.createCachedBitmapIfNeeded(scaledWidth, scaledHeight);
    if (!mAllowCaching) {
        mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
    } else {
        if (!mVectorState.canReuseCache()) {
            mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
            mVectorState.updateCacheStates();
        }
    }
    mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter, mTmpBounds);
    canvas.restoreToCount(saveCount);
}

From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java

@Override
public float getScale() {
    return (float) Math.sqrt((float) Math.pow(getValue(mSuppMatrix, Matrix.MSCALE_X), 2)
            + (float) Math.pow(getValue(mSuppMatrix, Matrix.MSKEW_Y), 2));
}

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

/**
 * Reset the image based on the specified {@link AutoResetMode} mode.
 *//*  w  w w. j a v a2s . co m*/
private void resetImage() {
    switch (autoResetMode) {
    case AutoResetMode.UNDER:
        if (mValues[Matrix.MSCALE_X] <= startValues[Matrix.MSCALE_X]) {
            reset();
        } else {
            center();
        }
        break;
    case AutoResetMode.OVER:
        if (mValues[Matrix.MSCALE_X] >= startValues[Matrix.MSCALE_X]) {
            reset();
        } else {
            center();
        }
        break;
    case AutoResetMode.ALWAYS:
        reset();
        break;
    case AutoResetMode.NEVER:
        center();
    }
}