com.bumptech.glide.request.RequestOptions Java Examples

The following examples show how to use com.bumptech.glide.request.RequestOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: titanium-imagepicker   Author: prashantsaini1   File: ImagePickerActivity.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void setupGlideOptions() {
   	options = new RequestOptions();
   	int size;

   	if (isShapeCircle) {
   		if (Defaults.CIRCLE_RADIUS > 0) {
   			size = (int) (0.65 * Defaults.IMAGE_HEIGHT);
   			options.transforms(new CenterCrop(), new RoundedCorners(Defaults.CIRCLE_RADIUS));

   		} else {
   			size = Defaults.IMAGE_HEIGHT;
   			options.circleCrop();
   		}

   	} else {
   		size = (int) (0.65 * Defaults.IMAGE_HEIGHT);
   	}

   	options.override(size, size);
   	options.error(error_image);
   	options.priority(Priority.HIGH);
   }
 
Example #2
Source Project: a   Author: 804463258   File: MediaPlayerPop.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void setCover(String coverPath) {
    if (TextUtils.isEmpty(coverPath)) return;
    if (coverPath.startsWith("http")) {
        Glide.with(this).load(coverPath)
                .apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop()
                        .placeholder(R.drawable.img_cover_default))
                .into(ivCover);
        Glide.with(this).load(coverPath)
                .apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop()
                        .placeholder(R.drawable.img_cover_gs))
                .apply(RequestOptions.bitmapTransform(new BlurTransformation(getContext(), 25)))
                .into(ivCoverBg);
    } else {
        File file = new File(coverPath);
        Glide.with(this).load(file)
                .apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop()
                        .placeholder(R.drawable.img_cover_default))
                .into(ivCover);
        Glide.with(this).load(file)
                .apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop()
                        .placeholder(R.drawable.img_cover_gs))
                .apply(RequestOptions.bitmapTransform(new BlurTransformation(getContext(), 25)))
                .into(ivCoverBg);
    }
}
 
Example #3
Source Project: a   Author: 804463258   File: DownloadAdapter.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position, @NonNull List<Object> payloads) {
    final DownloadBookBean item = data.get(holder.getLayoutPosition());
    if (!payloads.isEmpty()) {
        holder.tvName.setText(String.format(Locale.getDefault(), "%s(正在下载)", item.getName()));
        holder.tvDownload.setText(activity.getString(R.string.un_download, (Integer) payloads.get(0)));
    }else {
        holder.ivDel.getDrawable().mutate();
        holder.ivDel.getDrawable().setColorFilter(activity.getResources().getColor(R.color.tv_text_default), PorterDuff.Mode.SRC_ATOP);
        Glide.with(activity)
                .load(item.getCoverUrl())
                .apply(new RequestOptions()
                        .diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop()
                        .dontAnimate().placeholder(R.drawable.img_cover_default)
                        .error(R.drawable.img_cover_default))
                .into(holder.ivCover);
        if (item.getSuccessCount() > 0) {
            holder.tvName.setText(String.format(Locale.getDefault(), "%s(正在下载)", item.getName()));
        } else {
            holder.tvName.setText(String.format(Locale.getDefault(), "%s(等待下载)", item.getName()));
        }
        holder.tvDownload.setText(activity.getString(R.string.un_download, item.getDownloadCount() - item.getSuccessCount()));
        holder.ivDel.setOnClickListener(view -> DownloadService.removeDownload(activity, item.getNoteUrl()));
    }
}
 
Example #4
Source Project: ShareBox   Author: Kerr1Gan   File: FileExpandableAdapter.java    License: Apache License 2.0 6 votes vote down vote up
protected void setChildViewThumb(FileUtil.MediaFileType type, String f, ImageView icon, RequestOptions options) {
    if (type == FileUtil.MediaFileType.MOVIE ||
            type == FileUtil.MediaFileType.IMG) {
        if (options == null) {
            Glide.with(mContext).load(f).listener(mRequestListener).into(icon);
        } else {
            Glide.with(mContext).load(f).listener(mRequestListener).apply(options).into(icon);
        }
    } else if (type == FileUtil.MediaFileType.APP) {
        Bitmap b = sLruCache.get(f);
        if (b == null) {
            AppThumbTask task = new AppThumbTask(sLruCache, mContext, icon);
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new File(f));
        } else
            icon.setImageBitmap(b);
    } else if (type == FileUtil.MediaFileType.MP3) {
        icon.setImageResource(R.mipmap.music);
    } else if (type == FileUtil.MediaFileType.DOC) {
        icon.setImageResource(R.mipmap.document);
    } else if (type == FileUtil.MediaFileType.RAR) {
        icon.setImageResource(R.mipmap.rar);
    }
}
 
