Search in sources :

Example 36 with ViewOutlineProvider

use of android.view.ViewOutlineProvider in project Shuttle by timusus.

the class PlayPauseView method onSizeChanged.

@Override
protected void onSizeChanged(final int w, final int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    drawable.setBounds(0, 0, w, h);
    width = w;
    height = h;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setOutlineProvider(new ViewOutlineProvider() {

            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, view.getWidth(), view.getHeight());
            }
        });
        setClipToOutline(true);
    }
}
Also used : Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) TargetApi(android.annotation.TargetApi) View(android.view.View)

Example 37 with ViewOutlineProvider

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

the class StretchyChangeBounds method createAnimator.

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    final View view = endValues.view;
    final ViewGroup parent = ((ViewGroup) view.getParent());
    final Rect startBounds = (Rect) startValues.values.get(PROPNAME_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROPNAME_BOUNDS);
    // as the captured bounds are in window-space, adjust them to local bounds
    int dx = Math.max(view.getLeft(), 0) - endBounds.left;
    int dy = Math.max(view.getTop(), 0) - endBounds.top;
    startBounds.offset(dx, dy);
    endBounds.offset(dx, dy);
    // hide the view during the transition and let us draw outside of our bounds
    final Drawable background = view.getBackground();
    view.setBackground(null);
    final ViewOutlineProvider outlineProvider = view.getOutlineProvider();
    view.setOutlineProvider(null);
    final boolean clipChildren = parent.getClipChildren();
    parent.setClipChildren(false);
    // use our own drawable in the overlay which we can reposition without thrashing layout
    StretchColorDrawable drawable = new StretchColorDrawable(color);
    drawable.setBounds(startBounds);
    view.getOverlay().add(drawable);
    // work out the direction and size change,
    // use this to determine which edges are leading vs trailing.
    boolean upward = startBounds.centerY() > endBounds.centerY();
    boolean expanding = startBounds.width() < endBounds.width();
    Interpolator fastOutSlowInInterpolator = AnimUtils.getFastOutSlowInInterpolator(sceneRoot.getContext());
    Interpolator slowOutFastInInterpolator = AnimationUtils.loadInterpolator(sceneRoot.getContext(), io.plaidapp.R.interpolator.slow_out_fast_in);
    AnimatorSet transition = new AnimatorSet();
    long trailingDuration = calculateTrailingDuration(startBounds, endBounds, sceneRoot.getContext());
    Animator leadingEdges, trailingEdges;
    if (expanding) {
        // expanding, left/right move at speed of leading edge
        PropertyValuesHolder left = PropertyValuesHolder.ofInt(StretchColorDrawable.LEFT, startBounds.left, endBounds.left);
        PropertyValuesHolder right = PropertyValuesHolder.ofInt(StretchColorDrawable.RIGHT, startBounds.right, endBounds.right);
        PropertyValuesHolder leadingEdge = PropertyValuesHolder.ofInt(upward ? StretchColorDrawable.TOP : StretchColorDrawable.BOTTOM, upward ? startBounds.top : startBounds.bottom, upward ? endBounds.top : endBounds.bottom);
        leadingEdges = ObjectAnimator.ofPropertyValuesHolder(drawable, left, right, leadingEdge);
        leadingEdges.setDuration(leadingDuration);
        leadingEdges.setInterpolator(fastOutSlowInInterpolator);
        trailingEdges = ObjectAnimator.ofInt(drawable, upward ? StretchColorDrawable.BOTTOM : StretchColorDrawable.TOP, upward ? startBounds.bottom : startBounds.top, upward ? endBounds.bottom : endBounds.top);
        trailingEdges.setDuration(trailingDuration);
        trailingEdges.setInterpolator(slowOutFastInInterpolator);
    } else {
        // contracting, left/right move at speed of trailing edge
        leadingEdges = ObjectAnimator.ofInt(drawable, upward ? StretchColorDrawable.TOP : StretchColorDrawable.BOTTOM, upward ? startBounds.top : startBounds.bottom, upward ? endBounds.top : endBounds.bottom);
        leadingEdges.setDuration(leadingDuration);
        leadingEdges.setInterpolator(fastOutSlowInInterpolator);
        PropertyValuesHolder left = PropertyValuesHolder.ofInt(StretchColorDrawable.LEFT, startBounds.left, endBounds.left);
        PropertyValuesHolder right = PropertyValuesHolder.ofInt(StretchColorDrawable.RIGHT, startBounds.right, endBounds.right);
        PropertyValuesHolder trailingEdge = PropertyValuesHolder.ofInt(upward ? StretchColorDrawable.BOTTOM : StretchColorDrawable.TOP, upward ? startBounds.bottom : startBounds.top, upward ? endBounds.bottom : endBounds.top);
        trailingEdges = ObjectAnimator.ofPropertyValuesHolder(drawable, left, right, trailingEdge);
        trailingEdges.setDuration(trailingDuration);
        trailingEdges.setInterpolator(slowOutFastInInterpolator);
    }
    transition.playTogether(leadingEdges, trailingEdges);
    transition.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            // clean up
            parent.setClipChildren(clipChildren);
            view.setBackground(background);
            view.setOutlineProvider(outlineProvider);
            view.getOverlay().clear();
        }
    });
    return transition;
}
Also used : Rect(android.graphics.Rect) ViewGroup(android.view.ViewGroup) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) ViewOutlineProvider(android.view.ViewOutlineProvider) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder) Interpolator(android.view.animation.Interpolator)

