Dimezis / BlurView

Dynamic iOS-like blur of underlying Views for Android
Apache License 2.0
3.48k stars 331 forks source link

Wrong activity background blurring effect #178

Open luongvo opened 2 years ago

luongvo commented 2 years ago

Please include: 1) Library version: version-2.0.0 2) Device and OS version: all API versions, tested on API 23 and 30 3) Detailed steps to reproduce the issue

4) XML layout and code for BlurView setup: Reproduce commit here https://github.com/luongvo/BlurView/commit/6835fd2b97593ec5eaf794d28f9c53a2a6953168

5) Stacktrace in case of a crash: None

Expected: set android:background="@drawable/lines" in activity_main.xml could produce an expected result

https://user-images.githubusercontent.com/16315358/168729864-0a766a4c-7948-4954-8eed-a87b10978593.mp4

Actual: using <item name="android:windowBackground">@drawable/lines</item> in AppTheme and .setFrameClearDrawable(windowBackground) set in MainActivity does not work properly.

https://user-images.githubusercontent.com/16315358/168729902-c95bcc00-d2fa-4ce8-9095-ba130a6dc2b3.mp4

Dimezis commented 2 years ago

Apparently, there's some weird bug with android:windowBackground as an image (BitmapDrawable). I'll see what I can do about it, but be aware that even regardless of this bug, your Expected result is probably impossible with setFrameClearDrawable, because the drawable doesn't have a trackable position on the screen.

That means, that even if I fix the bug, the bottom BlurView won't be able to properly blur the bottom of this drawable.

To fix this, you can either pass the (ViewGroup) getWindow().getDecorView() as a rootView, or set the background in activity_main.xml as you did.

luongvo commented 2 years ago

@Dimezis I tried to apply using getWindow().getDecorView() but it does not work.

This lib https://github.com/mmin18/RealtimeBlurView using the same approach but it works properly, here is the POC https://github.com/luongvo/RealtimeBlurView/commit/b87607a7fb1f76841b4cdd8f828a7c12949751b4. The bad thing is https://github.com/mmin18/RealtimeBlurView does not support latest API RenderEffect from API 31 and discontinued.

https://user-images.githubusercontent.com/16315358/168785323-c8e70297-d254-462d-b0f9-5c3d73c92e59.mp4

I think even there are some issues, we should support getWindow().getDecorView() directly from this nice library instead.

Dimezis commented 2 years ago

I tried to apply using getWindow().getDecorView() but it does not work.

Can you post a commit with this change? It works fine for me on your branch

luongvo commented 2 years ago

@Dimezis I made a draft PR here, please check it out https://github.com/Dimezis/BlurView/pull/179 🙏

The update from the PR above still does not work:

Actual:

Expected:

luongvo commented 2 years ago

@Dimezis I think this logic could help https://github.com/mmin18/RealtimeBlurView/blob/master/library/src/com/github/mmin18/widget/RealtimeBlurView.java#L245-L261 🤔

Dimezis commented 2 years ago

Responded - https://github.com/Dimezis/BlurView/pull/179#discussion_r874664955