I've got custom sliding view, which I can move up and down, over another view (ImageView).
I've also got blurred version of said view prepared in memory. What I want to achive is blurring this background view during sliding up/down as I would cover it with a blurry glass. Also, I need to reverse this process too, that's why I'm keeping both Bitmaps.
Hope I made myself clear here.
sadly, this project requires me to use API >= 8
Related
To set the transparency level of a view background we use
mView.getBackground().setAlpha(mViewTransparencyLvl);
How to set the blur level of a view background?
Knowing that the background is a shape drawable not an image. Knowing that the user controls the blur degree. Knowing that this view is over part of another view.
Android doesn't provide this functionality for UI elements as iOS does. It's not part of the UI rendering engine and to obtain these kind of effects you need to use third-party libraries which will essentially take a snapshot of the drawing cache, reduce its size for a faster processing and then put the generated bitmap into a view.
Here are some example libraries:
BlurrView
Blurry
Please bear in mind that this will have a serious performance hit on mid-low end phones.
background
I've made a simple app called "LWP+", which shows a cropped image . When the user chooses a photo, I save it into a file, and then do the cropping when needed. I do this by using 2 libraries. One for allowing the user to choose the cropping rectangle, and one for the actual cropping.
The problem
This is just for a normal cropping, but a nicer feature I'd like to add is a way to scroll through the content of the entire given image, at least horizontally.
On a normal Activity, I'd probably use a ViewPager that has an ImageView for each page.
But here a live wallpaper doesn't really have a layout.
What I've found
There isn't much of information about live wallpapers in general, but when I've searched for scrolling of an image in it, I've found just how to move the canvas.
This can actually be a good idea, of somehow having bitmaps (or partial decoding of the image) around the current position, and translating the canvas as needed. I could also use a GestureDetector class to identify flinging, but this is only a tiny fraction of what's needed to do a nice scrolling of a zoomed image.
It is also very complex, as it requires good memory considerations in mind.
If I could use a normal view, I could have used a ViewPager, or even a third library that shows an image and allows to scroll in it freely , like in the gallery app (such as this one).
The question
Given a View of any kind, such as ViewPager or another, is it possible to host it somehow inside the LiveWallpaper, to let it show content, and to handle touch events ?
Alternatively, is there an efficient way to view content as I've written, yet in a live wallpaper? Meaning viewing a portion of a large image, while allowing to scroll though it (like a ViewPager, but maybe even freely like on a photo viewer library, in all directions) ?
I am searching for it from very long time. I want to blur the background of the new added view to the frame layout. The new added view is a linear layout which opens as a pop up. Now how can I blur that frame layout.
I have gone through all the posts regarding blurring the background but i did not find that useful for my problem Because they all suggest to create a bitmap and set it blur on the bitmap. I simply want to blur the complete view behind the pop up
Use this library to blur the background of popup https://github.com/faradaj/BlurBehind
On BlurredActivity show the popup and finish the activity when pop dismiss.
You can use Renderscript Intrinsics, which are a set of built-in functions that require very little code to use, but are optimized for high-performance.
Once you have the blurring, the rest of the process is fairly straight forward. When you plan to leave an activity, create a bitmap of the current view and write it to disk. When you start your new activity (which should have a transparent background), you override the transition (otherwise you’ll get the default zoom), and set the background to the blurred image you saved earlier. Add a fade in for the alpha and you get a nice little effect!
If you’d like to see how this looks in a sample project, you can find it on Github here.
I like the style iOS 7 has used for their Notification and Music popover like below.
So, I try to implement this thing in Android. After doing some search, I achieved how to do that. What I have tried is following.
1) First I take a root reference of the View and take a snap of it using getDrawingCache() function of View.
linearLayout.buildDrawingCache();
SoftReference<Bitmap> bitmap = new SoftReference<Bitmap>(
Bitmap.createBitmap(linearLayout.getDrawingCache()));
linearLayout.destroyDrawingCache();
2) I take the position relative to its parent and cut the image as per requirement.
SoftReference<Bitmap> temp = new SoftReference<Bitmap>(
Bitmap.createBitmap(bitmap.get(), 0,
(parentHeight - childHeight), childWidth, childHeight));
3) I make that bitmap image blur with some algorithm. ( I use Fast Bitmap Blur For Android SDK fastBlur effect )
4) set it in the overlay view.
imageView1.setImageBitmap(Utils.fastblur(temp.get(), 8));
But my problem is it takes time to take a snap then giving blur effect and cutting image and then i got final result. While iOS has very fast blurring process like when drawer is coming from bottom, it immediately blur the screen which is behind it.
Is there any other way to achieve that? Because using my scenario, i can't take every second snap of screen and do all process 1 to 4 every second on every move of drawer.
http://nicolaspomepuy.fr/blur-effect-for-android-design/
I don't know if you have seen this link, but check it out. It talks about how blur effects can be achieved in around 200ms.
PS: check out the comments as well !
Ok so if I understand your problem correctly is that is you have a drawer mechanisme that you need to update the blurred image every pixel the drawer has moved?
Then the solution to your problem would be to blur the screen one time and use this image together with some fancy algorithm to show/hide and position that image so that it seems that the drawer will blur instantly but in actually what's happening is that the image was already generated.
You just show more or less of the image to create the effect.
Don't know if I'm making sense or if I even understand your question.
Currently Im developing fling action (similar to that one implemented in IPhones gallery app) in my custom view (image as background + some other staff). I have already working code, but I am thinking if there is a way to increase performance. My idea is simple: I pass 3 bitmaps to view: previous, current and next. When user perform move action on the screen he can see current bitmap + next/previous depend on the movment direction. A big dissadvantage is that I have to have 3 bitmaps loaded in memory all the time. I am using drawBitmap method to draw resized bitmaps to the screen and BitmapFactory to load it. Sometimes UI is not responsive for a while. I think it because there are only space for two bitmaps in memory so one is recycled and have to be reloaded by system. Also in my plans I have also scrolling in vertical directions so that will give me another two bitmaps cached in memory. Is there any chcance to improove performance in my solution, or any other solutions? I was thinking about extending gallery widget, but I need zooming and vertical scrolling also.