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

项目: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;
}
项目:android-issue-reporter    文件: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;
}
项目: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();
    }
}
项目:the-ssn-app    文件: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();

    //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;
}
项目:Loyalty    文件:MultiMode.java   
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;
}
项目: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();
}
项目: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;
}
项目: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;
}
项目: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;
}
项目:NumberPadTimePicker    文件:NumberPadTimePickerBottomSheetComponent.java   
@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;
}
项目: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));
}
项目:CameraButton    文件:TypedArrayHelper.java   
@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));
    }
}
项目: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));
}
项目:CameraButton    文件:TypedArrayHelper.java   
static int getInteger(Context context,
                      TypedArray array,
                      @StyleableRes int attr,
                      @IntegerRes int defaultIntRes) {

    return array.getInteger(
            attr, context.getResources().getInteger(defaultIntRes));
}
项目:boohee_v5.6    文件: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;
}
项目:boohee_v5.6    文件: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;
}
项目:boohee_v5.6    文件: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;
}
项目:rview    文件:FixedSizeLayout.java   
@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();
}
项目:px-android    文件:MPLoadingSpinner.java   
/**
 * 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;
}
项目:BottomSheetPickers    文件:NumberPadTimePickerBottomSheetComponent.java   
@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;
}
项目:material-components-android    文件:MotionSpec.java   
/**
 * 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;
}
项目:material-components-android    文件:MaterialResources.java   
/**
 * 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);
}
项目:material-components-android    文件:MaterialResources.java   
/**
 * 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);
}
项目:material-components-android    文件:MaterialResources.java   
/**
 * 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;
}
项目:material-components-android    文件:MaterialResources.java   
/**
 * 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;
}
项目:amplify    文件:CustomLayoutPromptViewConfig.java   
/**
 * @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;
}
项目:amplify    文件:DefaultLayoutPromptViewConfig.java   
/**
 * @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;
}
项目:amplify    文件:BasePromptViewConfig.java   
/**
 * @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;
}
项目:Lock.Android    文件:AuthConfig.java   
/**
 * 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;
}
项目: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;
}
项目:Android-Client    文件:TextViewAttrHelper.java   
public static void applyAttributes(TextView textView, @Nullable AttributeSet attrs, @StyleableRes int[] styleableIds, @StyleableRes int fontStyableId) {
    Context context = textView.getContext();

    Typeface typeface = Font.MEDIUM.getTypeface(context);

    if (attrs != null) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, styleableIds);

        int fontId = typedArray.getInt(fontStyableId, Font.MEDIUM.getId());
        typeface = Font.fromId(fontId).getTypeface(context);

        typedArray.recycle();
    }

    textView.setTypeface(typeface);
}
项目:StickyScrollView    文件:ResourceProvider.java   
public ResourceProvider(Context context, AttributeSet attrs, @StyleableRes int[] styleRes) {
    mTypeArray = context.obtainStyledAttributes(attrs, styleRes);
}
项目:StickyScrollView    文件:ResourceProvider.java   
@Override
public int getResourceId(@StyleableRes int styleResId) {
    return mTypeArray.getResourceId(styleResId, 0);
}
项目: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));
}
项目: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));
}
项目: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));
}
项目: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);
}
项目:boohee_v5.6    文件:TypedArrayUtils.java   
public static boolean getBoolean(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, boolean defaultValue) {
    return a.getBoolean(index, a.getBoolean(fallbackIndex, defaultValue));
}
项目:boohee_v5.6    文件:TypedArrayUtils.java   
public static int getInt(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, int defaultValue) {
    return a.getInt(index, a.getInt(fallbackIndex, defaultValue));
}
项目:boohee_v5.6    文件: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));
}