androidx.annotation.AttrRes Java Examples

The following examples show how to use androidx.annotation.AttrRes. 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 File: StarkSpinner.java    From SSForms with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example #2
Source File: SelectorPre21DrawableCreator.java    From BackgroundLibrary with 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 #3
Source File: ButtonDrawableCreator.java    From BackgroundLibrary with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #4
Source File: ThemeUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #5
Source File: Utils.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
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));
    }
}
 
Example #6
Source File: Utils.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #7
Source File: Utils.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #8
Source File: ReactWithAnyEmojiBottomSheetDialogFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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();
  }
}
 
Example #9
Source File: ThemeUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: ThemeUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #11
Source File: Utils.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
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));
    }
}
 
Example #12
Source File: DynamicResourceUtils.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example #13
Source File: FixOnItemTouchListenerRecyclerView.java    From AndroidFastScroll with Apache License 2.0 5 votes vote down vote up
public FixOnItemTouchListenerRecyclerView(@NonNull Context context,
                                          @Nullable AttributeSet attrs,
                                          @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    init();
}
 
Example #14
Source File: ATHUtil.java    From a with GNU General Public License v3.0 5 votes vote down vote up
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();
    }
}
 
Example #15
Source File: ColorUtils.java    From android-DarkTheme with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example #16
Source File: Service.java    From Twire with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #17
Source File: DynamicResourceUtils.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example #18
Source File: CommonUtils.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #19
Source File: Utils.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #20
Source File: FastScrollNestedScrollView.java    From AndroidFastScroll with Apache License 2.0 4 votes vote down vote up
public FastScrollNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs,
                                  @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    init();
}
 
Example #21
Source File: FastScrollScrollView.java    From AndroidFastScroll with Apache License 2.0 4 votes vote down vote up
public FastScrollScrollView(@NonNull Context context, @Nullable AttributeSet attrs,
                            @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    init();
}
 
Example #22
Source File: FastScrollScrollView.java    From AndroidFastScroll with Apache License 2.0 4 votes vote down vote up
public FastScrollScrollView(@NonNull Context context, @Nullable AttributeSet attrs,
                            @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    init();
}
 
Example #23
Source File: DynamicSeekBarPreference.java    From dynamic-support with Apache License 2.0 4 votes vote down vote up
public DynamicSeekBarPreference(@NonNull Context context,
        @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}
 
Example #24
Source File: DynamicToolbar.java    From dynamic-support with Apache License 2.0 4 votes vote down vote up
public DynamicToolbar(@NonNull Context context,
        @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    loadFromAttributes(attrs);
}
 
Example #25
Source File: ReactWithAnyEmojiViewModel.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@AttrRes int getCategoryIconAttr(int position) {
  return repository.getEmojiPageModels().get(position).getIconAttr();
}
 
Example #26
Source File: FastScrollWebView.java    From AndroidFastScroll with Apache License 2.0 4 votes vote down vote up
public FastScrollWebView(@NonNull Context context, @Nullable AttributeSet attrs,
                         @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    init();
}
 
Example #27
Source File: DynamicFrameLayout.java    From dynamic-support with Apache License 2.0 4 votes vote down vote up
public DynamicFrameLayout(@NonNull Context context,
        @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    loadFromAttributes(attrs);
}
 
Example #28
Source File: DynamicColorView.java    From dynamic-support with Apache License 2.0 4 votes vote down vote up
public DynamicColorView(@NonNull Context context,
        @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    loadFromAttributes(attrs);
}
 
Example #29
Source File: DynamicNightThemePreference.java    From dynamic-support with Apache License 2.0 4 votes vote down vote up
public DynamicNightThemePreference(@NonNull Context context,
        @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}
 
Example #30
Source File: DynamicSeekBar.java    From dynamic-support with Apache License 2.0 4 votes vote down vote up
public DynamicSeekBar(@NonNull Context context,
        @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    loadFromAttributes(attrs);
}