Search in sources :

Example 1 with ColorInt

use of androidx.annotation.ColorInt in project k-9 by k9mail.

the class CryptoInfoDialog method setMessageSingleLine.

private void setMessageSingleLine(@AttrRes int colorAttr, @StringRes int titleTextRes, @StringRes Integer descTextRes, @DrawableRes int statusIconRes) {
    @ColorInt int color = ThemeUtils.getStyledColor(getActivity(), colorAttr);
    statusIcon.setImageResource(statusIconRes);
    statusIcon.setColorFilter(color);
    titleText.setText(titleTextRes);
    if (descTextRes != null) {
        descriptionText.setText(descTextRes);
        descriptionText.setVisibility(View.VISIBLE);
    } else {
        descriptionText.setVisibility(View.GONE);
    }
}
Also used : ColorInt(androidx.annotation.ColorInt) SuppressLint(android.annotation.SuppressLint)

Example 2 with ColorInt

use of androidx.annotation.ColorInt in project Lightning-Browser by anthonycr.

the class ThemeUtils method getColor.

/**
 * Gets the color attribute from the current theme.
 *
 * @param context  the context to get the theme from.
 * @param resource the color attribute resource.
 * @return the color for the given attribute.
 */
@ColorInt
public static int getColor(@NonNull Context context, @AttrRes int resource) {
    TypedArray a = context.obtainStyledAttributes(sTypedValue.data, new int[] { resource });
    int color = a.getColor(0, 0);
    a.recycle();
    return color;
}
Also used : TypedArray(android.content.res.TypedArray) Paint(android.graphics.Paint) ColorInt(androidx.annotation.ColorInt)

Example 3 with ColorInt

use of androidx.annotation.ColorInt in project AntennaPod by AntennaPod.

the class Timeline method colorToHtml.

private String colorToHtml(Context context, int colorAttr) {
    TypedArray res = context.getTheme().obtainStyledAttributes(new int[] { colorAttr });
    @ColorInt int col = res.getColor(0, 0);
    final String color = "rgba(" + Color.red(col) + "," + Color.green(col) + "," + Color.blue(col) + "," + (Color.alpha(col) / 255.0) + ")";
    res.recycle();
    return color;
}
Also used : ColorInt(androidx.annotation.ColorInt) TypedArray(android.content.res.TypedArray)

Example 4 with ColorInt

use of androidx.annotation.ColorInt in project Conversations by siacs.

the class StylingHelper method makeKeywordOpaque.

private static void makeKeywordOpaque(final Editable editable, int start, int end, @ColorInt int fallbackTextColor) {
    QuoteSpan[] quoteSpans = editable.getSpans(start, end, QuoteSpan.class);
    @ColorInt int textColor = quoteSpans.length > 0 ? quoteSpans[0].getColor() : fallbackTextColor;
    @ColorInt int keywordColor = transformColor(textColor);
    editable.setSpan(new ForegroundColorSpan(keywordColor), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Also used : ColorInt(androidx.annotation.ColorInt) ForegroundColorSpan(android.text.style.ForegroundColorSpan) QuoteSpan(eu.siacs.conversations.ui.text.QuoteSpan)

Example 5 with ColorInt

use of androidx.annotation.ColorInt in project FlexibleAdapter by davideas.

the class DrawableUtils method getColorControlHighlight.

/**
 * Helper method to get the <i>system (or overridden)</i> default {@code colorControlHighlight}.
 * Returns the color of the {@code R.attr.colorControlHighlight} of the style attribute.
 *
 * @param context the context
 * @return Default Color Control Highlight
 * @since 1.0.0-b1
 */
@ColorInt
public static int getColorControlHighlight(Context context) {
    TypedValue outValue = new TypedValue();
    // It's important to not use the android.R because this wouldn't add the overridden drawable
    context.getTheme().resolveAttribute(R.attr.colorControlHighlight, outValue, true);
    if (FlexibleUtils.hasMarshmallow()) {
        return context.getColor(outValue.resourceId);
    } else {
        return context.getResources().getColor(outValue.resourceId);
    }
}
Also used : TypedValue(android.util.TypedValue) ColorInt(androidx.annotation.ColorInt)

Aggregations

ColorInt (androidx.annotation.ColorInt)10 TypedArray (android.content.res.TypedArray)3 TypedValue (android.util.TypedValue)3 ForegroundColorSpan (android.text.style.ForegroundColorSpan)2 SuppressLint (android.annotation.SuppressLint)1 Resources (android.content.res.Resources)1 Paint (android.graphics.Paint)1 SpannedString (android.text.SpannedString)1 AppCompatResources (androidx.appcompat.content.res.AppCompatResources)1 QuoteSpan (eu.siacs.conversations.ui.text.QuoteSpan)1 Matcher (java.util.regex.Matcher)1