Example #5
Source Project: a   Author: 804463258   File: BookInfoEditActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void initCover() {
    if (!this.isFinishing() && book != null) {
        if (TextUtils.isEmpty(book.getCustomCoverPath())) {
            Glide.with(this).load(book.getBookInfoBean().getCoverUrl())
                    .apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop()
                            .placeholder(R.drawable.img_cover_default)).into(ivCover);
        } else if (book.getCustomCoverPath().startsWith("http")) {
            Glide.with(this).load(book.getCustomCoverPath())
                    .apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop()
                            .placeholder(R.drawable.img_cover_default)).into(ivCover);
        } else {
            Glide.with(this).load(new File(book.getCustomCoverPath()))
                    .apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop()
                            .placeholder(R.drawable.img_cover_default)).into(ivCover);
        }
    }
}
 
Example #6
Source Project: leafpicrevived   Author: apcro   File: VideoFragment.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mPlayVideoIcon.setOnClickListener(v -> {
        Uri uri = StorageHelper.getUriForFile(getContext(), media.getFile());
        Intent intent = new Intent(Intent.ACTION_VIEW).setDataAndType(uri, media.getMimeType());
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(intent);
    });

    // TODO: See where we can move this. Seems like boilerplate code that belongs in
    // a utility class or Builder of some sort.
    RequestOptions options =
            new RequestOptions().signature(media.getSignature()).centerCrop()
                    .diskCacheStrategy(
                            DiskCacheStrategy.AUTOMATIC);

    Glide.with(getContext()).load(media.getUri()).apply(options).into(previewView);
    setTapListener(previewView);
}
 
Example #7
Source Project: SendBird-Android   Author: sendbird   File: ImageUtils.java    License: MIT License 6 votes vote down vote up
/**
 * Crops image into a circle that fits within the ImageView.
 */
public static void displayRoundImageFromUrl(final Context context, final String url, final ImageView imageView) {
    RequestOptions myOptions = new RequestOptions()
            .centerCrop()
            .dontAnimate();

    Glide.with(context)
            .asBitmap()
            .apply(myOptions)
            .load(url)
            .into(new BitmapImageViewTarget(imageView) {
                @Override
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable circularBitmapDrawable =
                            RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                    circularBitmapDrawable.setCircular(true);
                    imageView.setImageDrawable(circularBitmapDrawable);
                }
            });
}
 
Example #8
Source Project: HaoReader   Author: Invinciblelee   File: DownloadAdapter.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position, @NonNull List<Object> payloads) {
    final DownloadBookBean item = dataS.get(holder.getLayoutPosition());
    if (!payloads.isEmpty()) {
        holder.tvName.setText(String.format(Locale.getDefault(), "[正在下载]%s", item.getName()));
        holder.tvName.getPaint().setFakeBoldText(true);
        holder.tvDownload.setText(activity.getString(R.string.un_download, (Integer) payloads.get(0)));
    } else {
        Glide.with(activity)
                .load(item.getCoverUrl())
                .apply(new RequestOptions()
                        .diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop()
                        .dontAnimate().placeholder(R.drawable.img_cover_default)
                        .error(R.drawable.img_cover_default))
                .into(holder.ivCover);
        if (item.getSuccessCount() > 0) {
            holder.tvName.setText(String.format(Locale.getDefault(), "[正在下载]%s", item.getName()));
            holder.tvName.getPaint().setFakeBoldText(true);
        } else {
            holder.tvName.setText(String.format(Locale.getDefault(), "[等待下载]%s", item.getName()));
            holder.tvName.getPaint().setFakeBoldText(false);
        }
        holder.tvDownload.setText(activity.getString(R.string.un_download, item.getDownloadCount() - item.getSuccessCount()));
        holder.ivDel.setOnClickListener(view -> DownloadService.removeDownload(activity, item.getNoteUrl()));
    }
}
 
