@ColorInt
private static int[] resolveThemeColors(@NonNull Context context, @AttrRes @StyleableRes int[] attrs, @ColorInt int[] defaultColors) {
if (attrs.length != defaultColors.length)
throw new IllegalArgumentException("Argument attrs must be the same size as defaultColors");
TypedValue typedValue = new TypedValue();
TypedArray a = context.obtainStyledAttributes(typedValue.data, attrs);
for (int i = 0; i < attrs.length; i++) {
defaultColors[i] = a.getColor(0, defaultColors[i]);
}
a.recycle();
return defaultColors;
}
java类android.support.annotation.StyleableRes的实例源码
ThemeUtils.java 文件源码
项目:More-For-GO
阅读 44
收藏 0
点赞 0
评论 0
ThemeUtils.java 文件源码
项目:android-issue-reporter
阅读 38
收藏 0
点赞 0
评论 0
@ColorInt
private static int[] resolveThemeColors(@NonNull Context context, @AttrRes @StyleableRes int[] attrs, @ColorInt int[] defaultColors) {
if (attrs.length != defaultColors.length)
throw new IllegalArgumentException("Argument attrs must be the same size as defaultColors");
TypedValue typedValue = new TypedValue();
TypedArray a = context.obtainStyledAttributes(typedValue.data, attrs);
for (int i = 0; i < attrs.length; i++) {
defaultColors[i] = a.getColor(0, defaultColors[i]);
}
a.recycle();
return defaultColors;
}
FontViewHelper.java 文件源码
项目:openwebnet-android
阅读 37
收藏 0
点赞 0
评论 0
public static void initCustomFont(TextView view, AttributeSet attributeSet,
@StyleableRes int[] attrs, int attrIndex) {
TypedArray typedArray = view.getContext().getTheme()
.obtainStyledAttributes(attributeSet, attrs, 0, 0);
try {
int fontIndex = typedArray.getInt(attrIndex, DEFAULT_FONT);
String fontPath = FONTS.get(fontIndex);
if (fontPath != null) {
view.setTypeface(Typeface.createFromAsset(view.getContext().getAssets(), fontPath));
} else {
throw new IllegalArgumentException("invalid font path");
}
} finally {
typedArray.recycle();
}
}
ThemeUtils.java 文件源码
项目:the-ssn-app
阅读 38
收藏 0
点赞 0
评论 0
@ColorInt
private static int[] resolveThemeColors(@NonNull Context context, @AttrRes @StyleableRes int[] attrs, @ColorInt int[] defaultColors) {
if (attrs.length != defaultColors.length)
throw new IllegalArgumentException("Argument attrs must be the same size as defaultColors");
TypedValue typedValue = new TypedValue();
//noinspection ResourceType
TypedArray a = context.obtainStyledAttributes(typedValue.data, attrs);
for (int i = 0; i < attrs.length; i++) {
defaultColors[i] = a.getColor(0, defaultColors[i]);
}
a.recycle();
return defaultColors;
}
MultiMode.java 文件源码
项目:Loyalty
阅读 33
收藏 0
点赞 0
评论 0
private ToolbarState initPrevState(Toolbar toolbar) {
ToolbarState prevState = new ToolbarState();
if (toolbar.getBackground() != null) {
prevState.toolbarColor = ((ColorDrawable) (toolbar.getBackground())).getColor();
}
Context context = toolbar.getContext();
TypedValue typedValue = new TypedValue();
TypedArray attr = context.obtainStyledAttributes(typedValue.data,
new int[]{R.attr.colorPrimary, R.attr.colorPrimaryDark});
if (attr != null) {
if (prevState.toolbarColor > 0) {
prevState.toolbarColor = attr.getColor(0, 0);
}
@StyleableRes int index = 1;
prevState.statusBarColor = attr.getColor(index, prevState.toolbarColor);
attr.recycle();
}
if (toolbar.getTitle() != null) {
prevState.title = toolbar.getTitle().toString();
}
if (toolbar.getSubtitle() != null) {
prevState.subTitle = toolbar.getSubtitle().toString();
}
prevState.title = prevState.title != null ? prevState.title : EMPTY;
prevState.subTitle = prevState.subTitle != null ? prevState.subTitle : EMPTY;
prevState.logo = toolbar.getLogo();
prevState.navigationIcon = toolbar.getNavigationIcon();
return prevState;
}
StickyScrollPresenter.java 文件源码
项目:StickyScrollView
阅读 32
收藏 0
点赞 0
评论 0
public void onGlobalLayoutChange(@StyleableRes int headerRes, @StyleableRes int footerRes){
int headerId = mTypedArrayResourceProvider.getResourceId(headerRes);
if(headerId != 0) {
mStickyScrollPresentation.initHeaderView(headerId);
}
int footerId = mTypedArrayResourceProvider.getResourceId(footerRes);
if(footerId != 0){
mStickyScrollPresentation.initFooterView(footerId);
}
mTypedArrayResourceProvider.recycle();
}
TypedArrayUtils.java 文件源码
项目:letv
阅读 36
收藏 0
点赞 0
评论 0
public static Drawable getDrawable(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex) {
Drawable val = a.getDrawable(index);
if (val == null) {
return a.getDrawable(fallbackIndex);
}
return val;
}
TypedArrayUtils.java 文件源码
项目:letv
阅读 45
收藏 0
点赞 0
评论 0
public static String getString(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex) {
String val = a.getString(index);
if (val == null) {
return a.getString(fallbackIndex);
}
return val;
}
TypedArrayUtils.java 文件源码
项目:letv
阅读 45
收藏 0
点赞 0
评论 0
public static CharSequence[] getTextArray(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex) {
CharSequence[] val = a.getTextArray(index);
if (val == null) {
return a.getTextArray(fallbackIndex);
}
return val;
}
NumberPadTimePickerBottomSheetComponent.java 文件源码
项目:NumberPadTimePicker
阅读 48
收藏 0
点赞 0
评论 0
@NonNull
private static int[] resolveColorAttributesFromTheme(Context context, @StyleableRes int[] attrs) {
final TypedArray ta = context.obtainStyledAttributes(attrs);
final int[] colors = new int[attrs.length];
for (int idxAttr = 0; idxAttr < colors.length; idxAttr++) {
colors[idxAttr] = ta.getColor(idxAttr, 0);
}
ta.recycle();
return colors;
}
TypedArrayHelper.java 文件源码
项目:CameraButton
阅读 47
收藏 0
点赞 0
评论 0
@Px
static int getDimension(Context context,
TypedArray array,
@StyleableRes int attr,
@DimenRes int defaultDimenRes) {
return array.getDimensionPixelOffset(
attr, context.getResources().getDimensionPixelSize(defaultDimenRes));
}
TypedArrayHelper.java 文件源码
项目:CameraButton
阅读 39
收藏 0
点赞 0
评论 0
@ColorInt
static int getColor(Context context,
TypedArray array,
@StyleableRes int attr,
@ColorRes int defaultColorRes) {
if (Build.VERSION.SDK_INT >= 23) {
return array.getColor(attr, context.getColor(defaultColorRes));
} else {
return array.getColor(attr, context.getResources().getColor(defaultColorRes));
}
}
TypedArrayHelper.java 文件源码
项目:CameraButton
阅读 36
收藏 0
点赞 0
评论 0
@ColorInt
static int[] getColors(Context context,
TypedArray array,
@StyleableRes int attr,
@ArrayRes int defaultColorsRes) {
return context.getResources().getIntArray(
array.getResourceId(attr, defaultColorsRes));
}
TypedArrayHelper.java 文件源码
项目:CameraButton
阅读 41
收藏 0
点赞 0
评论 0
static int getInteger(Context context,
TypedArray array,
@StyleableRes int attr,
@IntegerRes int defaultIntRes) {
return array.getInteger(
attr, context.getResources().getInteger(defaultIntRes));
}
TypedArrayUtils.java 文件源码
项目:boohee_v5.6
阅读 40
收藏 0
点赞 0
评论 0
public static Drawable getDrawable(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex) {
Drawable val = a.getDrawable(index);
if (val == null) {
return a.getDrawable(fallbackIndex);
}
return val;
}
TypedArrayUtils.java 文件源码
项目:boohee_v5.6
阅读 34
收藏 0
点赞 0
评论 0
public static String getString(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex) {
String val = a.getString(index);
if (val == null) {
return a.getString(fallbackIndex);
}
return val;
}
TypedArrayUtils.java 文件源码
项目:boohee_v5.6
阅读 33
收藏 0
点赞 0
评论 0
public static CharSequence[] getTextArray(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex) {
CharSequence[] val = a.getTextArray(index);
if (val == null) {
return a.getTextArray(fallbackIndex);
}
return val;
}
FixedSizeLayout.java 文件源码
项目:rview
阅读 49
收藏 0
点赞 0
评论 0
@SuppressWarnings("ResourceType")
public FixedSizeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
@StyleableRes int[] sizeAttrs = { android.R.attr.maxWidth, android.R.attr.maxHeight };
TypedArray a = context.obtainStyledAttributes(attrs, sizeAttrs);
mMaxLayoutWidth = a.getLayoutDimension(0, -1);
mMaxLayoutHeight = a.getLayoutDimension(1, -1);
a.recycle();
}
MPLoadingSpinner.java 文件源码
项目:px-android
阅读 34
收藏 0
点赞 0
评论 0
/**
* Load the color from xml attributes or fallback to the default if not found
*
* @param typedArray attributes typed array
* @param index the styleable index
* @param defaultColor the default color resource id
* @return the color to use
*/
@ColorInt
private int loadColor(TypedArray typedArray, @StyleableRes int index, @ColorRes int defaultColor) {
int loadedColor = ContextCompat.getColor(getContext(), defaultColor);
ColorStateList colorList = typedArray.getColorStateList(index);
if (colorList != null) {
loadedColor = colorList.getDefaultColor();
}
return loadedColor;
}
NumberPadTimePickerBottomSheetComponent.java 文件源码
项目:BottomSheetPickers
阅读 45
收藏 0
点赞 0
评论 0
@NonNull
private static int[] resolveColorAttributesFromTheme(Context context, @StyleableRes int[] attrs) {
final TypedArray ta = context.obtainStyledAttributes(attrs);
final int[] colors = new int[attrs.length];
for (int idxAttr = 0; idxAttr < colors.length; idxAttr++) {
colors[idxAttr] = ta.getColor(idxAttr, 0);
}
ta.recycle();
return colors;
}
MotionSpec.java 文件源码
项目:material-components-android
阅读 34
收藏 0
点赞 0
评论 0
/**
* Inflates an instance of MotionSpec from the animator resource indexed in the given attributes
* array.
*/
@Nullable
public static MotionSpec createFromAttribute(
Context context, TypedArray attributes, @StyleableRes int index) {
if (attributes.hasValue(index)) {
int resourceId = attributes.getResourceId(index, 0);
if (resourceId != 0) {
return createFromResource(context, resourceId);
}
}
return null;
}
MaterialResources.java 文件源码
项目:material-components-android
阅读 40
收藏 0
点赞 0
评论 0
/**
* Returns the {@link ColorStateList} from the given attributes. The resource can include
* themeable attributes, regardless of API level.
*/
@Nullable
public static ColorStateList getColorStateList(
Context context, TypedArray attributes, @StyleableRes int index) {
if (attributes.hasValue(index)) {
int resourceId = attributes.getResourceId(index, 0);
if (resourceId != 0) {
ColorStateList value = AppCompatResources.getColorStateList(context, resourceId);
if (value != null) {
return value;
}
}
}
return attributes.getColorStateList(index);
}
MaterialResources.java 文件源码
项目:material-components-android
阅读 35
收藏 0
点赞 0
评论 0
/**
* Returns the drawable object from the given attributes.
*
* <p>This method supports inflation of {@code <vector>} and {@code <animated-vector>} resources
* on devices where platform support is not available.
*/
@Nullable
public static Drawable getDrawable(
Context context, TypedArray attributes, @StyleableRes int index) {
if (attributes.hasValue(index)) {
int resourceId = attributes.getResourceId(index, 0);
if (resourceId != 0) {
Drawable value = AppCompatResources.getDrawable(context, resourceId);
if (value != null) {
return value;
}
}
}
return attributes.getDrawable(index);
}
MaterialResources.java 文件源码
项目:material-components-android
阅读 36
收藏 0
点赞 0
评论 0
/**
* Returns a TextAppearanceSpan object from the given attributes.
*
* <p>You only need this if you are drawing text manually. Normally, TextView takes care of this.
*/
@Nullable
public static TextAppearance getTextAppearance(
Context context, TypedArray attributes, @StyleableRes int index) {
if (attributes.hasValue(index)) {
int resourceId = attributes.getResourceId(index, 0);
if (resourceId != 0) {
return new TextAppearance(context, resourceId);
}
}
return null;
}
MaterialResources.java 文件源码
项目:material-components-android
阅读 32
收藏 0
点赞 0
评论 0
/**
* Returns the @StyleableRes index that contains value in the attributes array. If both indices
* contain values, the first given index takes precedence and is returned.
*/
@StyleableRes
static int getIndexWithValue(TypedArray attributes, @StyleableRes int a, @StyleableRes int b) {
if (attributes.hasValue(a)) {
return a;
}
return b;
}
CustomLayoutPromptViewConfig.java 文件源码
项目:amplify
阅读 35
收藏 0
点赞 0
评论 0
/**
* @return the color value for the attribute at <code>index</code>, if defined; null otherwise
*/
@Nullable
@LayoutRes
private static Integer suppliedLayoutOrNull(@NonNull final TypedArray typedArray, @StyleableRes final int index) {
final int layoutResourceId = typedArray.getResourceId(index, DEFAULT_LAYOUT_RES_ID_IF_UNDEFINED);
//noinspection ResourceType
return layoutResourceId != DEFAULT_LAYOUT_RES_ID_IF_UNDEFINED ? layoutResourceId : null;
}
DefaultLayoutPromptViewConfig.java 文件源码
项目:amplify
阅读 40
收藏 0
点赞 0
评论 0
/**
* @return the dimension in px defined for the attribute at <code>index</code>, if defined; null otherwise
*/
@Nullable
@Px
private static Integer suppliedDimensionOrNull(
@NonNull final TypedArray typedArray,
@StyleableRes final int index) {
final int dimensionPixelSize = typedArray.getDimensionPixelSize(index, DEFAULT_DIMENSION_VALUE_IF_UNDEFINED);
//noinspection ResourceType
return dimensionPixelSize != DEFAULT_DIMENSION_VALUE_IF_UNDEFINED ? dimensionPixelSize : null;
}
BasePromptViewConfig.java 文件源码
项目:amplify
阅读 69
收藏 0
点赞 0
评论 0
/**
* @return the long value for the attribute at <code>index</code>, if defined; null otherwise
*/
@Nullable
private static Long suppliedLongOrNull(
@Nullable final TypedArray typedArray,
@StyleableRes final int index) {
if (typedArray != null) {
final int integer = typedArray.getInt(index, DEFAULT_INTEGER_VALUE_IF_UNDEFINED);
return integer != DEFAULT_INTEGER_VALUE_IF_UNDEFINED ? (long) integer : null;
}
return null;
}
AuthConfig.java 文件源码
项目:Lock.Android
阅读 37
收藏 0
点赞 0
评论 0
/**
* Retrieves the resource id of the given Style index.
*
* @param context a valid Context
* @param index The index to search on the Style definition.
* @return the id if found or -1.
*/
int getIdForResource(@NonNull Context context, @StyleableRes int index) {
final int[] attrs = new int[]{index};
final TypedArray typedArray = context.getTheme().obtainStyledAttributes(styleRes, attrs);
int id = typedArray.getResourceId(0, -1);
typedArray.recycle();
return id;
}
TooltipView.java 文件源码
项目:tooltip-view
阅读 35
收藏 0
点赞 0
评论 0
private int getDimension(TypedArray a, @StyleableRes int styleableId,
@DimenRes int defaultDimension) {
int result = a.getDimensionPixelSize(styleableId, NOT_PRESENT);
if (result == NOT_PRESENT) {
result = getResources().getDimensionPixelSize(defaultDimension);
}
return result;
}