Example usage for android.support.v4.content ContextCompat getDrawable

List of usage examples for android.support.v4.content ContextCompat getDrawable

Introduction

In this page you can find the example usage for android.support.v4.content ContextCompat getDrawable.

Prototype

public static final Drawable getDrawable(Context context, int i) 

Source Link

Usage

From source file:com.hartcode.hartweather.search.SearchItemViewHolder.java

public void bindData(@NonNull Model model, int position) {
    this.model = model;
    this.weather = model.getSearchItem(position);
    this.txtCityName.setText(weather.cityName);
    String temp = String.format(resources.getString(R.string.temp_format), (int) weather.temp, (char) 0x00B0);
    this.txtWeatherTemp.setText(temp);
    Drawable iconResource = ContextCompat.getDrawable(this.view.getContext(),
            resources.getIdentifier(resources.getString(R.string.weather_image_prefix) + weather.icon,
                    resources.getString(R.string.weather_image_resource_type),
                    this.view.getContext().getPackageName()));
    this.txtWeatherTemp.setCompoundDrawablesWithIntrinsicBounds(iconResource, null, null, null);
}

From source file:android.support.v7.widget.AppCompatImageHelper.java

public void setImageResource(int resId) {
    if (resId != 0) {
        final Drawable d = mDrawableManager != null ? mDrawableManager.getDrawable(mView.getContext(), resId)
                : ContextCompat.getDrawable(mView.getContext(), resId);
        if (d != null) {
            DrawableUtils.fixDrawable(d);
        }//from   w  w w.  j  a va  2 s . com
        mView.setImageDrawable(d);
    } else {
        mView.setImageDrawable(null);
    }
}

From source file:cn.finalteam.galleryfinal.adapter.PhotoListAdapter.java

@Override
public void onBindViewHolder(PhotoViewHolder holder, int position) {
    PhotoInfo photoInfo = getDatas().get(position);

    String path = "";
    if (photoInfo != null) {
        path = photoInfo.getPhotoPath();
    }//from   ww w  .ja  v  a  2  s. com

    holder.mIvThumb.setImageResource(R.drawable.ic_gf_default_photo);
    Drawable defaultDrawable = ContextCompat.getDrawable(mActivity, R.drawable.ic_gf_default_photo);
    GalleryFinal.getCoreConfig().getImageLoader().displayImage(mActivity, path, holder.mIvThumb,
            defaultDrawable, mRowWidth, mRowWidth);
    holder.mView.setAnimation(null);
    if (GalleryFinal.getCoreConfig().getAnimation() > 0) {
        holder.mView.setAnimation(
                AnimationUtils.loadAnimation(mActivity, GalleryFinal.getCoreConfig().getAnimation()));
    }
    holder.mIvCheck.setImageResource(GalleryFinal.getGalleryTheme().getIconCheck());
    if (GalleryFinal.getFunctionConfig().isMutiSelect()) {
        holder.mIvCheck.setVisibility(View.VISIBLE);
        if (mSelectList.contains(photoInfo)) {
            holder.mIvCheck.setBackgroundColor(GalleryFinal.getGalleryTheme().getCheckSelectedColor());
        } else {
            holder.mIvCheck.setBackgroundColor(GalleryFinal.getGalleryTheme().getCheckNornalColor());
        }
    } else {
        holder.mIvCheck.setVisibility(View.GONE);
    }
}

From source file:com.android.example.leanback.fastlane.LeanbackBrowseFragment.java

public void init() {
    mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
    setAdapter(mRowsAdapter);/*  ww  w.j av  a2s  . c  o  m*/

    setBrandColor(ContextCompat.getColor(getContext(), R.color.primary));
    setBadgeDrawable(ContextCompat.getDrawable(getContext(), R.drawable.filmi));

    for (int position = 0; position < HEADERS.length; position++) {
        ObjectAdapter rowContents = new CursorObjectAdapter((new SinglePresenterSelector(new CardPresenter())));
        VideoDataManager manager = new VideoDataManager(getActivity(), getLoaderManager(),
                VideoItemContract.VideoItem.buildDirUri(), rowContents);
        manager.startDataLoading();

        HeaderItem headerItem = new HeaderItem(position, HEADERS[position]);
        mRowsAdapter.add(new ListRow(headerItem, manager.getItemList()));
    }

    setOnItemViewClickedListener(getDefaultItemViewClickedListener());
    setOnItemViewSelectedListener(getDefaultItemSelectedListener());

    bgHelper = new BackgroundHelper(getActivity());
    bgHelper.prepareBackgroundManager();

}

