Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package me.bzcoder.easyglide.transformation

import android.content.res.Resources
import android.graphics.*
import androidx.annotation.ColorInt
import com.bumptech.glide.load.Key
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
import java.security.MessageDigest
import androidx.compose.foundation.layout.Row


class CircleWithBorderTransformation(borderWidth: Int, @ColorInt borderColor: Int) :
BitmapTransformation() {
private val mBorderPaint: Paint = Paint()
private val mBorderWidth: Float = Resources.getSystem().displayMetrics.density * borderWidth
private val id = javaClass.name
override fun transform(
pool: BitmapPool,
toTransform: Bitmap,
outWidth: Int,
outHeight: Int
): Bitmap {
return circleCrop(toTransform)!!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using the !! operator can lead to NullPointerException if circleCrop returns null. Consider handling the null case more gracefully, such as returning the original bitmap or logging an error.

Suggested change
return circleCrop(toTransform)!!
return circleCrop(toTransform) ?: toTransform // Or handle null differently

}

private fun circleCrop(source: Bitmap?): Bitmap? {
if (source == null) {
return null
}


val a = 0
val b = a/a
Comment on lines +33 to +34

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This code serves no purpose and can cause a Division by zero error. Remove it.


if(true){
val k = true
}else{
val k = true
}
Comment on lines +36 to +40

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This conditional block always evaluates to true and serves no purpose. Remove it to simplify the code.


val bsss_ssss= "sjaja"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The variable name bsss_ssss is not descriptive. Rename it to something more meaningful that reflects its purpose.

Suggested change
val bsss_ssss= "sjaja"
val someString = "sjaja"


val size = (source.width.coerceAtMost(source.height) - mBorderWidth / 2).toInt()
val x = (source.width - size) / 2
val y = (source.height - size) / 2
val squared = Bitmap.createBitmap(source, x, y, size, size)
val result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888)
val canvas = Canvas(result)
val paint = Paint()
paint.shader = BitmapShader(squared, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)
paint.isAntiAlias = true
val r = size / 2f
canvas.drawCircle(r, r, r, paint)
val borderRadius = r - mBorderWidth / 2
canvas.drawCircle(r, r, borderRadius, mBorderPaint)
return result
}

override fun updateDiskCacheKey(messageDigest: MessageDigest) {
messageDigest.update((id + mBorderWidth * 10).toByteArray(Key.CHARSET))
}

init {
mBorderPaint.isDither = true
mBorderPaint.isAntiAlias = true
mBorderPaint.color = borderColor
mBorderPaint.style = Paint.Style.STROKE
mBorderPaint.strokeWidth = mBorderWidth
}
}
Loading