Skip to content

Instantly share code, notes, and snippets.

@KonstantinBerkow
Last active December 11, 2017 09:13
Show Gist options
  • Save KonstantinBerkow/5a729339eb66d3d036e0ca9dd651ee56 to your computer and use it in GitHub Desktop.
Save KonstantinBerkow/5a729339eb66d3d036e0ca9dd651ee56 to your computer and use it in GitHub Desktop.
Verbose toString for android.graphics.BitmapFactory.Options
import android.graphics.BitmapFactory;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
/**
* Created by konstantinberkow on 12/11/17.
*/
public final class BitmapFactoryOptionsToString {
private BitmapFactoryOptionsToString() {
}
@NonNull
public static String toString(@Nullable BitmapFactory.Options options) {
if (options == null) {
return "null";
}
final StringBuilder builder = new StringBuilder(1024)
.append("BitmapFactory.Options{")
.append("\"inBitmap\": ").append(options.inBitmap).append(", ")
.append("\"inDensity\": ").append(options.inDensity).append(", ")
.append("\"inJustDecodeBounds\": ").append(options.inJustDecodeBounds).append(", ")
.append("\"inMutable\": ").append(options.inMutable).append(", ")
.append("\"inPreferredConfig\": ").append(options.inPreferredConfig).append(", ")
.append("\"inSampleSize\": ").append(options.inSampleSize).append(", ")
.append("\"inScaled\": ").append(options.inScaled).append(", ")
.append("\"inScreenDensity\": ").append(options.inScreenDensity).append(", ")
.append("\"inTargetDensity\": ").append(options.inTargetDensity).append(", ")
.append("\"outHeight\": ").append(options.outHeight).append(", ")
.append("\"outMimeType\": ").append(options.outMimeType).append(", ")
.append("\"outWidth\": ").append(options.outWidth).append(", ")
.append("\"inTempStorage\": ");
// append inTempStorage without Arrays.toString
final byte[] array = options.inTempStorage;
final int length = array == null ? -1 : array.length;
if (length == -1) {
builder.append("null");
} else if (length > 0) {
builder.append('[').append(array[0]);
for (int i = 1; i < length; i++) {
builder.append(", ").append(array[i]);
}
builder.append(']');
} else {
builder.append("[]");
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
builder.append(", ").append("\"inPremultiplied\": ").append(options.inPremultiplied);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
builder.append(", ").append("\"inInputShareable\": ").append(options.inInputShareable)
.append(", ").append("\"inPurgeable\": ").append(options.inPurgeable);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
builder.append(", ").append("\"inDither\": ").append(options.inDither)
.append(", ").append("\"inPreferQualityOverSpeed\": ").append(options.inPreferQualityOverSpeed)
.append(", ").append("\"mCancel\": ").append(options.mCancel);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder.append(", ").append("\"inPreferredColorSpace\": ").append(options.inPreferredColorSpace)
.append(", ").append("\"outColorSpace\": ").append(options.outColorSpace)
.append(", ").append("\"outConfig\": ").append(options.outConfig);
}
return builder.append('}').toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment