Search in sources :

Example 46 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project CustomViews by AndroidStudy233.

the class GlideUtils method loadImg.

public static void loadImg(Context context, String imageUrl, ImageView targetIv) {
    RequestOptions requestOptions = new RequestOptions();
    requestOptions.error(R.drawable.pic_deauft);
    requestOptions.placeholder(R.drawable.pic_deauft);
    Glide.with(context).load(imageUrl).apply(requestOptions).into(targetIv);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions)

Example 47 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project DevRing by LJYcoder.

the class GlideManager method load.

private RequestBuilder load(RequestBuilder requestBuilder, LoadOption loadOption) {
    RequestOptions requestOptions = new RequestOptions();
    mImageConfig = DevRing.ringComponent().imageConfig();
    // 使用全局的配置进行设置
    if (loadOption == null) {
        if (mImageConfig.isShowTransition()) {
            requestBuilder.transition(DrawableTransitionOptions.withCrossFade(600));
        }
        if (mImageConfig.getLoadingResId() > 0) {
            requestOptions.placeholder(mImageConfig.getLoadingResId());
        }
        if (mImageConfig.getErrorResId() > 0) {
            requestOptions.error(mImageConfig.getErrorResId());
        }
        requestOptions.skipMemoryCache(!mImageConfig.isUseMemoryCache());
        if (mImageConfig.isUseDiskCache()) {
            requestOptions.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);
        } else {
            requestOptions.diskCacheStrategy(DiskCacheStrategy.NONE);
        }
    } else // 使用临时的配置进行设置
    {
        if (loadOption.isShowTransition()) {
            requestBuilder.transition(DrawableTransitionOptions.withCrossFade(600));
        }
        if (loadOption.getLoadingResId() > 0) {
            requestOptions.placeholder(loadOption.getLoadingResId());
        }
        if (loadOption.getErrorResId() > 0) {
            requestOptions.error(loadOption.getErrorResId());
        }
        requestOptions.skipMemoryCache(!loadOption.isUseMemoryCache());
        if (loadOption.isUseDiskCache()) {
            requestOptions.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);
        } else {
            requestOptions.diskCacheStrategy(DiskCacheStrategy.NONE);
        }
        CircleBorderTransformation circleTransformation = null;
        // CropCircleTransformation circleTransformation = null;
        RoundedCornersTransformation roundedCornersTransformation = null;
        BlurTransformation blurTransformation = null;
        GrayscaleTransformation grayscaleTransformation = null;
        if (loadOption.isCircle()) {
            // circleTransformation = new CropCircleTransformation();
            int borderWidth = loadOption.getBorderWidth();
            int borderColor = loadOption.getBorderColor();
            if (borderWidth > 0 && borderColor != 0) {
                circleTransformation = new CircleBorderTransformation(borderWidth, borderColor);
            } else {
                circleTransformation = new CircleBorderTransformation();
            }
        } else if (loadOption.getRoundRadius() > 0) {
            roundedCornersTransformation = new RoundedCornersTransformation(loadOption.getRoundRadius(), 0);
        }
        if (loadOption.getBlurRadius() > 0) {
            blurTransformation = new BlurTransformation(loadOption.getBlurRadius());
        }
        if (loadOption.isGray()) {
            grayscaleTransformation = new GrayscaleTransformation();
        }
        MultiTransformation multiTransformation = getMultiTransformation(circleTransformation, roundedCornersTransformation, blurTransformation, grayscaleTransformation);
        if (multiTransformation != null)
            requestOptions.transform(multiTransformation);
    }
    return requestBuilder.apply(requestOptions);
}
Also used : BlurTransformation(jp.wasabeef.glide.transformations.BlurTransformation) RequestOptions(com.bumptech.glide.request.RequestOptions) CircleBorderTransformation(com.ljy.devring.image.support.CircleBorderTransformation) GrayscaleTransformation(jp.wasabeef.glide.transformations.GrayscaleTransformation) MultiTransformation(com.bumptech.glide.load.MultiTransformation) RoundedCornersTransformation(jp.wasabeef.glide.transformations.RoundedCornersTransformation)

Example 48 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project MusicVideoPlayer by MartingKing.

the class OnlineMusicAdapter method getView.

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_holder_music, parent, false);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    OnlineMusic onlineMusic = mData.get(position);
    Glide.with(parent).load(onlineMusic.getPic_small()).apply(new RequestOptions().placeholder(R.drawable.default_cover).error(R.drawable.default_cover)).into(holder.ivCover);
    holder.tvTitle.setText(onlineMusic.getTitle());
    String artist = FileUtils.getArtistAndAlbum(onlineMusic.getArtist_name(), onlineMusic.getAlbum_title());
    holder.tvArtist.setText(artist);
    holder.ivMore.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mListener.onMoreClick(position);
        }
    });
    holder.vDivider.setVisibility(isShowDivider(position) ? View.VISIBLE : View.GONE);
    return convertView;
}
Also used : OnlineMusic(com.huadong.musicvideoplayer.model.OnlineMusic) RequestOptions(com.bumptech.glide.request.RequestOptions) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 49 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project MusicVideoPlayer by MartingKing.

the class ArtistInfoActivity method setData.

