android.support.annotation.DrawableRes Java Examples

The following examples show how to use android.support.annotation.DrawableRes. 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: Wear.java    From ZadakNotification with MIT License 6 votes vote down vote up
@SuppressLint("ResourceType")
public Wear remoteInput(@DrawableRes int icon, String title, PendingIntent pendingIntent) {
    if (icon <= 0) {
        throw new IllegalArgumentException("Resource ID Icon Should Not Be Less Than Or Equal To Zero!");
    }

    if (title == null) {
        throw new IllegalArgumentException("Title Must Not Be Null!");
    }

    if (pendingIntent == null) {
        throw new IllegalArgumentException("PendingIntent Must Not Be Null!");
    }

    this.remoteInput = new RemoteInput.Builder(ZadakNotification.mSingleton.mContext.getString(R.string.key_voice_reply))
            .setLabel(ZadakNotification.mSingleton.mContext.getString(R.string.label_voice_reply))
            .setChoices(ZadakNotification.mSingleton.mContext.getResources().getStringArray(R.array.reply_choices))
            .build();
    wearableExtender.addAction(new NotificationCompat.Action.Builder(icon,
            title, pendingIntent)
            .addRemoteInput(remoteInput)
            .build());
    return this;
}
 
Example #2
Source File: ImageUtils.java    From Android-utils with Apache License 2.0 5 votes vote down vote up
public static Bitmap getBitmap(@DrawableRes final int resId) {
    Drawable drawable = ContextCompat.getDrawable(UtilsApp.getApp(), resId);
    Canvas canvas = new Canvas();
    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
            drawable.getIntrinsicHeight(),
            Bitmap.Config.ARGB_8888);
    canvas.setBitmap(bitmap);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
Example #3
Source File: ChannelView.java    From ChannelView with Apache License 2.0 5 votes vote down vote up
/**
 * 设置频道正常状态下背景
 *
 * @see StyleAdapter#setNormalStyle(ViewHolder)
 */
@Deprecated
public void setChannelNormalBackground(@DrawableRes int channelNormalBackground) {
    if (checkDefaultAdapter()) {
        for (View view : allTextView) {
            defaultStyleAdapter.setBackgroundResource(view, channelNormalBackground);
        }
    }
}
 
Example #4
Source File: RecyclerViewActivity.java    From input-samples with Apache License 2.0 5 votes vote down vote up
FieldMetadata(AutofillId autofillId, String autofillHint, @StringRes int labelRes,
        @DrawableRes int iconRes, int inputType) {
    mAutofillId = autofillId;
    mAutofillHint = autofillHint;
    mLabelRes = labelRes;
    mIconRes = iconRes;
    mInputType = inputType;
}
 
Example #5
Source File: RemoteViewsHelper.java    From input-samples with Apache License 2.0 5 votes vote down vote up
private static RemoteViews simpleRemoteViews(String packageName, String remoteViewsText,
        @DrawableRes int drawableId) {
    RemoteViews presentation = new RemoteViews(packageName,
            R.layout.multidataset_service_list_item);
    presentation.setTextViewText(R.id.text, remoteViewsText);
    presentation.setImageViewResource(R.id.icon, drawableId);
    return presentation;
}
 
Example #6
Source File: AttachmentView.java    From weMessage with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Drawable getMessageSelector(@ColorInt int normalColor, @ColorInt int selectedColor, @ColorInt int pressedColor, @DrawableRes int shape) {
    Drawable drawable = DrawableCompat.wrap(getVectorDrawable(shape)).mutate();
    DrawableCompat.setTintList(
            drawable,
            new ColorStateList(
                    new int[][]{
                            new int[]{android.R.attr.state_selected},
                            new int[]{android.R.attr.state_pressed},
                            new int[]{-android.R.attr.state_pressed, -android.R.attr.state_selected}
                    },
                    new int[]{selectedColor, pressedColor, normalColor}
            ));
    return drawable;
}
 
Example #7
Source File: SpecialTab.java    From timecat with Apache License 2.0 5 votes vote down vote up
/**
 * 方便初始化的方法
 * @param drawableRes           默认状态的图标
 * @param checkedDrawableRes    选中状态的图标
 * @param title                 标题
 */