Example #9
Source Project: AndroidAnimationExercise   Author: REBOOTERS   File: StaggeredRecyclerViewAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(MyHolder holder, final int position) {
    ViewGroup.LayoutParams params = holder.mImageView.getLayoutParams();
    params.height = heights.get(position);
    holder.mImageView.setLayoutParams(params);

    Glide.with(mContext).
            load(demos.get(position))
            .apply(new RequestOptions().placeholder(R.drawable.a6))
            .into(holder.mImageView);
    holder.itemshell.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });
}
 
Example #10
Source Project: androidtv-Leanback   Author: googlearchive   File: VideoDetailsFragment.java    License: Apache License 2.0 6 votes vote down vote up
private void updateBackground(String uri) {
    RequestOptions options = new RequestOptions()
            .centerCrop()
            .error(mDefaultBackground);

    Glide.with(this)
            .asBitmap()
            .load(uri)
            .apply(options)
            .into(new SimpleTarget<Bitmap>(mMetrics.widthPixels, mMetrics.heightPixels) {
                @Override
                public void onResourceReady(
                        Bitmap resource,
                        Transition<? super Bitmap> transition) {
                    mBackgroundManager.setBitmap(resource);
                }
            });
}
 
Example #11
Source Project: Collection-Android   Author: usernameyangyan   File: GlideUtils.java    License: MIT License 6 votes vote down vote up
/**
 * 处理Glide You cannot start a load for a destroyed activity问题
 *
 * @param context
 * @param url               网络图片
 * @param defaultLoadingImg 默认加载图片
 * @param imageView
 */
public static void loadImg(Context context, String url, int defaultLoadingImg, ImageView imageView) {
	try {
		RequestOptions options = new RequestOptions()
				.placeholder(defaultLoadingImg)
				.error(defaultLoadingImg)
				.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
				.priority(Priority.HIGH);

		Glide.with(context)
				.load(url)
				.apply(options)
				.into(imageView);

	} catch (Exception exception) {
		return;
	}
}
 
Example #12
Source Project: react-native-syan-image-picker   Author: syanbo   File: GlideEngine.java    License: MIT License 6 votes vote down vote up
/**
 * 加载相册目录
 *
 * @param context   上下文
 * @param url       图片路径
 * @param imageView 承载图片ImageView
 */
@Override
public void loadFolderImage(@NonNull Context context, @NonNull String url, @NonNull ImageView imageView) {
    Glide.with(context)
            .asBitmap()
            .load(url)
            .override(180, 180)
            .centerCrop()
            .sizeMultiplier(0.5f)
            .apply(new RequestOptions().placeholder(R.drawable.picture_image_placeholder))
            .into(new BitmapImageViewTarget(imageView) {
                @Override
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable circularBitmapDrawable =
                            RoundedBitmapDrawableFactory.
                                    create(context.getResources(), resource);
                    circularBitmapDrawable.setCornerRadius(8);
                    imageView.setImageDrawable(circularBitmapDrawable);
                }
            });
}
 
Example #13
Source Project: leanback-showcase   Author: googlearchive   File: VideoCardPresenter.java    License: Apache License 2.0 6 votes vote down vote up
CardViewHolder(ImageCardView view, Context context) {
    super(view);
    mContext = context;
    Context wrapper = new ContextThemeWrapper(mContext, R.style.MyPopupMenu);
    mPopupMenu = new PopupMenu(wrapper, view);
    mPopupMenu.inflate(R.menu.popup_menu);

    mPopupMenu.setOnMenuItemClickListener(this);
    view.setOnLongClickListener(this);

    mOwner = (LifecycleOwner) mContext;

    mDefaultBackground = mContext.getResources().getDrawable(R.drawable.no_cache_no_internet, null);
    mDefaultPlaceHolder = new RequestOptions().
            placeholder(mDefaultBackground);

    mCardView = (ImageCardView) CardViewHolder.this.view;
    Resources resources = mCardView.getContext().getResources();
    mCardView.setMainImageDimensions(Math.round(
            resources.getDimensionPixelSize(R.dimen.card_width)),
            resources.getDimensionPixelSize(R.dimen.card_height));

    mFragmentActivity = (FragmentActivity) context;
    mViewModel = ViewModelProviders.of(mFragmentActivity).get(VideosViewModel.class);
}
 
Example #14
Source Project: PopularMovies   Author: YassinAJDI   File: BindingAdapters.java    License: MIT License 5 votes vote down vote up
/**
 * Movie details poster image
 */
