Search in sources :

Example 16 with SimpleTarget

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);
                }
            }
        }
    }
}
Also used : OCCapability(com.owncloud.android.lib.resources.status.OCCapability) ViewGroup(android.view.ViewGroup) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) TextDrawable(com.owncloud.android.ui.TextDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) MenuSimpleTarget(com.owncloud.android.utils.svg.MenuSimpleTarget) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) CapabilityBooleanType(com.owncloud.android.lib.resources.status.CapabilityBooleanType) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion)

Example 17 with SimpleTarget

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));
                    }
                }
            }
        });
    }
}
Also used : RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Drawable(android.graphics.drawable.Drawable) TextDrawable(com.owncloud.android.ui.TextDrawable) RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable) Photo(ezvcard.property.Photo) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) CheckedTextView(android.widget.CheckedTextView) IOException(java.io.IOException) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) VCardToggleEvent(com.owncloud.android.ui.events.VCardToggleEvent) ImageView(android.widget.ImageView) VCard(ezvcard.VCard)

Example 18 with SimpleTarget

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);
            }
        }));
    }
}
Also used : SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) MediaInfo(com.google.android.gms.cast.MediaInfo) Drawable(android.graphics.drawable.Drawable) MediaMetadata(com.google.android.gms.cast.MediaMetadata) WebImage(com.google.android.gms.common.images.WebImage) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SQLiteException(android.database.sqlite.SQLiteException) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) ConcurrentModificationException(java.util.ConcurrentModificationException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException)

Example 19 with SimpleTarget

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);
                }
            });
        }
    }
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) RequestListener(com.bumptech.glide.request.RequestListener) ViewGroup(android.view.ViewGroup) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Target(com.bumptech.glide.request.target.Target) Bitmap(android.graphics.Bitmap) Realm(io.realm.Realm) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Example 20 with SimpleTarget

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);
        }
    });
}
Also used : RequestListener(com.bumptech.glide.request.RequestListener) RequestOptions(com.bumptech.glide.request.RequestOptions) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) DataSource(com.bumptech.glide.load.DataSource) Bitmap(android.graphics.Bitmap) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Target(com.bumptech.glide.request.target.Target) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(android.support.annotation.Nullable)

Aggregations

SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)25 Drawable (android.graphics.drawable.Drawable)18 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)18 Bitmap (android.graphics.Bitmap)17 ColorDrawable (android.graphics.drawable.ColorDrawable)6 ImageView (android.widget.ImageView)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)5 View (android.view.View)5 Target (com.bumptech.glide.request.target.Target)5 LayerDrawable (android.graphics.drawable.LayerDrawable)4 Nullable (android.support.annotation.Nullable)4 RequestListener (com.bumptech.glide.request.RequestListener)4 SuppressLint (android.annotation.SuppressLint)3 Intent (android.content.Intent)3 Palette (android.support.v7.graphics.Palette)3 ViewGroup (android.view.ViewGroup)3 TextDrawable (com.owncloud.android.ui.TextDrawable)3 MenuSimpleTarget (com.owncloud.android.utils.svg.MenuSimpleTarget)3 PendingIntent (android.app.PendingIntent)2 SQLiteException (android.database.sqlite.SQLiteException)2