Search in sources :

Example 1 with RippleDrawable

use of carbon.drawable.ripple.RippleDrawable in project Carbon by ZieIony.

the class Button method updateBackgroundTint.

private void updateBackgroundTint() {
    Drawable background = getBackground();
    if (background instanceof RippleDrawable)
        background = ((RippleDrawable) background).getBackground();
    if (background == null)
        return;
    if (backgroundTint != null && backgroundTintMode != null) {
        int color = backgroundTint.getColorForState(getDrawableState(), backgroundTint.getDefaultColor());
        background.setColorFilter(new PorterDuffColorFilter(color, backgroundTintMode));
    } else {
        background.setColorFilter(null);
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) RippleDrawable(carbon.drawable.ripple.RippleDrawable) ColorStateListDrawable(carbon.drawable.ColorStateListDrawable) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) RippleDrawable(carbon.drawable.ripple.RippleDrawable)

Example 2 with RippleDrawable

use of carbon.drawable.ripple.RippleDrawable in project Carbon by ZieIony.

the class CheckBox method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    final Drawable buttonDrawable = drawable;
    if (buttonDrawable != null) {
        final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
        final int drawableHeight = buttonDrawable.getIntrinsicHeight();
        final int drawableWidth = buttonDrawable.getIntrinsicWidth();
        final int top;
        switch(verticalGravity) {
            case Gravity.BOTTOM:
                top = getHeight() - drawableHeight;
                break;
            case Gravity.CENTER_VERTICAL:
                top = (getHeight() - drawableHeight) / 2;
                break;
            default:
                top = 0;
        }
        final int bottom = top + drawableHeight;
        final int left = isLayoutRtl() ? getWidth() - drawableWidth - getPaddingRight() : getPaddingLeft();
        final int right = isLayoutRtl() ? getWidth() - getPaddingRight() : drawableWidth + getPaddingLeft();
        buttonDrawable.setBounds(left, top, right, bottom);
        final Drawable background = getBackground();
        if (background != null && background instanceof RippleDrawable) {
        //TODO: hotspotBounds
        // ((RippleDrawable)background).setHotspotBounds(left, top, right, bottom);
        }
    }
    super.onDraw(canvas);
    if (buttonDrawable != null) {
        final int scrollX = getScrollX();
        final int scrollY = getScrollY();
        if (scrollX == 0 && scrollY == 0) {
            buttonDrawable.draw(canvas);
        } else {
            canvas.translate(scrollX, scrollY);
            buttonDrawable.draw(canvas);
            canvas.translate(-scrollX, -scrollY);
        }
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) RippleDrawable(carbon.drawable.ripple.RippleDrawable) CheckableDrawable(carbon.drawable.CheckableDrawable) RippleDrawable(carbon.drawable.ripple.RippleDrawable)

Example 3 with RippleDrawable

use of carbon.drawable.ripple.RippleDrawable in project Carbon by ZieIony.

the class CheckedTextView method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    final Drawable buttonDrawable = drawable;
    if (buttonDrawable != null) {
        final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
        final int drawableHeight = buttonDrawable.getIntrinsicHeight();
        final int drawableWidth = buttonDrawable.getIntrinsicWidth();
        final int top;
        switch(verticalGravity) {
            case Gravity.BOTTOM:
                top = getHeight() - drawableHeight;
                break;
            case Gravity.CENTER_VERTICAL:
                top = (getHeight() - drawableHeight) / 2;
                break;
            default:
                top = 0;
        }
        final int bottom = top + drawableHeight;
        final int left = isLayoutRtl() ? getPaddingLeft() : getWidth() - drawableWidth - getPaddingRight();
        final int right = isLayoutRtl() ? drawableWidth + getPaddingLeft() : getWidth() - getPaddingRight();
        buttonDrawable.setBounds(left, top, right, bottom);
        final Drawable background = getBackground();
        if (background != null && background instanceof RippleDrawable) {
        //TODO: hotspotBounds
        // ((RippleDrawable)background).setHotspotBounds(left, top, right, bottom);
        }
    }
    super.onDraw(canvas);
    if (buttonDrawable != null) {
        final int scrollX = getScrollX();
        final int scrollY = getScrollY();
        if (scrollX == 0 && scrollY == 0) {
            buttonDrawable.draw(canvas);
        } else {
            canvas.translate(scrollX, scrollY);
            buttonDrawable.draw(canvas);
            canvas.translate(-scrollX, -scrollY);
        }
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) RippleDrawable(carbon.drawable.ripple.RippleDrawable) CheckableDrawable(carbon.drawable.CheckableDrawable) RippleDrawable(carbon.drawable.ripple.RippleDrawable)