public void initialize(@DrawableRes int drawableRes, @DrawableRes int checkedDrawableRes, String title)
{
    mDefaultDrawable = drawableRes;
    mCheckedDrawable = checkedDrawableRes;
    mTitle.setText(title);
}
 
Example #8
Source File: BaseItemDecoration.java    From FlexItemDecoration with Apache License 2.0 5 votes vote down vote up
/**
 * @param drawableId 最右边分割线的drawable资源id
 * @return
 */
public BaseBuilder redrawRightDividerDrawable(@DrawableRes int drawableId) {
	this.mRightDividerDrawable = ContextCompat.getDrawable(mContext.getApplicationContext(), drawableId);
	if (this.mRightDividerWidth == 0) {
		this.mRightDividerWidth = mRightDividerDrawable.getIntrinsicWidth();
	}
	return this;
}
 
Example #9
Source File: ChannelView.java    From ChannelView with Apache License 2.0 5 votes vote down vote up
/**
 * 设置固定频道的背景
 *
 * @param channelFixedBackground
 * @see StyleAdapter#setFixedStyle(ViewHolder)
 */
@Deprecated
public void setChannelFixedBackground(@DrawableRes int channelFixedBackground) {
    if (checkDefaultAdapter()) {
        for (View view : fixedTextView) {
            defaultStyleAdapter.setBackgroundResource(view, channelFixedBackground);
        }
    }
}
 
Example #10
Source File: BottomThirdBar.java    From Common with Apache License 2.0 5 votes vote down vote up
public Item(@Type int type, @DrawableRes int res, String content,
            @FloatRange(from = 0f, to = 1f) float weight) {
    this.type = type;
    this.res = res;
    this.content = content;
    this.weight = weight;
}
 
Example #11
Source File: ChannelView.java    From ChannelView with Apache License 2.0 5 votes vote down vote up
/**
 * 设置编辑按键背景
 *
 * @param tipEditBackground
 */
public void setTipEditBackground(@DrawableRes int tipEditBackground) {
    this.tipEditBackground = tipEditBackground;
    if (channelLayout != null && channelLayout.tipEdit != null) {
        channelLayout.tipEdit.setBackgroundResource(tipEditBackground);
    }
}
 
Example #12
Source File: ChannelView.java    From ChannelView with Apache License 2.0 5 votes vote down vote up
/**
 * 设置完成按键背景
 *
 * @param tipFinishBackground
 */
public void setTipFinishBackground(@DrawableRes int tipFinishBackground) {
    this.tipFinishBackground = tipFinishBackground;
    if (channelLayout != null && channelLayout.tipFinish != null) {
        channelLayout.tipFinish.setBackgroundResource(tipFinishBackground);
    }
}
 
Example #13
Source File: FingerprintIconView.java    From BiometricPromptCompat with Apache License 2.0 5 votes vote down vote up
@DrawableRes
private static int getDrawable(State currentState, State newState, boolean animate) {
    switch (newState) {
        case OFF:
            if (animate) {
                if (currentState == State.ON) {
                    return R.drawable.fingerprint_draw_off_animation;
                } else if (currentState == State.ERROR) {
                    return R.drawable.fingerprint_error_off_animation;
                }
            }

            return 0;
        case ON:
            if (animate) {
                if (currentState == State.OFF) {
                    return R.drawable.fingerprint_draw_on_animation;
                } else if (currentState == State.ERROR) {
                    return R.drawable.fingerprint_error_state_to_fp_animation;
                }
            }

            return R.drawable.fingerprint_fingerprint;
        case ERROR:
            if (animate) {
                if (currentState == State.ON) {
                    return R.drawable.fingerprint_fp_to_error_state_animation;
                } else if (currentState == State.OFF) {
                    return R.drawable.fingerprint_error_on_animation;
                }
            }

            return R.drawable.fingerprint_error;
        default:
            throw new IllegalArgumentException("Unknown state: " + newState);
    }
}
 
