Search in sources :

Example 1 with ViewOutlineProvider

use of android.view.ViewOutlineProvider in project plaid by nickbutcher.

the class FabTransform method createAnimator.

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) {
    if (startValues == null || endValues == null)
        return null;
    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);
    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Rect fabBounds = fromFab ? startBounds : endBounds;
    final Interpolator fastOutSlowInInterpolator = AnimUtils.getFastOutSlowInInterpolator(sceneRoot.getContext());
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;
    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }
    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }
    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab)
        fabColor.setAlpha(0);
    view.getOverlay().add(fabColor);
    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(), iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab)
        fabIcon.setAlpha(0);
    view.getOverlay().add(fabIcon);
    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startBounds.width() / 2, (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2));
        circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator(sceneRoot.getContext()));
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2), endBounds.width() / 2);
        circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator(sceneRoot.getContext()));
        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                view.setOutlineProvider(new ViewOutlineProvider() {

                    @Override
                    public void getOutline(View view, Outline outline) {
                        final int left = (view.getWidth() - fabBounds.width()) / 2;
                        final int top = (view.getHeight() - fabBounds.height()) / 2;
                        outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height());
                        view.setClipToOutline(true);
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);
    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0) : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);
    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }
    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);
    // Work around issue with elevation shadows. At the end of the return transition the shared
    // element's shadow is drawn twice (by each activity) which is jarring. This workaround
    // still causes the shadow to snap, but it's better than seeing it double drawn.
    Animator elevation = null;
    if (!fromFab) {
        elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation());
        elevation.setDuration(duration);
        elevation.setInterpolator(fastOutSlowInInterpolator);
    }
    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (elevation != null)
        transition.play(elevation);
    if (fromFab) {
        transition.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                // Clean up
                view.getOverlay().clear();
            }
        });
    }
    return new AnimUtils.NoPauseAnimator(transition);
}
Also used : Rect(android.graphics.Rect) ViewGroup(android.view.ViewGroup) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) Outline(android.graphics.Outline) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) ViewOutlineProvider(android.view.ViewOutlineProvider) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ColorDrawable(android.graphics.drawable.ColorDrawable) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Interpolator(android.view.animation.Interpolator)

Example 2 with ViewOutlineProvider

use of android.view.ViewOutlineProvider in project android_frameworks_base by DirtyUnicorns.

the class TaskView method onFinishInflate.

@Override
protected void onFinishInflate() {
    // Bind the views
    mHeaderView = (TaskViewHeader) findViewById(R.id.task_view_bar);
    mThumbnailView = (TaskViewThumbnail) findViewById(R.id.task_view_thumbnail);
    mThumbnailView.updateClipToTaskBar(mHeaderView);
    mActionButtonView = findViewById(R.id.lock_to_app_fab);
    mActionButtonView.setOutlineProvider(new ViewOutlineProvider() {

        @Override
        public void getOutline(View view, Outline outline) {
            // Set the outline to match the FAB background
            outline.setOval(0, 0, mActionButtonView.getWidth(), mActionButtonView.getHeight());
            outline.setAlpha(0.35f);
        }
    });
    mActionButtonView.setOnClickListener(this);
    mActionButtonTranslationZ = mActionButtonView.getTranslationZ();
}
Also used : Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) View(android.view.View) TextView(android.widget.TextView)

Example 3 with ViewOutlineProvider

use of android.view.ViewOutlineProvider in project android_frameworks_base by DirtyUnicorns.

the class TaskCardView method setAsScreenShotView.

private void setAsScreenShotView(Bitmap screenshot, ImageView screenshotView) {
    LayoutParams lp = (LayoutParams) screenshotView.getLayoutParams();
    lp.width = LayoutParams.MATCH_PARENT;
    lp.height = LayoutParams.MATCH_PARENT;
    screenshotView.setLayoutParams(lp);
    screenshotView.setClipToOutline(true);
    screenshotView.setOutlineProvider(new ViewOutlineProvider() {

        @Override
        public void getOutline(View view, Outline outline) {
            outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), mCornerRadius);
        }
    });
    screenshotView.setImageBitmap(screenshot);
}
Also used : Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 4 with ViewOutlineProvider

use of android.view.ViewOutlineProvider in project android_frameworks_base by AOSPA.

the class TaskCardView method setAsScreenShotView.

private void setAsScreenShotView(Bitmap screenshot, ImageView screenshotView) {
    LayoutParams lp = (LayoutParams) screenshotView.getLayoutParams();
    lp.width = LayoutParams.MATCH_PARENT;
    lp.height = LayoutParams.MATCH_PARENT;
    screenshotView.setLayoutParams(lp);
    screenshotView.setClipToOutline(true);
    screenshotView.setOutlineProvider(new ViewOutlineProvider() {

        @Override
        public void getOutline(View view, Outline outline) {
            outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), mCornerRadius);
        }
    });
    screenshotView.setImageBitmap(screenshot);
}
Also used : Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 5 with ViewOutlineProvider

use of android.view.ViewOutlineProvider in project google-io-2014 by romainguy.

the class CardFrameLayout method onSizeChanged.

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    final float radius = getResources().getDimensionPixelSize(R.dimen.card_corner_radius);
    final int vw = w;
    final int vh = h;
    final ViewOutlineProvider vop = new ViewOutlineProvider() {

        @Override
        public void getOutline(View view, Outline outline) {
            outline.setRoundRect(0, 0, vw, vh, radius);
        }
    };
    setOutlineProvider(vop);
    setClipToOutline(true);
}
Also used : Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) View(android.view.View)

Aggregations

ViewOutlineProvider (android.view.ViewOutlineProvider)55 Outline (android.graphics.Outline)54 View (android.view.View)54 TextView (android.widget.TextView)24 AnimatedView (carbon.animation.AnimatedView)17 RippleView (carbon.drawable.ripple.RippleView)17 MarginView (carbon.view.MarginView)17 MaxSizeView (carbon.view.MaxSizeView)17 RevealView (carbon.view.RevealView)17 ShadowView (carbon.view.ShadowView)16 ShapeModelView (carbon.view.ShapeModelView)16 StateAnimatorView (carbon.view.StateAnimatorView)16 StrokeView (carbon.view.StrokeView)16 TouchMarginView (carbon.view.TouchMarginView)16 VisibleView (carbon.view.VisibleView)16 TargetApi (android.annotation.TargetApi)12 ComponentView (carbon.component.ComponentView)12 InsetView (carbon.view.InsetView)12 TransformationView (carbon.view.TransformationView)12 BehaviorView (carbon.view.BehaviorView)10