Java Code Examples for android.view.animation.Transformation#clear()

The following examples show how to use android.view.animation.Transformation#clear() . 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: Gallery.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean getChildStaticTransformation(View child, Transformation t) {
    
    t.clear();
    t.setAlpha(child == mSelectedChild ? 1.0f : mUnselectedAlpha);
    
    return true;
}
 
Example 2
Source File: TwoDScrollerListview.java    From 2DScroller with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean getChildStaticTransformation(View child, Transformation t) {

	int topCenterView = mHeightCenter - mChildrenHeightMiddle;
	int childTop      = Math.max(0,child.getTop());
	float offset      = (-childTop + topCenterView)/ (float) mSpaceBetweenViews;
	final Matrix matrix = t.getMatrix();
	if (offset != 0) {
		float absOffset = Math.abs(offset);
		t.clear();
		t.setTransformationType(Transformation.TYPE_MATRIX);

		float px = child.getLeft() + (child.getWidth()) / 2;
		float py = child.getTop() + (child.getHeight()) / 2; 

		if (mTranslatateEnbabled){
			matrix.setTranslate(mTranslate * absOffset, 0);
		}

		if (offset > 0) {
			matrix.preTranslate(-px,0);
			matrix.postTranslate(px,0);
		} else {
			matrix.preTranslate(-px, -py);
			matrix.postTranslate(px, py);
		}
	}
	return true;
}
 
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;
}
 
Example 4
Source File: CoverFlow.java    From superXingPostCard with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean getChildStaticTransformation(View child, Transformation t) {
    // We can cast here because FancyCoverFlowAdapter only creates wrappers.
    CoverFlowItemWrapper item = (CoverFlowItemWrapper) child;

    // Since Jelly Bean childs won't get invalidated automatically, needs to be added for the smooth coverflow animation
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        item.invalidate();
    }

    final int coverFlowWidth = this.getWidth();
    final int coverFlowCenter = coverFlowWidth / 2;
    final int childWidth = item.getWidth();
    final int childHeight = item.getHeight();
    final int childCenter = item.getLeft() + childWidth / 2;

    // Use coverflow width when its defined as automatic.
    final int actionDistance = (this.actionDistance == ACTION_DISTANCE_AUTO) ? (int) ((coverFlowWidth + childWidth) / 2.0f) : this.actionDistance;

    // Calculate the abstract amount for all effects.
    final float effectsAmount = Math.min(1.0f, Math.max(-1.0f, (1.0f / actionDistance) * (childCenter - coverFlowCenter)));

    // Clear previous transformations and set transformation type (matrix + alpha).
    t.clear();
    t.setTransformationType(Transformation.TYPE_BOTH);

    // Alpha
    if (this.unselectedAlpha != 1) {
        final float alphaAmount = (this.unselectedAlpha - 1) * Math.abs(effectsAmount) + 1;
        t.setAlpha(alphaAmount);
    }

    // Saturation
    if (this.unselectedSaturation != 1) {
        // Pass over saturation to the wrapper.
        final float saturationAmount = (this.unselectedSaturation - 1) * Math.abs(effectsAmount) + 1;
        item.setSaturation(saturationAmount);
    }

    final Matrix imageMatrix = t.getMatrix();

    // Apply rotation.
    if (this.maxRotation != 0) {
        final int rotationAngle = (int) (-effectsAmount * this.maxRotation);
        this.transformationCamera.save();
        this.transformationCamera.rotateY(rotationAngle);
        this.transformationCamera.getMatrix(imageMatrix);
        this.transformationCamera.restore();
    }

    // Zoom.
    if (this.unselectedScale != 1) {
        final float zoomAmount = (this.unselectedScale - 1) * Math.abs(effectsAmount) + 1;
        // Calculate the scale anchor (y anchor can be altered)
        final float translateX = childWidth / 2.0f;
        final float translateY = childHeight * this.scaleDownGravity;
        imageMatrix.preTranslate(-translateX, -translateY);
        imageMatrix.postScale(zoomAmount, zoomAmount);
        imageMatrix.postTranslate(translateX, translateY);
    }

    return true;
}
 
