diff --git a/blurry/src/main/java/jp/wasabeef/blurry/Blur.java b/blurry/src/main/java/jp/wasabeef/blurry/Blur.java index ed25460..74161d3 100644 --- a/blurry/src/main/java/jp/wasabeef/blurry/Blur.java +++ b/blurry/src/main/java/jp/wasabeef/blurry/Blur.java @@ -6,6 +6,7 @@ import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; +import android.graphics.PorterDuffXfermode; import android.renderscript.Allocation; import android.renderscript.Element; import android.renderscript.RSRuntimeException; @@ -49,7 +50,7 @@ public static Bitmap of(Context context, Bitmap source, BlurFactor factor) { return null; } - Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + Bitmap bitmap = Bitmap.createBitmap(context.getResources().getDisplayMetrics(), width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.scale(1 / (float) factor.sampling, 1 / (float) factor.sampling); @@ -66,6 +67,11 @@ public static Bitmap of(Context context, Bitmap source, BlurFactor factor) { bitmap = Blur.stack(bitmap, factor.radius, true); } + if (factor.hotRect != null) { + paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); + canvas.drawBitmap(source, factor.hotRect, factor.hotRect, paint); + } + if (factor.sampling == BlurFactor.DEFAULT_SAMPLING) { return bitmap; } else { diff --git a/blurry/src/main/java/jp/wasabeef/blurry/BlurFactor.java b/blurry/src/main/java/jp/wasabeef/blurry/BlurFactor.java index 4484220..19aa40d 100644 --- a/blurry/src/main/java/jp/wasabeef/blurry/BlurFactor.java +++ b/blurry/src/main/java/jp/wasabeef/blurry/BlurFactor.java @@ -1,6 +1,7 @@ package jp.wasabeef.blurry; import android.graphics.Color; +import android.graphics.Rect; /** * Copyright (C) 2020 Wasabeef @@ -28,4 +29,5 @@ class BlurFactor { public int radius = DEFAULT_RADIUS; public int sampling = DEFAULT_SAMPLING; public int color = Color.TRANSPARENT; + public Rect hotRect; } diff --git a/blurry/src/main/java/jp/wasabeef/blurry/BlurTask.java b/blurry/src/main/java/jp/wasabeef/blurry/BlurTask.java index 94b7b43..254bd93 100644 --- a/blurry/src/main/java/jp/wasabeef/blurry/BlurTask.java +++ b/blurry/src/main/java/jp/wasabeef/blurry/BlurTask.java @@ -61,7 +61,7 @@ public void execute() { THREAD_POOL.execute(new Runnable() { @Override public void run() { - Context context = contextWeakRef.get(); + final Context context = contextWeakRef.get(); if (callback != null) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override diff --git a/blurry/src/main/java/jp/wasabeef/blurry/Blurry.java b/blurry/src/main/java/jp/wasabeef/blurry/Blurry.java index f887eac..91e968b 100644 --- a/blurry/src/main/java/jp/wasabeef/blurry/Blurry.java +++ b/blurry/src/main/java/jp/wasabeef/blurry/Blurry.java @@ -2,6 +2,7 @@ import android.content.Context; import android.graphics.Bitmap; +import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.view.View; @@ -95,9 +96,23 @@ public BitmapComposer from(Bitmap bitmap) { } public void onto(final ViewGroup target) { + onto(target, null); + } + + public void onto(final ViewGroup target, final View hotView) { factor.width = target.getMeasuredWidth(); factor.height = target.getMeasuredHeight(); + if (hotView != null) { + final int[] hotPos = new int[2]; + hotView.getLocationOnScreen(hotPos); + final int[] targetPos = new int[2]; + target.getLocationOnScreen(targetPos); + final int relativeX = hotPos[0] - targetPos[0]; + final int relativeY = hotPos[1] - targetPos[1]; + factor.hotRect = new Rect(relativeX, relativeY, hotView.getWidth() + relativeX, hotView.getHeight() + relativeY); + } + if (async) { BlurTask task = new BlurTask(target, factor, new BlurTask.Callback() { @Override diff --git a/build.gradle b/build.gradle index 808b056..10f426e 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:7.1.0-beta04' + classpath 'com.android.tools.build:gradle:4.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // TODO: Close JCenter on May 1st https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/ diff --git a/example/src/main/java/jp/wasabeef/example/blurry/MainActivity.kt b/example/src/main/java/jp/wasabeef/example/blurry/MainActivity.kt index e8f0912..3f50547 100644 --- a/example/src/main/java/jp/wasabeef/example/blurry/MainActivity.kt +++ b/example/src/main/java/jp/wasabeef/example/blurry/MainActivity.kt @@ -59,7 +59,7 @@ class MainActivity : AppCompatActivity() { .sampling(2) .async() .animate(500) - .onto(findViewById(R.id.content) as ViewGroup) + .onto(findViewById(R.id.content) as ViewGroup, findViewById(R.id.hotView)) Log.d(getString(R.string.app_name), "TIME " + (System.currentTimeMillis() - startMs).toString() + "ms") } diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml index 281ed22..4bc5189 100644 --- a/example/src/main/res/layout/activity_main.xml +++ b/example/src/main/res/layout/activity_main.xml @@ -68,5 +68,12 @@ android:textSize="88sp" android:textStyle="bold" /> + +