use of com.bumptech.glide.request.RequestListener in project glide by bumptech.
the class FullscreenActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fullscreen_activity);
String resultJson = getIntent().getStringExtra(EXTRA_RESULT_JSON);
final Api.GifResult result = new Gson().fromJson(resultJson, Api.GifResult.class);
ImageView gifView = (ImageView) findViewById(R.id.fullscreen_gif);
gifView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("giphy_url", result.images.original.url);
clipboard.setPrimaryClip(clip);
if (gifDrawable != null) {
if (gifDrawable.isRunning()) {
gifDrawable.stop();
} else {
gifDrawable.start();
}
}
}
});
RequestBuilder<Drawable> thumbnailRequest = GlideApp.with(this).load(result).decode(Bitmap.class);
GlideApp.with(this).load(result.images.original.url).thumbnail(thumbnailRequest).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
if (resource instanceof GifDrawable) {
gifDrawable = (GifDrawable) resource;
} else {
gifDrawable = null;
}
return false;
}
}).into(gifView);
}
use of com.bumptech.glide.request.RequestListener in project 91Pop by DanteAndroid.
the class PictureAdapter method instantiateItem.
@NonNull
@Override
public View instantiateItem(@NonNull ViewGroup container, final int position) {
View contentView = LayoutInflater.from(container.getContext()).inflate(R.layout.item_picture_adapter, container, false);
PhotoView photoView = contentView.findViewById(R.id.photoView);
final ProgressBar progressBar = contentView.findViewById(R.id.progressBar);
String url = imageList.get(position);
if (url.contains("meizitu.net")) {
GlideApp.with(container).load(buildGlideUrl(url)).transition(new DrawableTransitionOptions().crossFade(300)).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
}).into(photoView);
} else {
GlideApp.with(container).load(Uri.parse(url)).transition(new DrawableTransitionOptions().crossFade(300)).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
}).into(photoView);
}
// Now just add PhotoView to ViewPager and return it
container.addView(contentView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
photoView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onImageClickListener != null) {
onImageClickListener.onImageClick(v, position);
}
}
});
photoView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (onImageClickListener != null) {
onImageClickListener.onImageLongClick(v, position);
}
return true;
}
});
Logger.t(TAG).d("instantiateItem");
return contentView;
}
use of com.bumptech.glide.request.RequestListener in project BBS-Android by bdpqchen.
the class GlideImageGeter method getDrawable.
@Override
public Drawable getDrawable(String url) {
final UrlDrawable urlDrawable = new UrlDrawable(mContext);
final GenericRequestBuilder load;
final Target target;
load = Glide.with(mContext).load(url).asBitmap().fitCenter().listener(new RequestListener<String, Bitmap>() {
@Override
public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
LogUtil.dd("glide laod onException");
return false;
}
@Override
public boolean onResourceReady(Bitmap resource, String model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
LogUtil.dd("glide load onResourceReady");
return false;
}
});
target = new BitmapTarget(urlDrawable);
// load.override(100, 100).into(target);
load.override(600, 600);
load.into(target);
return urlDrawable;
}
use of com.bumptech.glide.request.RequestListener in project Signal-Android by signalapp.
the class AvatarPreviewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
super.onCreate(savedInstanceState, ready);
setTheme(R.style.TextSecure_MediaPreview);
setContentView(R.layout.contact_photo_preview_activity);
if (Build.VERSION.SDK_INT >= 21) {
postponeEnterTransition();
TransitionInflater inflater = TransitionInflater.from(this);
getWindow().setSharedElementEnterTransition(inflater.inflateTransition(R.transition.full_screen_avatar_image_enter_transition_set));
getWindow().setSharedElementReturnTransition(inflater.inflateTransition(R.transition.full_screen_avatar_image_return_transition_set));
}
Toolbar toolbar = findViewById(R.id.toolbar);
EmojiTextView title = findViewById(R.id.title);
ImageView avatar = findViewById(R.id.avatar);
setSupportActionBar(toolbar);
requireSupportActionBar().setDisplayHomeAsUpEnabled(true);
requireSupportActionBar().setDisplayShowTitleEnabled(false);
Context context = getApplicationContext();
RecipientId recipientId = RecipientId.from(getIntent().getStringExtra(RECIPIENT_ID_EXTRA));
Recipient.live(recipientId).observe(this, recipient -> {
ContactPhoto contactPhoto = recipient.isSelf() ? new ProfileContactPhoto(recipient, recipient.getProfileAvatar()) : recipient.getContactPhoto();
FallbackContactPhoto fallbackPhoto = recipient.isSelf() ? new ResourceContactPhoto(R.drawable.ic_profile_outline_40, R.drawable.ic_profile_outline_20, R.drawable.ic_person_large) : recipient.getFallbackContactPhoto();
Resources resources = this.getResources();
GlideApp.with(this).asBitmap().load(contactPhoto).fallback(fallbackPhoto.asCallCard(this)).error(fallbackPhoto.asCallCard(this)).diskCacheStrategy(DiskCacheStrategy.ALL).addListener(new RequestListener<Bitmap>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
Log.w(TAG, "Unable to load avatar, or avatar removed, closing");
finish();
return false;
}
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}).into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
avatar.setImageDrawable(RoundedBitmapDrawableFactory.create(resources, resource));
if (Build.VERSION.SDK_INT >= 21) {
startPostponedEnterTransition();
}
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
title.setText(recipient.getDisplayName(context));
});
FullscreenHelper fullscreenHelper = new FullscreenHelper(this);
findViewById(android.R.id.content).setOnClickListener(v -> fullscreenHelper.toggleUiVisibility());
fullscreenHelper.configureToolbarSpacer(findViewById(R.id.toolbar_cutout_spacer));
fullscreenHelper.showAndHideWithSystemUI(getWindow(), findViewById(R.id.toolbar_layout));
}
Aggregations