Java Code Examples for android.support.annotation.DrawableRes

The following are top voted examples for showing how to use android.support.annotation.DrawableRes. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: q-mail   File: SecurityInfoDialog.java   View source code 6 votes vote down vote up
private void setCryptoMessageSingleLine(@AttrRes int colorAttr,
        @StringRes int topTextRes, @DrawableRes int statusIconRes,
        @DrawableRes Integer statusDotsRes) {
    @ColorInt int color = ThemeUtils.getStyledColor(getActivity(), colorAttr);

    authenticationIcon_1.setImageResource(statusIconRes);
    authenticationIcon_1.setColorFilter(color);
    authenticationText.setText(topTextRes);

    if (statusDotsRes != null) {
        authenticationIcon_3.setImageResource(statusDotsRes);
        authenticationIcon_3.setColorFilter(color);
        authenticationIcon_3.setVisibility(View.VISIBLE);
    } else {
        authenticationIcon_3.setVisibility(View.GONE);
    }

    trustText.setVisibility(View.GONE);
    trustIconFrame.setVisibility(View.GONE);
}
 
Example 2
Project: q-mail   File: SecurityInfoDialog.java   View source code 6 votes vote down vote up
private void setCryptoMessageWithAnimation(@AttrRes int colorAttr,
        @StringRes int topTextRes, @DrawableRes int statusIconRes,
        @StringRes int bottomTextRes, @DrawableRes int statusDotsRes) {
    authenticationIcon_1.setImageResource(statusIconRes);
    authenticationIcon_2.setImageResource(statusDotsRes);
    authenticationIcon_3.setVisibility(View.GONE);
    authenticationText.setText(topTextRes);

    trustIcon_1.setImageResource(statusIconRes);
    trustIcon_2.setImageResource(statusDotsRes);
    trustText.setText(bottomTextRes);

    authenticationIcon_1.setColorFilter(ThemeUtils.getStyledColor(getActivity(), colorAttr));
    trustIcon_2.setColorFilter(ThemeUtils.getStyledColor(getActivity(), colorAttr));

    prepareIconAnimation();
}
 
Example 3
Project: Steps_Android   File: CircleImageSteps.java   View source code 6 votes vote down vote up
/**
 * Function to add view to component
 *
 * @param tag              View tag usually the step number
 * @param drawableResource drawable resource of view
 */
private void addView(int tag, @DrawableRes int drawableResource, boolean isLastStep) {
    // inflate view to component
    View view = LayoutInflater.from(getContext()).inflate(R.layout.step_view_item, rootView, false);

    //set view size and margins
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(stepSize, stepSize);
    layoutParams.setMargins(10, 10, 10, 10);
    view.findViewById(R.id.iv_main_step_image).setLayoutParams(layoutParams);
    view.setTag(tag);

    //set view background color
    setStepColorStatus(false, view);

    //add Image icon to view and add view
    ((ImageView) view.findViewById(R.id.iv_main_step_image)).setImageResource(drawableResource);
    rootView.addView(view);

    if (!isLastStep) {
        view = LayoutInflater.from(getContext()).inflate(R.layout.split_view_item, rootView, false);
        rootView.addView(view);
    }

}
 
Example 4
Project: GifEmoji   File: EmoticonDecoder.java   View source code 6 votes vote down vote up
private void load(Context context, @DrawableRes int drawableRes, int textSize, String url) {
    if (!nativeLoad(handle, url)) {
        nativeClose(handle);
        throw new RuntimeException("not gif");
    } else {
        frameNum = nativeGetFrameCount(handle);
        for (int i = 0; i < frameNum; i++) {
            BitmapDrawable drawable = new BitmapDrawable(context.getResources(), nativeGetFrame(handle, i));
            int width = (textSize * drawable.getIntrinsicWidth()) / drawable.getIntrinsicHeight();
            drawable.setBounds(0, 0, width, textSize);
            EmoticonCache.saveDrawable(drawableRes, i, drawable);
            delay = nativeGetDelay(handle, i);
        }
        nativeClose(handle);
    }
}
 