Example #14
Source File: BaseItemDecoration.java    From FlexItemDecoration with Apache License 2.0 5 votes vote down vote up
public BaseItemDecoration redrawFooterDividerDrawable(@DrawableRes int drawableId) {
	this.mFooterDividerDrawable = ContextCompat.getDrawable(mContext.getApplicationContext(), drawableId);
	if (this.mFooterDividerHeight == 0) {
		this.mFooterDividerHeight = this.mFooterDividerDrawable.getIntrinsicHeight();
	}
	return this;
}
 
Example #15
Source File: SpannableStringUtils.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置图片
 *
 * @param resourceId 图片资源id
 * @param align      对齐
 * @return {@link Builder}
 */
public Builder setResourceId(@DrawableRes int resourceId, @Align int align) {
    this.resourceId = resourceId;
    this.align = align;
    this.text = " " + this.text;
    imageIsResourceId = true;
    return this;
}
 
Example #16
Source File: LoopBanner.java    From LoopBanner with Apache License 2.0 5 votes vote down vote up
private void setIndicatorResource(@DrawableRes int selectRes, @DrawableRes int unSelectRes, boolean byUser) {
    if (byUser) {
        checkAdapter("setIndicatorResource");
    }
    Drawable selectDrawable = ContextCompat.getDrawable(getContext(), selectRes);
    Drawable unSelectDrawable = ContextCompat.getDrawable(getContext(), unSelectRes);
    this.mSelectDrawable = selectDrawable;
    this.mUnSelectDrawable = unSelectDrawable;
}
 
Example #17
Source File: ImageFragment.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
private void setInfo(String txt, @DrawableRes int drawableId) {
      Log.d(TAG, "setInfo " + txt);
centerInfo.setVisibility(View.VISIBLE);
      centerInfo.setText(txt);
      centerInfo.setTextColor(0xffffffff);
      centerInfo.setCompoundDrawablesWithIntrinsicBounds(0, drawableId, 0, 0);
  }
 
Example #18
Source File: BaseItemDecoration.java    From FlexItemDecoration with Apache License 2.0 5 votes vote down vote up
/**
 * @param drawableId 定制分割线的drawable资源id
 * @return
 */
public BaseBuilder redrawDividerDrawable(@DrawableRes int drawableId) {
	this.mDividerDrawable = ContextCompat.getDrawable(mContext.getApplicationContext(), drawableId);
	if (mOrientation == VERTICAL) {
		if (this.mRedrawDividerHeight == 0) {
			this.mRedrawDividerHeight = mDividerDrawable.getIntrinsicHeight();
		}
	} else {
		if (mRedrawDividerWidth == 0) {
			this.mRedrawDividerWidth = mDividerDrawable.getIntrinsicWidth();
		}
	}
	return this;
}
 
Example #19
Source File: ToolbarEx.java    From SimpleProject with MIT License 5 votes vote down vote up
/**
 * 设置右边Icon的资源
 * @param resId
 * @param horizontalPadding
 * @param marginRight 最右边Icon的右边距
 * @param listeners
 * @return
 */
public ToolbarEx setRightIcon(@DrawableRes int resId, int horizontalPadding, int marginRight, OnClickListener listeners) {
	Toolbar.LayoutParams params = generateDefaultLayoutParams();
	params.rightMargin = marginRight;
	params.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
	rightIcon = new ImageView(getContext());
	rightIcon.setImageResource(resId);
	rightIcon.setPadding(horizontalPadding, 0, horizontalPadding, 0);
	rightIcon.setOnClickListener(listeners);
	addView(rightIcon, params);

	return this;
}
 
Example #20
Source File: PalmApp.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Drawable getDrawableCompact(@DrawableRes int resId) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        return getContext().getDrawable(resId);
    } else {
        return getContext().getResources().getDrawable(resId);
    }
}
 
