下面列出了怎么用com.bumptech.glide.signature.ObjectKey的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Glide图片加载
*/
private void glideLoad(){
RequestOptions options1 = new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.signature(new ObjectKey(SPUtils.get(MainActivity.this,"head_signature","")))
.placeholder(R.drawable.default_photo);
RequestOptions options2 =new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.signature(new ObjectKey(SPUtils.get(MainActivity.this,"head_signature","")))
.placeholder(R.drawable.ic_img1);
Glide.with(getApplicationContext())
.load(SPUtils.get(MainActivity.this, "path" ,""))
.apply(options1)
.into(user_image);
Glide.with(getApplicationContext())
.load(SPUtils.get(MainActivity.this, "path" ,""))
.apply(bitmapTransform(new BlurTransformation(25, 3)))
.apply(options2)
.into(nav_bg);
}
private void displayTokenIcon()
{
String correctedAddr = Keys.toChecksumAddress(token.getAddress());
String tURL = assetDefinition.getTokenImageUrl(token.tokenInfo.chainId, token.getAddress());
if (TextUtils.isEmpty(tURL))
{
tURL = TRUST_ICON_REPO.replace(ICON_REPO_ADDRESS_TOKEN, correctedAddr);
}
int fallbackIcon = EthereumNetworkRepository.getChainLogo(token.tokenInfo.chainId);
Glide.with(getContext().getApplicationContext())
.load(tURL)
.signature(new ObjectKey(correctedAddr + "-" + token.tokenInfo.chainId))
.apply(new RequestOptions().circleCrop())
.apply(new RequestOptions().placeholder(fallbackIcon))
.into(icon);
icon.setVisibility(View.VISIBLE);
}
public static void loadExperimentOverviewImage(
AppAccount appAccount, ImageView imageView, String experimentOverviewFilePath) {
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
String fullPath =
PictureUtils.getExperimentOverviewFullImagePath(appAccount, experimentOverviewFilePath);
File file = new File(fullPath);
Context context = imageView.getContext();
GlideApp.with(context)
.load(fullPath)
.placeholder(R.drawable.experiment_card_placeholder)
// Create a signature based on the last modified time so that cached images will
// not be used if the underlying file changes. This may happen if the user has
// picked an experiment photo from the "edit experiment" page because there is only
// one filename used for that photo.
.signature(new ObjectKey(file.getPath() + file.lastModified()))
.into(imageView);
}
public static void loadAvatar(RequestManager glide, ImageView view, String avatarUrl) {
avatarUrl = Utils.nullToText(avatarUrl);
String cacheKey = AVATAR_CACHE_KEYS.get(avatarUrl);
if (cacheKey == null) {
cacheKey = avatarUrl;
}
if (HiSettingsHelper.getInstance().isCircleAvatar()) {
glide.load(new AvatarModel(avatarUrl))
.signature(new ObjectKey(cacheKey))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.circleCrop()
.error(DEFAULT_USER_ICON)
.transition(DrawableTransitionOptions.withCrossFade())
.into(view);
} else {
glide.load(new AvatarModel(avatarUrl))
.signature(new ObjectKey(cacheKey))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.transform(new CenterCrop(), new RoundedCorners(Utils.dpToPx(4)))
.error(DEFAULT_USER_ICON)
.transition(DrawableTransitionOptions.withCrossFade())
.into(view);
}
}
@Override
public LoadData<BlurHash> buildLoadData(@NonNull BlurHash blurHash,
int width,
int height,
@NonNull Options options)
{
return new LoadData<>(new ObjectKey(blurHash.getHash()), new BlurDataFetcher(blurHash));
}
@Override
public void onBindViewHolder(ClockRecyclerViewAdapter.ViewHolder ViewHolder, int i) {
RequestOptions options2 =new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.skipMemoryCache(true)
.signature(new ObjectKey(SPUtils.get(context,"head_signature","")))
.placeholder(R.drawable.ic_img1);
ViewHolder.clock_title.setText(tomatoList.get(tomatoList.size()-1-i).getTitle());
ViewHolder.work_time.setText(tomatoList.get(tomatoList.size()-1-i).getWorkLength() + " 分钟");
ViewHolder.clock_card_bg.setImageBitmap(BitmapUtils.readBitMap(context,tomatoList.get(tomatoList.size()-1-i).getImgId()));
}
@Override
public void onBindViewHolder(TodoRecyclerViewAdapter.ViewHolder ViewHolder, int i) {
RequestOptions options2 =new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.skipMemoryCache(true)
.signature(new ObjectKey(SPUtils.get(context,"head_signature","")))
.placeholder(R.drawable.ic_img1);
ViewHolder.todo_title.setText(todosList.get(todosList.size()-1-i).getTitle());
ViewHolder.todo_desc.setText(todosList.get(todosList.size()-1-i).getDesc());
ViewHolder.todo_date.setText(todosList.get(todosList.size()-1-i).getDate() + " "+ todosList.get(todosList.size()-1-i).getTime());
ViewHolder.card_background.setImageBitmap(BitmapUtils.readBitMap(context, todosList.get(todosList.size()-1-i).getImgId()));
if (todosList.get(todosList.size()-1-i).getIsRepeat() == 1){
ViewHolder.isRepeat.setText("重复");
ViewHolder.isRepeat.setTextSize(TypedValue.COMPLEX_UNIT_SP,10);
}else {
ViewHolder.isRepeat.setText("单次");
ViewHolder.isRepeat.setTextSize(TypedValue.COMPLEX_UNIT_SP,10);
}
if(todosList.get(todosList.size()-1-i).getRemindTime() <= System.currentTimeMillis() ){
ViewHolder.timelineView.setMarker(context.getResources().getDrawable(R.drawable.ic_marker));
}else {
ViewHolder.timelineView.setMarker(context.getResources().getDrawable(R.drawable.round));
}
}
/**
* Glide图片加载
*/
private void glideLoad(){
RequestOptions options_1 = new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.signature(new ObjectKey(SPUtils.get(UserDataActivity.this,"head_signature","")))
.placeholder(R.drawable.default_photo);
RequestOptions options_2 = new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.signature(new ObjectKey(SPUtils.get(UserDataActivity.this,"head_signature","")))
.placeholder(R.drawable.ic_img1);
Glide.with(getApplicationContext())
.load(SPUtils.get(UserDataActivity.this, "path" ,""))
.apply(options_1)
.into(toolbar_userhead);
Glide.with(getApplicationContext())
.load(SPUtils.get(UserDataActivity.this, "path" ,""))
.apply(options_1)
.into(user_head);
Glide.with(getApplicationContext())
.load(SPUtils.get(UserDataActivity.this, "path" ,""))
.apply(bitmapTransform(new BlurTransformation(25, 3)))
.apply(options_2)
.into(top_bg);
}
public static void loadExperimentImage(
Context context,
ImageView view,
AppAccount appAccount,
String experimentId,
String relativeFilePath,
boolean scale) {
if (isDestroyed(context)) {
if (Log.isLoggable(TAG, Log.ERROR)) {
Log.e(TAG, "Trying to load image for destroyed context");
}
// Nothing we can do, return
return;
}
File file =
FileMetadataUtil.getInstance()
.getExperimentFile(appAccount, experimentId, relativeFilePath);
if (scale) {
// Use last modified time as part of the signature to force a glide cache refresh.
GlideApp.with(context)
.load(file.getAbsolutePath())
.placeholder(R.drawable.placeholder)
.signature(new ObjectKey(file.getPath() + file.lastModified()))
.centerCrop()
// caches only the final image, after reducing the resolution
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.into(view);
} else {
// Use last modified time as part of the signature to force a glide cache refresh.
GlideApp.with(context)
.load(file.getAbsolutePath())
.placeholder(R.drawable.placeholder)
.signature(new ObjectKey(file.getPath() + file.lastModified()))
.fitCenter()
// caches only the final image, after reducing the resolution
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.into(view);
}
}
@Nullable
@Override
public LoadData<ByteBuffer> buildLoadData(@NonNull String origin, int width, int height, @NonNull Options options) {
return new LoadData<>(new ObjectKey(origin),new ApkIconFetcher(context, origin.substring(8)));
}
public ObjectKey getSignature() {
return new ObjectKey(getDateModified() + getPath() + getOrientation());
}
@Nullable
@Override
public LoadData<InputStream> buildLoadData(@NonNull AudioFileCover audioFileCover, int width, int height, @NonNull Options options) {
return new LoadData<InputStream>(new ObjectKey(audioFileCover.filePath),new AudioFileCoverFetcher(audioFileCover));
}
public ObjectKey getArtistSignature(String artistName, boolean isLoadOriginal, int whichImage) {
String value = String.valueOf(getArtistSignatureRaw(artistName));
return new ObjectKey(artistName+"_"+"original="+isLoadOriginal+"_"+"pos="+whichImage+"_"+String.valueOf(getArtistSignatureRaw(artistName)));
}
public Key getGlideSignature() {
File file = new File(getPath());
String lastModified = String.valueOf(file.lastModified());
return new ObjectKey(lastModified);
}
@Override
public LoadData<InputStream> buildLoadData(@NonNull AudioFileCover model, int width, int height,
@NonNull Options options) {
return new LoadData<>(new ObjectKey(model.filePath), new AudioFileCoverFetcher(model));
}
@Override
public LoadData<InputStream> buildLoadData(@NonNull ArtistImage model, int width, int height,
@NonNull Options options) {
return new LoadData<>(new ObjectKey(model.artistName), new ArtistImageFetcher(context, deezerClient, okhttp, model));
}
public ObjectKey getArtistSignature(String artistName) {
return new ObjectKey(String.valueOf(getArtistSignatureRaw(artistName)));
}
@Override
public LoadData<InputStream> buildLoadData(@NonNull GlideUrl model, int width, int height, @NonNull Options options) {
return new LoadData<>(new ObjectKey(model), new ImageStreamFetcher(client, model));
}
@Override
public LoadData<InputStream> buildLoadData(@NonNull AvatarModel model, int width, int height, @NonNull Options options) {
return new LoadData<>(new ObjectKey(model), new AvatarStreamFetcher(client, model));
}