Example 5
Project: butterknife-parent   File: Utils.java   View source code 6 votes vote down vote up
@UiThread // Implicit synchronization for use of shared resource VALUE.
public static Drawable getTintedDrawable(Context context,
    @DrawableRes int id, @AttrRes int tintAttrId) {
  boolean attributeFound = context.getTheme().resolveAttribute(tintAttrId, VALUE, true);
  if (!attributeFound) {
    throw new Resources.NotFoundException("Required tint color attribute with name "
        + context.getResources().getResourceEntryName(tintAttrId)
        + " and attribute ID "
        + tintAttrId
        + " was not found.");
  }

  Drawable drawable = ContextCompat.getDrawable(context, id);
  drawable = DrawableCompat.wrap(drawable.mutate());
  int color = ContextCompat.getColor(context, VALUE.resourceId);
  DrawableCompat.setTint(drawable, color);
  return drawable;
}
 
Example 6
Project: memetastic   File: ContextUtils.java   View source code 6 votes vote down vote up
public Bitmap drawTextToDrawable(@DrawableRes int resId, String text, int textSize) {
    Resources resources = _context.getResources();
    float scale = resources.getDisplayMetrics().density;
    Bitmap bitmap = getBitmapFromDrawable(resId);

    bitmap = bitmap.copy(bitmap.getConfig(), true);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.rgb(61, 61, 61));
    paint.setTextSize((int) (textSize * scale));
    paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);

    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    int x = (bitmap.getWidth() - bounds.width()) / 2;
    int y = (bitmap.getHeight() + bounds.height()) / 2;
    canvas.drawText(text, x, y, paint);

    return bitmap;
}
 
Example 7
Project: GitHub   File: CircleIndicator.java   View source code 6 votes vote down vote up
private void addIndicator(int orientation, @DrawableRes int backgroundDrawableId,
        Animator animator) {
    if (animator.isRunning()) {
        animator.end();
        animator.cancel();
    }

    View Indicator = new View(getContext());
    Indicator.setBackgroundResource(backgroundDrawableId);
    addView(Indicator, mIndicatorWidth, mIndicatorHeight);
    LayoutParams lp = (LayoutParams) Indicator.getLayoutParams();

    if (orientation == HORIZONTAL) {
        lp.leftMargin = mIndicatorMargin;
        lp.rightMargin = mIndicatorMargin;
    } else {
        lp.topMargin = mIndicatorMargin;
        lp.bottomMargin = mIndicatorMargin;
    }

    Indicator.setLayoutParams(lp);

    animator.setTarget(Indicator);
    animator.start();
}
 
Example 8
Project: ImmerseMode   File: TpSbTlNbwFCImmerseMode.java   View source code 5 votes vote down vote up
@Override
public boolean setStatusDrawableRes(@DrawableRes int drawableRes) {
    Activity activity = mActivityRef.get();
    if (activity != null) {
        Drawable drawable = ContextCompat.getDrawable(activity, drawableRes);
        setStatusDrawable(drawable);
    }
    return true;
}
 
Example 9
Project: Android-skin-support   File: SkinCompatRadioButton.java   View source code 5 votes vote down vote up
@Override
public void setCompoundDrawablesRelativeWithIntrinsicBounds(
        @DrawableRes int start, @DrawableRes int top, @DrawableRes int end, @DrawableRes int bottom) {
    super.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
    if (mTextHelper != null) {
        mTextHelper.onSetCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
    }
}
 
Example 10
Project: xlight_android_native   File: Ui.java   View source code 5 votes vote down vote up
public static Drawable getTintedDrawable(Context ctx, @DrawableRes int drawableResId,
                                         @ColorRes int colorResId) {
    Resources res = ctx.getResources();
    Drawable drawable = ContextCompat.getDrawable(ctx, drawableResId);
    int color = res.getColor(colorResId);
    drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
    return drawable;
}
 
Example 11
Project: Android-skin-support   File: SkinCompatImageView.java   View source code 5 votes vote down vote up
@Override
public void setImageResource(@DrawableRes int resId) {
    // Intercept this call and instead retrieve the Drawable via the image helper
    if (mImageHelper != null) {
        mImageHelper.setImageResource(resId);
    }
}
 
Example 12
Project: microMathematics   File: CompatUtils.java   View source code 5 votes vote down vote up
/**
 * Procedure sets the background for given view as a drawable with given resource id
 */