Example #21
Source File: MorphView.java    From MorphView with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    if (isInEditMode()) {
        setImageResource(android.R.drawable.ic_media_play);
        return;
    }

    TypedArray a = context.getTheme().obtainStyledAttributes(
            attrs,
            R.styleable.MorphView,
            0, 0);

    @DrawableRes int avdFromRes;
    @DrawableRes int avdToRes;
    try {
        avdFromRes = a.getResourceId(R.styleable.MorphView_avdFirst, -1);
        avdToRes = a.getResourceId(R.styleable.MorphView_avdSecond, -1);
    } finally {
        a.recycle();
    }

    showingAvdFirst = true;
    avdFirstToSecond = AnimatedVectorDrawableCompat.create(getContext(), avdFromRes);
    avdSecondToFirst = AnimatedVectorDrawableCompat.create(getContext(), avdToRes);

    if (avdSecondToFirst == null || avdFirstToSecond == null) {
        throw new RuntimeException("Drawable is not a valid AnimatedVectorDrawable");
    } else {
        setImageDrawable(avdFirstToSecond);
    }
}
 
Example #22
Source File: CardsPack.java    From landlord_client with Apache License 2.0 5 votes vote down vote up
private @DrawableRes
int getName2ResId(String resName) {
    int imgRid = 0;
    try {
        imgRid = R.mipmap.class.getDeclaredField(resName).getInt(R.mipmap.class);
    } catch (Exception e) {
        Logger.e(e.getMessage());
    }
    return imgRid;
}
 
Example #23
Source File: DividerGridItemDecoration.java    From FlexItemDecoration with Apache License 2.0 5 votes vote down vote up
public Builder setStickyDrawable(@DrawableRes int drawableId) {
	this.mStickyDrawable = ContextCompat.getDrawable(mContext.getApplicationContext(), drawableId);
	;
	if (this.mStickyHeightOrWidth == 0) {
		this.mStickyHeightOrWidth = mStickyDrawable.getIntrinsicHeight();
	}
	return this;
}
 
Example #24
Source File: CompatResourceUtils.java    From WheelViewDemo with Apache License 2.0 5 votes vote down vote up
public static Drawable getDrawable(@NonNull Context context, @DrawableRes int resId){
    Drawable drawable;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M){
        drawable = context.getResources().getDrawable(resId, context.getTheme());
    } else {
        drawable = context.getResources().getDrawable(resId);
    }
    return drawable;
}
 
Example #25
Source File: FragmentUtils.java    From MvpRoute with Apache License 2.0 5 votes vote down vote up
/**
 * 设置背景资源
 *
 * @param drawid
 * @return
 */
public FragmentWrapper setBackgroundResource(@DrawableRes int drawid) {

	View view = baseFragment.getView();
	if (view != null) {
		view.setBackgroundResource(drawid);
	}
	return this;
}
 
Example #26
Source File: BaseRecyclerAdapter.java    From sealrtc-android with MIT License 5 votes vote down vote up
/**
 * ImageView 设置图片 res
 *
 * @param id
 * @param drawable
 * @return
 */
public BaseViewHolder setImageResource(@IdRes int id, @DrawableRes int drawable) {
    View view = getViewById(id);
    if (view instanceof ImageView) {
        ((ImageView) view).setImageResource(drawable);
    }
    return this;
}
 
Example #27
Source File: FragmentUtils.java    From styT with Apache License 2.0 5 votes vote down vote up
/**
 * 设置背景资源
 *
 * @param fragment fragment
 * @param resId    资源Id
 */
public static void setBackgroundResource(@NonNull final Fragment fragment, @DrawableRes final int resId) {
    View view = fragment.getView();
    if (view != null) {
        view.setBackgroundResource(resId);
    }
}
 
Example #28
Source File: ViewSource.java    From Kalle with Apache License 2.0 4 votes vote down vote up
@Override
void setHomeAsUpIndicator(@DrawableRes int icon) {
    setHomeAsUpIndicator(ContextCompat.getDrawable(getContext(), icon));
}
 
Example #29
Source File: AttachmentView.java    From weMessage with GNU Affero General Public License v3.0 4 votes vote down vote up
protected Drawable getVectorDrawable(@DrawableRes int drawable) {
    return ContextCompat.getDrawable(getContext(), drawable);
}
 
Example #30
Source File: CardTitleView.java    From OmniList with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setIcon(@DrawableRes int mIcon) {
    binding.ivIcon.setImageResource(mIcon);
}