Added fail safe

pull/215/head
M66B 8 months ago
parent 2eea158226
commit f44ad49b97

@ -356,33 +356,37 @@ public class FragmentDialogPrint extends FragmentDialogBase {
for (EntityAttachment attachment : attachments) for (EntityAttachment attachment : attachments)
if (attachment.isAttachment()) { if (attachment.isAttachment()) {
int resid = 0; String uri = null;
Bitmap bm = null; if (print_html_images)
if (print_html_images) { try {
String extension = Helper.guessExtension(attachment.getMimeType()); int resid = 0;
if (extension != null) String extension = Helper.guessExtension(attachment.getMimeType());
resid = context.getResources().getIdentifier("file_" + extension, "drawable", context.getPackageName()); if (extension != null)
Drawable d = ContextCompat.getDrawable(context, resid == 0 ? R.drawable.file_bin : resid); resid = context.getResources().getIdentifier("file_" + extension, "drawable", context.getPackageName());
if (d != null) { Drawable d = ContextCompat.getDrawable(context, resid == 0 ? R.drawable.file_bin : resid);
int h = Helper.dp2pixels(context, 12); if (d != null) {
int w = h * d.getIntrinsicWidth() / d.getIntrinsicHeight(); int h = Helper.dp2pixels(context, 12);
bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); int w = h * d.getIntrinsicWidth() / d.getIntrinsicHeight();
Canvas canvas = new Canvas(bm); Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
d.setBounds(0, 0, w, h); Canvas canvas = new Canvas(bm);
d.draw(canvas); d.setBounds(0, 0, w, h);
d.draw(canvas);
Helper.ByteArrayInOutStream bos = new Helper.ByteArrayInOutStream();
bm.compress(Bitmap.CompressFormat.PNG, 90, bos);
uri = ImageHelper.getDataUri(bos.getInputStream(), "image/png");
}
} catch (Throwable ex) {
Log.e(ex);
} }
}
Element span = document.createElement("span"); Element span = document.createElement("span");
if (bm == null) { if (uri == null) {
Element strong = document.createElement("strong"); Element strong = document.createElement("strong");
strong.text(context.getString(R.string.title_attachment)); strong.text(context.getString(R.string.title_attachment));
span.appendChild(strong); span.appendChild(strong);
} else { } else {
Element img = document.createElement("img"); Element img = document.createElement("img");
Helper.ByteArrayInOutStream bos = new Helper.ByteArrayInOutStream();
bm.compress(Bitmap.CompressFormat.PNG, 90, bos);
String uri = ImageHelper.getDataUri(bos.getInputStream(), "image/png");
img.attr("src", uri); img.attr("src", uri);
img.attr("style", "vertical-align: middle; padding-top: 3px; padding-bottom: 3px;"); img.attr("style", "vertical-align: middle; padding-top: 3px; padding-bottom: 3px;");
span.appendChild(img); span.appendChild(img);

Loading…
Cancel
Save