@SuppressWarnings("deprecation")
public static void updateBackground(Context c, View v, @DrawableRes int drawableId)
{
    Drawable bg = null;

    if (drawableId >= 0)
    {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            bg = c.getResources().getDrawable(drawableId, c.getTheme());
        }
        else
        {
            bg = c.getResources().getDrawable(drawableId);
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
    {
        v.setBackground(bg);
    }
    else
    {
        v.setBackgroundDrawable(bg);
    }
}
 
Example 13
Project: baselibrary-master   File: BaseFragment.java   View source code 5 votes vote down vote up
/**
 * 淡入淡出加载图片
 *
 * @param imageview        图片控件
 * @param uri              图片uri
 * @param errorResId       加载失败时显示的图片资源id
 * @param placeholderResId 加载时的占位图资源id
 */
public void setImageUri(@NonNull ImageView imageview, Uri uri, @DrawableRes int errorResId, @DrawableRes int placeholderResId) {
    Glide.with(mContext)
            .load(uri)
            .crossFade()
            .error(errorResId)
            .placeholder(placeholderResId)
            .into(imageview);
}
 
Example 14
Project: Android-skin-support   File: SkinCompatCircleImageView.java   View source code 5 votes vote down vote up
@Override
public void setImageResource(@DrawableRes int resId) {
    super.setImageResource(resId);
    if (mImageHelper != null) {
        mImageHelper.setImageResource(resId);
    }
}
 
Example 15
Project: loadingdots   File: LoadingDots.java   View source code 5 votes vote down vote up
@Override
public void setImageResource(@DrawableRes int resId) {
    if (animation != null) {
        throw new IllegalStateException("Changing the LoadingDots image resource is not supported");
    } else {
        super.setImageResource(resId);
    }
}
 
Example 16
Project: TextEmoji   File: CombinedTabView.java   View source code 5 votes vote down vote up
public CombinedTabView(Context context, AttributeSet attrs, @StringRes int name, @DrawableRes int normal, @DrawableRes int selected, @ColorRes int colorNormal, @ColorRes int colorSelected) {
    super(context, attrs);
    inflate(context, R.layout.tab_item, this);
    mNormal = normal;
    mSelected = selected;
    mColorNormal = colorNormal;
    mColorSelected = colorSelected;
    mName = name;

    mItemIcon = (ImageView) findViewById(R.id.icon);
    mItemName = (TextView) findViewById(R.id.name);

    init();
}
 
Example 17
Project: Android-skin-support   File: SkinCompatRadioButton.java   View source code 5 votes vote down vote up
@Override
public void setButtonDrawable(@DrawableRes int resId) {
    super.setButtonDrawable(resId);
    if (mCompoundButtonHelper != null) {
        mCompoundButtonHelper.setButtonDrawable(resId);
    }
}
 
Example 18
Project: markor   File: ShareUtilBase.java   View source code 5 votes vote down vote up
public void createLauncherDesktopShortcut(Intent shortcutIntent, @DrawableRes int shortcutIconRes, String shortcutTitle, String shortcutCreateToast) {
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutTitle);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(_context, shortcutIconRes));
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    _context.sendBroadcast(addIntent);

    Toast.makeText(_context, shortcutCreateToast, Toast.LENGTH_LONG).show();
}
 
Example 19
Project: Sendroid   File: SenImage.java   View source code 5 votes vote down vote up
public ImageRequest load(@DrawableRes int drawableId) {
    final ImageRequest req = ImageTypeRequest.buildImageRequest(drawableId);
    final String cacheKey = req.getCacheKey();
    // mCancelableRequestDelegate.putRequest();
    // Bitmap bitmap = mLruCache.get(cacheKey);
    return req.request();
}
 
Example 20
Project: Pluto-Android   File: PlutoActivity.java   View source code 5 votes vote down vote up
/** 设置ActionBar左上角图标 */
protected void setHomeAsUpIndicator(@DrawableRes int resId) {
	ActionBar actionBar = getSupportActionBar();
	if (actionBar != null) {
		actionBar.setHomeAsUpIndicator(resId);
	}
}
 
Example 21
Project: Android-skin-support   File: SkinCompatMultiAutoCompleteTextView.java   View source code 5 votes vote down vote up
@Override
public void setBackgroundResource(@DrawableRes int resId) {
    super.setBackgroundResource(resId);
    if (mBackgroundTintHelper != null) {
        mBackgroundTintHelper.onSetBackgroundResource(resId);
    }
}
 
Example 22
Project: Android-skin-support   File: SkinSegmentTabLayout.java   View source code 5 votes vote down vote up
@Override
public void setBackgroundResource(@DrawableRes int resId) {
    super.setBackgroundResource(resId);
    if (mBackgroundTintHelper != null) {
        mBackgroundTintHelper.onSetBackgroundResource(resId);
    }
}
 
