类androidx.annotation.AttrRes源码实例Demo

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

源代码1 项目: SSForms   文件: StarkSpinner.java
public StarkSpinner(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    mContext = context;
    getAttributeSet(attrs, defStyleAttr, defStyleRes);

    final LayoutInflater factory = LayoutInflater.from(context);
    factory.inflate(R.layout.view_stark_spinner, this, true);

    mSpinnerListContainer = (LinearLayout) factory.inflate(R.layout.view_list, this, false);
    mSpinnerListView = (ListView) mSpinnerListContainer.findViewById(R.id.LstVw_SpinnerListView);
    if (mListItemDivider != null) {
        mSpinnerListView.setDivider(mListItemDivider);
        mSpinnerListView.setDividerHeight(mListDividerSize);
    }
    mEmptyTextView = (TextView) mSpinnerListContainer.findViewById(R.id.TxtVw_EmptyText);
    mSpinnerListView.setEmptyView(mEmptyTextView);
}
 
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);
    }
}
 
源代码3 项目: BackgroundLibrary   文件: ButtonDrawableCreator.java
private void setSelectorDrawable(TypedArray typedArray, TypedArray buttonTa,
                                 StateListDrawable stateListDrawable, int attr, @AttrRes int functionId) throws Exception {
    int color = 0;
    Drawable resDrawable = null;

    //这里用try catch先判断是否是颜色而不是直接调用getDrawable,为了方便填入的是颜色时可以沿用其他属性,
    //否则如果是其他资源会覆盖app:corners_radius等其他shape属性设置的效果
    try {
        color = buttonTa.getColor(attr, 0);
        if (color == 0) {
            resDrawable = buttonTa.getDrawable(attr);
        }
    } catch (Exception e) {
        resDrawable = buttonTa.getDrawable(attr);
    }
    if (resDrawable == null && color != 0) {
        GradientDrawable tmpDrawable = DrawableFactory.getDrawable(typedArray);
        tmpDrawable.setColor(color);
        stateListDrawable.addState(new int[]{functionId}, tmpDrawable);
    } else {
        stateListDrawable.addState(new int[]{functionId}, resDrawable);
    }
}
 
private void presentCategoryLabel(@AttrRes int iconAttr) {
  switch (iconAttr) {
    case R.attr.emoji_category_recent:
      categoryLabel.setText(getString(R.string.ReactWithAnyEmojiBottomSheetDialogFragment__recently_used));
      break;
    case R.attr.emoji_category_people:
      categoryLabel.setText(getString(R.string.ReactWithAnyEmojiBottomSheetDialogFragment__smileys_and_people));
      break;
    case R.attr.emoji_category_nature:
      categoryLabel.setText(getString(R.string.ReactWithAnyEmojiBottomSheetDialogFragment__nature));
      break;
    case R.attr.emoji_category_foods:
      categoryLabel.setText(getString(R.string.ReactWithAnyEmojiBottomSheetDialogFragment__food));
      break;
    case R.attr.emoji_category_activity:
      categoryLabel.setText(getString(R.string.ReactWithAnyEmojiBottomSheetDialogFragment__activities));
      break;
    case R.attr.emoji_category_places:
      categoryLabel.setText(getString(R.string.ReactWithAnyEmojiBottomSheetDialogFragment__places));
      break;
    case R.attr.emoji_category_objects:
      categoryLabel.setText(getString(R.string.ReactWithAnyEmojiBottomSheetDialogFragment__objects));
      break;
    case R.attr.emoji_category_symbols:
      categoryLabel.setText(getString(R.string.ReactWithAnyEmojiBottomSheetDialogFragment__symbols));
      break;
    case R.attr.emoji_category_flags:
      categoryLabel.setText(getString(R.string.ReactWithAnyEmojiBottomSheetDialogFragment__flags));
      break;
    case R.attr.emoji_category_emoticons:
      categoryLabel.setText(getString(R.string.ReactWithAnyEmojiBottomSheetDialogFragment__emoticons));
      break;
    default:
      throw new AssertionError();
  }
}
 
源代码5 项目: mollyim-android   文件: ThemeUtil.java
public static boolean getThemedBoolean(@NonNull Context context, @AttrRes int attr) {
  TypedValue      typedValue = new TypedValue();
  Resources.Theme theme      = context.getTheme();

  if (theme.resolveAttribute(attr, typedValue, true)) {
    return typedValue.data != 0;
  }

  return false;
}
 
源代码6 项目: mollyim-android   文件: ThemeUtil.java
public static @ColorInt int getThemedColor(@NonNull Context context, @AttrRes int attr) {
  TypedValue typedValue = new TypedValue();
  Resources.Theme theme = context.getTheme();

  if (theme.resolveAttribute(attr, typedValue, true)) {
    return typedValue.data;
  }
  return Color.RED;
}
 
源代码7 项目: mollyim-android   文件: ThemeUtil.java
public static @Nullable Drawable getThemedDrawable(@NonNull Context context, @AttrRes int attr) {
  TypedValue      typedValue = new TypedValue();
  Resources.Theme theme      = context.getTheme();

  if (theme.resolveAttribute(attr, typedValue, true)) {
    return AppCompatResources.getDrawable(context, typedValue.resourceId);
  }

  return null;
}
 
源代码8 项目: dynamic-support   文件: DynamicResourceUtils.java
/**
 * Get the value resource id of a given attribute.
 *
 * @param context The context to retrieve resources.
 * @param attrRes The resource id of the attribute.
 *
 * @return The value resource id of the supplied attribute.
 */
public static int getResourceIdFromAttributes(@NonNull Context context,
        @NonNull AttributeSet attrs, @AttrRes int attrRes) {
    TypedArray a = context.obtainStyledAttributes(attrs, new int[] { attrRes });

    try {
        return a.getResourceId(0, ADS_DEFAULT_RESOURCE_VALUE);
    } finally {
        a.recycle();
    }
}
 
源代码9 项目: a   文件: ATHUtil.java
public static int resolveColor(Context context, @AttrRes int attr, int fallback) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{attr});
    try {
        return a.getColor(0, fallback);
    } finally {
        a.recycle();
    }
}
 
public FixOnItemTouchListenerRecyclerView(@NonNull Context context,
                                          @Nullable AttributeSet attrs,
                                          @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    init();
}
 
源代码11 项目: android-DarkTheme   文件: ColorUtils.java
/**
 * Queries the theme of the given {@code context} for a theme color.
 *
 * @param context   the context holding the current theme.
 * @param attrResId the theme color attribute to resolve.
 * @return the theme color
 */
@ColorInt
public static int getThemeColor(@NonNull Context context, @AttrRes int attrResId) {
    TypedArray a = context.obtainStyledAttributes(null, new int[]{attrResId});
    try {
        return a.getColor(0, Color.MAGENTA);
    } finally {
        a.recycle();
    }
}
 
源代码12 项目: Twire   文件: Service.java
/**
 * Finds and returns an attribute color. If it was not found the method returns the default color
 */
public static int getColorAttribute(@AttrRes int attribute, @ColorRes int defaultColor, Context context) {
    TypedValue a = new TypedValue();
    context.getTheme().resolveAttribute(attribute, a, true);
    if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return a.data;
    } else {
        return ContextCompat.getColor(context, defaultColor);
    }
}
 
源代码13 项目: dynamic-support   文件: DynamicResourceUtils.java
/**
 * Extract the supplied integer attribute value from the theme.
 *
 * @param theme The theme to get the styled attributes.
 * @param attr The integer attribute whose value should be extracted.
 * @param defaultValue The value to return if the attribute is not defined or not a resource.
 *
 * @return The value of the supplied attribute.
 */
public static int resolveInteger(@NonNull Context context,
        @StyleRes int theme, @AttrRes int attr, int defaultValue) {
    TypedArray a = context.getTheme().obtainStyledAttributes(theme, new int[] { attr });

    try {
        return a.getInteger(0, defaultValue);
    } catch (Exception e) {
        return defaultValue;
    } finally {
        a.recycle();
    }
}
 
源代码14 项目: CommonUtils   文件: CommonUtils.java
@ColorInt
public static int resolveAttrAsColor(@NonNull Context context, @AttrRes int id) {
    TypedArray a = context.obtainStyledAttributes(new int[]{id});
    int color = a.getColor(0, 0);
    a.recycle();
    return color;
}
 
源代码15 项目: onpc   文件: Utils.java
/**
 * Procedure sets AppCompatImageButton color given by attribute ID
 */