@BindingAdapter({"imageUrl"})
public static void bindImage(ImageView imageView, String imagePath) {
    GlideApp.with(imageView.getContext())
            .load(Constants.IMAGE_URL + imagePath)
            .placeholder(R.color.md_grey_200)
            .apply(new RequestOptions().transforms(new CenterCrop(),
                    new RoundedCorners((int) UiUtils.dipToPixels(imageView.getContext(), 8))))
            .into(imageView);
}
 
Example #15
Source Project: AlbumCameraRecorder   Author: zhongjhATC   File: Glide4EngineProgress.java    License: MIT License 5 votes vote down vote up
@Override
public void loadGifImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) {
    Glide.with(context)
            .asGif()
            .load(uri)
            .apply(new RequestOptions()
                    .override(resizeX, resizeY)
                    .priority(Priority.HIGH)
                    .fitCenter())
            .into(imageView);
}
 
Example #16
Source Project: MusicBobber   Author: Cleveroad   File: MusicAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public void onBindViewHolder(MusicViewHolder holder, int position) {
    MusicItem item = getItem(position);
    holder.title.setText(getFilter().highlightFilteredSubstring(item.title()));
    holder.artist.setText(getFilter().highlightFilteredSubstring(item.artist()));
    holder.album.setText(getFilter().highlightFilteredSubstring(item.album()));
    holder.duration.setText(convertDuration(item.duration()));
    Glide.with(getContext())
            .asBitmap()
            .load(item.albumArtUri())
            .apply((new RequestOptions()).circleCrop())
            .placeholder(R.drawable.aw_ic_default_album)
            .error(R.drawable.aw_ic_default_album)
            .into(holder.albumCover);
}
 
Example #17
Source Project: MusicBobber   Author: Cleveroad   File: MusicService.java    License: MIT License 5 votes vote down vote up
@Override
public void onPrepared(MediaPlayer mp) {
    preparing = false;
    mediaPlayer.start();
    if (!audioWidget.isShown()) {
        audioWidget.show(preferences.getInt(KEY_POSITION_X, 100), preferences.getInt(KEY_POSITION_Y, 100));
    }
    audioWidget.controller().start();
    audioWidget.controller().position(0);
    audioWidget.controller().duration(mediaPlayer.getDuration());
    stopTrackingPosition();
    startTrackingPosition();
    int size = getResources().getDimensionPixelSize(R.dimen.cover_size);
    Glide.with(this)
            .asBitmap()
            .load(items.get(playingIndex).albumArtUri())
            .override(size, size)
            .centerCrop()
            .apply((new RequestOptions()).circleCrop())
            .into(new SimpleTarget<Bitmap>() {
                @Override
                public void onLoadFailed(@Nullable Drawable errorDrawable) {
                    super.onLoadFailed(errorDrawable);
                    if (audioWidget != null) {
                        audioWidget.controller().albumCover(null);
                    }
                }

                @Override
                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                    if (audioWidget != null) {
                        audioWidget.controller().albumCoverBitmap(resource);
                    }
                }
            });
}
 
Example #18
Source Project: ExFilePicker   Author: bartwell   File: FileFilesListHolder.java    License: MIT License 5 votes vote down vote up
@Override
public void bind(@NonNull File file, boolean isMultiChoiceModeEnabled, boolean isSelected, @Nullable OnListItemClickListener listener) {
    super.bind(file, isMultiChoiceModeEnabled, isSelected, listener);
    if (mFileSize != null) {
        mFileSize.setVisibility(View.VISIBLE);
        mFileSize.setText(Utils.getHumanReadableFileSize(mContext, file.length()));
    }

    RequestOptions options = new RequestOptions()
            .error(R.drawable.efp__ic_file);
    Glide.with(mContext)
            .load(file)
            .apply(options)
            .into(mThumbnail);
}
 
Example #19
Source Project: Easy_xkcd   Author: tom-anders   File: OverviewBaseFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        lastComicNumber = savedInstanceState.getInt(LAST_COMIC);
    } else {
        lastComicNumber = getArguments().getInt(LAST_COMIC);
    }
    //We don't need override(Target.SIZE_ORIGINAL) here, so set empty defaultRequestOptions for Glide
    GlideApp.with(this).setDefaultRequestOptions(new RequestOptions());
    super.onCreate(savedInstanceState);
}
 
