Giter Club home page Giter Club logo

blurdialogfragment's Introduction

BlurDialogFragment

This project allows to display DialogFragment with a burring effect behind. The blurring part is achieved through FastBlur algorithm thanks to the impressive work of Pavlo Dudka (cf Special Thanks).

Android Arsenal

Sample app

Download the sample app on the Google Play store.

Example

Activity with action bar [blurRadius 4, downScaleFactor 5.0] : action bar blur

Fullscreen activity [blurRadius 2, downScaleFactor 8.0] : full screen blur

Dependency

In order to use this library, just add a new gradle dependency : BlurDialogFragment dependency

Simple usage using inheritance

If you are using android.app.DialogFragment : extends BlurDialogFragment. Play with the blur radius and the down scale factor to obtain the perfect blur.

Don't forget to enable log in order to keep on eye the perfomance.

/**
 * Simple fragment with blurring effect behind.
 */
public class SampleDialogFragment extends BlurDialogFragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.debug(true);
        this.setBlurRadius(4);
        this.setDownScaleFactor(5.0f);
        
        ...
    }
    
    ...
}

If you are using android.support.v4.app.DialogFragment : extends SupportBlurDialogFragment. Play with the blur radius and the down scale factor to obtain the perfect blur.

Don't forget to enable log in order to keep on eye the perfomance.

/**
 * Simple fragment with blurring effect behind.
 */
public class SampleDialogFragment extends SupportBlurDialogFragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.debug(true);
        this.setBlurRadius(4);
        this.setDownScaleFactor(5.0f);
        
        ...
    }
    
    ...
}

Default values are set to :

   /**
    * Since image is going to be blurred, we don't care about resolution.
    * Down scale factor reduces blurring time and memory allocation.
    */
   private static final float BLUR_DOWN_SCALE_FACTOR = 4.0f;

   /**
    * Radius used to blur the background.
    */
   private static final int BLUR_RADIUS = 8;
   

Avoiding inheritance

If you want to avoid inheritance, use directly the BlurEngine. Don't forget to link the engine to the lifecycle of your DialogFragment.

/**
 * Your blur fragment directly using BlurEngine.
 */
public class SampleDialogFragment extends MyCustomDialogFragment {

     /**
     * Engine used to blur.
     */
    private BlurDialogEngine mBlurEngine;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        mBlurEngine = new BlurDialogEngine(getActivity());
        mBlurEngine.debug(mDebugEnable);
        mBlurEngine.setBlurRadius(8);
        mBlurEngine.setDownScaleFactor(8f);
    }
    
    @Override
    public void onResume() {
        super.onResume();
        mBlurEngine.onResume(getRetainInstance());
    }
    
     @Override
    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        mBlurEngine.onDismiss();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mBlurEngine.onDestroy();
    }

    @Override
    public void onDestroyView() {
        if (getDialog() != null) {
            getDialog().setDismissMessage(null);
        }
        super.onDestroyView();
    }
    
    ...
}

Benchmark

We used a Nexus 5 running a 4.4.4 stock rom for this bench.

Down scale factor 8.0 & Blur Radius 8 : Screenshot

Radius : 8
Down Scale Factor : 8.0
Blurred achieved in : 18 ms
Allocation : 4320ko (screen capture) + 270ko (FastBlur)

Down scale factor 6.0 & Blur Radius 12 : Screenshot

Radius : 12
Down Scale Factor : 6.0
Blurred achieved in : 31 ms
Allocation : 4320ko (screen capture) + 360ko (FastBlur)

Down scale factor 4.0 & Blur Radius 20 : Screenshot

Radius : 20
Down Scale Factor : 4.0
Blurred achieved in : 75 ms
Allocation : 4320ko (screen capture) + 540ko (FastBlur)

Known bugs

  • Wrong top offset when using the following line in application Theme :
<item name="android:windowActionBarOverlay">true</item>

RenderScript or not RenderScript

Since ScriptIntrinsicBlur seems to doens't work with RGB_565 Bitmap (used to reduce by half Bitmap allocation) I keep thinking about using RenderScript for applying blur effect.

Find more information on the memory trace and on the execution time.

TODO

  • Implement SherlockBlurDialogFragment since actionbarsherlock and appcompat are mutually exclusive.

Change logs

  • 0.1.2 : Fix bottom offset introduce by the navigation bar on Lollipop.
  • 0.1.1 : Fix top offset when using Toolbar.
  • 0.1.0 : Support appcompat-v7:21.
  • 0.0.9 : Change default blur radius (8) and default down scale factor (4).
  • 0.0.8 : Fix NoClassDefFound.
  • 0.0.7 : Avoid using inheritance through BlurDialogEngine if needed.

Contributing

Contributions are welcome (: You can contribute through GitHub by forking the repository and sending a pull request.

When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible. Please also make sure your code fit these convention by running gradlew check.

Credits

Credits go to Thomas Barthélémy https://github.com/tbarthel-fr and Vincent Barthélémy https://github.com/vbarthel-fr.

License

Copyright (C) 2014 tvbarthel

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.

Special Thanks to ...

Pavlo Dudka https://github.com/paveldudka/ , for his impressive article on Advanced blurring techniques.

Vincent Brison https://github.com/vincentbrison , for his early day support.

blurdialogfragment's People

Contributors

tbarthel-fr avatar

Watchers

James Cloos avatar  avatar

Forkers

rakeshcs797

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.