private void setData(ArtistInfo artistInfo) {
    String name = artistInfo.getName();
    String avatarUri = artistInfo.getAvatar_s1000();
    String country = artistInfo.getCountry();
    String constellation = artistInfo.getConstellation();
    float stature = artistInfo.getStature();
    float weight = artistInfo.getWeight();
    String birth = artistInfo.getBirth();
    String intro = artistInfo.getIntro();
    String url = artistInfo.getUrl();
    if (!TextUtils.isEmpty(avatarUri)) {
        ImageView ivAvatar = new ImageView(this);
        ivAvatar.setScaleType(ImageView.ScaleType.FIT_START);
        Glide.with(this).load(avatarUri).apply(new RequestOptions().placeholder(R.drawable.default_artist).error(R.drawable.default_artist)).into(ivAvatar);
        llArtistInfoContainer.addView(ivAvatar);
    }
    if (!TextUtils.isEmpty(name)) {
        setTitle(name);
        TextView tvName = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
        tvName.setText(getString(R.string.artist_info_name, name));
        llArtistInfoContainer.addView(tvName);
    }
    if (!TextUtils.isEmpty(country)) {
        TextView tvCountry = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
        tvCountry.setText(getString(R.string.artist_info_country, country));
        llArtistInfoContainer.addView(tvCountry);
    }
    if (!TextUtils.isEmpty(constellation) && !TextUtils.equals(constellation, "未知")) {
        TextView tvConstellation = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
        tvConstellation.setText(getString(R.string.artist_info_constellation, constellation));
        llArtistInfoContainer.addView(tvConstellation);
    }
    if (stature != 0f) {
        TextView tvStature = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
        tvStature.setText(getString(R.string.artist_info_stature, String.valueOf(stature)));
        llArtistInfoContainer.addView(tvStature);
    }
    if (weight != 0f) {
        TextView tvWeight = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
        tvWeight.setText(getString(R.string.artist_info_weight, String.valueOf(weight)));
        llArtistInfoContainer.addView(tvWeight);
    }
    if (!TextUtils.isEmpty(birth) && !TextUtils.equals(birth, "0000-00-00")) {
        TextView tvBirth = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
        tvBirth.setText(getString(R.string.artist_info_birth, birth));
        llArtistInfoContainer.addView(tvBirth);
    }
    if (!TextUtils.isEmpty(intro)) {
        TextView tvIntro = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
        tvIntro.setText(getString(R.string.artist_info_intro, intro));
        llArtistInfoContainer.addView(tvIntro);
    }
    if (!TextUtils.isEmpty(url)) {
        TextView tvUrl = (TextView) LayoutInflater.from(this).inflate(R.layout.item_artist_info, llArtistInfoContainer, false);
        tvUrl.setLinkTextColor(ContextCompat.getColor(this, R.color.blue));
        tvUrl.setMovementMethod(LinkMovementMethod.getInstance());
        SpannableString spannableString = new SpannableString("查看更多信息");
        spannableString.setSpan(new URLSpan(url), 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        tvUrl.setText(spannableString);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        tvUrl.setLayoutParams(layoutParams);
        llArtistInfoContainer.addView(tvUrl);
    }
    if (llArtistInfoContainer.getChildCount() == 0) {
        ViewUtils.changeViewState(svArtistInfo, llLoading, llLoadFail, LoadStateEnum.LOAD_FAIL);
        ((TextView) llLoadFail.findViewById(R.id.tv_load_fail_text)).setText(R.string.artist_info_empty);
    }
}
Also used : SpannableString(android.text.SpannableString) RequestOptions(com.bumptech.glide.request.RequestOptions) TextView(android.widget.TextView) SpannableString(android.text.SpannableString) ImageView(android.widget.ImageView) URLSpan(android.text.style.URLSpan) LinearLayout(android.widget.LinearLayout)

Example 50 with RequestOptions

use of com.bumptech.glide.request.RequestOptions in project MusicVideoPlayer by MartingKing.

the class PlaylistActivity method initHeader.

private void initHeader() {
    final ImageView ivHeaderBg = (ImageView) vHeader.findViewById(R.id.iv_header_bg);
    final ImageView ivCover = (ImageView) vHeader.findViewById(R.id.iv_cover);
    TextView tvTitle = (TextView) vHeader.findViewById(R.id.tv_title);
    TextView tvUpdateDate = (TextView) vHeader.findViewById(R.id.tv_update_date);
    TextView tvComment = (TextView) vHeader.findViewById(R.id.tv_comment);
    tvTitle.setText(mOnlineMusicList.getBillboard().getName());
    tvUpdateDate.setText(getString(R.string.recent_update, mOnlineMusicList.getBillboard().getUpdate_date()));
    tvComment.setText(mOnlineMusicList.getBillboard().getComment());
    Glide.with(this).asBitmap().load(mOnlineMusicList.getBillboard().getPic_s640()).apply(new RequestOptions().placeholder(R.drawable.default_cover).error(R.drawable.default_cover).override(200, 200)).into(new SimpleTarget<Bitmap>() {

        @Override
        public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
            ivCover.setImageBitmap(resource);
            ivHeaderBg.setImageBitmap(ImageUtils.blur(resource));
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) RequestOptions(com.bumptech.glide.request.RequestOptions) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Aggregations

RequestOptions (com.bumptech.glide.request.RequestOptions)96 ImageView (android.widget.ImageView)23 View (android.view.View)18 Drawable (android.graphics.drawable.Drawable)16 TextView (android.widget.TextView)13 Bitmap (android.graphics.Bitmap)9 BitmapDrawable (android.graphics.drawable.BitmapDrawable)8 File (java.io.File)8 Uri (android.net.Uri)7 ColorDrawable (android.graphics.drawable.ColorDrawable)6 Context (android.content.Context)5 Intent (android.content.Intent)5 RecyclerView (android.support.v7.widget.RecyclerView)5 DataSource (com.bumptech.glide.load.DataSource)5 GlideException (com.bumptech.glide.load.engine.GlideException)5 FitCenter (com.bumptech.glide.load.resource.bitmap.FitCenter)5 RoundedCorners (com.bumptech.glide.load.resource.bitmap.RoundedCorners)5 Test (org.junit.Test)5 Activity (android.app.Activity)3 LayoutInflater (android.view.LayoutInflater)3