Example 4 with RippleDrawable

use of carbon.drawable.ripple.RippleDrawable in project Carbon by ZieIony.

the class ConstraintLayout method drawChild.

@Override
protected boolean drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime) {
    if (child instanceof ShadowView && (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH || ((ShadowView) child).getElevationShadowColor() != null)) {
        ShadowView shadowView = (ShadowView) child;
        shadowView.drawShadow(canvas);
    }
    if (child instanceof RippleView) {
        RippleView rippleView = (RippleView) child;
        RippleDrawable rippleDrawable = rippleView.getRippleDrawable();
        if (rippleDrawable != null && rippleDrawable.getStyle() == RippleDrawable.Style.Borderless) {
            int saveCount = canvas.save(Canvas.MATRIX_SAVE_FLAG);
            canvas.translate(child.getLeft(), child.getTop());
            canvas.concat(MatrixHelper.getMatrix(child));
            rippleDrawable.draw(canvas);
            canvas.restoreToCount(saveCount);
        }
    }
    return super.drawChild(canvas, child, drawingTime);
}
Also used : ShadowView(carbon.shadow.ShadowView) RippleView(carbon.drawable.ripple.RippleView) Paint(android.graphics.Paint) RippleDrawable(carbon.drawable.ripple.RippleDrawable)

Example 5 with RippleDrawable

use of carbon.drawable.ripple.RippleDrawable in project Carbon by ZieIony.

