onDraw should be the proper indicator of when you should update your view (though it will be called for any update to your view, not only just when the background changes). I'm not sure there's even a way to distinguish who's "responsible" for the refresh - your own changes or background changes.
You can however try to figure out yourself if the background changed enough to warrant an update - compare the previous background image to the current, you can allow some percentage of acceptable difference between the images to lower the amount of times you call renderscript. On Sunday, September 29, 2013 5:26:42 PM UTC+3, Harri Smått wrote: > > Hello All, > > I'm in the midst of implementing somewhat dynamic background blur effect > for Android (similar to what iOS7 has) and I'm keen to have this one > optimisation in place. > > In my implementation I'm trying to achieve following: > > 1. I extend default layout classes and call them blur layouts > > 2. When view contents below blur layout in the view tree changes, I render > what ever content there is into scaled offscreen bitmap (this is the part > needing optimisation) > > 3. Blur is applied on offscreen bitmap using RenderScript implementation > of stack blur > > 4. From then on the blur layout draws this blurred image as it's background > > Now.. Currently.. I'm using ViewTreeObserver to determine when current > screen is about to update (OnPreDrawListener) but this doesn't give me any > indication whether content below my layout has changed. It's triggered no > matter what update happens on the screen and though I'm recreating the blur > image way too often - also in cases content below hasn't changed. > > It would be great if someone with better knowledge on Android drawing > internals could help me out on this one. Say, if my layout occupies > Rect(100, 100, 200, 200) on the screen, I would like to observe in this > layout when content below within it's area has changed. Or is this even > possible? > > For interested ones current implementation can be found here: > https://github.com/harism/android_anndblur > > And precompiled application should appear in Play Market at some point. > > -- > Harri > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

