use of com.bumptech.glide.request.target.CustomTarget in project Signal-Android by WhisperSystems.
the class ConversationParentFragment method handleAddShortcut.
private void handleAddShortcut() {
Log.i(TAG, "Creating home screen shortcut for recipient " + recipient.get().getId());
final Context context = requireContext().getApplicationContext();
final Recipient recipient = this.recipient.get();
if (pinnedShortcutReceiver == null) {
pinnedShortcutReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, context.getString(R.string.ConversationActivity_added_to_home_screen), Toast.LENGTH_LONG).show();
}
};
requireActivity().registerReceiver(pinnedShortcutReceiver, new IntentFilter(ACTION_PINNED_SHORTCUT));
}
GlideApp.with(this).asBitmap().load(recipient.getContactPhoto()).error(recipient.getFallbackContactPhoto().asDrawable(context, recipient.getAvatarColor(), false)).into(new CustomTarget<Bitmap>() {
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
if (errorDrawable == null) {
throw new AssertionError();
}
Log.w(TAG, "Utilizing fallback photo for shortcut for recipient " + recipient.getId());
SimpleTask.run(() -> DrawableUtil.toBitmap(errorDrawable, SHORTCUT_ICON_SIZE, SHORTCUT_ICON_SIZE), bitmap -> addIconToHomeScreen(context, bitmap, recipient));
}
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
SimpleTask.run(() -> BitmapUtil.createScaledBitmap(resource, SHORTCUT_ICON_SIZE, SHORTCUT_ICON_SIZE), bitmap -> addIconToHomeScreen(context, bitmap, recipient));
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
}
use of com.bumptech.glide.request.target.CustomTarget in project Signal-Android by WhisperSystems.
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));
}
use of com.bumptech.glide.request.target.CustomTarget in project xabber-android by redsolution.
the class FileMessageVH method setUpImage.
private void setUpImage(String imagePath, String imageUrl, final String uniqueId, Integer imageWidth, Integer imageHeight, Context context) {
if (!SettingsManager.connectionLoadImages())
return;
if (imagePath != null) {
boolean result = FileManager.loadImageFromFile(context, imagePath, messageImage);
if (result) {
messageImage.setVisibility(View.VISIBLE);
} else {
final Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
MessageItem first = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, uniqueId).findFirst();
if (first != null) {
first.setFilePath(null);
}
}
});
}
} else {
final ViewGroup.LayoutParams layoutParams = messageImage.getLayoutParams();
if (imageWidth != null && imageHeight != null) {
FileManager.scaleImage(layoutParams, imageHeight, imageWidth);
Glide.with(context).load(imageUrl).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
messageImage.setVisibility(View.GONE);
return true;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}).into(messageImage);
messageImage.setVisibility(View.VISIBLE);
} else {
Glide.with(context).asBitmap().load(imageUrl).placeholder(R.drawable.ic_recent_image_placeholder).error(R.drawable.ic_recent_image_placeholder).into(new CustomTarget<Bitmap>() {
@Override
public void onLoadStarted(@Nullable Drawable placeholder) {
super.onLoadStarted(placeholder);
messageImage.setImageDrawable(placeholder);
messageImage.setVisibility(View.VISIBLE);
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
super.onLoadFailed(errorDrawable);
messageImage.setImageDrawable(errorDrawable);
messageImage.setVisibility(View.VISIBLE);
}
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
final int width = resource.getWidth();
final int height = resource.getHeight();
if (width <= 0 || height <= 0) {
messageImage.setVisibility(View.GONE);
return;
}
final Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
MessageItem first = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, uniqueId).findFirst();
if (first != null) {
first.setImageWidth(width);
first.setImageHeight(height);
}
}
});
FileManager.scaleImage(layoutParams, height, width);
messageImage.setImageBitmap(resource);
messageImage.setVisibility(View.VISIBLE);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
}
}
}
use of com.bumptech.glide.request.target.CustomTarget 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));
}
use of com.bumptech.glide.request.target.CustomTarget in project Signal-Android by signalapp.
the class ConversationParentFragment method handleAddShortcut.
private void handleAddShortcut() {
Log.i(TAG, "Creating home screen shortcut for recipient " + recipient.get().getId());
final Context context = requireContext().getApplicationContext();
final Recipient recipient = this.recipient.get();
if (pinnedShortcutReceiver == null) {
pinnedShortcutReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, context.getString(R.string.ConversationActivity_added_to_home_screen), Toast.LENGTH_LONG).show();
}
};
requireActivity().registerReceiver(pinnedShortcutReceiver, new IntentFilter(ACTION_PINNED_SHORTCUT));
}
GlideApp.with(this).asBitmap().load(recipient.getContactPhoto()).error(recipient.getFallbackContactPhoto().asDrawable(context, recipient.getAvatarColor(), false)).into(new CustomTarget<Bitmap>() {
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
if (errorDrawable == null) {
throw new AssertionError();
}
Log.w(TAG, "Utilizing fallback photo for shortcut for recipient " + recipient.getId());
SimpleTask.run(() -> DrawableUtil.toBitmap(errorDrawable, SHORTCUT_ICON_SIZE, SHORTCUT_ICON_SIZE), bitmap -> addIconToHomeScreen(context, bitmap, recipient));
}
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
SimpleTask.run(() -> BitmapUtil.createScaledBitmap(resource, SHORTCUT_ICON_SIZE, SHORTCUT_ICON_SIZE), bitmap -> addIconToHomeScreen(context, bitmap, recipient));
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
}
Aggregations