use of androidx.annotation.ColorInt in project react-native-navigation by wix.
the class TextViewUtils method getTextColor.
@ColorInt
public static int getTextColor(TextView view) {
SpannedString text = new SpannedString(view.getText());
ForegroundColorSpan[] spans = text.getSpans(0, text.length(), ForegroundColorSpan.class);
return spans.length == 0 ? view.getCurrentTextColor() : spans[0].getForegroundColor();
}
use of androidx.annotation.ColorInt in project AntennaPod by AntennaPod.
the class ThemeUtils method getColorFromAttr.
@ColorInt
public static int getColorFromAttr(Context context, @AttrRes int attr) {
TypedValue typedValue = new TypedValue();
context.getTheme().resolveAttribute(attr, typedValue, true);
if (typedValue.resourceId != 0) {
return ContextCompat.getColor(context, typedValue.resourceId);
}
return typedValue.data;
}
use of androidx.annotation.ColorInt in project Conversations by siacs.
the class StyledAttributes method getColor.
@ColorInt
public static int getColor(Context context, @AttrRes int attr) {
TypedArray typedArray = context.obtainStyledAttributes(new int[] { attr });
int color = typedArray.getColor(0, 0);
typedArray.recycle();
return color;
}
use of androidx.annotation.ColorInt in project ExoPlayer by google.
the class ColorParser method parseColorInternal.
@ColorInt
private static int parseColorInternal(String colorExpression, boolean alphaHasFloatFormat) {
Assertions.checkArgument(!TextUtils.isEmpty(colorExpression));
colorExpression = colorExpression.replace(" ", "");
if (colorExpression.charAt(0) == '#') {
// Parse using Long to avoid failure when colorExpression is greater than #7FFFFFFF.
int color = (int) Long.parseLong(colorExpression.substring(1), 16);
if (colorExpression.length() == 7) {
// Set the alpha value
color |= 0xFF000000;
} else if (colorExpression.length() == 9) {
// We have #RRGGBBAA, but we need #AARRGGBB
color = ((color & 0xFF) << 24) | (color >>> 8);
} else {
throw new IllegalArgumentException();
}
return color;
} else if (colorExpression.startsWith(RGBA)) {
Matcher matcher = (alphaHasFloatFormat ? RGBA_PATTERN_FLOAT_ALPHA : RGBA_PATTERN_INT_ALPHA).matcher(colorExpression);
if (matcher.matches()) {
return Color.argb(alphaHasFloatFormat ? (int) (255 * Float.parseFloat(Assertions.checkNotNull(matcher.group(4)))) : Integer.parseInt(Assertions.checkNotNull(matcher.group(4)), 10), Integer.parseInt(Assertions.checkNotNull(matcher.group(1)), 10), Integer.parseInt(Assertions.checkNotNull(matcher.group(2)), 10), Integer.parseInt(Assertions.checkNotNull(matcher.group(3)), 10));
}
} else if (colorExpression.startsWith(RGB)) {
Matcher matcher = RGB_PATTERN.matcher(colorExpression);
if (matcher.matches()) {
return Color.rgb(Integer.parseInt(Assertions.checkNotNull(matcher.group(1)), 10), Integer.parseInt(Assertions.checkNotNull(matcher.group(2)), 10), Integer.parseInt(Assertions.checkNotNull(matcher.group(3)), 10));
}
} else {
// we use our own color map
Integer color = COLOR_MAP.get(Ascii.toLowerCase(colorExpression));
if (color != null) {
return color;
}
}
throw new IllegalArgumentException();
}
use of androidx.annotation.ColorInt in project Signal-Android by WhisperSystems.
the class ThemeUtil method getThemedColor.
@ColorInt
public static int getThemedColor(@NonNull Context context, @AttrRes int attr) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
if (theme.resolveAttribute(attr, typedValue, true)) {
return typedValue.data;
}
return Color.RED;
}
Aggregations