diff --git a/README.md b/README.md index cc50ba0..f6800d8 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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**. diff --git a/build.gradle b/build.gradle index 6356aab..d3ff69d 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/lib/build.gradle b/lib/build.gradle index 303e2cd..ae52eab 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -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 { @@ -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 { diff --git a/lib/src/main/java/fr/tvbarthel/lib/blurdialogfragment/BlurDialogEngine.java b/lib/src/main/java/fr/tvbarthel/lib/blurdialogfragment/BlurDialogEngine.java index 868ee86..cf0e9d0 100644 --- a/lib/src/main/java/fr/tvbarthel/lib/blurdialogfragment/BlurDialogEngine.java +++ b/lib/src/main/java/fr/tvbarthel/lib/blurdialogfragment/BlurDialogEngine.java @@ -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; @@ -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 @@ -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; } diff --git a/lib/src/main/java/fr/tvbarthel/lib/blurdialogfragment/FastBlurHelper.java b/lib/src/main/java/fr/tvbarthel/lib/blurdialogfragment/FastBlurHelper.java index ac15d38..f533e95 100644 --- a/lib/src/main/java/fr/tvbarthel/lib/blurdialogfragment/FastBlurHelper.java +++ b/lib/src/main/java/fr/tvbarthel/lib/blurdialogfragment/FastBlurHelper.java @@ -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. diff --git a/sample/build.gradle b/sample/build.gradle index 5ef96a5..a16bac9 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -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 { @@ -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") }