Example 38 with ViewOutlineProvider

use of android.view.ViewOutlineProvider in project Depth-LIB-Android- by danielzeller.

the class DepthLayout method initView.

private void initView(AttributeSet attrs) {
    edgePaint.setColor(DEFAULT_EDGE_COLOR);
    edgePaint.setAntiAlias(true);
    TypedArray arr = getContext().obtainStyledAttributes(attrs, R.styleable.DepthView);
    if (attrs != null) {
        try {
            edgePaint.setColor(arr.getInt(R.styleable.DepthView_edge_color, DEFAULT_EDGE_COLOR));
            setIsCircle(arr.getBoolean(R.styleable.DepthView_is_circle, false));
            depth = arr.getDimension(R.styleable.DepthView_depth, DEFAULT_THICKNESS * getResources().getDisplayMetrics().density);
            customShadowElevation = arr.getDimension(R.styleable.DepthView_custom_elevation, 0);
        } finally {
            arr.recycle();
        }
    } else {
        edgePaint.setColor(DEFAULT_EDGE_COLOR);
        depth = DEFAULT_THICKNESS * getResources().getDisplayMetrics().density;
    }
    setOutlineProvider(new ViewOutlineProvider() {

        @Override
        public void getOutline(View view, Outline outline) {
        }
    });
}
Also used : TypedArray(android.content.res.TypedArray) Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) View(android.view.View)

Example 39 with ViewOutlineProvider

use of android.view.ViewOutlineProvider in project Carbon by ZieIony.

the class CollapsingToolbarLayout method updateCorners.

private void updateCorners() {
    if (Carbon.IS_LOLLIPOP_OR_HIGHER) {
        if (!Carbon.isShapeRect(shapeModel, boundsRect))
            setClipToOutline(true);
        setOutlineProvider(new ViewOutlineProvider() {

            @Override
            public void getOutline(View view, Outline outline) {
                if (Carbon.isShapeRect(shapeModel, boundsRect)) {
                    outline.setRect(0, 0, getWidth(), getHeight());
                } else {
                    shadowDrawable.setBounds(0, 0, getWidth(), getHeight());
                    shadowDrawable.setShadowCompatibilityMode(MaterialShapeDrawable.SHADOW_COMPAT_MODE_NEVER);
                    shadowDrawable.getOutline(outline);
                }
            }
        });
    }
    boundsRect.set(shadowDrawable.getBounds());
    shadowDrawable.getPathForSize(getWidth(), getHeight(), cornersMask);
}
Also used : Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) ShadowView(carbon.view.ShadowView) ComponentView(carbon.component.ComponentView) StrokeView(carbon.view.StrokeView) View(android.view.View) RippleView(carbon.drawable.ripple.RippleView) RevealView(carbon.view.RevealView) TransformationView(carbon.view.TransformationView) InsetView(carbon.view.InsetView) AnimatedView(carbon.animation.AnimatedView) MarginView(carbon.view.MarginView) ShapeModelView(carbon.view.ShapeModelView) MaxSizeView(carbon.view.MaxSizeView) TouchMarginView(carbon.view.TouchMarginView) VisibleView(carbon.view.VisibleView) StateAnimatorView(carbon.view.StateAnimatorView)

Example 40 with ViewOutlineProvider

use of android.view.ViewOutlineProvider in project Carbon by ZieIony.

the class MotionLayout method updateCorners.

private void updateCorners() {
    if (Carbon.IS_LOLLIPOP_OR_HIGHER) {
        if (!Carbon.isShapeRect(shapeModel, boundsRect))
            setClipToOutline(true);
        setOutlineProvider(new ViewOutlineProvider() {

            @Override
            public void getOutline(View view, Outline outline) {
                if (Carbon.isShapeRect(shapeModel, boundsRect)) {
                    outline.setRect(0, 0, getWidth(), getHeight());
                } else {
                    shadowDrawable.setBounds(0, 0, getWidth(), getHeight());
                    shadowDrawable.setShadowCompatibilityMode(MaterialShapeDrawable.SHADOW_COMPAT_MODE_NEVER);
                    shadowDrawable.getOutline(outline);
                }
            }
        });
    }
    boundsRect.set(shadowDrawable.getBounds());
    shadowDrawable.getPathForSize(getWidth(), getHeight(), cornersMask);
}
Also used : Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) ShadowView(carbon.view.ShadowView) ComponentView(carbon.component.ComponentView) StrokeView(carbon.view.StrokeView) View(android.view.View) RippleView(carbon.drawable.ripple.RippleView) RevealView(carbon.view.RevealView) TransformationView(carbon.view.TransformationView) InsetView(carbon.view.InsetView) AnimatedView(carbon.animation.AnimatedView) MarginView(carbon.view.MarginView) ShapeModelView(carbon.view.ShapeModelView) BehaviorView(carbon.view.BehaviorView) MaxSizeView(carbon.view.MaxSizeView) TouchMarginView(carbon.view.TouchMarginView) VisibleView(carbon.view.VisibleView) StateAnimatorView(carbon.view.StateAnimatorView)

Aggregations

ViewOutlineProvider (android.view.ViewOutlineProvider)56 Outline (android.graphics.Outline)55 View (android.view.View)55 TextView (android.widget.TextView)25 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)16 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