Commit 69a8dfe2 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Scale and crop background on user details screen so to respect the aspect...

Scale and crop background on user details screen so to respect the aspect ratio of the original image
parent b59ba20a
......@@ -109,7 +109,9 @@ class UserDetailsActivity : AppCompatActivity(), UserDetailsView, HasSupportFrag
.get().also { showLoadingView(false) }
}
toolbar.background = BitmapDrawable(resources, image.blurred(this@UserDetailsActivity))
val blurredBitmap = image.blurred(context = this@UserDetailsActivity,
newWidth = toolbar.measuredWidth, newHeight = toolbar.measuredHeight)
toolbar.background = BitmapDrawable(resources, blurredBitmap)
GlideApp.with(this@UserDetailsActivity)
.asBitmap()
.transforms(RoundedCorners(25), CenterCrop())
......
......@@ -6,14 +6,22 @@ import android.renderscript.RenderScript
import android.renderscript.ScriptIntrinsicBlur
fun Bitmap.blurred(context: Context, intensity: Float = 25f): Bitmap {
fun Bitmap.blurred(context: Context, intensity: Float = 25f, newWidth: Int = -1, newHeight: Int = -1): Bitmap {
if (intensity <= 0 || intensity > 25) {
throw IllegalStateException("Intensity out of range (0 < intensity <= 25).")
}
val bitmap = copy(config, true)
val nonScaledBitmap = copy(config, true)
val bitmap = if (newWidth > 0 && newHeight > 0) {
val height = nonScaledBitmap.height
val width = nonScaledBitmap.width
val aspectRadio = width / height
val adjustedWidth = newHeight * aspectRadio
val adjustedHeight = newWidth * height / width
val scaledBitmap = Bitmap.createScaledBitmap(nonScaledBitmap, adjustedWidth, adjustedHeight, false)
Bitmap.createBitmap(scaledBitmap, 0, 0, adjustedWidth, newHeight)
} else nonScaledBitmap
val rs = RenderScript.create(context)
val input = Allocation.createFromBitmap(rs, this, Allocation.MipmapControl.MIPMAP_NONE,
val input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT)
val output = Allocation.createTyped(rs, input.type)
val script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment