Search in sources :

Example 11 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project TextSurface by elevenetc.

the class Rotate3D method start.

@Override
public void start(@Nullable final IEndListener listener) {
    PropertyValuesHolder valHolder = null;
    int fromDegree;
    int toDegree;
    text.setAlpha(255);
    if (show) {
        fromDegree = 90;
        toDegree = 0;
    } else {
        fromDegree = 0;
        toDegree = -90;
    }
    if ((pivot & Pivot.BOTTOM) == Pivot.BOTTOM) {
        valHolder = PropertyValuesHolder.ofFloat("rotationX", fromDegree, toDegree);
        cameraTransXPre = -text.getWidth() / 2;
        cameraTransXPost = text.getWidth() / 2;
        cameraTransYPre = -text.getFontDescent();
        cameraTransYPost = 0;
    } else if ((pivot & Pivot.TOP) == Pivot.TOP) {
        valHolder = PropertyValuesHolder.ofFloat("rotationX", -fromDegree, toDegree);
        cameraTransXPre = -text.getWidth() / 2;
        cameraTransXPost = text.getWidth() / 2;
        cameraTransYPre = text.getHeight() - text.getFontDescent();
        cameraTransYPost = -text.getHeight();
    }
    if ((pivot & Pivot.LEFT) == Pivot.LEFT) {
        valHolder = PropertyValuesHolder.ofFloat("rotationY", fromDegree, toDegree);
        cameraTransXPre = 0;
        cameraTransXPost = 0;
        cameraTransYPre = text.getHeight() / 2 - text.getFontDescent();
        cameraTransYPost = text.getHeight() / 2 - text.getHeight();
    } else if ((pivot & Pivot.RIGHT) == Pivot.RIGHT) {
        valHolder = PropertyValuesHolder.ofFloat("rotationY", -fromDegree, toDegree);
        cameraTransXPre = -text.getWidth();
        cameraTransXPost = text.getWidth();
        cameraTransYPre = text.getHeight() / 2 - text.getFontDescent();
        cameraTransYPost = text.getHeight() / 2 - text.getHeight();
    }
    if ((pivot & Pivot.CENTER) == Pivot.CENTER) {
        valHolder = PropertyValuesHolder.ofFloat(axis == Axis.Y ? "rotationY" : "rotationX", fromDegree, toDegree);
        cameraTransXPre = -text.getWidth() / 2;
        cameraTransXPost = text.getWidth() / 2;
        cameraTransYPre = text.getHeight() / 2 - text.getFontDescent();
        cameraTransYPost = text.getHeight() / 2 - text.getHeight();
    }
    if (valHolder != null) {
        animator = ObjectAnimator.ofPropertyValuesHolder(this, valHolder);
        animator.setInterpolator(new FastOutSlowInInterpolator());
        Utils.addEndListener(this, animator, new IEndListener() {

            @Override
            public void onAnimationEnd(ISurfaceAnimation animation) {
                text.removeEffect(Rotate3D.this);
                if (!show)
                    text.setAlpha(0);
                if (listener != null)
                    listener.onAnimationEnd(Rotate3D.this);
            }
        });
        animator.setDuration(duration);
        animator.addUpdateListener(this);
        animator.start();
    } else {
        throw new RuntimeException(getClass().getSuperclass() + " was not configured properly. Pivot:" + pivot);
    }
}
Also used : ISurfaceAnimation(su.levenetc.android.textsurface.interfaces.ISurfaceAnimation) FastOutSlowInInterpolator(android.support.v4.view.animation.FastOutSlowInInterpolator) PropertyValuesHolder(android.animation.PropertyValuesHolder) IEndListener(su.levenetc.android.textsurface.interfaces.IEndListener) Paint(android.graphics.Paint)

Example 12 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project TextSurface by elevenetc.

the class ScaleSurface method start.

@Override
public void start(@Nullable IEndListener listener) {
    float pivotX;
    float pivotY;
    if (fit == -1) {
        pivotX = textPivot.getPosition().getRelativeX(pivot, textPivot, true);
        pivotY = textPivot.getPosition().getRelativeY(pivot, textPivot, true);
    } else {
        int surfaceWidth = textSurface.getWidth();
        float textWidth = textPivot.getWidth();
        toScale = surfaceWidth / textWidth;
        pivotX = textPivot.getPosition().getRelativeX(Pivot.CENTER, textPivot, true);
        pivotY = textPivot.getPosition().getRelativeY(Pivot.CENTER, textPivot, true);
    }
    PropertyValuesHolder scaleHolder = PropertyValuesHolder.ofFloat("scale", camera.getScale(), toScale);
    PropertyValuesHolder pivotXHolder = PropertyValuesHolder.ofFloat("scalePivotX", camera.getScalePivotX(), pivotX);
    PropertyValuesHolder pivotYHolder = PropertyValuesHolder.ofFloat("scalePivotY", camera.getScalePivotY(), pivotY);
    animator = ObjectAnimator.ofPropertyValuesHolder(camera, scaleHolder, pivotXHolder, pivotYHolder);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    animator.setDuration(duration);
    animator.addUpdateListener(this);
    Utils.addEndListener(this, animator, listener);
    animator.start();
}
Also used : FastOutSlowInInterpolator(android.support.v4.view.animation.FastOutSlowInInterpolator) PropertyValuesHolder(android.animation.PropertyValuesHolder)

Example 13 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project Launcher3 by chislon.

