Java Code Examples for android.graphics.Matrix#setConcat()

The following examples show how to use android.graphics.Matrix#setConcat() . 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: CameraCoordinateTransformer.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
private Matrix cameraToPreviewTransform(boolean mirrorX, int displayOrientation,
                                        RectF previewRect)
{
    Matrix transform = new Matrix();

    // Need mirror for front camera.
    transform.setScale(mirrorX ? -1 : 1, 1);

    // Apply a rotate transform.
    // This is the value for android.hardware.Camera.setDisplayOrientation.
    transform.postRotate(displayOrientation);

    // Map camera driver coordinates to preview rect coordinates
    Matrix fill = new Matrix();
    fill.setRectToRect(CAMERA_DRIVER_RECT,
            previewRect,
            Matrix.ScaleToFit.FILL);

    // Concat the previous transform on top of the fill behavior.
    transform.setConcat(fill, transform);

    return transform;
}
 
Example 2
Source File: MaxScaleImageView.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
private void updateScale() {
    Drawable d = getDrawable();
    if(d instanceof BitmapDrawable) {
        BitmapDrawable bd = (BitmapDrawable) d;

        // Don't upscale if more than 2x larger
        if (getWidth() > mMaxScale * bd.getIntrinsicWidth()
                && getHeight() > mMaxScale * bd.getIntrinsicHeight()) {
            setScaleType(ScaleType.MATRIX);
            Matrix trans = new Matrix();
            Matrix scale = new Matrix();
            trans.setTranslate((getWidth() - mMaxScale * bd.getIntrinsicWidth())/2, (getHeight() - mMaxScale * bd.getIntrinsicHeight())/2);
            scale.setScale(mMaxScale, mMaxScale);
            Matrix m = new Matrix();
            
            if(isInEditMode()) {
                // WTF? Edit mode consider inversed matrix??
                m.setConcat(scale, trans);
            }else {
                m.setConcat(trans, scale);
            }
            setImageMatrix(m);
        }else {
            setScaleType(ScaleType.CENTER_CROP);
        }
    }
}
 
Example 3
Source File: HorizontalCarouselLayout.java    From CustomViewSets with Apache License 2.0 4 votes vote down vote up
protected boolean getChildStaticTransformation(View child, Transformation t) {
    Camera camera = new Camera();
    int leftCenterView = this.mWidthCenter - this.mChildrenWidthMiddle;
    float offset = (-child.getLeft() + leftCenterView) /
            this.mSpaceBetweenViews;
    if (offset != 0.0F) {
        float absOffset = Math.abs(offset);
        float scale = (float) Math.pow(0.8999999761581421D, absOffset);
        t.clear();
        t.setTransformationType(Transformation.TYPE_MATRIX);
        t.setAlpha(this.mSetInactiveViewTransparency);
        Matrix m = t.getMatrix();
        m.setScale(scale, scale);
        if (this.mTranslatateEnbabled) {
            m.setTranslate(0.0F, this.mTranslate * absOffset);
        }
        if (offset > 0.0F) {
            camera.save();
            camera.translate(0.0F, 0.0F, this.mViewZoomOutFactor * offset);
            camera.rotateY(this.mCoverflowRotation);
            camera.getMatrix(m);
            camera.restore();
            m.preTranslate(-this.mChildrenWidthMiddle, -this.mChildrenHeight);
            m.postTranslate(this.mChildrenWidthMiddle, this.mChildrenHeight);
        } else {
            camera.save();
            camera.translate(0.0F, 0.0F, -(this.mViewZoomOutFactor * offset));
            camera.rotateY(-this.mCoverflowRotation);
            camera.getMatrix(m);
            camera.restore();
            m.preTranslate(-this.mChildrenWidthMiddle, -this.mChildrenHeight);
            m.postTranslate(this.mChildrenWidthMiddle, this.mChildrenHeight);
        }
        this.mMatrix.reset();
        if (this.mRotationEnabled) {
            this.mMatrix.setRotate(this.mRotation * offset);
        }
        this.mMatrix.preTranslate(-this.mChildrenWidthMiddle, -this.mChildrenHeightMiddle);
        this.mMatrix.postTranslate(this.mChildrenWidthMiddle, this.mChildrenHeightMiddle);
        m.setConcat(m, this.mMatrix);
    }
    return true;
}