# BlurDialogFragment **Repository Path**: baijuncheng-open-source/blur-dialog-fragment ## Basic Information - **Project Name**: BlurDialogFragment - **Description**: 一个模糊视图的库。将视图进行模糊化处理,可快速模糊,可高斯模糊,可将视图宽高等比放大进行模糊 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-04-09 - **Last Updated**: 2021-07-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ![](https://images.gitee.com/uploads/images/2021/0713/165350_18382b7a_8230582.gif "HwVideoEditor_2021_07_13_162128557.gif") BlurDialogFragment ================== This project allows to display commonDialog with a burring effect behind. The blurring part is achieved through FastBlur algorithm. * [Sample hap](#sample-hap) * [Gradle dependency](#gradle-dependency) * [Use RenderScript in Your Project] (#use-renderscript-in-your-project) * [Simple usage using inheritance](#simple-usage-using-inheritance) * [Customize your blurring effect](#customize-your-blurring-effect) * [Avoiding inheritance](#avoiding-inheritance) * [Benchmark](#benchmark) * [RenderScript or not RenderScript](#renderscript-or-not-renderscript) * [Contributing](#contributing) * [Credits](#credits) * [License](#license) Sample hap ======= Download the source code and compile sample to get the hap. Gradle dependency ======= Since the library is promoted on maven central, just add a new gradle dependency : ```groovy compile 'com.gitee.baijuncheng-open-source:blur-dialog-fragment:1.0.0' ``` Don't forget to check the [Use RenderScript in Your Project] (#use-renderscript-in-your-project) if you're planning to use it. Simple usage using inheritance ======= If you are using ohos.agp.window.dialog.CommonDialog, Play with the blur radius and the down scale factor to obtain the perfect blur. Don't forget to enable log if you want to keep on eye the performance. ```java /** * Simple fragment with blurring effect behind. */ public class SampleDialogFragment extends BlurDialogFragment { } ``` Customize your blurring effect ====== ```java /** * Simple fragment with a customized blurring effect. */ public class SampleDialogFragment extends BlurDialogFragment { @Override public void onCreate(Bundle savedInstanceState) { ... } @Override protected float getDownScaleFactor() { // Allow to customize the down scale factor. return 5.0; } @Override protected int getBlurRadius() { // Allow to customize the blur radius factor. return 7; } @Override protected boolean isActionBarBlurred() { // Enable or disable the blur effect on the action bar. // Disabled by default. return true; } @Override protected boolean isDimmingEnable() { // Enable or disable the dimming effect. // Disabled by default. return true; } @Override protected boolean isRenderScriptEnable() { // Enable or disable the use of RenderScript for blurring effect // Disabled by default. return true; } @Override protected boolean isDebugEnable() { // Enable or disable debug mode. // False by default. return true; } ... ``` Default values are set to : ```java /** * Since image is going to be blurred, we don't care about resolution. * Down scale factor to reduce blurring time and memory allocation. */ static final float DEFAULT_BLUR_DOWN_SCALE_FACTOR = 4.0f; /** * Radius used to blur the background */ static final int DEFAULT_BLUR_RADIUS = 8; /** * Default dimming policy. */ static final boolean DEFAULT_DIMMING_POLICY = false; /** * Default debug policy. */ static final boolean DEFAULT_DEBUG_POLICY = false; /** * Default action bar blurred policy. */ static final boolean DEFAULT_ACTION_BAR_BLUR = false; /** * Default use of RenderScript. */ static final boolean DEFAULT_USE_RENDERSCRIPT = false; ``` Avoiding inheritance ======= If you want to **avoid inheritance**, use directly the **BlurEngine**. ```java /** * 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.setBlurRadius(8); mBlurEngine.setDownScaleFactor(8f); mBlurEngine.debug(true); mBlurEngine.setBlurActionBar(true); mBlurEngine.setUseRenderScript(true); } @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.onDetach(); } @Override public void onDestroyView() { if (getDialog() != null) { getDialog().setDismissMessage(null); } super.onDestroyView(); } ... } ``` Benchmark ======= Benchmark outdated. Please refer to the debug option of the sample in order to compare FastBlur and RenderScript. We used a Nexus 5 running a 4.4.4 stock rom for this bench. Down scale factor 8.0 & Blur Radius 8 : [Screenshot](/static/blur_8.0_8.png) ```javascript 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](/static/blur_6.0_12.png) ```javascript 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](/static/blur_4.0_20.png) ```javascript Radius : 20 Down Scale Factor : 4.0 Blurred achieved in : 75 ms Allocation : 4320ko (screen capture) + 540ko (FastBlur) ``` 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. ```