android.support.annotation.StyleableRes Java Examples

The following examples show how to use android.support.annotation.StyleableRes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: BackgroundLibrary   Author: JavaNoober   File: SelectorPre21DrawableCreator.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #2
Source Project: More-For-GO   Author: rosenpin-deprecated   File: ThemeUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #3
Source Project: openwebnet-android   Author: openwebnet   File: FontViewHelper.java    License: MIT License 6 votes vote down vote up
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();
    }
}
 
Example #4
Source Project: BackgroundLibrary   Author: JavaNoober   File: AnimationDrawableCreator.java    License: Apache License 2.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example #5
Source Project: StickyScrollView   Author: amarjain07   File: StickyScrollPresenter.java    License: MIT License 5 votes vote down vote up
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();
}
 
Example #6
Source Project: letv   Author: JackChan1999   File: TypedArrayUtils.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #7
Source Project: letv   Author: JackChan1999   File: TypedArrayUtils.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #8
Source Project: letv   Author: JackChan1999   File: TypedArrayUtils.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #9
Source Project: NumberPadTimePicker   Author: philliphsu   File: NumberPadTimePickerBottomSheetComponent.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #10
Source Project: CameraButton   Author: hluhovskyi   File: TypedArrayHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Px
static int getDimension(Context context,
                        TypedArray array,
                        @StyleableRes int attr,
                        @DimenRes int defaultDimenRes) {

    return array.getDimensionPixelOffset(
            attr, context.getResources().getDimensionPixelSize(defaultDimenRes));
}
 
Example #11
Source Project: CameraButton   Author: hluhovskyi   File: TypedArrayHelper.java    License: Apache License 2.0 5 votes vote down vote up
@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));
    }
}
 
Example #12
Source Project: CameraButton   Author: hluhovskyi   File: TypedArrayHelper.java    License: Apache License 2.0 5 votes vote down vote up
@ColorInt
static int[] getColors(Context context,
                       TypedArray array,
                       @StyleableRes int attr,
                       @ArrayRes int defaultColorsRes) {

    return context.getResources().getIntArray(
            array.getResourceId(attr, defaultColorsRes));
}
 
Example #13
Source Project: CameraButton   Author: hluhovskyi   File: TypedArrayHelper.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #14
Source Project: CameraButton   Author: hluhovskyi   File: TypedArrayHelper.java    License: Apache License 2.0 5 votes vote down vote up
static int getInteger(Context context,
                      TypedArray array,
                      @StyleableRes int attr,
                      @IntegerRes int defaultIntRes) {

    return array.getInteger(
            attr, context.getResources().getInteger(defaultIntRes));
}
 
Example #15
Source Project: BottomSheetPickers   Author: philliphsu   File: NumberPadTimePickerBottomSheetComponent.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #16
Source Project: tooltip-view   Author: venmo   File: TooltipView.java    License: MIT License 5 votes vote down vote up
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;
}
 
Example #17
Source Project: styT   Author: stytooldex   File: ActivityResourceFinder.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public TypedArray obtainStyledAttributes(@StyleRes int resId, @StyleableRes int[] attrs)
{
    return mActivity.obtainStyledAttributes(resId, attrs);
}
 
Example #18
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ThemeUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
    return Base.getTheme().obtainStyledAttributes(attrs);
}
 
Example #19
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ThemeUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static TypedArray obtainStyledAttributes(@StyleRes int resid, @StyleableRes int[] attrs) {
    return Base.getTheme().obtainStyledAttributes(resid, attrs);
}
 
Example #20
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ThemeUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    return Base.getTheme().obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes);
}
 
Example #21
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ContextUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
    return Base.getContext().obtainStyledAttributes(attrs);
}
 
Example #22
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ContextUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    return Base.getContext().obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes);
}
 
Example #23
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ContextUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs) {
    return Base.getContext().obtainStyledAttributes(set, attrs);
}
 
Example #24
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ContextUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static TypedArray obtainStyledAttributes(@StyleRes int resid, @StyleableRes int[] attrs) {
    return Base.getContext().obtainStyledAttributes(resid, attrs);
}
 
Example #25
Source Project: StickyScrollView   Author: amarjain07   File: ResourceProvider.java    License: MIT License 4 votes vote down vote up
public ResourceProvider(Context context, AttributeSet attrs, @StyleableRes int[] styleRes) {
    mTypeArray = context.obtainStyledAttributes(attrs, styleRes);
}
 
Example #26
Source Project: StickyScrollView   Author: amarjain07   File: ResourceProvider.java    License: MIT License 4 votes vote down vote up
@Override
public int getResourceId(@StyleableRes int styleResId) {
    return mTypeArray.getResourceId(styleResId, 0);
}
 
Example #27
Source Project: letv   Author: JackChan1999   File: TypedArrayUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean getBoolean(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, boolean defaultValue) {
    return a.getBoolean(index, a.getBoolean(fallbackIndex, defaultValue));
}
 
Example #28
Source Project: letv   Author: JackChan1999   File: TypedArrayUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static int getInt(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, int defaultValue) {
    return a.getInt(index, a.getInt(fallbackIndex, defaultValue));
}
 
Example #29
Source Project: letv   Author: JackChan1999   File: TypedArrayUtils.java    License: Apache License 2.0 4 votes vote down vote up
@AnyRes
public static int getResourceId(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, @AnyRes int defaultValue) {
    return a.getResourceId(index, a.getResourceId(fallbackIndex, defaultValue));
}
 
Example #30
Source Project: FontProvider   Author: RikkaApps   File: IntegerSimpleMenuPreference.java    License: MIT License 4 votes vote down vote up
@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);
}