diff --git a/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java b/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java index 10c4c762..e82d0d8b 100644 --- a/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java +++ b/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java @@ -206,6 +206,14 @@ public class SpannableTheme { // by default paint.color * TABLE_ODD_ROW_DEF_ALPHA 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) // TaskListDrawable can be used protected final Drawable taskListDrawable; @@ -236,6 +244,8 @@ public class SpannableTheme { this.tableBorderColor = builder.tableBorderColor; this.tableBorderWidth = builder.tableBorderWidth; this.tableOddRowBackgroundColor = builder.tableOddRowBackgroundColor; + this.tableEventRowBackgroundColor = builder.tableEvenRowBackgroundColor; + this.tableHeaderRowBackgroundColor = builder.tableHeaderRowBackgroundColor; this.taskListDrawable = builder.taskListDrawable; } @@ -493,6 +503,23 @@ public class SpannableTheme { 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 * @since 1.0.1 @@ -530,6 +557,8 @@ public class SpannableTheme { private int tableBorderColor; private int tableBorderWidth = -1; private int tableOddRowBackgroundColor; + private int tableEvenRowBackgroundColor; // @since 1.1.1 + private int tableHeaderRowBackgroundColor; // @since 1.1.1 private Drawable taskListDrawable; Builder() { @@ -733,6 +762,24 @@ public class SpannableTheme { 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 * is marked as done, then this drawable will be updated with an {@code int[] { android.R.attr.state_checked }} diff --git a/library/src/main/java/ru/noties/markwon/spans/TableRowSpan.java b/library/src/main/java/ru/noties/markwon/spans/TableRowSpan.java index 5dd1cd69..4d3a35fb 100644 --- a/library/src/main/java/ru/noties/markwon/spans/TableRowSpan.java +++ b/library/src/main/java/ru/noties/markwon/spans/TableRowSpan.java @@ -157,15 +157,28 @@ public class TableRowSpan extends ReplacementSpan { // feels like magic... final int heightDiff = (bottom - top - height) / 4; - if (odd) { - final int save = canvas.save(); - try { - rect.set(0, 0, width, bottom - top); + // @since 1.1.1 + // draw backgrounds + { + if (header) { + theme.applyTableHeaderRowStyle(this.paint); + } else if (odd) { theme.applyTableOddRowStyle(this.paint); - canvas.translate(x, top - heightDiff); - canvas.drawRect(rect, this.paint); - } finally { - canvas.restoreToCount(save); + } else { + // even + theme.applyTableEvenRowStyle(this.paint); + } + + // if present (0 is transparent) + if (this.paint.getColor() != 0) { + final int save = canvas.save(); + try { + rect.set(0, 0, width, bottom - top); + canvas.translate(x, top - heightDiff); + canvas.drawRect(rect, this.paint); + } finally { + canvas.restoreToCount(save); + } } }