Giter VIP home page Giter VIP logo

blurry's Introduction

Android Arsenal License Maven Central

Blurry is an easy blur library for Android.

logo

Screenshot

Demo

How do I use it?

Setup

Dependencies
repositories {
  mavenCentral()
}

dependencies {
    compile 'jp.wasabeef:blurry:4.0.1'
}

Functions

Overlay

Parent must be ViewGroup

Blurry.with(activity).radius(25).sampling(2).onto(rootView)

Into

// from View
Blurry.with(activity).capture(view).into(imageView)
// from Bitmap 
Blurry.with(activity).from(bitmap).into(imageView)

Blur Options

  • Radius
  • Down Sampling
  • Color Filter
  • Asynchronous Support
  • Animation (Overlay Only)
Blurry.with(activity)
  .radius(10)
  .sampling(8)
  .color(Color.argb(66, 255, 255, 0))
  .async()
  .animate(500)
  .onto(rootView);

Get a bitmap directly

// Sync
val bitmap = Blurry.with(activity)
  .radius(10)
  .sampling(8)
  .capture(findViewById(R.id.right_bottom)).get()
imageView.setImageDrawable(BitmapDrawable(resources, bitmap))

// Async
Blurry.with(activity)
  .radius(25)
  .sampling(4)
  .color(Color.argb(66, 255, 255, 0))
  .capture(findViewById(R.id.left_bottom))
  .getAsync {
    imageView.setImageDrawable(BitmapDrawable(resources, it))
  }

Blur a view that contains a Google Map or other surface

On API-26 and newer, Blurry uses PixelCopy to copy directly from the surface of the window,
and can thus obtain a bitmap that contains a GoogleMap. Blurry automatically use PixelCopy when using
Blurry.with(activity) instead of the deprecated Blurry.with(context). To use get a blurred view for any API,
something like this can be done:

fun runBlurry() {
    // Async to stay off UI thread
    Blurry.with(activity)
        .sampling(4) // This makes it much faster and more blurry, so less radius is needed, and less radius also makes it faster
        .radius(5)
        .capture(rootViewContainerToBlur)
        .getAsync { 
            val drawable = BitmapDrawable(target.resources, it)
            blurView.setImageDrawable(drawable)
        }
}

if (!Blurry.isSurfaceCaptureSupported) {
    // Before API-26, lets help Blurry out and capture the GoogleMap Surface into a regular ImageView, and proceed when ready
    blurryMapCaptureView.onMapCaptured {
        runBlurry()
    }
} else {
    runBlurry()
}

// Let blurryMapCaptureView cover the Google Map Fragment. 
val blurryMapCaptureView: BlurryMapCaptureView
class BlurryMapCaptureView : AppCompatImageView {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    private lateinit var map: GoogleMap

    fun initialize(map: GoogleMap) {
        this.map = map
    }

    fun onMapCaptured(onReadyToCaptureMapAction: () -> Unit) {
        map.snapshot { bitmap: Bitmap? ->
            visibility = VISIBLE
            setImageBitmap(bitmap)
            doOnPreDraw {
                onReadyToCaptureMapAction()
                visibility = GONE
                setImageBitmap(null)
            }
        }
    }

}```



Requirements
--------------
Android 5.+ (API 21)

Developed By
-------
Daichi Furiya (Wasabeef) - <[email protected]>

<a href="https://twitter.com/wasabeef_jp">
<img alt="Follow me on Twitter"
src="https://raw.githubusercontent.com/wasabeef/art/master/twitter.png" width="75"/>
</a>

License
-------

    Copyright (C) 2020 Wasabeef

    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, software
    distributed 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 and
    limitations under the License.

blurry's People

Contributors

arberg avatar easycheese avatar jasoncromer avatar kaustubhpatange avatar wasabeef avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.