use of com.bumptech.glide.request.target.SimpleTarget in project android by nextcloud.
the class DrawerActivity method updateHeaderBackground.
public void updateHeaderBackground() {
if (getAccount() != null && getStorageManager().getCapability(getAccount().name).getServerBackground() != null) {
final ViewGroup navigationHeader = (ViewGroup) findNavigationViewChildById(R.id.drawer_header_view);
if (navigationHeader != null) {
OCCapability capability = getStorageManager().getCapability(getAccount().name);
String background = capability.getServerBackground();
CapabilityBooleanType backgroundDefault = capability.getServerBackgroundDefault();
CapabilityBooleanType backgroundPlain = capability.getServerBackgroundPlain();
int primaryColor = ThemeUtils.primaryColor(getAccount());
if (backgroundDefault.isTrue() && backgroundPlain.isTrue()) {
// use only solid color
setNavigationHeaderBackground(new ColorDrawable(primaryColor), navigationHeader);
} else if (backgroundDefault.isTrue() && backgroundPlain.isFalse()) {
// use nc13 background image with themed color
Drawable[] drawables = { new ColorDrawable(primaryColor), getResources().getDrawable(R.drawable.background_nc13) };
LayerDrawable layerDrawable = new LayerDrawable(drawables);
setNavigationHeaderBackground(layerDrawable, navigationHeader);
} else {
// use url
if (URLUtil.isValidUrl(background) || background.isEmpty()) {
// background image
SimpleTarget target = new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
Drawable[] drawables = { new ColorDrawable(primaryColor), resource };
LayerDrawable layerDrawable = new LayerDrawable(drawables);
setNavigationHeaderBackground(layerDrawable, navigationHeader);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
Drawable[] drawables = { new ColorDrawable(primaryColor), errorDrawable };
LayerDrawable layerDrawable = new LayerDrawable(drawables);
setNavigationHeaderBackground(layerDrawable, navigationHeader);
}
};
int backgroundResource;
OwnCloudVersion ownCloudVersion = AccountUtils.getServerVersion(getAccount());
if (ownCloudVersion.compareTo(OwnCloudVersion.nextcloud_13) >= 0) {
backgroundResource = R.drawable.background_nc13;
} else {
backgroundResource = R.drawable.background;
}
Glide.with(this).load(background).centerCrop().placeholder(backgroundResource).error(backgroundResource).crossFade().into(target);
} else {
// plain color
setNavigationHeaderBackground(new ColorDrawable(primaryColor), navigationHeader);
}
}
}
}
}
use of com.bumptech.glide.request.target.SimpleTarget in project android by nextcloud.
the class ContactListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ContactListFragment.ContactItemViewHolder holder, final int position) {
final int verifiedPosition = holder.getAdapterPosition();
final VCard vcard = vCards.get(verifiedPosition);
if (vcard != null) {
if (checkedVCards.contains(position)) {
holder.getName().setChecked(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.getName().getCheckMarkDrawable().setColorFilter(ThemeUtils.primaryAccentColor(), PorterDuff.Mode.SRC_ATOP);
}
} else {
holder.getName().setChecked(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.getName().getCheckMarkDrawable().clearColorFilter();
}
}
holder.getName().setText(getDisplayName(vcard));
// photo
if (vcard.getPhotos().size() > 0) {
Photo firstPhoto = vcard.getPhotos().get(0);
String url = firstPhoto.getUrl();
byte[] data = firstPhoto.getData();
if (data != null && data.length > 0) {
Bitmap thumbnail = BitmapFactory.decodeByteArray(data, 0, data.length);
RoundedBitmapDrawable drawable = BitmapUtils.bitmapToCircularBitmapDrawable(context.getResources(), thumbnail);
holder.getBadge().setImageDrawable(drawable);
} else if (url != null) {
ImageView badge = holder.getBadge();
SimpleTarget target = new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
holder.getBadge().setImageDrawable(resource);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
holder.getBadge().setImageDrawable(errorDrawable);
}
};
DisplayUtils.downloadIcon(context, url, target, R.drawable.ic_user, badge.getWidth(), badge.getHeight());
}
} else {
try {
holder.getBadge().setImageDrawable(TextDrawable.createNamedAvatar(holder.getName().getText().toString(), context.getResources().getDimension(R.dimen.list_item_avatar_icon_radius)));
} catch (Exception e) {
holder.getBadge().setImageResource(R.drawable.ic_user);
}
}
// Checkbox
holder.setVCardListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.getName().setChecked(!holder.getName().isChecked());
if (holder.getName().isChecked()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.getName().getCheckMarkDrawable().setColorFilter(ThemeUtils.primaryAccentColor(), PorterDuff.Mode.SRC_ATOP);
}
if (!checkedVCards.contains(verifiedPosition)) {
checkedVCards.add(verifiedPosition);
}
if (checkedVCards.size() == 1) {
EventBus.getDefault().post(new VCardToggleEvent(true));
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.getName().getCheckMarkDrawable().clearColorFilter();
}
if (checkedVCards.contains(verifiedPosition)) {
checkedVCards.remove(verifiedPosition);
}
if (checkedVCards.size() == 0) {
EventBus.getDefault().post(new VCardToggleEvent(false));
}
}
}
});
}
}
use of com.bumptech.glide.request.target.SimpleTarget in project Shuttle by timusus.
the class MusicService method prepareChromeCastLoad.
void prepareChromeCastLoad(int position, boolean autoPlay) {
if (currentSong == null) {
return;
}
if (TextUtils.isEmpty(currentSong.path)) {
return;
}
MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
metadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, getAlbumArtistName());
metadata.putString(MediaMetadata.KEY_ALBUM_TITLE, getAlbumName());
metadata.putString(MediaMetadata.KEY_TITLE, getSongName());
metadata.addImage(new WebImage(Uri.parse("http://" + ShuttleUtils.getIpAddr() + ":5000" + "/image/" + getSongId())));
MediaInfo selectedMedia = new MediaInfo.Builder("http://" + ShuttleUtils.getIpAddr() + ":5000" + "/audio/" + getSongId()).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED).setContentType("audio/*").setMetadata(metadata).build();
if (ShuttleUtils.isUpgraded() && castManager != null) {
doOnMainThread(() -> Glide.with(MusicService.this).load(getSong()).asBitmap().override(1024, 1024).placeholder(PlaceholderProvider.getInstance().getPlaceHolderDrawable(getSong().name, true)).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
loadRemoteMedia(selectedMedia, position, autoPlay, resource, null);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
loadRemoteMedia(selectedMedia, position, autoPlay, null, errorDrawable);
}
}));
}
}
use of com.bumptech.glide.request.target.SimpleTarget in project xabber-android by redsolution.
the class ChatMessageAdapter method setUpImage.
private void setUpImage(MessageItem messageItem, final Message messageHolder) {
messageHolder.messageImage.setVisibility(View.GONE);
if (!messageItem.isImage() || !SettingsManager.connectionLoadImages()) {
return;
}
if (messageItem.getFilePath() != null) {
boolean result = FileManager.loadImageFromFile(context, messageItem.getFilePath(), messageHolder.messageImage);
if (result) {
messageHolder.messageImage.setVisibility(View.VISIBLE);
messageHolder.messageText.setVisibility(View.GONE);
} else {
final String uniqueId = messageItem.getUniqueId();
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 = messageHolder.messageImage.getLayoutParams();
Integer imageWidth = messageItem.getImageWidth();
Integer imageHeight = messageItem.getImageHeight();
if (imageWidth != null && imageHeight != null) {
FileManager.scaleImage(layoutParams, imageHeight, imageWidth);
Glide.with(context).load(messageItem.getText()).listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
messageHolder.messageImage.setVisibility(View.GONE);
messageHolder.messageText.setVisibility(View.VISIBLE);
return true;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
}).into(messageHolder.messageImage);
messageHolder.messageImage.setVisibility(View.VISIBLE);
messageHolder.messageText.setVisibility(View.GONE);
} else {
final String uniqueId = messageItem.getUniqueId();
Glide.with(context).load(messageItem.getText()).asBitmap().into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(final Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
final int width = resource.getWidth();
final int height = resource.getHeight();
if (width <= 0 || height <= 0) {
messageHolder.messageImage.setVisibility(View.GONE);
messageHolder.messageText.setVisibility(View.VISIBLE);
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);
messageHolder.messageImage.setImageBitmap(resource);
messageHolder.messageImage.setVisibility(View.VISIBLE);
messageHolder.messageText.setVisibility(View.GONE);
}
});
}
}
}
use of com.bumptech.glide.request.target.SimpleTarget in project Rocket by mozilla-tw.
the class TabTrayAdapter method loadCachedFavicon.
private void loadCachedFavicon(final Tab tab, final ViewHolder holder) {
RequestOptions options = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.RESOURCE).dontAnimate();
Bitmap favicon = tab.getFavicon();
FaviconModel model = new FaviconModel(tab.getUrl(), FavIconUtils.getFavIconType(holder.itemView.getResources(), favicon), favicon);
requestManager.load(model).apply(options).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
loadGeneratedFavicon(tab, holder);
return true;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}).into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
updateFavicon(holder, resource);
}
});
}
Aggregations