From source file:com.jaspersoft.android.jaspermobile.util.resource.viewbinder.CustomBitmapProcessor.java

private Bitmap staticThumbnail() {
    Drawable drawable = ContextCompat.getDrawable(mContext, mResId);
    return convertToBitmap(drawable);
}

From source file:com.flexible.flexibleadapter.common.DividerItemDecoration.java

/**
 * Custom divider with gap between sections (in dpi).
 * Passing a negative divider will only use
 *
 * @since 5.0.0-b6/*w  w w .ja  va 2 s . c o  m*/
 */
public DividerItemDecoration(@NonNull Context context, @DrawableRes int resId,
        @IntRange(from = 0) int sectionOffset) {
    if (resId > 0)
        mDivider = ContextCompat.getDrawable(context, resId);
    mSectionOffset = (int) (context.getResources().getDisplayMetrics().density * sectionOffset);
}

From source file:com.einzig.ipst2.util.ThemeHelper.java

public static void styleButton(Button button, Context context) {
    if (isDarkTheme(context)) {
        button.setBackground(ContextCompat.getDrawable(context, R.drawable.cell_shape_whiteoutline));
    } else {//  w  ww  .  j  a v a 2 s .c  o  m
        button.setTextColor(ContextCompat.getColor(context, R.color.white));
        button.setBackground(ContextCompat.getDrawable(context, R.drawable.button_bg));
    }
}

From source file:cn.finalteam.galleryfinal.adapter.FolderListAdapter.java

@Override
public void onBindViewHolder(FolderViewHolder holder, int position) {
    PhotoFolderInfo photoFolderInfo = getDatas().get(position);

    String path = "";
    PhotoInfo photoInfo = photoFolderInfo.getCoverPhoto();
    if (photoInfo != null) {
        path = photoInfo.getPhotoPath();
    }/*from ww  w .j a  va 2  s. c  om*/
    holder.mIvCover.setImageResource(R.drawable.ic_gf_default_photo);
    Drawable defaultDrawable = ContextCompat.getDrawable(mActivity, R.drawable.ic_gf_default_photo);
    GalleryFinal.getCoreConfig().getImageLoader().displayImage(mActivity, path, holder.mIvCover,
            defaultDrawable, 200, 200);

    holder.mTvFolderName.setText(photoFolderInfo.getFolderName());
    int size = 0;
    if (photoFolderInfo.getPhotoList() != null) {
        size = photoFolderInfo.getPhotoList().size();
    }
    holder.mTvPhotoCount.setText(mActivity.getString(R.string.folder_photo_size, size));
    if (GalleryFinal.getCoreConfig().getAnimation() > 0) {
        holder.mView.startAnimation(
                AnimationUtils.loadAnimation(mActivity, GalleryFinal.getCoreConfig().getAnimation()));
    }
    holder.mIvFolderCheck.setImageResource(GalleryFinal.getGalleryTheme().getIconCheck());
    if (mSelectFolder == photoFolderInfo || (mSelectFolder == null && position == 0)) {
        holder.mIvFolderCheck.setVisibility(View.VISIBLE);
        holder.mIvFolderCheck.setColorFilter(GalleryFinal.getGalleryTheme().getCheckSelectedColor());
    } else {
        holder.mIvFolderCheck.setVisibility(View.GONE);
    }
}

From source file:com.justplay1.shoppist.features.search.SearchAdapter.java

public SearchAdapter(Context context, final int contextType) {
    this.contextType = contextType;
    setHasStableIds(true);/* w  w  w .j  a v a 2 s .com*/
    data = new HashMap<>();
    itemsToDisplay = new ArrayList<>();
    iconEndDrawable = ContextCompat.getDrawable(context, R.drawable.ic_add_black_24dp);
    iconEndDrawable.setColorFilter(ContextCompat.getColor(context, R.color.action_mode_toolbar_color),
            PorterDuff.Mode.SRC_IN);
}

From source file:com.justplay1.shoppist.shared.widget.EmptyView.java

public void setInfoImage(@DrawableRes int resId) {
    Drawable drawable = ContextCompat.getDrawable(getContext(), resId);
    infoText.setCompoundDrawables(null, drawable, null, null);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        infoText.setCompoundDrawablesRelative(null, drawable, null, null);
    }//from w  w  w.j a v  a  2 s . c o  m
}