Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mask #85

Closed
ernest-p opened this issue Nov 30, 2018 · 5 comments
Closed

Support mask #85

ernest-p opened this issue Nov 30, 2018 · 5 comments

Comments

@ernest-p
Copy link

Work great with rectangular shapes.

It will be great to see support for round corners or mask.

@Dimezis
Copy link
Owner

Dimezis commented Nov 30, 2018

It supports rounded corners just like any other View.
#37

@ernest-p
Copy link
Author

ernest-p commented Nov 30, 2018

@Dimezis Thanks, it's working, however two issues there:

  1. background color not only clipping but also affect image
  2. this method only supported on Lollipop and above

first issue I solved by providing almost transparent color "#0001"

second issue solved by extending BlurView


class ClippedBlurView : BlurView {

    constructor(context: Context) : super(context)

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)

    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    override fun draw(canvas: Canvas) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            val path = Path()
            val px =
                Math.round(10 * (context!!.resources.displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)).toFloat()
            path.addRoundRect(RectF(1f, 1f, width.toFloat() - 2, height.toFloat() - 2), px, px, Path.Direction.CW)
            canvas.clipPath(path)
        }

        super.draw(canvas)
    }
}

@Dimezis
Copy link
Owner

Dimezis commented Nov 30, 2018

background color not only clipping but also affect image

What do you mean by this?

Well the thing is, BlurView is not anyhow special in regards to corners, clipping, etc. All the rules that apply to the regular View, work here as well.
So yeah, before Lollipop you got to clip manually.

@ernest-p
Copy link
Author

I mean if background is black it slightly tinted content to black

@Dimezis
Copy link
Owner

Dimezis commented Nov 30, 2018

The background color you define in XML drawable?
You don't have to do it, AFAIR, you can just have it completely transparent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants