微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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,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);

    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,@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,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 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 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,@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,@ArrayRes int defaultColorsRes) {

    return context.getResources().getIntArray(
            array.getResourceId(attr,defaultColorsRes));
}
项目:CameraButton    文件TypedArrayHelper.java   
static int getInteger(Context context,@IntegerRes int defaultIntRes) {

    return array.getInteger(
            attr,context.getResources().getInteger(defaultIntRes));
}
项目:boohee_v5.6    文件TypedArrayUtils.java   
public static Drawable getDrawable(TypedArray a,@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 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 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,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,@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,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,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,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,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,@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 fallbackIndex,boolean defaultValue) {
    return a.getBoolean(index,a.getBoolean(fallbackIndex,defaultValue));
}
项目:letv    文件TypedArrayUtils.java   
public static int getInt(TypedArray a,int defaultValue) {
    return a.getInt(index,a.getInt(fallbackIndex,defaultValue));
}
项目:letv    文件TypedArrayUtils.java   
@AnyRes
public static int getResourceId(TypedArray a,@AnyRes int defaultValue) {
    return a.getResourceId(index,a.getResourceId(fallbackIndex,defaultValue));
}
项目:FontProvider    文件IntegerSimpleMenuPreference.java   
@SuppressLint("RestrictedApi")
private static int[] getIntArray(TypedArray a,@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,defaultValue));
}
项目:boohee_v5.6    文件TypedArrayUtils.java   
public static int getInt(TypedArray a,defaultValue));
}
项目:boohee_v5.6    文件TypedArrayUtils.java   
@AnyRes
public static int getResourceId(TypedArray a,defaultValue));
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。