Blurry icon indicating copy to clipboard operation
Blurry copied to clipboard

Blurry not working in onCreate?

Open AndroidLTG opened this issue 8 years ago • 5 comments

Hi wasabeef, i really like blurry library, but i had a problem with this. When i set Blurry(..) in OnCreate method then it not working ?

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getId();//get id of rela_Background init(); Blurry.with(context) .radius(25) .sampling(6) .async() .animate(500) .onto(rela_Background); }

How to blur "rela_Background" when open app .

AndroidLTG avatar Mar 09 '16 10:03 AndroidLTG

try this:


yourView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    Blurry.with(context)
                    .radius(25)
                    .sampling(6)
                    .async()
                    .animate(500)
                    .onto(rela_Background);

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
                        searchView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    else
                        searchView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                }
            });

if not work, try to call

           Blurry.with(context)
                    .radius(25)
                    .sampling(6)
                    .async()
                    .animate(500)
                    .onto(rela_Background);

two times. I don't know why but Blurry works to me only after second call.

rkyd avatar Mar 12 '16 14:03 rkyd

ohh. this work !! thanks . me too " I don't know why but Blurry works to me only after second call. " :)

AndroidLTG avatar Mar 14 '16 01:03 AndroidLTG

You can also do it this way:

yourView.post(new Runnable() {
    @Override
    public void run() {
        Blurry.with(context)
                    .radius(25)
                    .sampling(6)
                    .async()
                    .animate(500)
                    .onto(rela_Background);
    }
});

It has the same effect as 15555's method.

Pkmmte avatar Mar 18 '16 23:03 Pkmmte

My onCreate is below:

 final LinearLayout root = (LinearLayout) findViewById(R.id.login_view);
    root.post(new Runnable() {
        @Override
        public void run() {
            Blurry.with(LoginActivity.this)
                    .radius(25)
                    .sampling(2)
                    .async()
                    .animate(500)
                    .onto((ViewGroup) root);

        }
    });

Blurry is still not working for me and if i call it twice as mentioned above, i get the below error:

java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@4a28ec at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1270) at android.graphics.Canvas.drawBitmap(Canvas.java:1325) at jp.wasabeef.blurry.internal.Blur.of(Blur.java:63) at jp.wasabeef.blurry.internal.BlurTask$1.run(BlurTask.java:61) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)

kalkrishnan avatar Aug 27 '16 20:08 kalkrishnan

So I'm adding the blur within onBindViewHolder() on my recycler view adapter. Calling it twice didn't work, but post() does. Thanks @Pkmmte!

cobear25 avatar May 19 '17 16:05 cobear25