Add table customizations (even and header rows)

This commit is contained in:
Dimitry Ivanov 2018-08-14 11:42:41 +03:00
parent 66ac3382ee
commit 171467a50d
2 changed files with 68 additions and 8 deletions

View File

@ -206,6 +206,14 @@ public class SpannableTheme {
// by default paint.color * TABLE_ODD_ROW_DEF_ALPHA // by default paint.color * TABLE_ODD_ROW_DEF_ALPHA
protected final int tableOddRowBackgroundColor; protected final int tableOddRowBackgroundColor;
// @since 1.1.1
// by default no background
protected final int tableEventRowBackgroundColor;
// @since 1.1.1
// by default no background
protected final int tableHeaderRowBackgroundColor;
// drawable that will be used to render checkbox (should be stateful) // drawable that will be used to render checkbox (should be stateful)
// TaskListDrawable can be used // TaskListDrawable can be used
protected final Drawable taskListDrawable; protected final Drawable taskListDrawable;
@ -236,6 +244,8 @@ public class SpannableTheme {
this.tableBorderColor = builder.tableBorderColor; this.tableBorderColor = builder.tableBorderColor;
this.tableBorderWidth = builder.tableBorderWidth; this.tableBorderWidth = builder.tableBorderWidth;
this.tableOddRowBackgroundColor = builder.tableOddRowBackgroundColor; this.tableOddRowBackgroundColor = builder.tableOddRowBackgroundColor;
this.tableEventRowBackgroundColor = builder.tableEvenRowBackgroundColor;
this.tableHeaderRowBackgroundColor = builder.tableHeaderRowBackgroundColor;
this.taskListDrawable = builder.taskListDrawable; this.taskListDrawable = builder.taskListDrawable;
} }
@ -493,6 +503,23 @@ public class SpannableTheme {
paint.setStyle(Paint.Style.FILL); paint.setStyle(Paint.Style.FILL);
} }
/**
* @since 1.1.1
*/
public void applyTableEvenRowStyle(@NonNull Paint paint) {
// by default to background to even row
paint.setColor(tableEventRowBackgroundColor);
paint.setStyle(Paint.Style.FILL);
}
/**
* @since 1.1.1
*/
public void applyTableHeaderRowStyle(@NonNull Paint paint) {
paint.setColor(tableHeaderRowBackgroundColor);
paint.setStyle(Paint.Style.FILL);
}
/** /**
* @return a Drawable to be used as a checkbox indication in task lists * @return a Drawable to be used as a checkbox indication in task lists
* @since 1.0.1 * @since 1.0.1
@ -530,6 +557,8 @@ public class SpannableTheme {
private int tableBorderColor; private int tableBorderColor;
private int tableBorderWidth = -1; private int tableBorderWidth = -1;
private int tableOddRowBackgroundColor; private int tableOddRowBackgroundColor;
private int tableEvenRowBackgroundColor; // @since 1.1.1
private int tableHeaderRowBackgroundColor; // @since 1.1.1
private Drawable taskListDrawable; private Drawable taskListDrawable;
Builder() { Builder() {
@ -733,6 +762,24 @@ public class SpannableTheme {
return this; return this;
} }
/**
* @since 1.1.1
*/
@NonNull
public Builder tableEvenRowBackgroundColor(@ColorInt int tableEvenRowBackgroundColor) {
this.tableEvenRowBackgroundColor = tableEvenRowBackgroundColor;
return this;
}
/**
* @since 1.1.1
*/
@NonNull
public Builder tableHeaderRowBackgroundColor(int tableHeaderRowBackgroundColor) {
this.tableHeaderRowBackgroundColor = tableHeaderRowBackgroundColor;
return this;
}
/** /**
* Supplied Drawable must be stateful ({@link Drawable#isStateful()} returns true). If a task * Supplied Drawable must be stateful ({@link Drawable#isStateful()} returns true). If a task
* is marked as done, then this drawable will be updated with an {@code int[] { android.R.attr.state_checked }} * is marked as done, then this drawable will be updated with an {@code int[] { android.R.attr.state_checked }}

View File

@ -157,17 +157,30 @@ public class TableRowSpan extends ReplacementSpan {
// feels like magic... // feels like magic...
final int heightDiff = (bottom - top - height) / 4; final int heightDiff = (bottom - top - height) / 4;
if (odd) { // @since 1.1.1
// draw backgrounds
{
if (header) {
theme.applyTableHeaderRowStyle(this.paint);
} else if (odd) {
theme.applyTableOddRowStyle(this.paint);
} else {
// even
theme.applyTableEvenRowStyle(this.paint);
}
// if present (0 is transparent)
if (this.paint.getColor() != 0) {
final int save = canvas.save(); final int save = canvas.save();
try { try {
rect.set(0, 0, width, bottom - top); rect.set(0, 0, width, bottom - top);
theme.applyTableOddRowStyle(this.paint);
canvas.translate(x, top - heightDiff); canvas.translate(x, top - heightDiff);
canvas.drawRect(rect, this.paint); canvas.drawRect(rect, this.paint);
} finally { } finally {
canvas.restoreToCount(save); canvas.restoreToCount(save);
} }
} }
}
// @since 1.1.1 reset after applying background color // @since 1.1.1 reset after applying background color
// as background changes color attribute and if not specific tableBorderColor // as background changes color attribute and if not specific tableBorderColor