Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KonstantinBerkow/8b84204de95035e1abe5498cd777f3ef to your computer and use it in GitHub Desktop.
Save KonstantinBerkow/8b84204de95035e1abe5498cd777f3ef to your computer and use it in GitHub Desktop.
fun BitmapFactory.Options.verboseToString(): String {
val builder = StringBuilder(1024)
.append("BitmapFactory.Options{")
.append("\"inBitmap\": ").append(inBitmap).append(", ")
.append("\"inDensity\": ").append(inDensity).append(", ")
.append("\"inJustDecodeBounds\": ").append(inJustDecodeBounds).append(", ")
.append("\"inMutable\": ").append(inMutable).append(", ")
.append("\"inPreferredConfig\": ").append(inPreferredConfig).append(", ")
.append("\"inSampleSize\": ").append(inSampleSize).append(", ")
.append("\"inScaled\": ").append(inScaled).append(", ")
.append("\"inScreenDensity\": ").append(inScreenDensity).append(", ")
.append("\"inTargetDensity\": ").append(inTargetDensity).append(", ")
.append("\"outHeight\": ").append(outHeight).append(", ")
.append("\"outMimeType\": ").append(outMimeType).append(", ")
.append("\"outWidth\": ").append(outWidth).append(", ")
.append("\"inTempStorage\": ")
// append inTempStorage without Arrays.toString
val array = inTempStorage
val size = array?.size ?: -1
when {
array == null -> builder.append("null")
size == 0 -> builder.append("[]")
else -> {
builder.append('[').append(array[0].toInt())
for (i in 1 until size) {
builder.append(", ").append(array[i].toInt())
}
builder.append(']')
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
builder.append(", ").append("\"inPremultiplied\": ").append(inPremultiplied)
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
@Suppress("DEPRECATION")
builder.append(", ").append("\"inInputShareable\": ").append(inInputShareable)
.append(", ").append("\"inPurgeable\": ").append(inPurgeable)
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
@Suppress("DEPRECATION")
builder.append(", ").append("\"inDither\": ").append(inDither)
.append(", ").append("\"inPreferQualityOverSpeed\": ").append(inPreferQualityOverSpeed)
.append(", ").append("\"mCancel\": ").append(mCancel)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder.append(", ").append("\"inPreferredColorSpace\": ").append(inPreferredColorSpace)
.append(", ").append("\"outColorSpace\": ").append(outColorSpace)
.append(", ").append("\"outConfig\": ").append(outConfig)
}
return builder.append('}').toString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment