Refactoring

pull/178/head
M66B 5 years ago
parent 2fd58cb1fa
commit 93541c7823

@ -46,8 +46,6 @@ import androidx.appcompat.app.AlertDialog;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import java.io.InputStream;
public class ActivitySignature extends ActivityBase {
private EditTextCompose etText;
private BottomNavigationView style_bar;
@ -188,7 +186,7 @@ public class ActivitySignature extends ActivityBase {
etText.setText(HtmlHelper.fromHtml(html, new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
return getDrawableByUri(ActivitySignature.this, Uri.parse(source));
return ImageHelper.decodeImage(ActivitySignature.this, -1, source, true, 0, etText);
}
}, null));
dirty = false;
@ -282,7 +280,9 @@ public class ActivitySignature extends ActivityBase {
else {
SpannableStringBuilder ssb = new SpannableStringBuilder(etText.getText());
ssb.insert(start, "\uFFFC"); // Object replacement character
ImageSpan is = new ImageSpan(getDrawableByUri(this, uri), uri.toString(), ImageSpan.ALIGN_BASELINE);
String source = uri.toString();
Drawable d = ImageHelper.decodeImage(this, -1, source, true, 0, etText);
ImageSpan is = new ImageSpan(d, source);
ssb.setSpan(is, start, start + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
etText.setText(ssb);
etText.setSelection(start + 1);
@ -291,29 +291,4 @@ public class ActivitySignature extends ActivityBase {
Log.unexpectedError(getSupportFragmentManager(), ex);
}
}
static Drawable getDrawableByUri(Context context, Uri uri) {
if ("content".equals(uri.getScheme())) {
Drawable d;
try {
Log.i("Loading image source=" + uri);
InputStream inputStream = context.getContentResolver().openInputStream(uri);
d = Drawable.createFromStream(inputStream, uri.toString());
} catch (Throwable ex) {
// FileNotFound, Security
Log.w(ex);
d = context.getResources().getDrawable(R.drawable.baseline_broken_image_24);
}
int w = Helper.dp2pixels(context, d.getIntrinsicWidth());
int h = Helper.dp2pixels(context, d.getIntrinsicHeight());
d.setBounds(0, 0, w, h);
return d;
} else {
Drawable d = context.getResources().getDrawable(R.drawable.baseline_image_24);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
}
}

@ -4567,7 +4567,7 @@ public class FragmentCompose extends FragmentBase {
signature = HtmlHelper.fromHtml(identity.signature, new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
return ActivitySignature.getDrawableByUri(getContext(), Uri.parse(source));
return ImageHelper.decodeImage(getContext(), -1, source, true, 0, tvSignature);
}
}, null);
tvSignature.setText(signature);

@ -40,6 +40,7 @@ import android.graphics.drawable.LevelListDrawable;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.Base64;
@ -58,6 +59,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
@ -225,9 +227,9 @@ class ImageHelper {
boolean embedded = a.source.startsWith("cid:");
boolean data = a.source.startsWith("data:");
boolean content = a.source.startsWith("content:");
Log.d("Image show=" + show + " inline=" + inline +
" embedded=" + embedded + " data=" + data + " source=" + a.source);
Log.d("Image show=" + show + " inline=" + inline + " source=" + a.source);
// Embedded images
if (embedded && (show || inline)) {
@ -311,7 +313,27 @@ class ImageHelper {
return d;
}
if (!show) {
if (content && (show || inline)) {
Drawable d;
try {
Uri uri = Uri.parse(a.source);
Log.i("Loading image source=" + uri);
InputStream inputStream = context.getContentResolver().openInputStream(uri);
d = Drawable.createFromStream(inputStream, uri.toString());
} catch (Throwable ex) {
// FileNotFound, Security
Log.w(ex);
d = context.getResources().getDrawable(R.drawable.baseline_broken_image_24);
}
int w = Helper.dp2pixels(context, d.getIntrinsicWidth());
int h = Helper.dp2pixels(context, d.getIntrinsicHeight());
d.setBounds(0, 0, w, h);
return d;
}
if (!show || id < 0) {
// Show placeholder icon
int resid = (embedded || data ? R.drawable.baseline_photo_library_24 : R.drawable.baseline_image_24);
Drawable d = res.getDrawable(resid, theme);

Loading…
Cancel
Save