From 9b6f3d06e16c7a6cb91eeac71b519a9c58fa119b Mon Sep 17 00:00:00 2001 From: nemanja_tomasevic Date: Fri, 16 Apr 2021 09:36:48 +0200 Subject: [PATCH] adding configurable alpha channel for odd rows of a table --- .../noties/markwon/ext/tables/TableTheme.java | 19 ++++++++++++++++++- .../recycler/table/TableEntryTheme.java | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/markwon-ext-tables/src/main/java/io/noties/markwon/ext/tables/TableTheme.java b/markwon-ext-tables/src/main/java/io/noties/markwon/ext/tables/TableTheme.java index 1f1c4dd1..c56878f5 100644 --- a/markwon-ext-tables/src/main/java/io/noties/markwon/ext/tables/TableTheme.java +++ b/markwon-ext-tables/src/main/java/io/noties/markwon/ext/tables/TableTheme.java @@ -47,6 +47,9 @@ public class TableTheme { // by default paint.color * TABLE_ODD_ROW_DEF_ALPHA protected final int tableOddRowBackgroundColor; + // by default TABLE_ODD_ROW_DEF_ALPHA + protected int tableOddRowBackgroundColorOpacity; + // @since 1.1.1 // by default no background protected final int tableEvenRowBackgroundColor; @@ -62,6 +65,12 @@ public class TableTheme { this.tableOddRowBackgroundColor = builder.tableOddRowBackgroundColor; this.tableEvenRowBackgroundColor = builder.tableEvenRowBackgroundColor; this.tableHeaderRowBackgroundColor = builder.tableHeaderRowBackgroundColor; + + if(builder.tableOddRowBackgroundColorOpacity == -1) { + this.tableOddRowBackgroundColorOpacity = TABLE_ODD_ROW_DEF_ALPHA; + } else { + this.tableOddRowBackgroundColorOpacity = builder.tableOddRowBackgroundColorOpacity; + } } /** @@ -109,7 +118,8 @@ public class TableTheme { public void applyTableOddRowStyle(@NonNull Paint paint) { final int color; if (tableOddRowBackgroundColor == 0) { - color = ColorUtils.applyAlpha(paint.getColor(), TABLE_ODD_ROW_DEF_ALPHA); + + color = ColorUtils.applyAlpha(paint.getColor(), tableOddRowBackgroundColorOpacity); } else { color = tableOddRowBackgroundColor; } @@ -140,6 +150,7 @@ public class TableTheme { private int tableBorderColor; private int tableBorderWidth = -1; private int tableOddRowBackgroundColor; + private int tableOddRowBackgroundColorOpacity = -1; private int tableEvenRowBackgroundColor; // @since 1.1.1 private int tableHeaderRowBackgroundColor; // @since 1.1.1 @@ -167,6 +178,12 @@ public class TableTheme { return this; } + @NonNull + public Builder tableOddRowBackgroundColorOpacity(int tableOddRowBackgroundColorOpacity) { + this.tableOddRowBackgroundColorOpacity = tableOddRowBackgroundColorOpacity; + return this; + } + @NonNull public Builder tableEvenRowBackgroundColor(@ColorInt int tableEvenRowBackgroundColor) { this.tableEvenRowBackgroundColor = tableEvenRowBackgroundColor; diff --git a/markwon-recycler-table/src/main/java/io/noties/markwon/recycler/table/TableEntryTheme.java b/markwon-recycler-table/src/main/java/io/noties/markwon/recycler/table/TableEntryTheme.java index 987499c6..489c58b5 100644 --- a/markwon-recycler-table/src/main/java/io/noties/markwon/recycler/table/TableEntryTheme.java +++ b/markwon-recycler-table/src/main/java/io/noties/markwon/recycler/table/TableEntryTheme.java @@ -52,7 +52,7 @@ public class TableEntryTheme extends TableTheme { @ColorInt public int tableOddRowBackgroundColor(@NonNull Paint paint) { return tableOddRowBackgroundColor == 0 - ? ColorUtils.applyAlpha(paint.getColor(), TABLE_ODD_ROW_DEF_ALPHA) + ? ColorUtils.applyAlpha(paint.getColor(), tableOddRowBackgroundColorOpacity) : tableOddRowBackgroundColor; }