Example 5
Source File: FancyCoverFlow.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean getChildStaticTransformation(View child, Transformation t) {
    // We can cast here because FancyCoverFlowAdapter only creates wrappers.
    FancyCoverFlowItemWrapper item = (FancyCoverFlowItemWrapper) child;

    // Since Jelly Bean childs won't get invalidated automatically, needs to be added for the smooth coverflow animation
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        item.invalidate();
    }

    final int coverFlowWidth = this.getWidth();
    final int coverFlowCenter = coverFlowWidth / 2;
    final int childWidth = item.getWidth();
    final int childHeight = item.getHeight();
    final int childCenter = item.getLeft() + childWidth / 2;

    // Use coverflow width when its defined as automatic.
    final int actionDistance = (this.actionDistance == ACTION_DISTANCE_AUTO) ? (int) ((coverFlowWidth + childWidth) / 2.0f) : this.actionDistance;

    // Calculate the abstract amount for all effects.
    final float effectsAmount = Math.min(1.0f, Math.max(-1.0f, (1.0f / actionDistance) * (childCenter - coverFlowCenter)));

    // Clear previous transformations and set transformation type (matrix + alpha).
    t.clear();
    t.setTransformationType(Transformation.TYPE_BOTH);

    // Alpha
    if (this.unselectedAlpha != 1) {
        final float alphaAmount = (this.unselectedAlpha - 1) * Math.abs(effectsAmount) + 1;
        t.setAlpha(alphaAmount);
    }

    // Saturation
    if (this.unselectedSaturation != 1) {
        // Pass over saturation to the wrapper.
        final float saturationAmount = (this.unselectedSaturation - 1) * Math.abs(effectsAmount) + 1;
        item.setSaturation(saturationAmount);
    }

    final Matrix imageMatrix = t.getMatrix();

    // Apply rotation.
    if (this.maxRotation != 0) {
        final int rotationAngle = (int) (-effectsAmount * this.maxRotation);
        this.transformationCamera.save();
        this.transformationCamera.rotateY(rotationAngle);
        this.transformationCamera.getMatrix(imageMatrix);
        this.transformationCamera.restore();
    }

    // Zoom.
    if (this.unselectedScale != 1) {
        final float zoomAmount = (this.unselectedScale - 1) * Math.abs(effectsAmount) + 1;
        // Calculate the scale anchor (y anchor can be altered)
        final float translateX = childWidth / 2.0f;
        final float translateY = childHeight * this.scaleDownGravity;
        imageMatrix.preTranslate(-translateX, -translateY);
        imageMatrix.postScale(zoomAmount, zoomAmount);
        imageMatrix.postTranslate(translateX, translateY);
    }

    return true;
}
 
Example 6
Source File: FancyCoverFlow.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean getChildStaticTransformation(View child, Transformation t) {
    // We can cast here because FancyCoverFlowAdapter only creates wrappers.
    FancyCoverFlowItemWrapper item = (FancyCoverFlowItemWrapper) child;

    // Since Jelly Bean childs won't get invalidated automatically, needs to be added for the smooth coverflow animation
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        item.invalidate();
    }

    final int coverFlowWidth = this.getWidth();
    final int coverFlowCenter = coverFlowWidth / 2;
    final int childWidth = item.getWidth();
    final int childHeight = item.getHeight();
    final int childCenter = item.getLeft() + childWidth / 2;

    // Use coverflow width when its defined as automatic.
    final int actionDistance = (this.actionDistance == ACTION_DISTANCE_AUTO) ? (int) ((coverFlowWidth + childWidth) / 2.0f) : this.actionDistance;

    // Calculate the abstract amount for all effects.
    final float effectsAmount = Math.min(1.0f, Math.max(-1.0f, (1.0f / actionDistance) * (childCenter - coverFlowCenter)));

    // Clear previous transformations and set transformation type (matrix + alpha).
    t.clear();
    t.setTransformationType(Transformation.TYPE_BOTH);

    // Alpha
    if (this.unselectedAlpha != 1) {
        final float alphaAmount = (this.unselectedAlpha - 1) * Math.abs(effectsAmount) + 1;
        t.setAlpha(alphaAmount);
    }

    // Saturation
    if (this.unselectedSaturation != 1) {
        // Pass over saturation to the wrapper.
        final float saturationAmount = (this.unselectedSaturation - 1) * Math.abs(effectsAmount) + 1;
        item.setSaturation(saturationAmount);
    }

    final Matrix imageMatrix = t.getMatrix();

    // Apply rotation.
    if (this.maxRotation != 0) {
        final int rotationAngle = (int) (-effectsAmount * this.maxRotation);
        this.transformationCamera.save();
        this.transformationCamera.rotateY(rotationAngle);
        this.transformationCamera.getMatrix(imageMatrix);
        this.transformationCamera.restore();
    }

    // Zoom.
    if (this.unselectedScale != 1) {
        final float zoomAmount = (this.unselectedScale - 1) * Math.abs(effectsAmount) + 1;
        // Calculate the scale anchor (y anchor can be altered)
        final float translateX = childWidth / 2.0f;
        final float translateY = childHeight * this.scaleDownGravity;
        imageMatrix.preTranslate(-translateX, -translateY);
        imageMatrix.postScale(zoomAmount, zoomAmount);
        imageMatrix.postTranslate(translateX, translateY);
    }

    return true;
}