Add table customizations (even and header rows)
This commit is contained in:
parent
66ac3382ee
commit
171467a50d
@ -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 }}
|
||||||
|
@ -157,15 +157,28 @@ 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
|
||||||
final int save = canvas.save();
|
// draw backgrounds
|
||||||
try {
|
{
|
||||||
rect.set(0, 0, width, bottom - top);
|
if (header) {
|
||||||
|
theme.applyTableHeaderRowStyle(this.paint);
|
||||||
|
} else if (odd) {
|
||||||
theme.applyTableOddRowStyle(this.paint);
|
theme.applyTableOddRowStyle(this.paint);
|
||||||
canvas.translate(x, top - heightDiff);
|
} else {
|
||||||
canvas.drawRect(rect, this.paint);
|
// even
|
||||||
} finally {
|
theme.applyTableEvenRowStyle(this.paint);
|
||||||
canvas.restoreToCount(save);
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user