Skip to content

Commit

Permalink
Merge pull request #60 from tvbarthel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tbarthel-fr committed May 12, 2016
2 parents a934971 + 46ebbd0 commit f6c8727
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 52 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gradle dependency
Since the library is promoted on maven central, just add a new gradle dependency :

```groovy
compile 'fr.tvbarthel.blurdialogfragment:lib:2.1.5'
compile 'fr.tvbarthel.blurdialogfragment:lib:2.1.6'
```

Don't forget to check the [Use RenderScript in Your Project] (#use-renderscript-in-your-project) if you're planning to use it.
Expand Down Expand Up @@ -242,6 +242,8 @@ public class SampleDialogFragment extends MyCustomDialogFragment {
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)
Expand Down Expand Up @@ -285,6 +287,7 @@ Find more information on the [memory trace](http://tvbarthel.github.io/blur-dial
Change logs
=======
* 2.1.6 : Fix orientation change as well as retainInstance thanks to [IskuhiSargsyan](https://github.com/IskuhiSargsyan) report and tweak FastBlur implementation to avoid the allocation of 3 additional arrays for RGB channels thanks to [sh1](https://disqus.com/by/sh1sh1sh1/) feedback.
* 2.1.5 : Minor fixes thanks to [Edward S](https://github.com/edward-s) and [Tommy Chan](https://github.com/tommytcchan).
* 2.1.4 : Fix NPE during the blurring process thanks to [Anth06ny](https://github.com/Anth06ny), [jacobtabak](https://github.com/jacobtabak) and [serega2593](https://github.com/serega2593) reports.
* 2.1.3 : Remove unused resources thanks to [ligol](https://github.com/ligol) report.
Expand Down
2 changes: 2 additions & 0 deletions config/quality/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
<!-- xml in comments recognized as wrong HTML !-->
<suppress checks="JavadocStyleCheck" files="SupportBlurDialogFragment"/>
<suppress checks="JavadocStyleCheck" files="BlurDialogFragment"/>

<suppress checks="FileLength" files="BlurDialogEngine"/>
</suppressions>
11 changes: 6 additions & 5 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ apply plugin: 'com.jfrog.bintray'
apply from: '../config/quality.gradle'

group ='fr.tvbarthel.blurdialogfragment'
version = '2.1.5'
version = '2.1.6'


android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
minSdkVersion 9
targetSdkVersion 22
targetSdkVersion 23
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
}
Expand Down Expand Up @@ -92,7 +93,7 @@ install {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:appcompat-v7:23.1.1'
}

task sourcesJar(type: Jar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.LinearInterpolator;
Expand Down Expand Up @@ -145,15 +146,33 @@ public BlurDialogEngine(Activity holdingActivity) {
mAnimationDuration = holdingActivity.getResources().getInteger(R.integer.blur_dialog_animation_duration);
}

/**
* Must be linked to the original lifecycle.
*
* @param activity holding activity.
*/
public void onAttach(Activity activity) {
mHoldingActivity = activity;
}


/**
* Resume the engine.
*
* @param retainedInstance use getRetainInstance.
*/
public void onResume(boolean retainedInstance) {
if (mBlurredBackgroundView == null || retainedInstance) {
mBluringTask = new BlurAsyncTask();
mBluringTask.execute();
mHoldingActivity.getWindow().getDecorView().getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
mHoldingActivity.getWindow().getDecorView().getViewTreeObserver().removeOnPreDrawListener(this);
mBluringTask = new BlurAsyncTask();
mBluringTask.execute();
return false;
}
});
}
}

Expand Down Expand Up @@ -197,7 +216,7 @@ public void onAnimationCancel(Animator animation) {
/**
* Must be linked to the original lifecycle.
*/
public void onDestroy() {
public void onDetach() {
if (mBluringTask != null) {
mBluringTask.cancel(true);
}
Expand Down Expand Up @@ -268,7 +287,6 @@ public void setBlurRadius(int radius) {
*
* @param useRenderScript use of RenderScript
*/

public void setUseRenderScript(boolean useRenderScript) {
mUseRenderScript = useRenderScript;
}
Expand Down Expand Up @@ -570,8 +588,6 @@ protected Void doInBackground(Void... params) {
}
//clear memory
mBackground.recycle();
mBackgroundView.destroyDrawingCache();
mBackgroundView.setDrawingCacheEnabled(false);
return null;
}

Expand All @@ -580,6 +596,9 @@ protected Void doInBackground(Void... params) {
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);

mBackgroundView.destroyDrawingCache();
mBackgroundView.setDrawingCacheEnabled(false);

mHoldingActivity.getWindow().addContentView(
mBlurredBackgroundView,
mBlurredBackgroundLayoutParams
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.tvbarthel.lib.blurdialogfragment;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
Expand Down Expand Up @@ -32,6 +33,14 @@ public abstract class BlurDialogFragment extends DialogFragment {
*/
private boolean mDimmingEffect;

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (mBlurEngine != null) {
mBlurEngine.onAttach(activity); // re attached
}
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -77,7 +86,7 @@ public void onStart() {
int currentAnimation = dialog.getWindow().getAttributes().windowAnimations;
if (currentAnimation == 0) {
dialog.getWindow().getAttributes().windowAnimations
= R.style.BlurDialogFragment_Default_Animation;
= R.style.BlurDialogFragment_Default_Animation;
}
}
super.onStart();
Expand All @@ -97,9 +106,9 @@ public void onDismiss(DialogInterface dialog) {
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBit
// created Feburary 29, 2004
// Android port : Yahel Bouaziz <yahel at kayenko.com>
// http://www.kayenko.com
// ported april 5th, 2012
// ported April 5th, 2012
// Single buffer tweak by Thomas Barthelemy <thomas.barthelemy.utc at gmail.com>
// http://tvbarthel.fr/
// modified April 27th, 2016

// This is a compromise between Gaussian Blur and Box blur
// It creates much better looking blurs than Box Blur, but is
Expand Down Expand Up @@ -76,12 +79,9 @@ public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBit

int wm = w - 1;
int hm = h - 1;
int wh = w * h;
int div = radius + radius + 1;

int r[] = new int[wh];
int g[] = new int[wh];
int b[] = new int[wh];
int px = 0;
int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
int vmin[] = new int[Math.max(w, h)];

Expand Down Expand Up @@ -129,9 +129,7 @@ public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBit

for (x = 0; x < w; x++) {

r[yi] = dv[rsum];
g[yi] = dv[gsum];
b[yi] = dv[bsum];
pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];

rsum -= routsum;
gsum -= goutsum;
Expand All @@ -147,6 +145,7 @@ public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBit
if (y == 0) {
vmin[x] = Math.min(x + radius + 1, wm);
}

p = pix[yw + vmin[x]];

sir[0] = (p & 0xff0000) >> 16;
Expand Down Expand Up @@ -184,15 +183,17 @@ public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBit

sir = stack[i + radius];

sir[0] = r[yi];
sir[1] = g[yi];
sir[2] = b[yi];
px = pix[yi];

sir[0] = (px & 0xff0000) >> 16;
sir[1] = (px & 0x00ff00) >> 8;
sir[2] = (px & 0x0000ff);

rbs = r1 - Math.abs(i);

rsum += r[yi] * rbs;
gsum += g[yi] * rbs;
bsum += b[yi] * rbs;
rsum += sir[0] * rbs;
gsum += sir[1] * rbs;
bsum += sir[2] * rbs;

if (i > 0) {
rinsum += sir[0];
Expand Down Expand Up @@ -230,9 +231,11 @@ public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBit
}
p = x + vmin[y];

sir[0] = r[p];
sir[1] = g[p];
sir[2] = b[p];
px = pix[p];

sir[0] = (px & 0xff0000) >> 16;
sir[1] = (px & 0x00ff00) >> 8;
sir[2] = (px & 0x0000ff);

rinsum += sir[0];
ginsum += sir[1];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.tvbarthel.lib.blurdialogfragment;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
Expand Down Expand Up @@ -30,6 +31,14 @@ public abstract class SupportBlurDialogFragment extends DialogFragment {
*/
private boolean mDimmingEffect;

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (mBlurEngine != null) {
mBlurEngine.onAttach(activity); // re attached
}
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -75,7 +84,7 @@ public void onStart() {
int currentAnimation = dialog.getWindow().getAttributes().windowAnimations;
if (currentAnimation == 0) {
dialog.getWindow().getAttributes().windowAnimations
= R.style.BlurDialogFragment_Default_Animation;
= R.style.BlurDialogFragment_Default_Animation;
}
}
super.onStart();
Expand All @@ -94,9 +103,9 @@ public void onDismiss(DialogInterface dialog) {
}

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

@Override
Expand Down
14 changes: 7 additions & 7 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "fr.tvbarthel.lib.blurdialogfragment.sample"
minSdkVersion 9
targetSdkVersion 22
versionCode 6
versionName "1.5"
targetSdkVersion 23
versionCode 8
versionName "1.7"
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
}
Expand All @@ -23,7 +23,7 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:cardview-v7:22.2.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile project (":lib")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
Expand Down Expand Up @@ -107,13 +106,13 @@ public void onClick(View v) {
switch (v.getId()) {
case R.id.button:
SampleSupportDialogFragment fragment
= SampleSupportDialogFragment.newInstance(
mBlurRadiusSeekbar.getProgress() + 1,
(mDownScaleFactorSeekbar.getProgress() / 10f) + 2,
mDimmingEnable.isChecked(),
mDebugMode.isChecked(),
mBlurredActionBar.isChecked(),
mUseRenderScript.isChecked()
= SampleSupportDialogFragment.newInstance(
mBlurRadiusSeekbar.getProgress() + 1,
(mDownScaleFactorSeekbar.getProgress() / 10f) + 2,
mDimmingEnable.isChecked(),
mDebugMode.isChecked(),
mBlurredActionBar.isChecked(),
mUseRenderScript.isChecked()
);
fragment.show(getSupportFragmentManager(), "blur_sample");
break;
Expand Down

0 comments on commit f6c8727

Please sign in to comment.