Skip to content

Commit

Permalink
Merge pull request #22 from ligol/master
Browse files Browse the repository at this point in the history
Adding support of min API 9 for the library and RenderScript
  • Loading branch information
tbarthel-fr committed Mar 29, 2015
2 parents bef3fc1 + 1db598e commit 848b84d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 46 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This project allows to display DialogFragment with a burring effect behind. The
* [Sample app](#sample-app)
* [Example](#example)
* [Dependency](#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)
Expand Down Expand Up @@ -37,6 +38,20 @@ Dependency
=======
In order to use this library, just add a new gradle dependency : [BlurDialogFragment dependency](https://github.com/tvbarthel/maven#usage)

Use RenderScript in Your Project
======

Simply add this line to your build.gradle

```
defaultConfig {
...
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
...
}
```

Simple usage using inheritance
=======
If you are using **android.app.DialogFragment** : extends **BlurDialogFragment**.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.android.tools.build:gradle:1.1.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
12 changes: 7 additions & 5 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ apply from: '../config/quality.gradle'
def version = '1.1.0'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
minSdkVersion 14
targetSdkVersion 21
minSdkVersion 9
targetSdkVersion 22
versionCode 5
versionName "1.4"
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
}
buildTypes {
release {
Expand All @@ -24,7 +26,7 @@ android {

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

uploadArchives {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.res.Resources;
Expand Down Expand Up @@ -158,28 +159,33 @@ public void onResume(boolean retainedInstance) {
/**
* Must be linked to the original lifecycle.
*/
@SuppressLint("NewApi")
public void onDismiss() {
//remove blurred background and clear memory, could be null if dismissed before blur effect
//processing ends
if (mBlurredBackgroundView != null) {
mBlurredBackgroundView
.animate()
.alpha(0f)
.setDuration(mAnimationDuration)
.setInterpolator(new AccelerateInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
removeBlurredView();
}

@Override
public void onAnimationCancel(Animator animation) {
super.onAnimationCancel(animation);
removeBlurredView();
}
}).start();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
mBlurredBackgroundView
.animate()
.alpha(0f)
.setDuration(mAnimationDuration)
.setInterpolator(new AccelerateInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
removeBlurredView();
}

@Override
public void onAnimationCancel(Animator animation) {
super.onAnimationCancel(animation);
removeBlurredView();
}
}).start();
} else {
removeBlurredView();
}
}

//cancel async task
Expand Down Expand Up @@ -547,21 +553,25 @@ protected Void doInBackground(Void... params) {
}

@Override
@SuppressLint("NewApi")
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
mBlurredBackgroundView.setAlpha(0f);
mHoldingActivity.getWindow().addContentView(
mBlurredBackgroundView,
mBlurredBackgroundLayoutParams
);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
mBlurredBackgroundView
.animate()
.alpha(1f)
.setDuration(mAnimationDuration)
.setInterpolator(new LinearInterpolator())
.start();

mBlurredBackgroundView.setAlpha(0f);
mHoldingActivity.getWindow().addContentView(
mBlurredBackgroundView,
mBlurredBackgroundLayoutParams
);
mBlurredBackgroundView
.animate()
.alpha(1f)
.setDuration(mAnimationDuration)
.setInterpolator(new LinearInterpolator())
.start();

}
mBackgroundView = null;
mBackground = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;

/**
* Helper used to apply Fast blur algorithm on bitmap.
Expand Down
14 changes: 8 additions & 6 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
applicationId "fr.tvbarthel.lib.blurdialogfragment.sample"
minSdkVersion 14
targetSdkVersion 21
minSdkVersion 9
targetSdkVersion 22
versionCode 5
versionName "1.4"
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
}
buildTypes {
release {
Expand All @@ -21,7 +23,7 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:appcompat-v7:22.0.+'
compile 'com.android.support:cardview-v7:22.0.+'
compile project (":lib")
}

0 comments on commit 848b84d

Please sign in to comment.