Example usage for android.view.animation Transformation clear

List of usage examples for android.view.animation Transformation clear

Introduction

In this page you can find the example usage for android.view.animation Transformation clear.

Prototype

public void clear() 

Source Link

Document

Reset the transformation to a state that leaves the object being animated in an unmodified state.

Usage

From source file:com.inmobi.nativead.sample.photopages.CustomViewPager.java

@Override
protected boolean getChildStaticTransformation(View child, Transformation t) {
    // We can cast here because CustomPagerAdapter only creates wrappers.
    CustomViewPagerItemWrapper item = (CustomViewPagerItemWrapper) child;

    // Since Jelly Bean children won't get invalidated automatically,
    // needs to be added for the smooth coverflow animation
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        item.invalidate();/*from   ww  w  .j a  v  a2s.c o m*/
    }

    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;
}

From source file:android.widget.Gallery.java

@Override
protected boolean getChildStaticTransformation(View child, Transformation t) {

    t.clear();
    t.setAlpha(child == mSelectedChild ? 1.0f : mUnselectedAlpha);

    return true;// w  w  w  .  ja v  a2s. c o  m
}