Example usage for android.view.animation Transformation getMatrix

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

Introduction

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

Prototype

public Matrix getMatrix() 

Source Link

Usage

From source file:com.actionbarsherlock.internal.nineoldandroids.view.animation.AnimatorProxy.java

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    View view = mView.get();//from w ww .j av  a2s  . c  o m
    if (view != null) {
        t.setAlpha(mAlpha);
        transformMatrix(t.getMatrix(), view);
    }
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

@Override
public void onClick(final View v) {

    switch (v.getId()) {

    case R.id.set_button:
        setWallpaper();//from   w ww  .  ja  v  a  2s .c  o  m
        break;
    case R.id.floating_button_icon:
        final GradientDrawable circleDrawable = (GradientDrawable) getResources()
                .getDrawable(R.drawable.floating_button_circle);
        final float scale = (float) ((Math.hypot(addButtonBackground.getX(), addButtonBackground.getY())
                + addButtonBackground.getWidth()) / addButtonBackground.getWidth() * 2);

        Animation animation = new Animation() {

            private boolean needsFragment = true;
            private float pivot;

            @Override
            public void initialize(int width, int height, int parentWidth, int parentHeight) {
                super.initialize(width, height, parentWidth, parentHeight);

                pivot = resolveSize(RELATIVE_TO_SELF, 0.5f, width, parentWidth);
            }

            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {

                if (needsFragment && interpolatedTime >= 1) {
                    needsFragment = false;
                    showSourceAddFragment();
                } else {
                    float scaleFactor = 1.0f + ((scale - 1.0f) * interpolatedTime);
                    t.getMatrix().setScale(scaleFactor, scaleFactor, pivot, pivot);
                }
            }

            @Override
            public boolean willChangeBounds() {
                return true;
            }

        };

        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE));
                addButtonBackground.setImageDrawable(circleDrawable);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (needsButtonReset) {
                            addButton.setOnClickListener(SourceListFragment.this);
                            addButtonBackground.setScaleX(1.0f);
                            addButtonBackground.setScaleY(1.0f);
                            addButtonBackground.clearAnimation();
                            circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE));
                            addButtonBackground.setImageDrawable(circleDrawable);
                            addButton.setVisibility(View.VISIBLE);
                        }
                    }
                }, 100);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

        });

        ValueAnimator buttonColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
                getResources().getColor(R.color.ACCENT_OPAQUE),
                getResources().getColor(AppSettings.getBackgroundColorResource()));
        buttonColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                circleDrawable.setColor((Integer) animation.getAnimatedValue());
                addButtonBackground.setImageDrawable(circleDrawable);
            }

        });

        DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator();

        animation.setDuration(ADD_ANIMATION_TIME);
        buttonColorAnimation.setDuration((long) (ADD_ANIMATION_TIME * 0.9));
        buttonColorAnimation.setInterpolator(decelerateInterpolator);
        animation.setInterpolator(decelerateInterpolator);

        // Post a delayed Runnable to ensure reset even if animation is interrupted
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (needsButtonReset) {
                    addButtonBackground.setScaleX(1.0f);
                    addButtonBackground.setScaleY(1.0f);
                    addButtonBackground.clearAnimation();
                    circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE));
                    addButtonBackground.setImageDrawable(circleDrawable);
                    addButton.setVisibility(View.VISIBLE);
                    needsButtonReset = false;
                }
            }
        }, (long) (ADD_ANIMATION_TIME * 1.1f));

        needsButtonReset = true;
        addButton.setVisibility(View.GONE);
        buttonColorAnimation.start();
        addButtonBackground.startAnimation(animation);
        break;
    default:
    }
}

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();/* w w  w.  j  a  v a 2 s.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;
}