@Override protected void convert(CommonViewHolder holder, Book bookItem) { ImageView ivCover = holder.getView(R.id.iv_cover); GlideApp .with(mContext) .load(bookItem.getCoverUrl()) .transition(DrawableTransitionOptions.withCrossFade()) .placeholder(R.drawable.ic_book_cover_default) .into(ivCover); holder .setText(R.id.tv_author, bookItem.getAuthor()) .setText(R.id.tv_describe, bookItem.getDescribe()) .setText(R.id.tv_is_finish,bookItem.isFinished()? mContext.getString(R.string.book_finished):mContext.getString(R.string.book_unfinished)) .setText(R.id.tv_word_count,formatDownloads(bookItem.getBookWordNum())+"字") .setText(R.id.tv_title, bookItem.getName()); }
@Override public void onBindViewHolder(MyViewHolder holder, int position) { AppItem item = getItemInfoByPosition(position); holder.mName.setText(item.mName); holder.mUsage.setText(AppUtil.formatMilliSeconds(item.mUsageTime)); holder.mTime.setText(String.format(Locale.getDefault(), "%s · %d %s · %s", new SimpleDateFormat("yyyy.MM.dd HH:mm:ss", Locale.getDefault()).format(new Date(item.mEventTime)), item.mCount, getResources().getString(R.string.times_only), AppUtil.humanReadableByteCount(item.mMobile)) ); if (mTotal > 0) { holder.mProgress.setProgress((int) (item.mUsageTime * 100 / mTotal)); } else { holder.mProgress.setProgress(0); } GlideApp.with(MainActivity.this) .load(AppUtil.getPackageIcon(MainActivity.this, item.mPackageName)) .diskCacheStrategy(DiskCacheStrategy.ALL) .transition(new DrawableTransitionOptions().crossFade()) .into(holder.mIcon); holder.setOnClickListener(item); }
@Override public View getView(int position, View convertView, ViewGroup viewGroup) { GridViewHolder holder = null; if(convertView == null){ convertView = LayoutInflater.from(mContext).inflate(R.layout.rl_photo_gridview_item,viewGroup,false); holder = new GridViewHolder(convertView); convertView.setTag(holder); }else { holder = (GridViewHolder) convertView.getTag(); } OvLoad ovLoad = new OvLoad(); if(position != 0){ String path = (String) mData.get(position); ovLoad.loadPicture(mActivity,path,holder.mImg); }else { //位置0 加载本地资源文件 int itemPath = (int) mData.get(position); GlideApp.with(mContext) .load(itemPath) .transition(new DrawableTransitionOptions().crossFade(200)) .centerCrop() .into(holder.mImg); } return convertView; }
@Override protected void onProgressUpdate(byte[]... cover){ if(mContext != null && !((MainActivity) mContext.get()).isDestroyed() ) { GlideApp.with(mContext.get()). load(cover[0].length == 0 ? null : cover[0]) .thumbnail(0.1f) .error(R.drawable.ic_album_white_48px) .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE)) .apply(RequestOptions.skipMemoryCacheOf(true)) .transition(DrawableTransitionOptions.withCrossFade(100)) .fitCenter() .placeholder(R.drawable.ic_album_white_48px) .into(mHolder.get().mImageView); } System.gc(); }
@Override protected void load(Context context) { String url = "..."; Glide .with(context) .load(url) .apply(new RequestOptions() .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) .placeholder(R.drawable.glide_placeholder) .fallback(R.drawable.glide_fallback) .error(R.drawable.glide_error) ) .transition(new DrawableTransitionOptions() .crossFade() ) .listener(new LoggingListener<Drawable>()) .into(imageView) ; }
public UserRowHolder(View itemView) { super(itemView); profileIv = findViewById(R.id.user_row_profile); nameTv = findViewById(R.id.user_row_name); locationTv = findViewById(R.id.user_row_location); bioTv = findViewById(R.id.user_row_bio); moreView = findViewById(R.id.user_row_more); socialView = findViewById(R.id.user_row_social_layout); emailIv = findViewById(R.id.user_row_email); twitterIv = findViewById(R.id.user_row_twitter); insIv = findViewById(R.id.user_row_instagram); fadeInOptions = DrawableTransitionOptions.withCrossFade(); mCircleCropOption = RequestOptions.circleCropTransform(); }
public static void loadFlickrThumb(Photo photo, ImageView image) { final RequestOptions options = new RequestOptions() .diskCacheStrategy(DiskCacheStrategy.DATA) .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .dontTransform(); final RequestBuilder<Drawable> thumbRequest = Glide.with(image) .load(photo.getThumbnailUrl()) .apply(options) .transition(DrawableTransitionOptions.with(TRANSITION_FACTORY)); Glide.with(image).load(photo.getMediumUrl()) .apply(options) .thumbnail(thumbRequest) .into(image); }
@Test public void getDefaultTransitionOptions_withSuperClassRegistered_returnsSuperClassOptions() { DrawableTransitionOptions expected = new DrawableTransitionOptions(); transitionOptions.put(Drawable.class, expected); assertThat(context.getDefaultTransitionOptions(BitmapDrawable.class)) .isEqualTo(expected); assertThat(context.getDefaultTransitionOptions(GifDrawable.class)) .isEqualTo(expected); }
@Override public void onBindViewHolder(IgnoreViewHolder holder, int position) { IgnoreItem item = mData.get(position); holder.mCreated.setText(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault()).format(new Date(item.mCreated))); holder.mName.setText(item.mName); GlideApp.with(getApplicationContext()) .load(AppUtil.getPackageIcon(getApplicationContext(), item.mPackageName)) .transition(new DrawableTransitionOptions().crossFade()) .into(holder.mIcon); holder.setOnClickListener(item); }
public void bindTo(KitsuItem item) { this.item = item; if (null != item && null != item.type) { itemTypeView.setText(item.type); } else { itemTypeView.setText("Ouhh..."); } if (null != item && null != item.attributes && null != item.attributes.subtype) { itemSubtypeView.setText(item.attributes.subtype); } else { itemSubtypeView.setText("Ouhhhhh..."); } if (null != item && null != item.attributes && null != item.attributes.titles && null != item.attributes.titles.en_jp) { itemNameView.setText(item.attributes.titles.en_jp); } else { itemNameView.setText("Ouhhhhhhhh..."); } if (null != item && null != item.attributes && null != item.attributes.synopsis) { itemSynopsisView.setText(item.attributes.synopsis); } else { itemSynopsisView.setText("Ouhhhhhhhhhhh...\nYou know what?\nThe quick brown fox jumps over the lazy dog!"); } if (null != item && null != item.attributes && null != item.attributes.posterImage && null != item.attributes.posterImage.small) { itemCoverView.setVisibility(View.VISIBLE); Glide.with(itemView.getContext()) .load(item.attributes.posterImage.small) .apply(new RequestOptions().placeholder(R.drawable.empty_placeholder)) .transition(DrawableTransitionOptions.withCrossFade()) .into(itemCoverView); } else { Glide.with(itemView.getContext()).clear(itemCoverView); itemCoverView.setImageResource(R.drawable.empty_placeholder); } }
/** * 默认加载图片方式,使用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 void loadBigPicture(Context context, String url, ImageView targetView) { GlideApp.with(context) .load(url) .skipMemoryCache(false) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .transition(new DrawableTransitionOptions().crossFade(200)) .centerCrop() .priority(Priority.NORMAL) .into(targetView); }
/**有占位图的加载 * @param fragment 在Activity中加载 * @param url * @param targetView * @param placeHolder 加载图片时的占位图 */ public void loadHolderPicture(Fragment fragment, String url, ImageView targetView, int placeHolder) { GlideApp.with(fragment) .load(url) .centerCrop() .skipMemoryCache(false) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .priority(Priority.HIGH) .placeholder(placeHolder) .transition(new DrawableTransitionOptions().crossFade(200)) .into(targetView); }
@Override public void onBindViewHolder(StepsAdapter.StepsAdapterViewHolder holder, int position) { Step step = mStepList.get(position); if (step != null){ if (step.getVideoURL() != null && !step.getVideoURL().isEmpty()) { Glide.with(mContext) .load(step.getVideoURL()) .apply(new RequestOptions() .placeholder(R.drawable.placeholder_food) .fallback(R.drawable.placeholder_food) .centerCrop()) .into(holder.stepThumbnailView); } else if (step.getThumbnailURL() != null && !step.getVideoURL().isEmpty()) { Glide.with(mContext) .load(step.getThumbnailURL()) .apply(new RequestOptions() .placeholder(R.drawable.placeholder_food) .fallback(R.drawable.placeholder_food) .centerCrop()) .into(holder.stepThumbnailView); } else { Glide.with(mContext) .load(R.drawable.placeholder_food) .apply(new RequestOptions() .centerCrop()) .transition(DrawableTransitionOptions.withCrossFade()) .into(holder.stepThumbnailView); } holder.stepNameView.setText(step.getShortDescription()); } }
@Override public void onBindViewHolder(RecipeAdapterViewHolder holder, int position) { Recipe recipe = mRecipeList.get(position); if (recipe != null){ holder.titleView.setText(recipe.getName()); holder.servingsView.setText(Integer.toString(recipe.getServings())); if (recipe.getImage() != null && !recipe.getImage().isEmpty()){ Glide.with(mContext) .load(recipe.getImage()) .apply(new RequestOptions() .placeholder(R.drawable.placeholder_food) .fallback(R.drawable.placeholder_food) .centerCrop()) .transition(DrawableTransitionOptions.withCrossFade()) .into(holder.thumbnailView); } else { List<Step> steps = recipe.getSteps(); Glide.with(mContext) .load(steps.get(steps.size() - 1).getVideoURL()) .apply(new RequestOptions() .placeholder(R.drawable.placeholder_food) .fallback(R.drawable.placeholder_food) .centerCrop()) .transition(DrawableTransitionOptions.withCrossFade()) .into(holder.thumbnailView); } } }
private void setImagePath(String path) { try { Glide .with(getApplicationContext()) .load(new File(path)) .apply(options) .transition(DrawableTransitionOptions.withCrossFade()) .into(imView); } catch(Exception exc) {} }
private void loadImagePlaceholder() { GlideApp .with(context) .load(stockPhotoUrl) .placeholder(R.drawable.hourglass) .error(R.drawable.false_icon) .fallback(R.drawable.futurestudio_logo) .transition(DrawableTransitionOptions.withCrossFade(2000)) .into(imageView2); }
public GlideManager(Builder builder){ RequestOptions options = new RequestOptions() .placeholder(builder.placeresid); if (builder.eroorresid != 0){ options.error(builder.eroorresid); } switch (builder.type){ case BITMAP_SCAN_CENTERN: options.centerCrop(); break; case BITMAP_SCAN_FIT: options.fitCenter(); break; default: break; } if (builder.setCircleCrop){ options.circleCrop(); } if (builder.radius != 0){ options.transform(new RoundedCorners(builder.radius)); } RequestBuilder requestBuilder = null; requestBuilder = Glide.with(builder.context).load(builder.source); if (builder.animtime > 0){ requestBuilder.transition(new DrawableTransitionOptions().crossFade(builder.animtime)); } requestBuilder.apply(options) .listener(new LoadListener()) .into(builder.imageView); }
/** * Set the previous values(including cover art), * when user press back and cancel editing mode */ private void setPreviousValues(){ mTitleField.setText(mCurrentTitle); mArtistField.setText(mCurrentArtist); mAlbumField.setText(mCurrentAlbum); mNumberField.setText(mCurrentNumber); mYearField.setText(mCurrentYear); mGenreField.setText(mCurrentGenre); if(mCurrentCoverArt != null && (mCurrentCoverArtLength != mNewCoverArtLength) ) { GlideApp.with(mViewDetailsTrack). load(mCurrentCoverArt) .error(R.drawable.ic_album_white_48px) .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE)) .apply(RequestOptions.skipMemoryCacheOf(true)) .transition(DrawableTransitionOptions.withCrossFade(CROSS_FADE_DURATION)) .fitCenter() .placeholder(R.drawable.ic_album_white_48px) .into(mToolbarCover); mCurrentCoverArtLength = mCurrentCoverArt.length; return; } if(mCurrentCoverArt == null){ GlideApp.with(mViewDetailsTrack). load(null) .error(R.drawable.ic_album_white_48px) .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE)) .apply(RequestOptions.skipMemoryCacheOf(true)) .transition(DrawableTransitionOptions.withCrossFade(CROSS_FADE_DURATION)) .fitCenter() .placeholder(R.drawable.ic_album_white_48px) .into(mToolbarCover); mCurrentCoverArtLength = 0; } }
/** * Draws placeholder when cover is removed, * and updates info about it */ private void redrawCover() { mTrackDetailsActivityWeakReference.get().mAudioFile = new File(mTrackDetailsActivityWeakReference.get().mTrackPath); mTrackDetailsActivityWeakReference.get().mFileSize.setText(AudioItem.getFileSize(mTrackDetailsActivityWeakReference.get().mAudioFile.length())); mTrackDetailsActivityWeakReference.get().mImageSize.setText(AudioItem.getStringImageSize(null)); //set the generic cover art GlideApp.with(mTrackDetailsActivityWeakReference.get().mViewDetailsTrack). load(null) .error(R.drawable.ic_album_white_48px) .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE)) .apply(RequestOptions.skipMemoryCacheOf(true)) .transition(DrawableTransitionOptions.withCrossFade(CROSS_FADE_DURATION)) .fitCenter() .placeholder(R.drawable.ic_album_white_48px) .into(mTrackDetailsActivityWeakReference.get().mToolbarCover); mTrackDetailsActivityWeakReference.get().enableMiniFabs(true); mTrackDetailsActivityWeakReference.get().showSnackBar(Snackbar.LENGTH_SHORT, mTrackDetailsActivityWeakReference.get().getString(R.string.cover_removed),ACTION_NONE, null); mTrackDetailsActivityWeakReference.get().mTrackAdapter.notifyItemChanged(mTrackDetailsActivityWeakReference.get().mCurrentAudioItem.getPosition()); mTrackDetailsActivityWeakReference.get().cachingCurrentValues(); mTrackDetailsActivityWeakReference.get().disableFields(); mTrackDetailsActivityWeakReference.get().mAsyncUpdateData = null; mTrackDetailsActivityWeakReference.clear(); mTrackDetailsActivityWeakReference = null; System.gc(); }
@Override protected void onBindViewHolder(@NonNull PostsListViewBinder.ViewHolder holder, @NonNull final PostsListBean item) { final Context context = holder.itemView.getContext(); String publishedTime = item.getPublishedTime().substring(0, 10); String likesCount = item.getLikesCount() + "赞"; String commentsCount = item.getCommentsCount() + "条评论"; String titleImage = item.getTitleImage(); String title = item.getTitle(); if (!TextUtils.isEmpty(titleImage)) { titleImage = item.getTitleImage().replace("r.jpg", "b.jpg"); GlideApp.with(context) .load(titleImage) .centerCrop() .error(R.color.viewBackground) .transition(new DrawableTransitionOptions().crossFade()) .into(holder.iv_titleImage); } else { holder.iv_titleImage.setImageResource(R.drawable.error_image); holder.iv_titleImage.setScaleType(ImageView.ScaleType.CENTER_CROP); } holder.tv_publishedTime.setText(publishedTime); holder.tv_likesCount.setText(likesCount); holder.tv_commentsCount.setText(commentsCount); holder.tv_title.setText(title); holder.root.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PostsContentActivity.start(context, item.getTitleImage(), item.getTitle(), item.getSlug()); } }); }
@Override public void loadImage(String path, ImageView imageView, ImageType imageType) { Glide.with(imageView.getContext()) .load(path) .apply(new RequestOptions() .placeholder(imageType == ImageType.FOLDER ? R.drawable.ef_folder_placeholder : R.drawable.ef_image_placeholder) .error(imageType == ImageType.FOLDER ? R.drawable.ef_folder_placeholder : R.drawable.ef_image_placeholder) ) .transition(DrawableTransitionOptions.withCrossFade()) .into(imageView); }
@OnClick(R.id.button_download_direct) protected void downloadDirect() { // Download directly from StorageReference using Glide // (See MyAppGlideModule for Loader registration) GlideApp.with(this) .load(mImageRef) .centerCrop() .transition(DrawableTransitionOptions.withCrossFade()) .into(mImageView); }
public Target<PalettizedBitmapDrawable> newRequest(ArtInfo artInfo, ImageView imageView, @Nullable Paletteable paletteable, @Nullable Bundle extras) { PalettableImageViewTarget target = makeTarget(imageView, paletteable, extras); RequestOptions options = makeOptions(imageView, extras); return Glide.with(imageView.getContext()) .as(PalettizedBitmapDrawable.class) .apply(options) .transition(DrawableTransitionOptions.withCrossFade()) .load(new ArtInfoRequest(mAuthority, artInfo)) .into(target); }
public Target<PalettizedBitmapDrawable> newRequest(Uri uri, ImageView imageView, @Nullable Paletteable paletteable, @Nullable Bundle extras) { PalettableImageViewTarget target = makeTarget(imageView, paletteable, extras); RequestOptions options = makeOptions(imageView, extras); return Glide.with(imageView.getContext()) .as(PalettizedBitmapDrawable.class) .apply(options) .transition(DrawableTransitionOptions.withCrossFade()) .load(uri) .into(target); }
public Target<PalettizedBitmapDrawable> newRequest(ArtInfo artInfo, ImageView imageView, Palette.PaletteAsyncListener listener, @Nullable Bundle extras) { PalettableImageViewTarget target = makeTarget(imageView, listener); RequestOptions options = makeOptions(imageView, extras); return Glide.with(imageView.getContext()) .as(PalettizedBitmapDrawable.class) .apply(options) .transition(DrawableTransitionOptions.withCrossFade()) .load(new ArtInfoRequest(mAuthority, artInfo)) .into(target); }
public Target<PalettizedBitmapDrawable> newRequest(Uri uri, ImageView imageView, Palette.PaletteAsyncListener listener, @Nullable Bundle extras) { PalettableImageViewTarget target = makeTarget(imageView, listener); RequestOptions options = makeOptions(imageView, extras); return Glide.with(imageView.getContext()) .as(PalettizedBitmapDrawable.class) .apply(options) .transition(DrawableTransitionOptions.withCrossFade()) .load(uri) .into(target); }
@Override public void loadImage(Context ctx, ImageConfigImpl config) { if (ctx == null) throw new NullPointerException("Context is required"); if (config == null) throw new NullPointerException("ImageConfigImpl is required"); if (TextUtils.isEmpty(config.getUrl())) throw new NullPointerException("Url is required"); if (config.getImageView() == null) throw new NullPointerException("Imageview is required"); GlideRequests requests; requests = GlideArms.with(ctx);//如果context是activity则自动使用Activity的生命周期 GlideRequest<Drawable> glideRequest = requests.load(config.getUrl()) .transition(DrawableTransitionOptions.withCrossFade()) .centerCrop(); switch (config.getCacheStrategy()) {//缓存策略 case 0: glideRequest.diskCacheStrategy(DiskCacheStrategy.ALL); break; case 1: glideRequest.diskCacheStrategy(DiskCacheStrategy.NONE); break; case 2: glideRequest.diskCacheStrategy(DiskCacheStrategy.RESOURCE); break; case 3: glideRequest.diskCacheStrategy(DiskCacheStrategy.DATA); break; case 4: glideRequest.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); break; } if (config.getTransformation() != null) {//glide用它来改变图形的形状 glideRequest.transform(config.getTransformation()); } if (config.getPlaceholder() != 0)//设置占位符 glideRequest.placeholder(config.getPlaceholder()); if (config.getErrorPic() != 0)//设置错误的图片 glideRequest.error(config.getErrorPic()); if (config.getFallback() != 0)//设置请求 url 为空图片 glideRequest.fallback(config.getFallback()); glideRequest .into(config.getImageView()); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_step_detail, container, false); mPlayerView = mBinding.exoPlayer; if (getArguments() != null){ step = Parcels.unwrap(getArguments().getParcelable(STEP_EXTRA)); } if (step != null){ if (step.getVideoURL() != null && !step.getVideoURL().isEmpty()){ playWhenReady = getArguments().getBoolean(PLAY_EXTRA, false); mBinding.flStepDetailFragment.setVisibility(View.VISIBLE); mBinding.ivStepThumbnail.setVisibility(View.INVISIBLE); mBinding.exoPlayer.setVisibility(View.VISIBLE); initializeMediaSession(); initializePlayer(Uri.parse(step.getVideoURL())); } else if (step.getThumbnailURL() != null && !step.getThumbnailURL().isEmpty()){ mBinding.flStepDetailFragment.setVisibility(View.VISIBLE); mBinding.exoPlayer.setVisibility(View.INVISIBLE); mBinding.ivStepThumbnail.setVisibility(View.VISIBLE); Glide.with(getContext()) .load(step.getThumbnailURL()) .apply(new RequestOptions() .placeholder(R.drawable.placeholder_food) .fallback(R.drawable.placeholder_food) .centerCrop()) .transition(DrawableTransitionOptions.withCrossFade()) .into(mBinding.ivStepThumbnail); } else { mBinding.flStepDetailFragment.setVisibility(View.VISIBLE); mBinding.exoPlayer.setVisibility(View.INVISIBLE); mBinding.ivStepThumbnail.setVisibility(View.VISIBLE); Glide.with(getContext()) .load(R.drawable.placeholder_food) .apply(new RequestOptions() .centerCrop()) .transition(DrawableTransitionOptions.withCrossFade()) .into(mBinding.ivStepThumbnail); } mBinding.tvStepDetails.setText(step.getDescription()); } return mBinding.getRoot(); }
@Override public void loadImage(Context ctx, ImageConfigImpl config) { if (ctx == null) throw new NullPointerException("Context is required"); if (config == null) throw new NullPointerException("ImageConfigImpl is required"); if (TextUtils.isEmpty(config.getUrl())&&config.getPlaceholder()==0) throw new NullPointerException("Url is required"); if (config.getImageView() == null) throw new NullPointerException("Imageview is required"); GlideRequests requests; requests = GlideArms.with(ctx);//如果context是activity则自动使用Activity的生命周期 GlideRequest<Drawable> glideRequest; if (config.getDontAnimate()){ glideRequest = requests.load(config.getUrl()) .dontAnimate(); }else { glideRequest = requests.load(config.getUrl()) .transition(DrawableTransitionOptions.withCrossFade()) .centerCrop(); } switch (config.getCacheStrategy()) {//缓存策略 case 0: glideRequest.diskCacheStrategy(DiskCacheStrategy.ALL); break; case 1: glideRequest.diskCacheStrategy(DiskCacheStrategy.NONE); break; case 2: glideRequest.diskCacheStrategy(DiskCacheStrategy.RESOURCE); break; case 3: glideRequest.diskCacheStrategy(DiskCacheStrategy.DATA); break; case 4: glideRequest.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); break; } if (config.getTransformation() != null) {//glide用它来改变图形的形状 glideRequest.transform(config.getTransformation()); } if (config.getPlaceholder() != 0)//设置占位符 glideRequest.placeholder(config.getPlaceholder()); if (config.getErrorPic() != 0)//设置错误的图片 glideRequest.error(config.getErrorPic()); if (config.getFallback() != 0)//设置请求 url 为空图片 glideRequest.fallback(config.getFallback()); if (config.getResID() != 0) glideRequest.load(config.getResID()); glideRequest .into(config.getImageView()); }
@Override public void onBindViewHolder(final IconViewHolder holder, int position) { AppBean bean = dataList.get(position); holder.viewTag.setBackgroundResource(bean.isMark() ? R.drawable.tag_redraw : 0); // holder.ivIcon.setImageDrawable(bean.getIcon()); if (bean.getIcon() != null) { holder.ivIcon.setImageDrawable(bean.getIcon()); } else { holder.ivIcon.setImageResource(0); if (!TextUtils.isEmpty(bean.getIconUrl())) { Glide.with(context) .load(bean.getIconUrl()) .transition(DrawableTransitionOptions.withCrossFade()) .into(holder.ivIcon); } } holder.tvApp.setText(bean.getLabel()); holder.tvComponent.setText(PkgUtil.concatComponent(bean.getPkg(), bean.getLauncher())); if (bean.getReqTimes() >= 0) { holder.tvReqTimes.setText(ExtraUtil.renderReqTimes(bean.getReqTimes())); } else { holder.tvReqTimes.setText(""); } if (bean.isHintMark()) { holder.viewHint.setVisibility(View.VISIBLE); holder.viewHint.setBackground(context.getDrawable(R.drawable.dot_green)); } else if (bean.isHintUndoMark()) { holder.viewHint.setVisibility(View.VISIBLE); holder.viewHint.setBackground(context.getDrawable(R.drawable.dot_red)); } else if (bean.isHintLost()) { holder.viewHint.setVisibility(View.VISIBLE); holder.viewHint.setBackground(context.getDrawable(R.drawable.dot_red)); } else { holder.viewHint.setVisibility(View.GONE); } if (onItemClickListener != null) { holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int pos = holder.getAdapterPosition(); onItemClickListener.onClick(pos, dataList.get(pos)); } }); } }
@Override public void loadImage(Context context, ImageConfigImpl config) { Preconditions.checkNotNull(context, "Context is required"); Preconditions.checkNotNull(config, "ImageConfigImpl is required"); Preconditions.checkNotNull(config.getImageView(), "ImageView is required"); GlideRequests requests = GlideGm.with(context); GlideRequest<Drawable> glideRequest = requests.load(config.getUrl()) .transition(DrawableTransitionOptions.withCrossFade())//Animation .fitCenter();//Adapt to the center switch (config.getCacheStrategy()) {//Cache strategy case 0: glideRequest.diskCacheStrategy(DiskCacheStrategy.ALL); break; case 1: glideRequest.diskCacheStrategy(DiskCacheStrategy.NONE); break; case 2: glideRequest.diskCacheStrategy(DiskCacheStrategy.RESOURCE); break; case 3: glideRequest.diskCacheStrategy(DiskCacheStrategy.DATA); break; case 4: glideRequest.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); break; } if (config.getTransformation() != null)//Customize to change the picture shape glideRequest.transform(config.getTransformation()); if (config.getPlaceholder() != 0)//Set the placeholder glideRequest.placeholder(config.getPlaceholder()); if (config.getErrorPic() != 0)//Set the Error image glideRequest.error(config.getErrorPic()); if (config.getFallback() != 0)//Set url to null as image glideRequest.fallback(config.getFallback()); glideRequest.into(config.getImageView()); }
@Override public void loadImage(Context context, ImageConfigImpl config) { Preconditions.checkNotNull(context, "Context is required"); Preconditions.checkNotNull(config, "ImageConfigImpl is required"); Preconditions.checkNotNull(config.getImageView(), "ImageView is required"); GlideRequests requests = GlideGm.with(context); GlideRequest<Drawable> glideRequest = requests.load(config.getUrl()) .transition(DrawableTransitionOptions.withCrossFade())//Animation .fitCenter();//Adapt to the center switch (config.getCacheStrategy()) {//Cache strategy case 0: glideRequest.diskCacheStrategy(DiskCacheStrategy.ALL); break; case 1: glideRequest.diskCacheStrategy(DiskCacheStrategy.NONE); break; case 2: glideRequest.diskCacheStrategy(DiskCacheStrategy.RESOURCE); break; case 3: glideRequest.diskCacheStrategy(DiskCacheStrategy.DATA); break; case 4: glideRequest.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); break; default: break; } if (config.getTransformation() != null)//Customize to change the picture shape glideRequest.transform(config.getTransformation()); if (config.getPlaceholder() != 0)//Set the placeholder glideRequest.placeholder(config.getPlaceholder()); if (config.getErrorPic() != 0)//Set the Error image glideRequest.error(config.getErrorPic()); if (config.getFallback() != 0)//Set url to null as image glideRequest.fallback(config.getFallback()); glideRequest.into(config.getImageView()); }
@Override public void loadImage(Context context, ImageConfigImpl config) { Preconditions.checkNotNull(context, "Context is required"); Preconditions.checkNotNull(config, "ImageConfigImpl is required"); Preconditions.checkNotNull(config.getImageView(), "ImageView is required"); GlideRequests requests = GlideArms.with(context); GlideRequest<Drawable> glideRequest = requests.load(config.getUrl()) //动画 .transition(DrawableTransitionOptions.withCrossFade()) //适应居中 .fitCenter(); //缓存策略 switch (config.getCacheStrategy()) { case 0: glideRequest.diskCacheStrategy(DiskCacheStrategy.ALL); break; case 1: glideRequest.diskCacheStrategy(DiskCacheStrategy.NONE); break; case 2: glideRequest.diskCacheStrategy(DiskCacheStrategy.RESOURCE); break; case 3: glideRequest.diskCacheStrategy(DiskCacheStrategy.DATA); break; case 4: glideRequest.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); break; default: break; } //自定义改变图片形状 if (config.getTransformation() != null) { glideRequest.transform(config.getTransformation()); } //设置占位符 if (config.getPlaceholder() != 0) { glideRequest.placeholder(config.getPlaceholder()); } //设置错误图片 if (config.getErrorPic() != 0) { glideRequest.error(config.getErrorPic()); } //设置 url 为 null 是图片 if (config.getFallback() != 0) { glideRequest.fallback(config.getFallback()); } glideRequest.into(config.getImageView()); }
/** * Callback for processing the result from startActivityForResult call, * here we process the image picked by user and apply to audio file * @param requestCode is the code from what component * makes the request this can be snack bar, * toolbar or text "Añadir caratula de galería" * @param resultCode result code is the action requested, in this case * Intent.ACTION_PICK * @param data Data received, can be null */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (data != null){ try { Uri imageData = data.getData(); Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageData); if (bitmap.getHeight() > 1080 || bitmap.getWidth() > 1080) { showSnackBar(Snackbar.LENGTH_LONG, getString(R.string.image_too_big), ACTION_NONE, null); mNewCoverArt = mCurrentCoverArt; mCurrentCoverArtLength = mNewCoverArtLength; } else { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream); mNewCoverArt = byteArrayOutputStream.toByteArray(); mNewCoverArtLength = mNewCoverArt.length; GlideApp.with(mViewDetailsTrack). load(mNewCoverArt) .error(R.drawable.ic_album_white_48px) .transition(DrawableTransitionOptions.withCrossFade(CROSS_FADE_DURATION)) .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE)) .apply(RequestOptions.skipMemoryCacheOf(true)) .fitCenter() .placeholder(R.drawable.ic_album_white_48px) .into(mToolbarCover); if (requestCode == INTENT_OPEN_GALLERY) { //show the new cover in mToolbar cover if (!mEditMode) { enableFieldsToEdit(); } } else { mAsyncUpdateData = new AsyncUpdateData(ADD_COVER, false, this); mAsyncUpdateData.execute(); } mAppBarLayout.setExpanded(true); } } catch(IOException e){ e.printStackTrace(); showSnackBar(Snackbar.LENGTH_LONG, getString(R.string.error_load_image), ACTION_NONE, null); mNewCoverArt = mCurrentCoverArt; mNewCoverArtLength = mCurrentCoverArtLength; } } }
/** * Sets the extracted values into corresponding * View objects */ private void setCurrentValues(boolean error){ //file name over toolbar cover mTitleLayer.setText(mAudioFile.getName()); //path to file mSubtitleLayer.setText(AudioItem.getRelativePath(mAudioFile.getParent())); //set values of additional info about song mTrackType.setText(mFileType); mImageSize.setText(AudioItem.getStringImageSize(mCurrentCoverArt)); mFileSize.setText(AudioItem.getFileSize(mAudioFile.length())); mTrackLength.setText(AudioItem.getHumanReadableDuration(mCurrentDuration)); mStatus.setText(getStatusText()); mStatus.setCompoundDrawablesWithIntrinsicBounds(getStatusDrawable(),null,null,null); mBitrateField.setText(AudioItem.getBitrate(mBitrate)); mFrequency.setText(AudioItem.getFrequency(mFrequencyVal)); mResolution.setText(AudioItem.getResolution(mResolutionVal)); mChannels.setText(mChannelsVal); //Has occurred any error while reading file or tags, then //do not enable make any operations to file, only playing functionality if(error) return; //load a placeholder in case cover art is not present GlideApp.with(mViewDetailsTrack). load(mCurrentCoverArt) .error(R.drawable.ic_album_white_48px) .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE)) .apply(RequestOptions.skipMemoryCacheOf(true)) .transition(DrawableTransitionOptions.withCrossFade(CROSS_FADE_DURATION)) .fitCenter() .placeholder(R.drawable.ic_album_white_48px) .into(mToolbarCover); //set values into edit text objects mTitleField.setText(mCurrentTitle); mArtistField.setText(mCurrentArtist); mAlbumField.setText(mCurrentAlbum); mNumberField.setText(mCurrentNumber); mYearField.setText(mCurrentYear); mGenreField.setText(mCurrentGenre); //when intent brings correction mode == MANUAL, enable fields //to start immediately editing it if (mCorrectionMode == Constants.CorrectionModes.MANUAL) { enableFieldsToEdit(); } addActionListeners(); }
@Override public void load(Context context, GlideImageConfig config) { this.check(context, config); // 如果Context是Activity则自动使用Activity的生命周期 GlideRequests requests = GlideFrames.with(context); GlideRequest<Drawable> glideRequest = requests.load(config.getUrl()) .transition(DrawableTransitionOptions.withCrossFade()); // 缓存策略 switch (config.getCacheStrategy()) { case 0: glideRequest.diskCacheStrategy(DiskCacheStrategy.ALL); break; case 1: glideRequest.diskCacheStrategy(DiskCacheStrategy.NONE); break; case 2: glideRequest.diskCacheStrategy(DiskCacheStrategy.RESOURCE); break; case 3: glideRequest.diskCacheStrategy(DiskCacheStrategy.DATA); break; case 4: glideRequest.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC); break; } ImageScaleType scaleType = config.getScaleType(); if (scaleType != null) { switch (scaleType) { case CENTER_CROP: glideRequest.centerCrop(); break; case CENTER_INSIDE: glideRequest.centerInside(); break; case FIT_CENTER: glideRequest.fitCenter(); break; default: break; } } if (config.getTransformation() != null) {//glide用它来改变图形的形状 glideRequest.transform(config.getTransformation()); } // 设置占位符 if (config.getPlaceholder() != 0) { glideRequest.placeholder(config.getPlaceholder()); } // 设置错误的图片 if (config.getError() != 0) { glideRequest.error(config.getError()); } // 设置请求 url 为空图片 if (config.getFallback() != 0) { glideRequest.fallback(config.getFallback()); } glideRequest .into(config.getImageView()); }
public PhotoMiniHolder(View itemView) { super(itemView); thumbIv = findViewById(R.id.photo_mini_thumb); mOptions = DrawableTransitionOptions.withCrossFade(); }