- Notifications
You must be signed in to change notification settings - Fork89
Dali is an image blur library for Android. It contains several modules for static blurring, live blurring and animations.
License
patrickfav/Dali
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Dali is an image blur library for Android. It is easy to use, fast and extensible.Dali contains several modules for either static blurring, live blurring and animations.It uses RenderScript internally (although different implementations can be chosen) and is heavilycached to be fast and keeps small memory footprint. It features a lot of additional image filters and may beeasily extended and pretty every configuration can be changed.
Note: This library is in prototype state and not ready for prime time. It is mostly feature-complete (except for the animation module) although bugs are to be expected.
Add the following to your dependencies (add jcenter to your repositories if you haven't)
dependencies { compile'at.favre.lib:dali:0.4.0'}Then add the following to your app's build.gradle to get Renderscript to work
android {... defaultConfig {... renderscriptTargetApi24 renderscriptSupportModeEnabledtrue }}The quickest way to discover possible features, is to see what builder methodsDali.create(context) contains.
The test app is in the Playstore, you can get it hereDali Test App.
Static blur refers to blurring images that do not change dynamically in the UI (e.g. a static background image).Dali uses the builder pattern for easy and readable configuration. A very simple example would be:
Dali.create(context).load(R.drawable.test_img1).blurRadius(12).into(imageView);
which would blur given image in a background thread and set it to theImageView. Dali also supports additionalimage manipulation filters i.e. brightness, contrast and color.
Most of them use RenderScript, so they should be reasonably fast, although check compatibility.For details on the filter implementation, see theat.favre.lib.dali.builder.processor package.
Any other manipulation filter can be implemented through theIBitmapProcessor and.addPreProcessoron a builder.
A more complex example including filters would be:
Dali.create(context).load(R.drawable.test_img1).placeholder(R.drawable.test_img1).blurRadius(12) .downScale(2).colorFilter(Color.parseColor("#ffccdceb")).concurrent().reScale().into(iv3)
This will blur, color filter a down-scaled version of given image on a concurrent thread pool and rescales itthe target (the imageView) this case and will set a placeholder until the operations are finished.
Do note thatDali.create(context) will always create a new instance, so it may be advisable to keep the reference.
For more examples, seeSimpleBlurFragment.java andSimpleBlurBrightnessFragment.java
Apart from resource IDs, bitmaps, files and InputStreams.load(anyAndroidView) method also loads any View as sourceand blurs its drawingCache into the target view.
Dali.create(context).load(rootView.findViewById(R.id.blurTemplateView)).blurRadius(20) .downScale(2).concurrent().reScale().skipCache().into(imageView);
For more examples, seeViewBlurFragment.java
If you want to utilize Dali's features, without blurring the image, you could do:
Dali.create(context).load(R.drawable.test_img1).algorithm(EBlurAlgorithm.NONE).brightness(70).concurrent().into(iv);
Live blur refers to an effect where it a portion of the view blurs what's behind it. It can be used with e.g.aViewPager,Scrollview,RecyclerView, etc.
A very simple example with a ViewPager would be:
blurWorker =Dali.create(getActivity()).liveBlur(rootViewPagerWrapperView,topBlurView,bottomBlurView).downScale(8).assemble(true);mViewPager.addOnPageChangeListener(newViewPager.OnPageChangeListener() {@OverridepublicvoidonPageScrolled(intposition,floatpositionOffset,intpositionOffsetPixels) {blurWorker.updateBlurView(); }@OverridepublicvoidonPageSelected(intposition) {}@OverridepublicvoidonPageScrollStateChanged(intstate) {}});
A full example can be found in the test app'sLiveBlurFragment.java
The idea is basically to hook up to the scrollable view and every scroll event the blur has to be updated withblurWorker.updateBlurView(). Many of the views do not offer these features, therefore there are simple implementationsfor some views (see packageat.favre.lib.dali.view.Observable*)
A specialized version of live blur is blurring the background of aNavigationDrawer:
protectedvoidonCreate(BundlesavedInstanceState) { ...mDrawerToggle =newDaliBlurDrawerToggle(this,mDrawerLayout,toolbar,R.string.drawer_open,R.string.drawer_close) {publicvoidonDrawerClosed(Viewview) {super.onDrawerClosed(view);invalidateOptionsMenu();// creates call to onPrepareOptionsMenu() }publicvoidonDrawerOpened(ViewdrawerView) {super.onDrawerOpened(drawerView);invalidateOptionsMenu();// creates call to onPrepareOptionsMenu() } };mDrawerToggle.setDrawerIndicatorEnabled(true);// Set the drawer toggle as the DrawerListenermDrawerLayout.addDrawerListener(mDrawerToggle); ...}@OverrideprotectedvoidonPostCreate(BundlesavedInstanceState) {super.onPostCreate(savedInstanceState);mDrawerToggle.syncState();}@OverridepublicvoidonConfigurationChanged(ConfigurationnewConfig) {super.onConfigurationChanged(newConfig);mDrawerToggle.onConfigurationChanged(newConfig);}@OverridepublicbooleanonPrepareOptionsMenu(Menumenu) {booleandrawerOpen =mDrawerLayout.isDrawerOpen(mDrawerList);returnsuper.onPrepareOptionsMenu(menu);}
A full example can be found in the test app'sNavigationDrawerActivity.java
A simple framework for animating a static image from sharp to blur. It uses a key frames to configurethe animation:
BlurKeyFrameManagerman =newBlurKeyFrameManager();man.addKeyFrame(newBlurKeyFrame(2,4,0,300));man.addKeyFrame(newBlurKeyFrame(2,8,0,300));...
then anImageView can be animated:
BlurKeyFrameTransitionAnimationanimation =newBlurKeyFrameTransitionAnimation(getActivity(),man);animation.start(imageView);
A full example can be found in the test app'sSimpleAnimationFragment.java
The idea is from Roman Nurik's App Muzei where he explains how he does the blur transition smoothly and fast.Instead of just alpha fading the source and the final blur image, he creates different key frames with variousstates of blur and then fades through all those key frames. This is a compromise between performance and imagequality.See his Google+ blog post for more info.
Note: This module is not feature complete and has still terrible bugs, so use at your own risk.
Since v0.3.1 the lib includes its own proguard consumer rules and shouldwork out of the box with obfuscated builds.
Assemble the lib with the following command line call:
gradlew :dali:assembleThe .aar files can be found in the/dali/build/outputs/aar folder
- fix animations
- add tests
Copyright 2016 Patrick Favre-Bulle
Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
About
Dali is an image blur library for Android. It contains several modules for static blurring, live blurring and animations.
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.