Example #20
Source Project: Android   Author: PlexMediaInc   File: CreditsAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public void onBindViewHolder(CreditsAdapter.CreditsViewHolder holder, final int position) {

    holder.name.setText(casts.get(position).getName());
    holder.character.setText(casts.get(position).getCharacter());

    RequestOptions requestOptions = new RequestOptions();
    requestOptions.placeholder(R.drawable.if_person);
    requestOptions.error(R.drawable.if_person);
    Glide.with(mContext).setDefaultRequestOptions(requestOptions).load("http://image.tmdb.org/t/p/w185"+casts.get(position).getProfilePath()).apply(RequestOptions.circleCropTransform()).into(holder.thumbnail);


    //onClick
    //==================================================================

    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Fragment fragment = new ActorFragment();
            Bundle bundle = new Bundle();
            bundle.putInt("person_id", casts.get(position).getId());
            fragment.setArguments(bundle);
            FragmentTransaction fragmentTransaction = ((FragmentActivity)mContext).getSupportFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.frame, fragment,TAG_ACTOR_FRAGMENT);
            fragmentTransaction.addToBackStack(MainActivity.CURRENT_TAG);
            fragmentTransaction.commit();
        }
    });
}
 
Example #21
Source Project: XDroidMvp   Author: limedroid   File: GlideLoader.java    License: MIT License 5 votes vote down vote up
private RequestOptions wrapScaleType(Options options) {
    RequestOptions request = new RequestOptions()
            .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
            .priority(Priority.HIGH);

    if (options != null){
        if (options.scaleType != null) {
            if (options.loadingResId != Options.RES_NONE) {
                request.placeholder(options.loadingResId);
            }
            if (options.loadErrorResId != Options.RES_NONE) {
                request.error(options.loadErrorResId);
            }

            switch (options.scaleType) {
                case MATRIX:
                case FIT_XY:
                case FIT_START:
                case FIT_END:
                case CENTER:
                case CENTER_INSIDE:
                    break;

                case FIT_CENTER:
                    request.fitCenter();
                    break;

                case CENTER_CROP:
                    request.centerCrop();
                    break;
            }
        } else {
            request.centerCrop();
        }
    }else {
        request.centerCrop();
    }

    return request;
}
 
Example #22
Source Project: qiscus-sdk-android   Author: qiscus   File: ChatActivity.java    License: Apache License 2.0 5 votes vote down vote up
protected void showRoomImage() {
    for (QiscusRoomMember member : qiscusChatRoom.getMember()) {
        if (!member.getEmail().equalsIgnoreCase(qiscusAccount.getEmail())) {
            Nirmana.getInstance().get()
                    .setDefaultRequestOptions(new RequestOptions()
                            .error(com.qiscus.sdk.R.drawable.ic_qiscus_avatar)
                            .placeholder(com.qiscus.sdk.R.drawable.ic_qiscus_avatar)
                            .dontAnimate())
                    .load(member.getAvatar())
                    .into(ivAvatar);
            break;
        }
    }
}
 
Example #23
Source Project: DevUtils   Author: afkT   File: GlideUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 图片加载
 * @param uri     Image Uri
 * @param target  {@link Target}
 * @param options {@link RequestOptions}
 */
public void loadImageFile(final String uri, final Target<File> target, final RequestOptions options) {
    if (mRequestManager != null) {
        if (options != null) {
            mRequestManager.asFile().load(uri).apply(options).into(target);
        } else {
            mRequestManager.asFile().load(uri).into(target);
        }
    }
}
 
Example #24
Source Project: AndroidUiKit   Author: yangjiantao   File: PhotoViewerTestActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            final ImageView itemView = ((ViewHolder) holder).imageView;
            ((ViewHolder) holder).position = position;
            Glide.with(itemView.getContext())
                    .load(datas[position])
//                    .diskCacheStrategy(DiskCacheStrategy.NONE)
//                    .dontTransform()
//                    .placeholder(R.mipmap.ic_launcher_round)
//                    .crossFade()
                    .apply(new RequestOptions()
                            .override(360)
                            .placeholder(R.mipmap.ic_launcher))
                    .into(itemView);
        }
 
