use of android.graphics.drawable.InsetDrawable in project uitableview4android by DayS.
the class UITableCellView method setBackgroundColor.
public void setBackgroundColor(int[] colorDefault, int[] colorPressed) {
// Assign the right backgroundDrawable according to the cell's position in the group
Drawable backgroundDrawable;
if (indexPath.getRowsCount() == 1) {
backgroundDrawable = new UITableCellDrawable(10.0f, 10.0f, colorDefault, colorPressed, borderColor);
} else {
if (indexPath.isFirstCellOfGroup()) {
backgroundDrawable = new UITableCellDrawable(10.0f, 0, colorDefault, colorPressed, borderColor);
} else if (indexPath.isLastCellOfGroup()) {
backgroundDrawable = new UITableCellDrawable(0, 10.0f, colorDefault, colorPressed, borderColor);
} else {
backgroundDrawable = new UITableCellDrawable(0, 0, colorDefault, colorPressed, borderColor);
}
}
// Add extra space if this cell is the last one
int bottomInset = 0;
if (indexPath.isLastCell()) {
bottomInset = INSET;
}
setBackgroundDrawable(new InsetDrawable(backgroundDrawable, INSET, 0, INSET, bottomInset));
}
use of android.graphics.drawable.InsetDrawable in project Signal-Android by signalapp.
the class LiveUpdateMessage method toSpannable.
@NonNull
private static SpannableString toSpannable(@NonNull Context context, @NonNull UpdateDescription updateDescription, @NonNull String string, @ColorInt int defaultTint, boolean adjustPosition) {
boolean isDarkTheme = ThemeUtil.isDarkTheme(context);
int drawableResource = updateDescription.getIconResource();
int tint = isDarkTheme ? updateDescription.getDarkTint() : updateDescription.getLightTint();
if (tint == 0) {
tint = defaultTint;
}
if (drawableResource == 0) {
return new SpannableString(string);
} else {
Drawable drawable = ContextUtil.requireDrawable(context, drawableResource);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.setColorFilter(tint, PorterDuff.Mode.SRC_ATOP);
int insetTop = adjustPosition ? ViewUtil.dpToPx(2) : 0;
InsetDrawable insetDrawable = new InsetDrawable(drawable, 0, insetTop, 0, 0);
insetDrawable.setBounds(0, 0, drawable.getIntrinsicWidth(), insetDrawable.getIntrinsicHeight());
Drawable spaceDrawable = new ColorDrawable(Color.TRANSPARENT);
spaceDrawable.setBounds(0, 0, ViewUtil.dpToPx(8), drawable.getIntrinsicHeight());
Spannable stringWithImage = new SpannableStringBuilder().append(SpanUtil.buildImageSpan(drawable)).append(SpanUtil.buildImageSpan(spaceDrawable)).append(string);
return new SpannableString(SpanUtil.color(tint, stringWithImage));
}
}
Aggregations