Search in sources :

Example 36 with InsetDrawable

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));
}
Also used : UITableCellDrawable(fr.days.android.uitableview.drawable.UITableCellDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) Drawable(android.graphics.drawable.Drawable) UITableCellDrawable(fr.days.android.uitableview.drawable.UITableCellDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable)

Example 37 with InsetDrawable

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));
    }
}
Also used : SpannableString(android.text.SpannableString) ColorDrawable(android.graphics.drawable.ColorDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) InsetDrawable(android.graphics.drawable.InsetDrawable) Spannable(android.text.Spannable) SpannableStringBuilder(android.text.SpannableStringBuilder) NonNull(androidx.annotation.NonNull)

Aggregations

InsetDrawable (android.graphics.drawable.InsetDrawable)37 Drawable (android.graphics.drawable.Drawable)15 LayerDrawable (android.graphics.drawable.LayerDrawable)6 StateListDrawable (android.graphics.drawable.StateListDrawable)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 Resources (android.content.res.Resources)4 ColorDrawable (android.graphics.drawable.ColorDrawable)4 GradientDrawable (android.graphics.drawable.GradientDrawable)4 NonNull (androidx.annotation.NonNull)4 Context (android.content.Context)3 TypedArray (android.content.res.TypedArray)3 Bitmap (android.graphics.Bitmap)3 ShapeDrawable (android.graphics.drawable.ShapeDrawable)3 RoundRectShape (android.graphics.drawable.shapes.RoundRectShape)3 View (android.view.View)3 Attributes (com.cengalabs.flatui.Attributes)3 Activity (android.app.Activity)2 Intent (android.content.Intent)2 Typeface (android.graphics.Typeface)2