Search in sources :

Example 71 with Animator

use of android.animation.Animator in project platform_frameworks_base by android.

the class FastScroller method transitionPreviewLayout.

/**
     * Transitions the preview text to a new section. Handles animation,
     * measurement, and layout. If the new preview text is empty, returns false.
     *
     * @param sectionIndex The section index to which the preview should
     *            transition.
     * @return False if the new preview text is empty.
     */
private boolean transitionPreviewLayout(int sectionIndex) {
    final Object[] sections = mSections;
    String text = null;
    if (sections != null && sectionIndex >= 0 && sectionIndex < sections.length) {
        final Object section = sections[sectionIndex];
        if (section != null) {
            text = section.toString();
        }
    }
    final Rect bounds = mTempBounds;
    final View preview = mPreviewImage;
    final TextView showing;
    final TextView target;
    if (mShowingPrimary) {
        showing = mPrimaryText;
        target = mSecondaryText;
    } else {
        showing = mSecondaryText;
        target = mPrimaryText;
    }
    // Set and layout target immediately.
    target.setText(text);
    measurePreview(target, bounds);
    applyLayout(target, bounds);
    if (mPreviewAnimation != null) {
        mPreviewAnimation.cancel();
    }
    // Cross-fade preview text.
    final Animator showTarget = animateAlpha(target, 1f).setDuration(DURATION_CROSS_FADE);
    final Animator hideShowing = animateAlpha(showing, 0f).setDuration(DURATION_CROSS_FADE);
    hideShowing.addListener(mSwitchPrimaryListener);
    // Apply preview image padding and animate bounds, if necessary.
    bounds.left -= preview.getPaddingLeft();
    bounds.top -= preview.getPaddingTop();
    bounds.right += preview.getPaddingRight();
    bounds.bottom += preview.getPaddingBottom();
    final Animator resizePreview = animateBounds(preview, bounds);
    resizePreview.setDuration(DURATION_RESIZE);
    mPreviewAnimation = new AnimatorSet();
    final AnimatorSet.Builder builder = mPreviewAnimation.play(hideShowing).with(showTarget);
    builder.with(resizePreview);
    // The current preview size is unaffected by hidden or showing. It's
    // used to set starting scales for things that need to be scaled down.
    final int previewWidth = preview.getWidth() - preview.getPaddingLeft() - preview.getPaddingRight();
    // If target is too large, shrink it immediately to fit and expand to
    // target size. Otherwise, start at target size.
    final int targetWidth = target.getWidth();
    if (targetWidth > previewWidth) {
        target.setScaleX((float) previewWidth / targetWidth);
        final Animator scaleAnim = animateScaleX(target, 1f).setDuration(DURATION_RESIZE);
        builder.with(scaleAnim);
    } else {
        target.setScaleX(1f);
    }
    // If showing is larger than target, shrink to target size.
    final int showingWidth = showing.getWidth();
    if (showingWidth > targetWidth) {
        final float scale = (float) targetWidth / showingWidth;
        final Animator scaleAnim = animateScaleX(showing, scale).setDuration(DURATION_RESIZE);
        builder.with(scaleAnim);
    }
    mPreviewAnimation.start();
    return !TextUtils.isEmpty(text);
}
Also used : Rect(android.graphics.Rect) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet) View(android.view.View)

Example 72 with Animator

use of android.animation.Animator in project platform_frameworks_base by android.

the class FastScroller method transitionToVisible.

/**
     * Shows the thumb and track.
     */
private void transitionToVisible() {
    if (mDecorAnimation != null) {
        mDecorAnimation.cancel();
    }
    final Animator fadeIn = groupAnimatorOfFloat(View.ALPHA, 1f, mThumbImage, mTrackImage).setDuration(DURATION_FADE_IN);
    final Animator fadeOut = groupAnimatorOfFloat(View.ALPHA, 0f, mPreviewImage, mPrimaryText, mSecondaryText).setDuration(DURATION_FADE_OUT);
    final Animator slideIn = groupAnimatorOfFloat(View.TRANSLATION_X, 0f, mThumbImage, mTrackImage).setDuration(DURATION_FADE_IN);
    mDecorAnimation = new AnimatorSet();
    mDecorAnimation.playTogether(fadeIn, fadeOut, slideIn);
    mDecorAnimation.start();
    mShowingPreview = false;
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet)

Example 73 with Animator

use of android.animation.Animator in project android-ripple-background by skyfishjy.

the class RippleBackground method init.

