/**
* Obtains an array of colors from the current theme containing colors for control's normal,
* disabled and error state.
*
* @param context Context used to access current theme and process also its attributes.
* @return Array with following colors:
* <ul>
* <li>[{@link #THEME_COLOR_INDEX_NORMAL}] = {@link R.attr#colorControlNormal colorControlNormal}</li>
* <li>[{@link #THEME_COLOR_INDEX_DISABLED}] = colorControlNormal with alpha value of {@link android.R.attr#disabledAlpha android:disabledAlpha}</li>
* <li>[{@link #THEME_COLOR_INDEX_ERROR}] = {@link R.attr#uiColorErrorHighlight uiColorErrorHighlight}</li>
* </ul>
*/
@Size(3)
private static int[] obtainThemeColors(Context context) {
final TypedValue typedValue = new TypedValue();
final Resources.Theme theme = context.getTheme();
final boolean isDarkTheme = !theme.resolveAttribute(R.attr.isLightTheme, typedValue, true) || typedValue.data == 0;
final TypedArray typedArray = context.obtainStyledAttributes(null, R.styleable.Ui_Theme_Tint);
int colorNormal = isDarkTheme ? COLOR_NORMAL : COLOR_NORMAL_LIGHT;
int colorDisabled = isDarkTheme ? COLOR_DISABLED : COLOR_DISABLED_LIGHT;
int colorError = COLOR_ERROR;
if (typedArray != null) {
final int n = typedArray.getIndexCount();
for (int i = 0; i < n; i++) {
final int index = typedArray.getIndex(i);
if (index == R.styleable.Ui_Theme_Tint_colorControlNormal) {
colorNormal = typedArray.getColor(index, colorNormal);
} else if (index == R.styleable.Ui_Theme_Tint_android_disabledAlpha) {
colorDisabled = Colors.withAlpha(colorNormal, typedArray.getFloat(index, ALPHA_RATIO_DISABLED));
} else if (index == R.styleable.Ui_Theme_Tint_uiColorErrorHighlight) {
colorError = typedArray.getColor(index, colorError);
}
}
typedArray.recycle();
}
return new int[] {
colorNormal,
colorDisabled,
colorError
};
}
TintManager.java 文件源码
java
阅读 43
收藏 0
点赞 0
评论 0
项目:android_ui
作者:
评论列表
文章目录