private void loadProfileOnDrawer() { if(mUser != null) { LinearLayout linearLayout = (LinearLayout) mNavigationView.getHeaderView(0); //LinearLayout Index ImageView mImageViewProfile = linearLayout.findViewById(R.id.main_imageview_user_photo); TextView mTextViewUsername = linearLayout.findViewById(R.id.main_textview_username); TextView mTextViewTextEmail = linearLayout.findViewById(R.id.main_textview_user_email); mTextViewTextEmail.setText(mUser.getEmail()); mTextViewUsername.setText(mUser.getUsername()); GlideApp.with(this) .load(mUser.getPhotoUrl()) .apply(RequestOptions.circleCropTransform()) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(mImageViewProfile); //Test if (mIdlingResource != null) mIdlingResource.setIdleState(true); } }
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {//arg1:当前页面的位置,也就是position; arg2:当前页面偏移的百分比; arg3当前页面偏移的像素位置 PlayMusicActivity activity = weakActivity.get(); if (null != activity) { activity.mPositionOffset = positionOffset; if (position == 0) {//解决第一次进入的时候没有显示模糊效果 Glide.with(MyApplication.mContext)//底部的模糊效果 .load(activity.mList.get(position).getAlbumpic_big()) .bitmapTransform(new BlurTransformation(activity, 99)) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .crossFade() .into(activity.mImgBg); //首次进入获取正在播放歌曲的信息 activity.songNamePlaying = activity.mList.get(0).getSongname(); activity.singerNamePlaying = activity.mList.get(0).getSingername(); activity.showIsLike(); } } }
private void setUpBanner() { if(mBanner != null) { Glide.with(this) .load(mBanner) .diskCacheStrategy(DiskCacheStrategy.ALL) .crossFade() .centerCrop() .into(mBannerImage); mBannerImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(AnimeActivity.this, ImagePreviewActivity.class); intent.putExtra(ImagePreviewActivity.IMAGE_SOURCE, mBanner); TransitionHelper.startSharedImageTransition(AnimeActivity.this, view, getString(R.string.transition_image_preview), intent); } }); } }
@SuppressLint("SetTextI18n") @Override public void onBindViewHolder(ClickableViewHolder holder, int position) { if (holder instanceof ItemViewHolder) { ItemViewHolder itemViewHolder = (ItemViewHolder) holder; SearchMovieInfo.DataBean.ItemsBean itemsBean = movies.get(position); Glide.with(getContext()) .load(itemsBean.getCover()) .centerCrop() .dontAnimate() .placeholder(R.drawable.ico_user_default) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(itemViewHolder.mImage); itemViewHolder.mTitle.setText(itemsBean.getTitle()); } super.onBindViewHolder(holder, position); }
private Bitmap getBigPicture(@NonNull MasterSecret masterSecret, @NonNull SlideDeck slideDeck) { try { @SuppressWarnings("ConstantConditions") Uri uri = slideDeck.getThumbnailSlide().getThumbnailUri(); return Glide.with(context) .load(new DecryptableStreamUriLoader.DecryptableUri(masterSecret, uri)) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.NONE) .into(500, 500) .get(); } catch (InterruptedException | ExecutionException e) { throw new AssertionError(e); } }
public void setUpWithInfo(Activity activity, String name, int mid, String avatarUrl) { this.activity = activity; this.name = name; this.mid = mid; this.avatarUrl = avatarUrl; this.setUserName(name); Glide.with(getContext()) .load(this.avatarUrl) .centerCrop() .dontAnimate() .placeholder(R.drawable.ico_user_default) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(avatarView); }
@ReactMethod public void preload(final ReadableArray sources) { final Activity activity = getCurrentActivity(); activity.runOnUiThread(new Runnable() { @Override public void run() { for (int i = 0; i < sources.size(); i++) { final ReadableMap source = sources.getMap(i); final GlideUrl glideUrl = FastImageViewConverter.glideUrl(source); final Priority priority = FastImageViewConverter.priority(source); Glide .with(activity.getApplicationContext()) .load(glideUrl) .priority(priority) .placeholder(TRANSPARENT_DRAWABLE) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .preload(); } } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); image = (Image) getIntent().getSerializableExtra(EXTRA_IMAGE); if (image == null) { finish(); } else { TouchImageView imageView = findViewById(R.id.activity_image_image); Glide.with(this) .load(image.getUrl()) .apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL)) .into(imageView); setTitle(image.getName()); } }
/** * DrawableRequestBuilder 的通行配置 * @param ctx 上下文 * @param img ImageLoader封装器 * @param typeRequest url or resource * @param <T> String or Integer * @return DrawableRequestBuilder<T> */ private <T> DrawableRequestBuilder<T> getDrawableRequestBuilder(Context ctx, ImageLoader img, DrawableTypeRequest<T> typeRequest) { DrawableRequestBuilder<T> builder = typeRequest .placeholder(img.placeHolder) .error(img.errorHolder) .diskCacheStrategy(DiskCacheStrategy.ALL); // transform image type int transType = img.transType; if (transType == LoaderConfig.TRANS_CIRCLE) { builder = builder.transform(new GlideCircleTransform(ctx)); } else if (transType == LoaderConfig.TRANS_ROUND) { builder = builder.transform(new GlideRoundTransform(ctx)); } // SCALE type if (img.scaleType == LoaderConfig.SCALE_CENTER_CROP) { builder = builder.centerCrop(); } else if (img.scaleType == LoaderConfig.SCALE_FIT_CENTER) { builder = builder.fitCenter(); } return builder; }
@BindingAdapter({"imageAddress"}) public static void loadImage(final ImageView imageView, final String imageAddress) { if (imageAddress != null && imageAddress.startsWith("https://s3.amazonaws.com/bikedeboa/")) { Context context = imageView.getContext(); // Hopefully the thumbnail is already disk cached and no requests are made DrawableRequestBuilder<String> thumbnailRequest = Glide .with(context) .load(imageAddress.replace("images/", "images/thumbs/")) .diskCacheStrategy(DiskCacheStrategy.ALL) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .transform(new BlurTransformation(context)); Glide.with(context) .load(imageAddress) .thumbnail(thumbnailRequest) .crossFade() .diskCacheStrategy(DiskCacheStrategy.SOURCE) .priority(Priority.HIGH) .into(imageView); } }
@Override public void setData(final Recommend.RoomBean data) { super.setData(data); Glide.with(getContext()).load(data.getIcon()).error(R.drawable.default_recommend_icon).crossFade().centerCrop().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv); tvCategroy.setText(data.getName()); tvMore.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startLive(getContext(),data.getName(),data.getSlug()); } }); adapter.setListData(data.getList()); adapter.notifyDataSetChanged(); }
@SuppressLint("SetTextI18n") @Override public void onBindViewHolder(ClickableViewHolder holder, int position) { if (holder instanceof ItemViewHolder) { ItemViewHolder itemViewHolder = (ItemViewHolder) holder; UserInterestQuanInfo.DataBean.ResultBean resultBean = userInterestQuans.get(position); Glide.with(getContext()) .load(resultBean.getThumb()) .centerCrop() .diskCacheStrategy(DiskCacheStrategy.ALL) .placeholder(R.drawable.bili_default_image_tv) .into(itemViewHolder.mImage); itemViewHolder.mTitle.setText(resultBean.getName()); itemViewHolder.mDesc.setText(resultBean.getDesc()); itemViewHolder.mPostNickName.setText(resultBean.getPost_nickname() + ":"); itemViewHolder.mPostCount.setText(String.valueOf(resultBean.getPost_count())); itemViewHolder.mMemberNickName.setText(resultBean.getMember_nickname() + ":"); itemViewHolder.mMemberCount.setText(String.valueOf(resultBean.getMember_count())); } super.onBindViewHolder(holder, position); }
@Override protected void onBindViewHolder(@NonNull MeiziHolder holder, @NonNull Content data) { Glide.with(mContext) .load(data.url) .placeholder(R.mipmap.ic_bg_fuli) .diskCacheStrategy(DiskCacheStrategy.RESULT) .into(holder.mImageView); // Glide.with(context) // .load(data.url + URL_MEIZI_DIMENSION) // .placeholder(R.mipmap.ic_bg_fuli) // .diskCacheStrategy(DiskCacheStrategy.RESULT) // .into(holder.mImageView); holder.position = getPosition(holder); holder.url = data.url; }
@Override public void onBindViewHolder(ClickableViewHolder holder, int position) { if (holder instanceof ItemViewHolder) { ItemViewHolder itemViewHolder = (ItemViewHolder) holder; BangumiIndexInfo.ResultBean.CategoryBean categoryBean = categorys.get(position); Glide.with(getContext()) .load(categoryBean.getCover()) .centerCrop() .diskCacheStrategy(DiskCacheStrategy.ALL) .placeholder(R.drawable.bili_default_image_tv) .dontAnimate() .into(itemViewHolder.mImageView); itemViewHolder.mTextView.setText(categoryBean.getTag_name()); } super.onBindViewHolder(holder, position); }
@Override public void onBindViewHolder(ClickableViewHolder holder, int position) { if (holder instanceof ItemViewHolder) { ItemViewHolder itemViewHolder = (ItemViewHolder) holder; VideoDetailsInfo.DataBean.RelatesBean relatesBean = relates.get(position); Glide.with(getContext()) .load(relatesBean.getPic()) .centerCrop() .diskCacheStrategy(DiskCacheStrategy.ALL) .placeholder(R.drawable.bili_default_image_tv) .dontAnimate() .into(itemViewHolder.mVideoPic); itemViewHolder.mVideoTitle.setText(relatesBean.getTitle()); itemViewHolder.mVideoPlayNum.setText( NumberUtil.converString(relatesBean.getStat().getView())); itemViewHolder.mVideoReviewNum.setText( NumberUtil.converString(relatesBean.getStat().getDanmaku())); itemViewHolder.mUpName.setText(relatesBean.getOwner().getName()); } super.onBindViewHolder(holder, position); }
public void setVideoImgUrl(String imgUrl){ Glide.with(getContext()) .load(imgUrl) .placeholder(new ColorDrawable(0xffdcdcdc)) .centerCrop() .diskCacheStrategy(DiskCacheStrategy.SOURCE) .into(videoFrame); if(videoState == STATE_IDLE){ videoButton.setVisibility(View.VISIBLE); videoFrame.setVisibility(View.VISIBLE); }else if(videoState == STATE_ACTIVED){ videoButton.setVisibility(View.GONE); videoFrame.setVisibility(View.GONE); }else{ videoButton.setVisibility(View.VISIBLE); videoFrame.setVisibility(View.VISIBLE); } }
@SuppressLint("SetTextI18n") @Override public void onBindViewHolder(ClickableViewHolder holder, int position) { if (holder instanceof ItemViewHolder){ ItemViewHolder itemViewHolder = (ItemViewHolder) holder; UserChaseBangumiInfo.DataBean.ResultBean resultBean = mChaseBangumis.get(position); Glide.with(getContext()) .load(resultBean.getCover()) .centerCrop() .diskCacheStrategy(DiskCacheStrategy.ALL) .placeholder(R.drawable.bili_default_image_tv) .into(itemViewHolder.mImage); if (resultBean.getIs_finish() == 1){ itemViewHolder.mUpdate.setText(resultBean.getTotal_count() + "话全"); itemViewHolder.mUpdate.setTextColor(getContext().getResources().getColor(R.color.black_alpha_45)); } else { itemViewHolder.mUpdate.setText("更新至第" + resultBean.getTotal_count() + "话"); itemViewHolder.mUpdate.setTextColor(getContext().getResources().getColor(R.color.black_alpha_45)); } itemViewHolder.mTitle.setText(resultBean.getTitle()); itemViewHolder.mSubscribe.setText(resultBean.getFavorites() + "人订阅"); } super.onBindViewHolder(holder, position); }
@Override public Object instantiateItem(ViewGroup container, int position) { if (photos == null) { return null; } if (mViews == null) { mViews = new PhotoView[photos.size()]; for (int i = 0; i < 4; i++) { mViews[i] = new PhotoView(container.getContext()); mViews[i].setBackgroundColor(Color.BLACK); } } if (mViews[position] == null) { mViews[position] = mViews[position % 4]; } container.addView(mViews[position], ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); Log.e("TAG", "addView: " + position); GlideApp.with(GalleryActivity.this) .load(photos.get(position)) .format(DecodeFormat.PREFER_ARGB_8888) .diskCacheStrategy(DiskCacheStrategy.DATA) .into(mViews[position]); return mViews[position]; }
@SuppressLint("SetTextI18n") @Override public void onBindViewHolder(ClickableViewHolder holder, int position) { if (holder instanceof ItemViewHolder) { ItemViewHolder itemViewHolder = (ItemViewHolder) holder; CopyInfo.ActivityoListBean activityoListBean = mDataSources.get(position); Glide.with(getContext()) .load(activityoListBean.getPicture()) .centerCrop() .diskCacheStrategy(DiskCacheStrategy.ALL) .crossFade() .into(itemViewHolder.mCopyImage); itemViewHolder.mCopyName.setText("副本:" + activityoListBean.getName()); itemViewHolder.mCopyFounder.setText("队长:" + activityoListBean.getUser_name()); } super.onBindViewHolder(holder, position); }
@Override public void onBindViewHolder(ClickableViewHolder holder, int position) { if (holder instanceof ItemViewHolder) { ItemViewHolder itemViewHolder = (ItemViewHolder) holder; UserPlayGameInfo.DataBean.GamesBean gamesBean = games.get(position); Glide.with(getContext()) .load(gamesBean.getImage()) .centerCrop() .diskCacheStrategy(DiskCacheStrategy.ALL) .placeholder(R.drawable.bili_default_image_tv) .into(itemViewHolder.mImage); itemViewHolder.mTitle.setText(gamesBean.getName()); itemViewHolder.mDesc.setText(gamesBean.getName()); } super.onBindViewHolder(holder, position); }
@SuppressWarnings("ConstantConditions") protected void loadFileImage(File file, final ViewHolder holder) { final int iconColor = ATHUtil.resolveColor(activity, R.attr.iconColor); if (file.isDirectory()) { holder.image.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN); holder.image.setImageResource(R.drawable.ic_folder_white_24dp); } else { Drawable error = Util.getTintedVectorDrawable(activity, R.drawable.ic_file_music_white_24dp, iconColor); Glide.with(activity) .load(new AudioFileCover(file.getPath())) .diskCacheStrategy(DiskCacheStrategy.NONE) .error(error) .placeholder(error) .animate(android.R.anim.fade_in) .signature(new MediaStoreSignature("", file.lastModified(), 0)) .into(holder.image); } }
@Override public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder) { TopicViewHolder topicViewHolder = (TopicViewHolder) holder; Glide.with(mContext) .load(imgUrl) .centerCrop() .diskCacheStrategy(DiskCacheStrategy.ALL) .placeholder(R.drawable.bili_default_image_tv) .dontAnimate() .into(topicViewHolder.mImageView); topicViewHolder.mTextView.setText(title); if (TextUtils.isEmpty(title)) { topicViewHolder.mTextView.setVisibility(View.GONE); } else { topicViewHolder.mTextView.setVisibility(View.VISIBLE); } topicViewHolder.mCardView.setOnClickListener(v -> BrowserActivity. launch((Activity) mContext, link, title)); }
/** *load cache image with Glide */ private static void displayCache(String url, ImageView imageView) { Glide.with(imageView.getContext()).using(streamModelLoader).load(url) .dontAnimate() .placeholder(R.drawable.ic_place_holder_small) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(imageView); }
private void onBeginInit(Bundle savedInstanceState) { mViewPager.setOffscreenPageLimit(2); if(savedInstanceState == null) { mCurrentUser = getIntent().getParcelableExtra(PROFILE_INTENT_KEY); } else mCurrentUser = savedInstanceState.getParcelable(KEY_USER); if(mCurrentUser != null) { mPresenter = new UserProfilePresenter(ProfileActivity.this, mCurrentUser.getId()); user_anime_time.setText( mPresenter.getAnimeTime(mCurrentUser.getAnime_time())); user_manga_chap.setText(mCurrentUser.getManga_chap()); user_anime_total.setText("0"); user_manga_total.setText("0"); UserStats userStats = mCurrentUser.getStats(); if(userStats != null) { if(userStats.getStatus_distribution() != null) if(userStats.getStatus_distribution().getAnime() != null) user_anime_total.setText(userStats.getStatus_distribution().getAnime().getTotalAnime()); if(userStats.getStatus_distribution().getManga() != null) user_manga_total.setText(userStats.getStatus_distribution().getManga().getTotalManga()); } Glide.with(this) .load(mCurrentUser.getImage_url_banner()) .centerCrop() .diskCacheStrategy(DiskCacheStrategy.ALL) .into(user_banner); updateUI(); } else{ Toast.makeText(this, R.string.layout_empty_response, Toast.LENGTH_LONG).show(); } }
@Override protected void convert(BaseViewHolder helper, WeiXinBean.NewslistBean item) { helper.setText(R.id.txt_weixin_title, item.getTitle()); helper.setText(R.id.txt_weixin_author, item.getDescription()); helper.setText(R.id.txt_weixin_date, item.getCtime()); GlideApp.with(mContext) .load(item.getPicUrl()) .centerCrop() .placeholder(R.drawable.ic_ali) .priority(Priority.LOW) .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) .into((ImageView) helper.getView(R.id.img_weixin)); }
private void Image_URL(String title) { // image_url.setImageResource(R.drawable.loading); Glide.with(itemView.getContext()) .load(title) .crossFade() .placeholder(R.drawable.loading) .thumbnail(0.1f) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(image_url); }
@Override public void onBindData() { Track track=at(current()); artist.setText(track.getArtist()); trackTitle.setText(track.getTitle()); duration.setText(track.getFormatedDuration()); Glide.with(itemView.getContext()) .load(track.getArtworkUrl()) .priority(Priority.IMMEDIATE) .diskCacheStrategy(DiskCacheStrategy.RESULT) .into(trackArt); }
@Override protected void onPostExecute(File file) { super.onPostExecute(file); if (file != null) { // 从存储器加载用户头像 Glide.with(mActivity).load(file).diskCacheStrategy(DiskCacheStrategy.NONE).into(mIv); } else { // 从网络加载用户头像 Glide.with(mActivity).load(mAvatarLarge).into(mIv); } }
@Override public void onBindViewHolder(StickerViewHolder holder, int position) { holder.fileName = stickerFiles[position]; Glide.with(context) .load(Uri.parse("file:///android_asset/" + holder.fileName)) .diskCacheStrategy(DiskCacheStrategy.NONE) .into(holder.image); }
/** * 默认加载图片方式,使用Glide默认的加载方式,除此方法外,其他方案均有动画效果,并且跳过内存缓存,开启磁盘缓存 * @param activity 在Activity中加载 * @param url * @param targetView */ public void loadPicture(Activity activity, String url, ImageView targetView) { GlideApp.with(activity) .load(url) .skipMemoryCache(false) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .transition(new DrawableTransitionOptions().crossFade(200)) .centerCrop() .priority(Priority.HIGH) .into(targetView); }
public static void displaySmallPhoto(Context context, ImageView imageView, String url) { if (imageView == null) { throw new IllegalArgumentException("argument error"); } Glide.with(context).load(url).asBitmap() .diskCacheStrategy(DiskCacheStrategy.ALL) .placeholder(R.drawable.ic_image_loading) .error(R.drawable.ic_empty_picture) .thumbnail(0.5f) .into(imageView); }
public static void displayImage(Context context, ImageView imageView, Uri uri, int placeHolder){ test(uri.toString()); Glide .with(context) .load(uri) .crossFade() .diskCacheStrategy(DiskCacheStrategy.ALL) .placeholder(placeHolder) .error(placeHolder) .dontAnimate()// TODO: 2016/11/13 添加之后图片不会因为某张图片不存在,导致所有图片不加载。 .into(imageView); }
public static void display(Context context, ImageView imageView, String url) { if (imageView == null) { throw new IllegalArgumentException("argument error"); } Glide.with(context).load(url) .diskCacheStrategy(DiskCacheStrategy.ALL) .centerCrop() .placeholder(R.drawable.ic_image_loading) .error(R.drawable.ic_empty_picture) .crossFade().into(imageView); }
@Override public void onBindViewHolder(PhotoViewHolder holder, int position) { Photo photo = mPhotosList.get(position); Glide.clear(holder.mImageView); Glide.with(mContext) .load(photo.getUri()) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.SOURCE) .into(holder.mImageView); holder.mTextView.setText(photo.getTitle()); }
public Bitmap getBitmapFromUrl(String imageUrl) { try { return Glide.with(this) .load(imageUrl) .asBitmap() .centerCrop() .diskCacheStrategy(DiskCacheStrategy.SOURCE) .into(Constants.PushNotification.LARGE_ICONE_SIZE, Constants.PushNotification.LARGE_ICONE_SIZE) .get(); } catch (Exception e) { LogUtil.logError(TAG, "getBitmapfromUrl", e); return null; } }
private static RequestBuilder<Bitmap> getRequestBuilder( RequestManager requestManager, int width, int height) { return requestManager .asBitmap() .apply( diskCacheStrategyOf(DiskCacheStrategy.NONE) .skipMemoryCache(true) .override(width, height)); }
public void setData() { n = NewsUtil.CheckisFavourite(getActivity(), mTitle); if (n == 1) { n = 0; myFavoriteNews.setImageResource(R.drawable.star); } else { n = 1; myFavoriteNews.setImageResource(R.drawable.star_off); } //Got Advantages why to use Glide over picasso that's why replaced picasso. Glide.with(this).load(mUrlToImage) .thumbnail(0.1f) .error(placeholder) .crossFade() .diskCacheStrategy(DiskCacheStrategy.SOURCE) .skipMemoryCache(true) .into(mToolbarImage); mTitleText.setText(mTitle); mByText.setText(mAuthor); mArticleBody.setText(mDescription); myFavoriteNews.setContentDescription(getString(R.string.my_favorite_save)); mTitleText.setContentDescription(getString(R.string.content_desc_title)+mTitle); mByText.setContentDescription(getString(R.string.content_desc_author)+mAuthor); mArticleBody.setContentDescription(getString(R.string.content_desc_article)+mDescription); AppCompatActivity activity = (AppCompatActivity)getActivity(); // We need to start the enter transition after the data has loaded if ( mTransitionAnimation ) { activity.supportStartPostponedEnterTransition(); if ( null != toolbar ) { activity.setSupportActionBar(toolbar); activity.getSupportActionBar().setDisplayShowTitleEnabled(false); activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); } } }
public static void loadLiveItemImg(Context context, String url, ImageView view) { Glide.with(context).load(url) .apply(new RequestOptions() .centerCrop() .placeholder(R.drawable.nodata_img_panda) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)) .into(view); }
/** * 图片加载 * @author leibing * @createTime 2016/8/15 * @lastModify 2016/8/15 * @param context 上下文 * @param imageView 图片显示控件 * @param localPath 图片本地链接 * @param defaultImage 默认占位图片 * @param errorImage 加载失败后图片 * @param isCropCircle 是否圆角 * @return */ public void load(Context context, ImageView imageView, File localPath, Drawable defaultImage, Drawable errorImage , boolean isCropCircle){ // 图片加载库采用Glide框架 DrawableTypeRequest request = Glide.with(context).load(localPath); // 设置scaleType request.centerCrop(); // 圆角裁切 if (isCropCircle) request.bitmapTransform(new CropCircleTransformation(context)); request.thumbnail(0.1f) //用原图的1/10作为缩略图 .placeholder(defaultImage) //设置资源加载过程中的占位Drawable .crossFade() //设置加载渐变动画 .priority(Priority.NORMAL) //指定加载的优先级,优先级越高越优先加载, // 但不保证所有图片都按序加载 // 枚举Priority.IMMEDIATE,Priority.HIGH,Priority.NORMAL,Priority.LOW // 默认为Priority.NORMAL .fallback(null) //设置model为空时要显示的Drawable // 如果没设置fallback,model为空时将显示error的Drawable, // 如果error的Drawable也没设置,就显示placeholder的Drawable .error(errorImage) //设置load失败时显示的Drawable .skipMemoryCache(true) //设置跳过内存缓存,但不保证一定不被缓存 // (比如请求已经在加载资源且没设置跳过内存缓存,这个资源就会被缓存在内存中) .diskCacheStrategy(DiskCacheStrategy.RESULT) //缓存策略DiskCacheStrategy.SOURCE: // 缓存原始数据,DiskCacheStrategy.RESULT: // 缓存变换(如缩放、裁剪等)后的资源数据, // DiskCacheStrategy.NONE:什么都不缓存, // DiskCacheStrategy.ALL:缓存SOURC和RESULT。 // 默认采用DiskCacheStrategy.RESULT策略, // 对于download only操作要使用DiskCacheStrategy.SOURCE .into(imageView); }
protected void loadAvatar(String url, ImageView view) { getRequestManager() .load(url) .diskCacheStrategy(DiskCacheStrategy.ALL) .error(R.drawable.ic_default_image) .fitCenter() .crossFade() .into(view); }