Files
FairEmail/app/src/main/java/eu/faircode/email/StyledQuoteSpan.java

63 lines
1.9 KiB
Java
Raw Normal View History

2019-01-08 12:29:05 +00:00
package eu.faircode.email;
2019-05-04 22:49:22 +02:00
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2020-01-05 18:32:53 +01:00
Copyright 2018-2020 by Marcel Bokhorst (M66B)
2019-05-04 22:49:22 +02:00
*/
2019-09-24 07:48:47 +02:00
import android.content.Context;
2019-01-08 12:29:05 +00:00
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 {
2019-09-24 07:48:47 +02:00
private int stripeWidth;
private int gapWidth;
StyledQuoteSpan(Context context, int color) {
2019-01-08 12:29:05 +00:00
super(color);
2019-09-24 07:48:47 +02:00
stripeWidth = Helper.dp2pixels(context, 3);
gapWidth = Helper.dp2pixels(context, 6);
2019-01-08 12:29:05 +00:00
}
@Override
public int getLeadingMargin(boolean first) {
2019-09-24 07:48:47 +02:00
return stripeWidth + gapWidth;
2019-01-08 12:29:05 +00:00
}
@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());
2019-09-24 07:48:47 +02:00
c.drawRect(x, top, x + dir * stripeWidth, bottom, p);
2019-01-08 12:29:05 +00:00
p.setStyle(style);
p.setColor(color);
}
}