private void init(final Context context, final AttributeSet attrs) {
    if (isInEditMode())
        return;
    if (null == attrs) {
        throw new IllegalArgumentException("Attributes should be provided to this view,");
    }
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleBackground);
    rippleColor = typedArray.getColor(R.styleable.RippleBackground_rb_color, getResources().getColor(R.color.rippelColor));
    rippleStrokeWidth = typedArray.getDimension(R.styleable.RippleBackground_rb_strokeWidth, getResources().getDimension(R.dimen.rippleStrokeWidth));
    rippleRadius = typedArray.getDimension(R.styleable.RippleBackground_rb_radius, getResources().getDimension(R.dimen.rippleRadius));
    rippleDurationTime = typedArray.getInt(R.styleable.RippleBackground_rb_duration, DEFAULT_DURATION_TIME);
    rippleAmount = typedArray.getInt(R.styleable.RippleBackground_rb_rippleAmount, DEFAULT_RIPPLE_COUNT);
    rippleScale = typedArray.getFloat(R.styleable.RippleBackground_rb_scale, DEFAULT_SCALE);
    rippleType = typedArray.getInt(R.styleable.RippleBackground_rb_type, DEFAULT_FILL_TYPE);
    typedArray.recycle();
    rippleDelay = rippleDurationTime / rippleAmount;
    paint = new Paint();
    paint.setAntiAlias(true);
    if (rippleType == DEFAULT_FILL_TYPE) {
        rippleStrokeWidth = 0;
        paint.setStyle(Paint.Style.FILL);
    } else
        paint.setStyle(Paint.Style.STROKE);
    paint.setColor(rippleColor);
    rippleParams = new LayoutParams((int) (2 * (rippleRadius + rippleStrokeWidth)), (int) (2 * (rippleRadius + rippleStrokeWidth)));
    rippleParams.addRule(CENTER_IN_PARENT, TRUE);
    animatorSet = new AnimatorSet();
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorList = new ArrayList<Animator>();
    for (int i = 0; i < rippleAmount; i++) {
        RippleView rippleView = new RippleView(getContext());
        addView(rippleView, rippleParams);
        rippleViewList.add(rippleView);
        final ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleX", 1.0f, rippleScale);
        scaleXAnimator.setRepeatCount(ObjectAnimator.INFINITE);
        scaleXAnimator.setRepeatMode(ObjectAnimator.RESTART);
        scaleXAnimator.setStartDelay(i * rippleDelay);
        scaleXAnimator.setDuration(rippleDurationTime);
        animatorList.add(scaleXAnimator);
        final ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleY", 1.0f, rippleScale);
        scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);
        scaleYAnimator.setRepeatMode(ObjectAnimator.RESTART);
        scaleYAnimator.setStartDelay(i * rippleDelay);
        scaleYAnimator.setDuration(rippleDurationTime);
        animatorList.add(scaleYAnimator);
        final ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(rippleView, "Alpha", 1.0f, 0f);
        alphaAnimator.setRepeatCount(ObjectAnimator.INFINITE);
        alphaAnimator.setRepeatMode(ObjectAnimator.RESTART);
        alphaAnimator.setStartDelay(i * rippleDelay);
        alphaAnimator.setDuration(rippleDurationTime);
        animatorList.add(alphaAnimator);
    }
    animatorSet.playTogether(animatorList);
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) TypedArray(android.content.res.TypedArray) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) AnimatorSet(android.animation.AnimatorSet) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 74 with Animator

use of android.animation.Animator in project android-ripple-background by skyfishjy.

the class MainActivity method foundDevice.

private void foundDevice() {
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(400);
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    ArrayList<Animator> animatorList = new ArrayList<Animator>();
    ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(foundDevice, "ScaleX", 0f, 1.2f, 1f);
    animatorList.add(scaleXAnimator);
    ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(foundDevice, "ScaleY", 0f, 1.2f, 1f);
    animatorList.add(scaleYAnimator);
    animatorSet.playTogether(animatorList);
    foundDevice.setVisibility(View.VISIBLE);
    animatorSet.start();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ArrayList(java.util.ArrayList) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) AnimatorSet(android.animation.AnimatorSet)

Example 75 with Animator

use of android.animation.Animator in project platform_frameworks_base by android.

the class RenderSessionImpl method animate.

/**
     * Animate an object
     * <p>
     * {@link #acquire(long)} must have been called before this.
     *
     * @throws IllegalStateException if the current context is different than the one owned by
     *      the scene, or if {@link #acquire(long)} was not called.
     *
     * @see RenderSession#animate(Object, String, boolean, IAnimationListener)
     */
public Result animate(Object targetObject, String animationName, boolean isFrameworkAnimation, IAnimationListener listener) {
    checkLock();
    BridgeContext context = getContext();
    // find the animation file.
    ResourceValue animationResource;
    int animationId = 0;
    if (isFrameworkAnimation) {
        animationResource = context.getRenderResources().getFrameworkResource(ResourceType.ANIMATOR, animationName);
        if (animationResource != null) {
            animationId = Bridge.getResourceId(ResourceType.ANIMATOR, animationName);
        }
    } else {
        animationResource = context.getRenderResources().getProjectResource(ResourceType.ANIMATOR, animationName);
        if (animationResource != null) {
            animationId = context.getLayoutlibCallback().getResourceId(ResourceType.ANIMATOR, animationName);
        }
    }
    if (animationResource != null) {
        try {
            Animator anim = AnimatorInflater.loadAnimator(context, animationId);
            if (anim != null) {
                anim.setTarget(targetObject);
                new PlayAnimationThread(anim, this, animationName, listener).start();
                return SUCCESS.createResult();
            }
        } catch (Exception e) {
            // get the real cause of the exception.
            Throwable t = e;
            while (t.getCause() != null) {
                t = t.getCause();
            }
            return ERROR_UNKNOWN.createResult(t.getMessage(), t);
        }
    }
    return ERROR_ANIM_NOT_FOUND.createResult();
}
Also used : Animator(android.animation.Animator) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext)

Aggregations

Animator (android.animation.Animator)1413 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)868 ObjectAnimator (android.animation.ObjectAnimator)724 ValueAnimator (android.animation.ValueAnimator)630 AnimatorSet (android.animation.AnimatorSet)285 View (android.view.View)230 ViewGroup (android.view.ViewGroup)110 ArrayList (java.util.ArrayList)104 PropertyValuesHolder (android.animation.PropertyValuesHolder)96 Paint (android.graphics.Paint)79 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)75 ImageView (android.widget.ImageView)68 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)67 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)65 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)64 TextView (android.widget.TextView)61 RenderNodeAnimator (android.view.RenderNodeAnimator)51 ViewPropertyAnimator (android.view.ViewPropertyAnimator)51 Rect (android.graphics.Rect)50 Interpolator (android.view.animation.Interpolator)49