Made the project compatible with Android Studios new "instant run" feature. Also using the native renderscript libraries instead of the support version now.
This commit is contained in:
parent
1cde43af07
commit
418713df8a
4 changed files with 27 additions and 25 deletions
|
|
@ -61,7 +61,6 @@ android {
|
|||
targetSdkVersion 23
|
||||
|
||||
renderscriptTargetApi 23
|
||||
renderscriptSupportModeEnabled true
|
||||
|
||||
applicationId "com.kabouzeid.gramophone"
|
||||
versionCode 80
|
||||
|
|
|
|||
|
|
@ -4,13 +4,14 @@ import android.content.Context;
|
|||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.renderscript.Allocation;
|
||||
import android.renderscript.Element;
|
||||
import android.renderscript.RSRuntimeException;
|
||||
import android.renderscript.RenderScript;
|
||||
import android.renderscript.ScriptIntrinsicBlur;
|
||||
import android.support.annotation.FloatRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v8.renderscript.Allocation;
|
||||
import android.support.v8.renderscript.Element;
|
||||
import android.support.v8.renderscript.RSRuntimeException;
|
||||
import android.support.v8.renderscript.RenderScript;
|
||||
import android.support.v8.renderscript.ScriptIntrinsicBlur;
|
||||
|
||||
import com.kabouzeid.gramophone.BuildConfig;
|
||||
import com.kabouzeid.gramophone.helper.StackBlur;
|
||||
|
|
@ -56,28 +57,30 @@ public class BlurProcessor implements BitmapProcessor {
|
|||
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
|
||||
canvas.drawBitmap(bitmap, 0, 0, paint);
|
||||
|
||||
try {
|
||||
final RenderScript rs = RenderScript.create(context.getApplicationContext());
|
||||
final Allocation input = Allocation.createFromBitmap(rs, out, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
|
||||
final Allocation output = Allocation.createTyped(rs, input.getType());
|
||||
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
|
||||
if (Build.VERSION.SDK_INT > 16) {
|
||||
try {
|
||||
final RenderScript rs = RenderScript.create(context.getApplicationContext());
|
||||
final Allocation input = Allocation.createFromBitmap(rs, out, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
|
||||
final Allocation output = Allocation.createTyped(rs, input.getType());
|
||||
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
|
||||
|
||||
script.setRadius(blurRadius);
|
||||
script.setInput(input);
|
||||
script.forEach(output);
|
||||
script.setRadius(blurRadius);
|
||||
script.setInput(input);
|
||||
script.forEach(output);
|
||||
|
||||
output.copyTo(out);
|
||||
output.copyTo(out);
|
||||
|
||||
rs.destroy();
|
||||
rs.destroy();
|
||||
|
||||
return out;
|
||||
return out;
|
||||
|
||||
} catch (RSRuntimeException e) {
|
||||
// on some devices RenderScript.create() throws: android.support.v8.renderscript.RSRuntimeException: Error loading libRSSupport library
|
||||
if (BuildConfig.DEBUG) e.printStackTrace();
|
||||
|
||||
return StackBlur.blur(out, blurRadius);
|
||||
} catch (RSRuntimeException e) {
|
||||
// on some devices RenderScript.create() throws: android.support.v8.renderscript.RSRuntimeException: Error loading libRSSupport library
|
||||
if (BuildConfig.DEBUG) e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return StackBlur.blur(out, blurRadius);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue