类android.support.annotation.StyleableRes源码实例Demo

下面列出了怎么用android.support.annotation.StyleableRes的API类实例代码及写法,或者点击链接到github查看源代码。

private void setSelectorDrawable(StateListDrawable stateListDrawable, @StyleableRes int solidAttr, @StyleableRes int strokeAttr, @AttrRes int functionId) throws Exception {
    if (typedArray.hasValue(solidAttr) || typedArray.hasValue(strokeAttr)) {
        GradientDrawable tmpDrawable = DrawableFactory.getDrawable(typedArray);
        if (typedArray.hasValue(solidAttr)) {
            tmpDrawable.setColor(typedArray.getColor(solidAttr, 0));
        }
        if (typedArray.hasValue(strokeAttr)) {
            int strokeWidth = typedArray.getDimensionPixelSize(R.styleable.background_bl_stroke_width, 0);
            int strokeColor = typedArray.getColor(strokeAttr, 0);
            float strokeDashWidth = typedArray.getDimension(R.styleable.background_bl_stroke_dashWidth, 0f);
            float strokeGap = typedArray.getDimension(R.styleable.background_bl_stroke_dashGap, 0f);
            tmpDrawable.setStroke(strokeWidth, strokeColor, strokeDashWidth, strokeGap);
        }
        stateListDrawable.addState(new int[]{functionId}, tmpDrawable);
    }
}
 
源代码2 项目: More-For-GO   文件: ThemeUtils.java
@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;
}
 
源代码3 项目: openwebnet-android   文件: FontViewHelper.java
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();
    }
}
 
private void addFrame(@StyleableRes int itemDrawableId, @StyleableRes int itemDurationId){
    if(animationTa.hasValue(itemDrawableId)){
        Drawable itemDrawable = animationTa.getDrawable(itemDrawableId);
        if(itemDrawable != null){
            if(animationTa.hasValue(itemDurationId)){
                drawable.addFrame(itemDrawable, animationTa.getInt(itemDurationId, 0));
            }else {
                drawable.addFrame(itemDrawable, duration);
            }
        }
    }
}
 
源代码5 项目: StickyScrollView   文件: StickyScrollPresenter.java
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();
}
 
源代码6 项目: letv   文件: TypedArrayUtils.java
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;
}
 
源代码7 项目: letv   文件: TypedArrayUtils.java
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;
}
 
源代码8 项目: letv   文件: TypedArrayUtils.java
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;
}
 
@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;
}
 
源代码10 项目: CameraButton   文件: TypedArrayHelper.java
@Px
static int getDimension(Context context,
                        TypedArray array,
                        @StyleableRes int attr,
                        @DimenRes int defaultDimenRes) {

    return array.getDimensionPixelOffset(
            attr, context.getResources().getDimensionPixelSize(defaultDimenRes));
}
 
源代码11 项目: CameraButton   文件: TypedArrayHelper.java
@ColorInt
@SuppressWarnings("deprecation")
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));
    }
}
 
源代码12 项目: CameraButton   文件: TypedArrayHelper.java
@ColorInt
static int[] getColors(Context context,
                       TypedArray array,
                       @StyleableRes int attr,
                       @ArrayRes int defaultColorsRes) {

    return context.getResources().getIntArray(
            array.getResourceId(attr, defaultColorsRes));
}
 
源代码13 项目: CameraButton   文件: TypedArrayHelper.java
@DrawableRes
@Nullable
static int[] getDrawableResources(Context context,
                                  TypedArray array,
                                  @StyleableRes int attr) {

    int resourceId = array.getResourceId(attr, -1);
    return resourceId == -1 ? null : context.getResources().getIntArray(resourceId);
}
 
源代码14 项目: CameraButton   文件: TypedArrayHelper.java
static int getInteger(Context context,
                      TypedArray array,
                      @StyleableRes int attr,
                      @IntegerRes int defaultIntRes) {

    return array.getInteger(
            attr, context.getResources().getInteger(defaultIntRes));
}
 
@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;
}
 
源代码16 项目: tooltip-view   文件: TooltipView.java
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;
}
 
源代码17 项目: styT   文件: ActivityResourceFinder.java
@NonNull
@Override
public TypedArray obtainStyledAttributes(@StyleRes int resId, @StyleableRes int[] attrs)
{
    return mActivity.obtainStyledAttributes(resId, attrs);
}
 
源代码18 项目: PowerFileExplorer   文件: ThemeUtil.java
public static TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
    return Base.getTheme().obtainStyledAttributes(attrs);
}
 
源代码19 项目: PowerFileExplorer   文件: ThemeUtil.java
public static TypedArray obtainStyledAttributes(@StyleRes int resid, @StyleableRes int[] attrs) {
    return Base.getTheme().obtainStyledAttributes(resid, attrs);
}
 
源代码20 项目: PowerFileExplorer   文件: ThemeUtil.java
public static TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    return Base.getTheme().obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes);
}
 
源代码21 项目: PowerFileExplorer   文件: ContextUtil.java
public static TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
    return Base.getContext().obtainStyledAttributes(attrs);
}
 
源代码22 项目: PowerFileExplorer   文件: ContextUtil.java
public static TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    return Base.getContext().obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes);
}
 
源代码23 项目: PowerFileExplorer   文件: ContextUtil.java
public static TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs) {
    return Base.getContext().obtainStyledAttributes(set, attrs);
}
 
源代码24 项目: PowerFileExplorer   文件: ContextUtil.java
public static TypedArray obtainStyledAttributes(@StyleRes int resid, @StyleableRes int[] attrs) {
    return Base.getContext().obtainStyledAttributes(resid, attrs);
}
 
源代码25 项目: StickyScrollView   文件: ResourceProvider.java
public ResourceProvider(Context context, AttributeSet attrs, @StyleableRes int[] styleRes) {
    mTypeArray = context.obtainStyledAttributes(attrs, styleRes);
}
 
源代码26 项目: StickyScrollView   文件: ResourceProvider.java
@Override
public int getResourceId(@StyleableRes int styleResId) {
    return mTypeArray.getResourceId(styleResId, 0);
}
 
源代码27 项目: letv   文件: TypedArrayUtils.java
public static boolean getBoolean(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, boolean defaultValue) {
    return a.getBoolean(index, a.getBoolean(fallbackIndex, defaultValue));
}
 
源代码28 项目: letv   文件: TypedArrayUtils.java
public static int getInt(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, int defaultValue) {
    return a.getInt(index, a.getInt(fallbackIndex, defaultValue));
}
 
源代码29 项目: letv   文件: TypedArrayUtils.java
@AnyRes
public static int getResourceId(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, @AnyRes int defaultValue) {
    return a.getResourceId(index, a.getResourceId(fallbackIndex, defaultValue));
}
 
源代码30 项目: FontProvider   文件: IntegerSimpleMenuPreference.java
@SuppressLint("RestrictedApi")
private static int[] getIntArray(TypedArray a, @StyleableRes int index,
                                 @StyleableRes int fallbackIndex) {
    int resourceId = TypedArrayUtils.getResourceId(a, index, fallbackIndex, 0);
    return a.getResources().getIntArray(resourceId);
}
 
 同包方法