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);
}
}
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;
}
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) {
}
});
}
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);
}
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);
}
Aggregations