1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-03 13:44:40 +00:00

Layout improvement, refactoring

This commit is contained in:
M66B 2019-01-08 12:29:05 +00:00
parent 4d3fcf51ff
commit 043f55e94c
3 changed files with 75 additions and 45 deletions

View file

@ -29,9 +29,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.database.Cursor;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@ -1041,44 +1039,19 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Spanned html = decodeHtml(message, body);
SpannableStringBuilder builder = new SpannableStringBuilder(html);
QuoteSpan[] quotes = builder.getSpans(0, builder.length(), QuoteSpan.class);
for (QuoteSpan quote : quotes) {
QuoteSpan[] quoteSpans = builder.getSpans(0, builder.length(), QuoteSpan.class);
for (QuoteSpan quoteSpan : quoteSpans) {
builder.setSpan(
new StyledQuoteSpan(),
builder.getSpanStart(quote),
builder.getSpanEnd(quote),
builder.getSpanFlags(quote));
builder.removeSpan(quote);
new StyledQuoteSpan(colorPrimary),
builder.getSpanStart(quoteSpan),
builder.getSpanEnd(quoteSpan),
builder.getSpanFlags(quoteSpan));
builder.removeSpan(quoteSpan);
}
return builder;
}
class StyledQuoteSpan extends QuoteSpan {
StyledQuoteSpan() {
super(colorPrimary);
}
@Override
public int getLeadingMargin(boolean first) {
return 6 /* stripeWidth */ + 12 /* gapWidth */;
}
@Override
public void drawLeadingMargin(@NonNull Canvas c, @NonNull Paint p, int x, int dir, int top, int baseline, int bottom, @NonNull CharSequence text, int start, int end, boolean first, @NonNull Layout layout) {
Paint.Style style = p.getStyle();
int color = p.getColor();
p.setStyle(Paint.Style.FILL);
p.setColor(getColor());
c.drawRect(x, top, x + dir * 6 /* stripeWidth */, bottom, p);
p.setStyle(style);
p.setColor(color);
}
}
@Override
protected void onExecuted(Bundle args, SpannableStringBuilder body) {
TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");

View file

@ -52,9 +52,11 @@ import android.text.Editable;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ImageSpan;
import android.text.style.QuoteSpan;
import android.text.style.StyleSpan;
import android.text.style.TypefaceSpan;
import android.text.style.URLSpan;
@ -1835,18 +1837,36 @@ public class FragmentCompose extends FragmentEx {
final long reference = args.getLong("reference", -1);
String body = EntityMessage.read(context, id);
String quote = (reference < 0 ? null : HtmlHelper.getQuote(context, reference, true));
Spanned spannedBody = Html.fromHtml(body, cidGetter, null);
return new Spanned[]{
Html.fromHtml(body, cidGetter, null),
quote == null ? null : Html.fromHtml(quote,
new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
return HtmlHelper.decodeImage(source, context, reference, false);
}
},
null)};
String quote = (reference < 0 ? null : HtmlHelper.getQuote(context, reference, true));
Spanned spannedReference = null;
if (quote != null) {
Spanned spannedQuote = Html.fromHtml(quote,
new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
return HtmlHelper.decodeImage(source, context, reference, false);
}
},
null);
int colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary);
SpannableStringBuilder builder = new SpannableStringBuilder(spannedQuote);
QuoteSpan[] quoteSpans = builder.getSpans(0, builder.length(), QuoteSpan.class);
for (QuoteSpan quoteSpan : quoteSpans) {
builder.setSpan(
new StyledQuoteSpan(colorPrimary),
builder.getSpanStart(quoteSpan),
builder.getSpanEnd(quoteSpan),
builder.getSpanFlags(quoteSpan));
builder.removeSpan(quote);
}
spannedReference = builder;
}
return new Spanned[]{spannedBody, spannedReference};
}
@Override

View file

@ -0,0 +1,37 @@
package eu.faircode.email;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.Layout;
import android.text.style.QuoteSpan;
import androidx.annotation.NonNull;
public class StyledQuoteSpan extends QuoteSpan {
StyledQuoteSpan(int color) {
super(color);
}
@Override
public int getLeadingMargin(boolean first) {
return 6 /* stripeWidth */ + 12 /* gapWidth */;
}
@Override
public void drawLeadingMargin(
@NonNull Canvas c, @NonNull Paint p,
int x, int dir, int top, int baseline, int bottom,
@NonNull CharSequence text, int start, int end, boolean first,
@NonNull Layout layout) {
Paint.Style style = p.getStyle();
int color = p.getColor();
p.setStyle(Paint.Style.FILL);
p.setColor(getColor());
c.drawRect(x, top, x + dir * 6 /* stripeWidth */, bottom, p);
p.setStyle(style);
p.setColor(color);
}
}