private static void setImageButtonColorAttr(Context context, AppCompatImageButton b, @AttrRes int resId)
{
    final int c = getThemeColorAttr(context, resId);
    b.clearColorFilter();
    b.setColorFilter(c, PorterDuff.Mode.SRC_ATOP);
}
 
源代码16 项目: onpc   文件: Utils.java
public static void setButtonEnabled(Context context, View b, boolean isEnabled)
{
    @AttrRes int resId = isEnabled ? R.attr.colorButtonEnabled : R.attr.colorButtonDisabled;
    b.setEnabled(isEnabled);
    if (b instanceof AppCompatImageButton)
    {
        Utils.setImageButtonColorAttr(context, (AppCompatImageButton) b, resId);
    }
    if (b instanceof AppCompatButton)
    {
        ((AppCompatButton) b).setTextColor(Utils.getThemeColorAttr(context, resId));
    }
}
 
源代码17 项目: onpc   文件: Utils.java
public static void setButtonSelected(Context context, View b, boolean isSelected)
{
    @AttrRes int resId = isSelected ? R.attr.colorAccent : R.attr.colorButtonEnabled;
    b.setSelected(isSelected);
    if (b instanceof AppCompatImageButton)
    {
        Utils.setImageButtonColorAttr(context, (AppCompatImageButton) b, resId);
    }
    if (b instanceof AppCompatButton)
    {
        ((AppCompatButton) b).setTextColor(Utils.getThemeColorAttr(context, resId));
    }
}
 
源代码18 项目: onpc   文件: Utils.java
/**
 * Procedure sets ImageView background color given by attribute ID
 */
public static void setImageViewColorAttr(Context context, ImageView b, @AttrRes int resId)
{
    final int c = getThemeColorAttr(context, resId);
    b.clearColorFilter();
    b.setColorFilter(c, PorterDuff.Mode.SRC_ATOP);
}
 
源代码19 项目: onpc   文件: Utils.java
/**
 * Fix dialog icon color after dialog creation. Necessary for older Android Versions
 */
public static void fixIconColor(@NonNull AlertDialog dialog, @AttrRes int resId)
{
    final ImageView imageView = dialog.findViewById(android.R.id.icon);
    if (imageView != null)
    {
        Utils.setImageViewColorAttr(dialog.getContext(), imageView, resId);
    }
}
 
@AttrRes int getCategoryIconAttr(int position) {
  return repository.getEmojiPageModels().get(position).getIconAttr();
}
 
源代码21 项目: dynamic-support   文件: DynamicTextView.java
public DynamicTextView(@NonNull Context context,
        @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    loadFromAttributes(attrs);
}
 
源代码22 项目: dynamic-support   文件: DynamicPopupBackground.java
public DynamicPopupBackground(@NonNull Context context,
        @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}
 
源代码23 项目: dynamic-support   文件: DynamicNestedGridView.java
public DynamicNestedGridView(@NonNull Context context,
        @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}
 
源代码24 项目: MyBookshelf   文件: ThemeStore.java
@Override
public ThemeStore primaryColorDarkAttr(@AttrRes int colorAttr) {
    return primaryColorDark(ATHUtil.resolveColor(mContext, colorAttr));
}
 
源代码25 项目: dynamic-support   文件: DynamicRadioButton.java
public DynamicRadioButton(@NonNull Context context,
        @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    loadFromAttributes(attrs);
}
 
源代码26 项目: mollyim-android   文件: ResUtil.java
public static int getDrawableRes(Theme theme, @AttrRes int attr) {
  final TypedValue out = new TypedValue();
  theme.resolveAttribute(attr, out, true);
  return out.resourceId;
}
 
源代码27 项目: dynamic-support   文件: ThemePreview.java
public ThemePreview(@NonNull Context context,
        @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}
 
源代码28 项目: dynamic-support   文件: DynamicLinearLayout.java
public DynamicLinearLayout(@NonNull Context context,
        @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    loadFromAttributes(attrs);
}
 
源代码29 项目: mollyim-android   文件: SearchView.java
public SearchView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
  super(context, attrs, defStyleAttr);
}
 
源代码30 项目: mollyim-android   文件: DarkSearchView.java
public DarkSearchView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
  super(context, attrs, defStyleAttr);

  EditText searchText = findViewById(androidx.appcompat.R.id.search_src_text);
  searchText.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_subtitle_color));
}