Example #25
Source Project: leanback-showcase   Author: googlearchive   File: ListenerModule.java    License: Apache License 2.0 5 votes vote down vote up
private void loadAndSetBackgroundImageParameter(VideoEntity selectedVideo,
        final Activity activity, DisplayMetrics metrics,
        final BackgroundManager backgroundManager, RequestOptions defaultPlaceHolder,
        Drawable defualtDrawble) {
    if (selectedVideo == null) {
        return;
    }
    String url1 = selectedVideo.getVideoBgImageLocalStorageUrl();
    String url2 = selectedVideo.getBgImageUrl();
    String loadedUri;
    if (url1.isEmpty()) {
        loadedUri = url2;
    } else {
        loadedUri = url1;
    }

    // wait until runtime the activity has window
    if (!backgroundManager.isAttached()) {
        backgroundManager.attach(activity.getWindow());
    }

    // glide on error
    Glide.with(activity)
            .asBitmap()
            .load(loadedUri)
            .apply(defaultPlaceHolder)
            .into(new SimpleTarget<Bitmap>(metrics.widthPixels, metrics.heightPixels) {
                @Override
                public void onResourceReady(Bitmap resource,
                        Transition<? super Bitmap> glideAnimation) {
                    backgroundManager.setDrawable(
                            new BitmapDrawable(activity.getResources(), resource));
                }
            });
}
 
Example #26
Source Project: ImagePicker   Author: Vanish136   File: GlideImagePickerDisplayer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void display(Context context, String url, ImageView imageView, int placeHolder, int errorHolder, int maxWidth, int maxHeight)
{
    RequestOptions options = new RequestOptions()
            .placeholder(placeHolder)
            .error(errorHolder)
            .override(maxWidth, maxHeight)
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC);
    Glide.with(context)
            .asBitmap()
            .load(url)
            .apply(options)
            .into(imageView);
}
 
Example #27
Source Project: a   Author: 804463258   File: BookDetailActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void upImageView(String path) {
    if (TextUtils.isEmpty(path)) return;
    if (Objects.equals(coverPath, path)) return;
    if (this.isFinishing()) return;
    coverPath = path;
    if (coverPath.startsWith("http")) {
        Glide.with(this).load(coverPath)
                .apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop()
                        .placeholder(R.drawable.img_cover_default))
                .into(ivCover);
        Glide.with(this).load(coverPath)
                .apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop()
                        .placeholder(R.drawable.img_cover_gs))
                .apply(RequestOptions.bitmapTransform(new BlurTransformation(this, 25)))
                .into(ivBlurCover);
    } else {
        File file = new File(coverPath);
        Glide.with(this).load(file)
                .apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop()
                        .placeholder(R.drawable.img_cover_default))
                .into(ivCover);
        Glide.with(this).load(file)
                .apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop()
                        .placeholder(R.drawable.img_cover_gs))
                .apply(RequestOptions.bitmapTransform(new BlurTransformation(this, 25)))
                .into(ivBlurCover);
    }
}
 
Example #28
Source Project: DevUtils   Author: afkT   File: GlideUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取自定义图片加载配置
 * @param options    {@link RequestOptions}
 * @param loadingRes 设置加载中显示的图片
 * @return {@link RequestOptions}
 */
public static RequestOptions getLoadResOptions(final RequestOptions options, @DrawableRes final int loadingRes) {
    if (options != null && loadingRes != 0) {
        options.placeholder(loadingRes) // 设置图片在下载期间显示的图片
                .fallback(loadingRes) // 设置图片 Uri 为空或是错误的时候显示的图片
                .error(loadingRes); // 设置图片 ( 加载 / 解码 ) 过程中错误时候显示的图片
    }
    return options;
}
 
Example #29
Source Project: SkyTube   Author: ram-on   File: PlaylistViewHolder.java    License: GNU General Public License v3.0 5 votes vote down vote up
void setPlaylist(final YouTubePlaylist playlist, Context context) {
	Glide.with(context)
					.load(playlist.getThumbnailUrl())
					.apply(new RequestOptions().placeholder(R.drawable.thumbnail_default))
					.into(thumbnailImageView);
	titleTextView.setText(playlist.getTitle());
	publishDateTextView.setText(playlist.getPublishDatePretty());
	videoCountTextView.setText(String.format(context.getString(R.string.num_videos), playlist.getVideoCount()));
	thumbnailImageView.setOnClickListener(view -> playlistClickListener.onClickPlaylist(playlist));
}
 
Example #30
Source Project: bannerview   Author: czy1121   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public View create(BannerItem item, int position, ViewGroup container) {
    ImageView iv = new ImageView(container.getContext());
    RequestOptions options = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.DATA);
    Glide.with(container.getContext().getApplicationContext()).load(item.image).apply(options).into(iv);
    return iv;
}