Example 23
Project: GitHub   File: GlideRequest.java   View source code 5 votes vote down vote up
/**
 * @see GlideOptions#placeholder(int)
 */
@CheckResult
public GlideRequest<TranscodeType> placeholder(@DrawableRes int arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(arg0);
  }
  return this;
}
 
Example 24
Project: GitHub   File: GlideRequest.java   View source code 5 votes vote down vote up
/**
 * @see GlideOptions#error(int)
 */
@CheckResult
public GlideRequest<TranscodeType> error(@DrawableRes int arg0) {
  if (getMutableOptions() instanceof GlideOptions) {
    this.requestOptions = ((GlideOptions) getMutableOptions()).error(arg0);
  } else {
    this.requestOptions = new GlideOptions().apply(this.requestOptions).error(arg0);
  }
  return this;
}
 
Example 25
Project: boohee_v5.6   File: VectorDrawableCompat.java   View source code 5 votes vote down vote up
@Nullable
public static VectorDrawableCompat create(@NonNull Resources res, @DrawableRes int resId, @Nullable Theme theme) {
    if (VERSION.SDK_INT >= 21) {
        VectorDrawableCompat drawable = new VectorDrawableCompat();
        drawable.mDelegateDrawable = ResourcesCompat.getDrawable(res, resId, theme);
        drawable.mCachedConstantStateDelegate = new VectorDrawableDelegateState(drawable.mDelegateDrawable.getConstantState());
        return drawable;
    }
    try {
        int type;
        XmlPullParser parser = res.getXml(resId);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        do {
            type = parser.next();
            if (type == 2) {
                break;
            }
        } while (type != 1);
        if (type == 2) {
            return createFromXmlInner(res, parser, attrs, theme);
        }
        throw new XmlPullParserException("No start tag found");
    } catch (XmlPullParserException e) {
        Log.e(LOGTAG, "parser error", e);
        return null;
    } catch (IOException e2) {
        Log.e(LOGTAG, "parser error", e2);
        return null;
    }
}
 
Example 26
Project: Neuronizer   File: SliderPageFactory.java   View source code 5 votes vote down vote up
private SliderPage createPageWith(@StringRes int title, @DrawableRes int drawable, @StringRes int description) {
    SliderPage page = new SliderPage();
    page.setTitle(context.getResources().getString(title));
    page.setImageDrawable(drawable);
    page.setDescription(context.getResources().getString(description));

    page.setBgColor(context.getResources().getColor(R.color.colorPrimary));
    page.setTitleTypeface(FONT_NAME_FULL);
    return page;
}
 
Example 27
Project: boohee_v5.6   File: AppCompatDrawableManager.java   View source code 5 votes vote down vote up
private static boolean tintDrawableUsingColorFilter(@NonNull Context context, @DrawableRes int resId, @NonNull Drawable drawable) {
    Mode tintMode = DEFAULT_MODE;
    boolean colorAttrSet = false;
    int colorAttr = 0;
    int alpha = -1;
    if (arrayContains(COLORFILTER_TINT_COLOR_CONTROL_NORMAL, resId)) {
        colorAttr = R.attr.colorControlNormal;
        colorAttrSet = true;
    } else if (arrayContains(COLORFILTER_COLOR_CONTROL_ACTIVATED, resId)) {
        colorAttr = R.attr.colorControlActivated;
        colorAttrSet = true;
    } else if (arrayContains(COLORFILTER_COLOR_BACKGROUND_MULTIPLY, resId)) {
        colorAttr = 16842801;
        colorAttrSet = true;
        tintMode = Mode.MULTIPLY;
    } else if (resId == R.drawable.abc_list_divider_mtrl_alpha) {
        colorAttr = 16842800;
        colorAttrSet = true;
        alpha = Math.round(40.8f);
    }
    if (!colorAttrSet) {
        return false;
    }
    if (DrawableUtils.canSafelyMutateDrawable(drawable)) {
        drawable = drawable.mutate();
    }
    drawable.setColorFilter(getPorterDuffColorFilter(ThemeUtils.getThemeAttrColor(context, colorAttr), tintMode));
    if (alpha != -1) {
        drawable.setAlpha(alpha);
    }
    return true;
}
 