the class SeekBar method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        if (radiusAnimator != null)
            radiusAnimator.end();
        radiusAnimator = ValueAnimator.ofFloat(thumbRadius, THUMB_RADIUS_DRAGGED);
        radiusAnimator.setDuration(200);
        radiusAnimator.setInterpolator(interpolator);
        radiusAnimator.addUpdateListener(animation -> {
            thumbRadius = (float) animation.getAnimatedValue();
            postInvalidate();
        });
        radiusAnimator.start();
        ViewParent parent = getParent();
        if (parent != null)
            parent.requestDisallowInterceptTouchEvent(true);
        if (showLabel)
            popup.show(this);
    } else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) {
        if (style == Style.Discrete) {
            float val = (float) Math.floor((value - min + step / 2) / step) * step + min;
            if (valueAnimator != null)
                valueAnimator.cancel();
            valueAnimator = ValueAnimator.ofFloat(value, val);
            valueAnimator.setDuration(200);
            valueAnimator.setInterpolator(interpolator);
            valueAnimator.addUpdateListener(animation -> {
                value = (float) animation.getAnimatedValue();
                int thumbX = (int) ((value - min) / (max - min) * (getWidth() - getPaddingLeft() - getPaddingRight()) + getPaddingLeft());
                int thumbY = getHeight() / 2;
                int radius = rippleDrawable.getRadius();
                rippleDrawable.setBounds(thumbX - radius, thumbY - radius, thumbX + radius, thumbY + radius);
                postInvalidate();
            });
            valueAnimator.start();
        }
        if (radiusAnimator != null)
            radiusAnimator.end();
        radiusAnimator = ValueAnimator.ofFloat(thumbRadius, THUMB_RADIUS);
        radiusAnimator.setDuration(200);
        radiusAnimator.setInterpolator(interpolator);
        radiusAnimator.addUpdateListener(animation -> {
            thumbRadius = (float) animation.getAnimatedValue();
            postInvalidate();
        });
        radiusAnimator.start();
        ViewParent parent = getParent();
        if (parent != null)
            parent.requestDisallowInterceptTouchEvent(false);
        if (showLabel)
            popup.dismiss();
    }
    float v = (event.getX() - getPaddingLeft()) / (getWidth() - getPaddingLeft() - getPaddingRight());
    v = Math.max(0, Math.min(v, 1));
    float newValue = v * (max - min) + min;
    int thumbX = (int) (v * (getWidth() - getPaddingLeft() - getPaddingRight()) + getPaddingLeft());
    int thumbY = getHeight() / 2;
    int radius = rippleDrawable.getRadius();
    if (showLabel) {
        int[] location = new int[2];
        getLocationInWindow(location);
        popup.setText(String.format(labelFormat, newValue));
        popup.update(thumbX + location[0] - popup.getBubbleWidth() / 2, thumbY - radius + location[1] - popup.getHeight());
    }
    if (rippleDrawable != null) {
        rippleDrawable.setHotspot(event.getX(), event.getY());
        rippleDrawable.setBounds(thumbX - radius, thumbY - radius, thumbX + radius, thumbY + radius);
    }
    postInvalidate();
    if (newValue != value && onValueChangedListener != null) {
        if (style == Style.Discrete) {
            int sv = stepValue(newValue);
            if (stepValue(value) != sv)
                onValueChangedListener.onValueChanged(this, sv);
        } else {
            onValueChangedListener.onValueChanged(this, newValue);
        }
    }
    value = newValue;
    super.onTouchEvent(event);
    return true;
}
Also used : Context(android.content.Context) Rect(android.graphics.Rect) NEEDS_PROXY(com.nineoldandroids.view.animation.AnimatorProxy.NEEDS_PROXY) ViewParent(android.view.ViewParent) AnimatorProxy.wrap(com.nineoldandroids.view.animation.AnimatorProxy.wrap) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) AnimatedView(carbon.animation.AnimatedView) NonNull(android.support.annotation.NonNull) Drawable(android.graphics.drawable.Drawable) TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) AttributeSet(android.util.AttributeSet) MotionEvent(android.view.MotionEvent) View(android.view.View) RippleDrawable(carbon.drawable.ripple.RippleDrawable) Canvas(android.graphics.Canvas) ViewCompat(android.support.v4.view.ViewCompat) Build(android.os.Build) TargetApi(android.annotation.TargetApi) DefaultPrimaryColorStateList(carbon.drawable.DefaultPrimaryColorStateList) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) R(carbon.R) RippleView(carbon.drawable.ripple.RippleView) SeekBarPopup(carbon.internal.SeekBarPopup) Animator(com.nineoldandroids.animation.Animator) StateAnimator(carbon.animation.StateAnimator) PorterDuff(android.graphics.PorterDuff) Carbon(carbon.Carbon) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) AnimatedColorStateList(carbon.animation.AnimatedColorStateList) AnimUtils(carbon.animation.AnimUtils) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) MathUtils(carbon.internal.MathUtils) ViewParent(android.view.ViewParent) Paint(android.graphics.Paint)

Aggregations

RippleDrawable (carbon.drawable.ripple.RippleDrawable)20 Paint (android.graphics.Paint)15 RippleView (carbon.drawable.ripple.RippleView)14 ShadowView (carbon.shadow.ShadowView)13 Drawable (android.graphics.drawable.Drawable)5 CheckableDrawable (carbon.drawable.CheckableDrawable)3 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)2 RippleDrawableFroyo (carbon.drawable.ripple.RippleDrawableFroyo)2 RippleDrawableLollipop (carbon.drawable.ripple.RippleDrawableLollipop)2 RippleDrawableMarshmallow (carbon.drawable.ripple.RippleDrawableMarshmallow)2 TargetApi (android.annotation.TargetApi)1 Context (android.content.Context)1 ColorStateList (android.content.res.ColorStateList)1 TypedArray (android.content.res.TypedArray)1 Canvas (android.graphics.Canvas)1 PorterDuff (android.graphics.PorterDuff)1 Rect (android.graphics.Rect)1 Build (android.os.Build)1 NonNull (android.support.annotation.NonNull)1 ViewCompat (android.support.v4.view.ViewCompat)1