the class LauncherTransitionable method growAndFadeOutFolderIcon.

private void growAndFadeOutFolderIcon(FolderIcon fi) {
    if (fi == null)
        return;
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
    FolderInfo info = (FolderInfo) fi.getTag();
    if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
        CellLayout cl = (CellLayout) fi.getParent().getParent();
        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
        cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
    }
    // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
    copyFolderIconToImage(fi);
    fi.setVisibility(View.INVISIBLE);
    ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, scaleX, scaleY);
    oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
    oa.start();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) PropertyValuesHolder(android.animation.PropertyValuesHolder)

Example 14 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project Launcher3 by chislon.

the class LauncherTransitionable method shrinkAndFadeInFolderIcon.

private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
    if (fi == null)
        return;
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
    final CellLayout cl = (CellLayout) fi.getParent().getParent();
    // We remove and re-draw the FolderIcon in-case it has changed
    mDragLayer.removeView(mFolderIconImageView);
    copyFolderIconToImage(fi);
    ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha, scaleX, scaleY);
    oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration));
    oa.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            if (cl != null) {
                cl.clearFolderLeaveBehind();
                // Remove the ImageView copy of the FolderIcon and make the original visible.
                mDragLayer.removeView(mFolderIconImageView);
                fi.setVisibility(View.VISIBLE);
            }
        }
    });
    oa.start();
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder)

Example 15 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project Signal-Android by WhisperSystems.

the class Tweener method to.

@SuppressLint("NewApi")
public static Tweener to(Object object, long duration, Object... vars) {
    long delay = 0;
    AnimatorUpdateListener updateListener = null;
    AnimatorListener listener = null;
    TimeInterpolator interpolator = null;
    // Iterate through arguments and discover properties to animate
    ArrayList<PropertyValuesHolder> props = new ArrayList<PropertyValuesHolder>(vars.length / 2);
    for (int i = 0; i < vars.length; i += 2) {
        if (!(vars[i] instanceof String)) {
            throw new IllegalArgumentException("Key must be a string: " + vars[i]);
        }
        String key = (String) vars[i];
        Object value = vars[i + 1];
        if ("simultaneousTween".equals(key)) {
        // TODO
        } else if ("ease".equals(key)) {
            // TODO: multiple interpolators?
            interpolator = (TimeInterpolator) value;
        } else if ("onUpdate".equals(key) || "onUpdateListener".equals(key)) {
            updateListener = (AnimatorUpdateListener) value;
        } else if ("onComplete".equals(key) || "onCompleteListener".equals(key)) {
            listener = (AnimatorListener) value;
        } else if ("delay".equals(key)) {
            delay = ((Number) value).longValue();
        } else if ("syncWith".equals(key)) {
        // TODO
        } else if (value instanceof float[]) {
            props.add(PropertyValuesHolder.ofFloat(key, ((float[]) value)[0], ((float[]) value)[1]));
        } else if (value instanceof Number) {
            float floatValue = ((Number) value).floatValue();
            props.add(PropertyValuesHolder.ofFloat(key, floatValue));
        } else {
            throw new IllegalArgumentException("Bad argument for key \"" + key + "\" with value " + value.getClass());
        }
    }
    // Re-use existing tween, if present
    Tweener tween = sTweens.get(object);
    ObjectAnimator anim = null;
    if (tween == null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(object, props.toArray(new PropertyValuesHolder[props.size()]));
        tween = new Tweener(anim);
        sTweens.put(object, tween);
        if (DEBUG)
            Log.v(TAG, "Added new Tweener " + tween);
    } else {
        anim = sTweens.get(object).animator;
        // Cancel all animators for given object
        replace(props, object);
    }
    if (interpolator != null) {
        anim.setInterpolator(interpolator);
    }
    // Update animation with properties discovered in loop above
    anim.setStartDelay(delay);
    anim.setDuration(duration);
    if (updateListener != null) {
        // There should be only one
        anim.removeAllUpdateListeners();
        anim.addUpdateListener(updateListener);
    }
    if (listener != null) {
        // There should be only one.
        anim.removeAllListeners();
        anim.addListener(listener);
    }
    anim.addListener(mCleanupListener);
    anim.start();
    return tween;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) ArrayList(java.util.ArrayList) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) TimeInterpolator(android.animation.TimeInterpolator) SuppressLint(android.annotation.SuppressLint) AnimatorListener(android.animation.Animator.AnimatorListener) PropertyValuesHolder(android.animation.PropertyValuesHolder) SuppressLint(android.annotation.SuppressLint)

Aggregations

PropertyValuesHolder (android.animation.PropertyValuesHolder)210 ObjectAnimator (android.animation.ObjectAnimator)144 Animator (android.animation.Animator)96 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)70 ValueAnimator (android.animation.ValueAnimator)64 Paint (android.graphics.Paint)33 AnimatorSet (android.animation.AnimatorSet)25 NonNull (android.support.annotation.NonNull)18 LinearInterpolator (android.view.animation.LinearInterpolator)18 Interpolator (android.view.animation.Interpolator)16 ArrayList (java.util.ArrayList)16 ViewGroup (android.view.ViewGroup)14 View (android.view.View)12 IntEvaluator (android.animation.IntEvaluator)11 Point (android.graphics.Point)11 Keyframe (android.animation.Keyframe)10 TimeAnimator (android.animation.TimeAnimator)10 Path (android.graphics.Path)10 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)8 Rect (android.graphics.Rect)7