Example 28
Project: XERUNG   File: MaterialEditText.java   View source code 5 votes vote down vote up
private Bitmap[] generateIconBitmaps(@DrawableRes int origin) {
  if (origin == -1) {
    return null;
  }
  BitmapFactory.Options options = new BitmapFactory.Options();
  options.inJustDecodeBounds = true;
  BitmapFactory.decodeResource(getResources(), origin, options);
  int size = Math.max(options.outWidth, options.outHeight);
  options.inSampleSize = size > iconSize ? size / iconSize : 1;
  options.inJustDecodeBounds = false;
  return generateIconBitmaps(BitmapFactory.decodeResource(getResources(), origin, options));
}
 
Example 29
Project: Alerter   File: Alerter.java   View source code 5 votes vote down vote up
/**
 * Set the Alert's Background Drawable Resource
 *
 * @param drawableResId Drawable Resource Id
 * @return This Alerter
 */
public Alerter setBackgroundResource(@DrawableRes final int drawableResId) {
    if (getAlert() != null) {
        getAlert().setAlertBackgroundResource(drawableResId);
    }

    return this;
}
 
Example 30
Project: LiteReader   File: ImageLoader.java   View source code 5 votes vote down vote up
public static void loadCircleWithPlaceHolder(ImageView imageView, String url, @DrawableRes int placeHolder) {
    Glide.with(imageView.getContext())
            .load(url)
            .bitmapTransform(new CropCircleTransformation(imageView.getContext()))
            .placeholder(placeHolder == 0 ? R.drawable.ic_placeholder : placeHolder)
            .into(imageView);
}
 
Example 31
Project: XERUNG   File: CircleIndicator.java   View source code 5 votes vote down vote up
private void addIndicator(@DrawableRes int backgroundDrawableId, Animator animator) {
    if (animator.isRunning()) animator.end();

    View Indicator = new View(getContext());
    Indicator.setBackgroundResource(backgroundDrawableId);
    addView(Indicator, mIndicatorWidth, mIndicatorHeight);
    LayoutParams lp = (LayoutParams) Indicator.getLayoutParams();
    lp.leftMargin = mIndicatorMargin;
    lp.rightMargin = mIndicatorMargin;
    Indicator.setLayoutParams(lp);

    animator.setTarget(Indicator);
    animator.start();
}
 
Example 32
Project: Android-skin-support   File: SkinCompatImageButton.java   View source code 5 votes vote down vote up
@Override
public void setBackgroundResource(@DrawableRes int resId) {
    super.setBackgroundResource(resId);
    if (mBackgroundTintHelper != null) {
        mBackgroundTintHelper.onSetBackgroundResource(resId);
    }
}
 
Example 33
Project: QiangHongBao   File: LViewHolder.java   View source code 4 votes vote down vote up
public LViewHolder setBackgroundResource(@IdRes int viewId, @DrawableRes int resId) {
    getView(viewId).setBackgroundResource(resId);
    return this;
}
 
Example 34
Project: aDictOnCopy   File: DictionaryOnCopyService.java   View source code 4 votes vote down vote up
@Override
public @DrawableRes int getNotificationSmallIcon() { return R.drawable.dictionary; }
 
Example 35
Project: login   File: BottomSheetBuilder.java   View source code 4 votes vote down vote up
public BottomSheetBuilder addItem(int id, @StringRes int title, @DrawableRes int icon) {
    return addItem(id, mContext.getString(title), ContextCompat.getDrawable(mContext, icon));
}
 
Example 36
Project: MultiViewAdapter   File: GridItem.java   View source code 4 votes vote down vote up
public GridItem(@ColorInt int color, @DrawableRes int drawable, String data) {
  this.color = color;
  this.drawable = drawable;
  this.data = data;
}
 
Example 37
Project: XERUNG   File: CircleImageView.java   View source code 4 votes vote down vote up
@Override
public void setImageResource(@DrawableRes int resId) {
    super.setImageResource(resId);
    mBitmap = getBitmapFromDrawable(getDrawable());
    setup();
}
 
Example 38
Project: yphoto   File: CircleImageView.java   View source code 4 votes vote down vote up
@Override
public void setImageResource(@DrawableRes int resId) {
    super.setImageResource(resId);
    initializeBitmap();
}
 
Example 39
Project: XERUNG   File: MaterialMultiAutoCompleteTextView.java   View source code 4 votes vote down vote up
public void setIconRight(@DrawableRes int res) {
  iconRightBitmaps = generateIconBitmaps(res);
  initPadding();
}
 
Example 40
Project: Rx_java2_soussidev   File: RxAlertDialogBuilder.java   View source code 4 votes vote down vote up
@Nullable @DrawableRes public Integer getIconRes()
{
    return iconRes;
}