19

Basically

In an activity, I have a ListView. When I select an item, an transparent activity opens as a small box. When this box appears, you can still view the previous activities screen,

What I am trying to figure out is how to blur the previous screen like the image linked here (Ignore the UI, just look at the blurred grass area).

How is this possible?

Thank you for any advice.

rennoDeniro
  • 920
  • 2
  • 8
  • 19

1 Answers1

36

For API < 14, you could use the flag WindowManager.LayoutParams.FLAG_BLUR_BEHIND, but it's been deprecated and built-in blurring is no longer supported on higher APIs

However, you could do this with a regular view or overlay. What you want to do is:

  • Create a Bitmap from your activity's overall layout (see here for example)
  • Blur that bitmap with whatever method you want(a few examples here)
  • Add(or unhide) a View in your layout that covers everything. Set bkg to blurred Bitmap
  • Open your dialog/transparent activity
  • When it closes, either remove the View, or setVisibility(GONE) if you'll be using it again.
Community
  • 1
  • 1
Geobits
  • 22,218
  • 6
  • 59
  • 103
  • Thank you, I shall attempt this now! – rennoDeniro Nov 15 '12 at 22:13
  • Hello, The blur examples take a few seconds to blur, so this delays the opening of the new activity, How can I get around this? As I would like it to blur and open as fast as possible. – rennoDeniro Nov 16 '12 at 23:45
  • Have you tried the NDK version of the answer shown? The author got a reported 40x speedup going native. Might be a bit much just for a blur if you're pure Java for everything else, but it's worth a shot. Another idea might be to alter the pixel loops by incrementing by 2 each round. It won't be a pixel-perfect blur, but if you just do every other pixel for both x/y, it should only take 1/4 the time. I'm not sure how it'll look, but it should only take a few minutes to change the loop to find out. – Geobits Nov 19 '12 at 01:22
  • Altering the algorithm didnt work. And now finding it difficult to implement the NDK version – rennoDeniro Nov 19 '12 at 22:29
  • 1
    Unfortunately, NDK is probably your best option. A good blur isn't the hardest image processing action, but it's not the fastest, either. You might be able to find a "dirty" blur algorithm that's fast enough in Java, but I don't have one to recommend off the top of my head. – Geobits Nov 20 '12 at 19:24
  • Hello, I have implemented the NDK version on the suggestion, but I cannot get the radius above 60 as it then starts to fail. If you have any idea why, please see my post on the issue linked, if not then thank you enormously for your help. Take care. http://stackoverflow.com/questions/13483556/android-ndk-gaussian-blur-implementation-cannot-exceed-radius60-and-random-act – rennoDeniro Nov 20 '12 at 22:51
  • Answer not valid answer as of now, was trying to find some alternate way for `FLAG_BLUR_BEHIND`. Found this SO post : [link](http://stackoverflow.com/questions/10372404/alternative-to-flag-blur-behind-in-android) – V_J Aug 18 '15 at 09:29
  • @VinodJaiswal Maybe you can clarify, but I don't see what in that answer invalidates this one. – Geobits Aug 18 '15 at 12:36
  • @Geobits: FLAG_BLUR_BEHIND is deprecated now and we can't achieve the blur effect by the method specified in the above answer. I am not invalidating your answer. I am just putting my findings in here. – V_J Aug 18 '15 at 12:43
  • @VinodJaiswal I know it's deprecated; that's in the very first sentence of this answer (and has been for almost three years). The rest is a method to work around that, and will still work (even if a bit inefficient). – Geobits Aug 18 '15 at 12:46
  • Is there no update to this or a better way to do this? I would imagine there are better solutions to this now. – AndyRoid Jan 06 '16 at 08:56