Search in sources :

Example 16 with ViewOutlineProvider

use of android.view.ViewOutlineProvider in project cardslib by gabrielemariotti.

the class LPreviewUtilsBase method setupCircleButton.

//----------------------------------------------------------------------------
// Circle Button
//----------------------------------------------------------------------------
public void setupCircleButton(ImageButton sourceButton) {
    if (hasL()) {
        if (sourceButton != null) {
            final int size = mActivity.getResources().getDimensionPixelSize(R.dimen.hd_fab_size);
            sourceButton.setOutlineProvider(new ViewOutlineProvider() {

                @Override
                public void getOutline(View view, Outline outline) {
                    outline.setOval(0, 0, size, size);
                }
            });
            sourceButton.setClipToOutline(true);
        }
    }
}
Also used : Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) View(android.view.View)

Example 17 with ViewOutlineProvider

use of android.view.ViewOutlineProvider in project ListenerMusicPlayer by hefuyicoder.

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);
    mDrawable.setBounds(0, 0, w, h);
    mWidth = w;
    mHeight = 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 18 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(), 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 19 with ViewOutlineProvider

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

the class DetailActivity method setOutlines.

private void setOutlines(int star, int info) {
    final int size = getResources().getDimensionPixelSize(R.dimen.floating_button_size);
    final ViewOutlineProvider vop = new ViewOutlineProvider() {

        @Override
        public void getOutline(View view, Outline outline) {
            outline.setOval(0, 0, size, size);
        }
    };
    findViewById(star).setOutlineProvider(vop);
    findViewById(info).setOutlineProvider(vop);
}
Also used : Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) ImageView(android.widget.ImageView) View(android.view.View) AnimatedPathView(com.example.android.io2014.ui.AnimatedPathView) TextView(android.widget.TextView)

Example 20 with ViewOutlineProvider

use of android.view.ViewOutlineProvider in project FloatingActionButton by Clans.

the class Label method createFillDrawable.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[] { android.R.attr.state_pressed }, createRectDrawable(mColorPressed));
    drawable.addState(new int[] {}, createRectDrawable(mColorNormal));
    if (Util.hasLollipop()) {
        RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][] { {} }, new int[] { mColorRipple }), drawable, null);
        setOutlineProvider(new ViewOutlineProvider() {

            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, view.getWidth(), view.getHeight());
            }
        });
        setClipToOutline(true);
        mBackgroundDrawable = ripple;
        return ripple;
    }
    mBackgroundDrawable = drawable;
    return drawable;
}
Also used : ColorStateList(android.content.res.ColorStateList) Outline(android.graphics.Outline) StateListDrawable(android.graphics.drawable.StateListDrawable) ViewOutlineProvider(android.view.ViewOutlineProvider) View(android.view.View) TextView(android.widget.TextView) RippleDrawable(android.graphics.drawable.RippleDrawable) TargetApi(android.annotation.TargetApi)

Aggregations

View (android.view.View)27 ViewOutlineProvider (android.view.ViewOutlineProvider)27 Outline (android.graphics.Outline)26 TextView (android.widget.TextView)16 TargetApi (android.annotation.TargetApi)8 ImageView (android.widget.ImageView)7 ColorDrawable (android.graphics.drawable.ColorDrawable)4 Animator (android.animation.Animator)3 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)3 AnimatorSet (android.animation.AnimatorSet)3 ObjectAnimator (android.animation.ObjectAnimator)3 ColorStateList (android.content.res.ColorStateList)3 Rect (android.graphics.Rect)3 Drawable (android.graphics.drawable.Drawable)3 RippleDrawable (android.graphics.drawable.RippleDrawable)3 ViewGroup (android.view.ViewGroup)3 Interpolator (android.view.animation.Interpolator)3 StateListDrawable (android.graphics.drawable.StateListDrawable)2 AdapterView (android.widget.AdapterView)2 PropertyValuesHolder (android.animation.PropertyValuesHolder)1