{"id":13643202,"url":"https://github.com/patrickfav/Dali","last_synced_at":"2025-04-20T21:33:26.847Z","repository":{"id":17422483,"uuid":"20195549","full_name":"patrickfav/Dali","owner":"patrickfav","description":"Dali is an image blur library for Android. It contains several modules for static blurring, live blurring and animations.","archived":false,"fork":false,"pushed_at":"2023-03-31T11:39:04.000Z","size":15359,"stargazers_count":1058,"open_issues_count":13,"forks_count":89,"subscribers_count":30,"default_branch":"main","last_synced_at":"2025-04-08T17:16:57.034Z","etag":null,"topics":["android","android-library","animation","blur","image-manipulation","live-blurring","renderscript"],"latest_commit_sha":null,"homepage":"https://favr.dev/opensource/dali","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patrickfav.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2014-05-26T19:00:25.000Z","updated_at":"2025-03-30T09:56:38.000Z","dependencies_parsed_at":"2022-07-16T03:46:10.756Z","dependency_job_id":"0d246a62-cb2a-4276-80a7-27cbd27b6f74","html_url":"https://github.com/patrickfav/Dali","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickfav%2FDali","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickfav%2FDali/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickfav%2FDali/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickfav%2FDali/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrickfav","download_url":"https://codeload.github.com/patrickfav/Dali/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249965566,"owners_count":21352926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","animation","blur","image-manipulation","live-blurring","renderscript"],"created_at":"2024-08-02T01:01:43.721Z","updated_at":"2025-04-20T21:33:25.180Z","avatar_url":"https://github.com/patrickfav.png","language":"Java","readme":"# Dali\n\nDali is an image blur library for Android. It is easy to use, fast and extensible.\nDali contains several modules for either static blurring, live blurring and animations.\nIt uses RenderScript internally (although different implementations can be chosen) and is heavily\ncached to be fast and keeps small memory footprint. It features a lot of additional image filters and may be\neasily extended and pretty every configuration can be changed.\n\n[![Maven Central](https://img.shields.io/maven-central/v/at.favre.lib/dali)](https://mvnrepository.com/artifact/at.favre.lib/dali)\n[![Build Status](https://travis-ci.com/patrickfav/Dali.svg?branch=master)](https://travis-ci.com/patrickfav/Dali)\n[![Javadocs](https://www.javadoc.io/badge/at.favre.lib/dali.svg)](https://www.javadoc.io/doc/at.favre.lib/dali)\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Dali-yellowgreen.svg?style=flat)](https://android-arsenal.com/details/1/5130)\n[![Maintainability](https://api.codeclimate.com/v1/badges/bc29814415f63a85c62d/maintainability)](https://codeclimate.com/github/patrickfav/Dali/maintainability)\n\n![Gallery](https://github.com/patrickfav/Dali/blob/main/misc/gallery1.png?raw=true)\n\n\n*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.*\n\n# Install\n\nAdd the following to your dependencies  ([add jcenter to your repositories](https://developer.android.com/studio/build/index.html#top-level) if you haven't)\n\n```groovy\ndependencies {\n    compile 'at.favre.lib:dali:0.4.0'\n}\n```\n\nThen add the following to your app's build.gradle to get Renderscript to work\n\n```groovy\nandroid {\n    ...\n    defaultConfig {\n        ...\n        renderscriptTargetApi 24\n        renderscriptSupportModeEnabled true\n    }\n}\n```\nThe quickest way to discover possible features, is to see what builder methods `Dali.create(context)` contains.\n\n## Download Test App\n\n[![Get it on Google Play](misc/playstore_badge_new.png)](https://play.google.com/store/apps/details?id=at.favre.app.dalitest\u0026pcampaignid=MKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1)\n\nThe test app is in the Playstore, you can get it here [Dali Test App](https://play.google.com/store/apps/details?id=at.favre.app.dalitest).\n\n# Features\n\n## Static Blur\n\nStatic blur refers to blurring images that do not change dynamically in the UI (e.g. a static background image).\nDali uses the builder pattern for easy and readable configuration. A very simple example would be:\n```java\nDali.create(context).load(R.drawable.test_img1).blurRadius(12).into(imageView);\n```\nwhich would blur given image in a background thread and set it to the `ImageView`. Dali also supports additional\nimage manipulation filters i.e. brightness, contrast and color.\n\nMost of them use RenderScript, so they should be reasonably fast, although check compatibility.\nFor details on the filter implementation, see the `at.favre.lib.dali.builder.processor` package.\n\nAny other manipulation filter can be implemented through the `IBitmapProcessor` and `.addPreProcessor`\non a builder.\n\nA more complex example including filters would be:\n```java\nDali.create(context).load(R.drawable.test_img1).placeholder(R.drawable.test_img1).blurRadius(12)\n    .downScale(2).colorFilter(Color.parseColor(\"#ffccdceb\")).concurrent().reScale().into(iv3)\n```\nThis will blur, color filter a down-scaled version of given image on a concurrent thread pool and rescales it\nthe target (the imageView) this case and will set a placeholder until the operations are finished.\n\n_Do note that `Dali.create(context)` will always create a new instance, so it may be advisable to keep the reference._\n\nFor more examples, see `SimpleBlurFragment.java` and `SimpleBlurBrightnessFragment.java`\n\n### Blur any View\n\nApart from resource IDs, bitmaps, files and InputStreams `.load(anyAndroidView)` method also loads any View as source\nand blurs its drawingCache into the target view.\n```java\nDali.create(context).load(rootView.findViewById(R.id.blurTemplateView)).blurRadius(20)\n    .downScale(2).concurrent().reScale().skipCache().into(imageView);\n```\nFor more examples, see `ViewBlurFragment.java`\n\n### Skip blurring\n\nIf you want to utilize Dali's features, without blurring the image, you could do:\n```java\nDali.create(context).load(R.drawable.test_img1).algorithm(EBlurAlgorithm.NONE).brightness(70).concurrent().into(iv);\n```\n\n## Live Blur\n\nLive blur refers to an effect where it a portion of the view blurs what's behind it. It can be used with e.g.\na `ViewPager`, `Scrollview`, `RecyclerView`, etc.\n\n![Live Blur Animation](https://github.com/patrickfav/Dali/blob/main/misc/viewpager_anim.gif?raw=true)\n\nA very simple example with a ViewPager would be:\n```java\nblurWorker = Dali.create(getActivity()).liveBlur(rootViewPagerWrapperView,topBlurView,bottomBlurView).downScale(8).assemble(true);\n\nmViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {\n    @Override\n    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {\n        blurWorker.updateBlurView();\n    }\n    @Override public void onPageSelected(int position) {}\n    @Override public void onPageScrollStateChanged(int state) {}\n});\n```\nA full example can be found in the test app's `LiveBlurFragment.java`\n\nThe idea is basically to hook up to the scrollable view and every scroll event the blur has to be updated with\n`blurWorker.updateBlurView()`. Many of the views do not offer these features, therefore there are simple implementations\nfor some views (see package `at.favre.lib.dali.view.Observable*`)\n\n\n## Navigation Drawer Background Blur\n\nA specialized version of live blur is blurring the background of a `NavigationDrawer`:\n\n![Blur Nav Animation](https://github.com/patrickfav/Dali/blob/main/misc/blur_nav.gif?raw=true)\n```java\nprotected void onCreate(Bundle savedInstanceState) {\n    ...\n    mDrawerToggle = new DaliBlurDrawerToggle(this, mDrawerLayout,\n            toolbar, R.string.drawer_open, R.string.drawer_close) {\n\n        public void onDrawerClosed(View view) {\n            super.onDrawerClosed(view);\n            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()\n        }\n\n        public void onDrawerOpened(View drawerView) {\n            super.onDrawerOpened(drawerView);\n            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()\n        }\n    };\n    mDrawerToggle.setDrawerIndicatorEnabled(true);\n    // Set the drawer toggle as the DrawerListener\n    mDrawerLayout.addDrawerListener(mDrawerToggle);\n    ...\n}\n\n@Override\nprotected void onPostCreate(Bundle savedInstanceState) {\n    super.onPostCreate(savedInstanceState);\n    mDrawerToggle.syncState();\n}\n\n@Override\npublic void onConfigurationChanged(Configuration newConfig) {\n    super.onConfigurationChanged(newConfig);\n    mDrawerToggle.onConfigurationChanged(newConfig);\n}\n\n@Override\npublic boolean onPrepareOptionsMenu(Menu menu) {\n    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);\n    return super.onPrepareOptionsMenu(menu);\n}\n```\n\nA full example can be found in the test app's `NavigationDrawerActivity.java`\n\n## Blur Transition Animation\n\nA simple framework for animating a static image from sharp to blur. It uses a key frames to configure\nthe animation:\n```java\nBlurKeyFrameManager man = new BlurKeyFrameManager();\nman.addKeyFrame(new BlurKeyFrame(2,4,0,300));\nman.addKeyFrame(new BlurKeyFrame(2,8,0,300));\n...\n```\nthen an `ImageView` can be animated:\n```java\nBlurKeyFrameTransitionAnimation animation = new BlurKeyFrameTransitionAnimation(getActivity(),man);\nanimation.start(imageView);\n```\n![Blur Animation](https://github.com/patrickfav/Dali/blob/main/misc/blur_anim.gif?raw=true)\n\nA full example can be found in the test app's `SimpleAnimationFragment.java`\n\nThe idea is from Roman Nurik's App Muzei where he explains how he does the blur transition smoothly and fast.\nInstead of just alpha fading the source and the final blur image, he creates different key frames with various\nstates of blur and then fades through all those key frames. This is a compromise between performance and image\nquality.\n[See his Google+ blog post for more info.](https://plus.google.com/+RomanNurik/posts/2sTQ1X2Cb2Z)\n\n_Note: This module is not feature complete and has still terrible bugs, so use at your own risk._\n\n## Proguard\n\nSince v0.3.1 the lib includes its own proguard consumer rules and should\nwork out of the box with obfuscated builds.\n\n## Advanced\n\n### How to build\n\nAssemble the lib with the following command line call:\n\n    gradlew :dali:assemble\n\nThe .aar files can be found in the `/dali/build/outputs/aar` folder\n\n### Caching\n\n## TODO\n\n* fix animations\n* add tests\n\n# License\n\nCopyright 2016 Patrick Favre-Bulle\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","funding_links":[],"categories":["模糊效果"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickfav%2FDali","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrickfav%2FDali","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickfav%2FDali/lists"}