mirror of https://github.com/M66B/FairEmail.git
Show signature images in composer
This commit is contained in:
parent
583a9f9a92
commit
ff546c79a6
|
@ -134,7 +134,7 @@ public class ActivitySignature extends ActivityBase {
|
||||||
etText.setText(HtmlHelper.fromHtml(html, new Html.ImageGetter() {
|
etText.setText(HtmlHelper.fromHtml(html, new Html.ImageGetter() {
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(String source) {
|
public Drawable getDrawable(String source) {
|
||||||
return getDrawableByUri(Uri.parse(source));
|
return getDrawableByUri(ActivitySignature.this, Uri.parse(source));
|
||||||
}
|
}
|
||||||
}, null));
|
}, null));
|
||||||
}
|
}
|
||||||
|
@ -207,26 +207,32 @@ public class ActivitySignature extends ActivityBase {
|
||||||
int start = etText.getSelectionStart();
|
int start = etText.getSelectionStart();
|
||||||
SpannableStringBuilder ssb = new SpannableStringBuilder(etText.getText());
|
SpannableStringBuilder ssb = new SpannableStringBuilder(etText.getText());
|
||||||
ssb.insert(start, " ");
|
ssb.insert(start, " ");
|
||||||
ImageSpan is = new ImageSpan(getDrawableByUri(uri), uri.toString(), ImageSpan.ALIGN_BASELINE);
|
ImageSpan is = new ImageSpan(getDrawableByUri(this, uri), uri.toString(), ImageSpan.ALIGN_BASELINE);
|
||||||
ssb.setSpan(is, start, start + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
ssb.setSpan(is, start, start + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
etText.setText(ssb);
|
etText.setText(ssb);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable getDrawableByUri(Uri uri) {
|
static Drawable getDrawableByUri(Context context, Uri uri) {
|
||||||
|
if ("content".equals(uri.getScheme())) {
|
||||||
Drawable d;
|
Drawable d;
|
||||||
try {
|
try {
|
||||||
Log.i("Loading image source=" + uri);
|
Log.i("Loading image source=" + uri);
|
||||||
InputStream inputStream = getContentResolver().openInputStream(uri);
|
InputStream inputStream = context.getContentResolver().openInputStream(uri);
|
||||||
d = Drawable.createFromStream(inputStream, uri.toString());
|
d = Drawable.createFromStream(inputStream, uri.toString());
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
Log.w(ex);
|
Log.w(ex);
|
||||||
d = getResources().getDrawable(R.drawable.baseline_broken_image_24);
|
d = context.getResources().getDrawable(R.drawable.baseline_broken_image_24);
|
||||||
}
|
}
|
||||||
|
|
||||||
int w = Helper.dp2pixels(this, d.getIntrinsicWidth());
|
int w = Helper.dp2pixels(context, d.getIntrinsicWidth());
|
||||||
int h = Helper.dp2pixels(this, d.getIntrinsicHeight());
|
int h = Helper.dp2pixels(context, d.getIntrinsicHeight());
|
||||||
|
|
||||||
d.setBounds(0, 0, w, h);
|
d.setBounds(0, 0, w, h);
|
||||||
return d;
|
return d;
|
||||||
|
} else {
|
||||||
|
Drawable d = context.getResources().getDrawable(R.drawable.baseline_image_24);
|
||||||
|
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
|
||||||
|
return d;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4185,11 +4185,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
signature = HtmlHelper.fromHtml(identity.signature, new Html.ImageGetter() {
|
signature = HtmlHelper.fromHtml(identity.signature, new Html.ImageGetter() {
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(String source) {
|
public Drawable getDrawable(String source) {
|
||||||
int px = Helper.dp2pixels(getContext(), 24);
|
return ActivitySignature.getDrawableByUri(getContext(), Uri.parse(source));
|
||||||
Drawable d = getContext().getResources()
|
|
||||||
.getDrawable(R.drawable.baseline_image_24, getContext().getTheme());
|
|
||||||
d.setBounds(0, 0, px, px);
|
|
||||||
return d;
|
|
||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
tvSignature.setText(signature);
|
tvSignature.setText(signature);
|
||||||
|
|
Loading…
Reference in New Issue