Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Dali is an image blur library for Android. It contains several modules for static blurring, live blurring and animations.

License

NotificationsYou must be signed in to change notification settings

patrickfav/Dali

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.

Maven CentralBuild StatusJavadocsAndroid ArsenalMaintainability

Gallery

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.

Install

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.

Download Test App

Get it on Google Play

The test app is in the Playstore, you can get it hereDali Test App.

Features

Static Blur

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

Blur any View

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

Skip blurring

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

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.

Live Blur Animation

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*)

Navigation Drawer Background Blur

A specialized version of live blur is blurring the background of aNavigationDrawer:

Blur Nav Animation

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

Blur Transition Animation

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);

Blur Animation

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.

Proguard

Since v0.3.1 the lib includes its own proguard consumer rules and shouldwork out of the box with obfuscated builds.

Advanced

How to build

Assemble the lib with the following command line call:

gradlew :dali:assemble

The .aar files can be found in the/dali/build/outputs/aar folder

Caching

TODO

  • fix animations
  • add tests

License

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.0

Unless 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

Stars

Watchers

Forks

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2026 Movatter.jp