Search in sources :

Example 21 with GlideException

use of com.bumptech.glide.load.engine.GlideException in project xabber-android by redsolution.

the class ImageViewerFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // get params
    Bundle args = getArguments();
    if (args == null)
        return;
    String source;
    String uri = args.getString(IMAGE_URL);
    final String path = args.getString(IMAGE_PATH);
    if (path != null)
        source = path;
    else
        source = uri;
    final String attachmentId = args.getString(ATTACHMENT_ID);
    // find views
    ivPhoto = view.findViewById(R.id.ivPhoto);
    progressBar = view.findViewById(R.id.progressBar);
    // setup image
    progressBar.setVisibility(View.VISIBLE);
    Glide.with(getActivity()).load(source).listener(new RequestListener<Drawable>() {

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
            if (e != null)
                showError(e.toString());
            if (path != null)
                MessageManager.setAttachmentLocalPathToNull(attachmentId);
            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(ivPhoto);
}
Also used : Target(com.bumptech.glide.request.target.Target) RequestListener(com.bumptech.glide.request.RequestListener) Bundle(android.os.Bundle) Drawable(android.graphics.drawable.Drawable) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(androidx.annotation.Nullable) DataSource(com.bumptech.glide.load.DataSource)

Example 22 with GlideException

use of com.bumptech.glide.load.engine.GlideException 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));
}
Also used : Context(android.content.Context) ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) TransitionInflater(android.transition.TransitionInflater) ContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ContactPhoto) ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) FallbackContactPhoto(org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto) ResourceContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto) DataSource(com.bumptech.glide.load.DataSource) FallbackContactPhoto(org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto) CustomTarget(com.bumptech.glide.request.target.CustomTarget) Target(com.bumptech.glide.request.target.Target) Bitmap(android.graphics.Bitmap) ResourceContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) ImageView(android.widget.ImageView) Resources(android.content.res.Resources) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(androidx.annotation.Nullable) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) Toolbar(androidx.appcompat.widget.Toolbar)

Example 23 with GlideException

use of com.bumptech.glide.load.engine.GlideException 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) {
                }
            });
        }
    }
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) RequestListener(com.bumptech.glide.request.RequestListener) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) DataSource(com.bumptech.glide.load.DataSource) CustomTarget(com.bumptech.glide.request.target.CustomTarget) Target(com.bumptech.glide.request.target.Target) Bitmap(android.graphics.Bitmap) Realm(io.realm.Realm) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(androidx.annotation.Nullable)

Example 24 with GlideException

use of com.bumptech.glide.load.engine.GlideException in project Douya by DreaminginCodeZH.

the class ImageUtils method loadNavigationHeaderAvatar.

public static void loadNavigationHeaderAvatar(final ImageView view, final String url) {
    Context context = view.getContext();
    int size = context.getResources().getDimensionPixelSize(R.dimen.navigation_header_avatar_size);
    GlideApp.with(context).load(url).apply(REQUEST_OPTIONS_LOAD_NAVIGATION_HEADER_AVATAR.override(size, size)).listener(new RequestListener<Drawable>() {

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
            (e != null ? e : new NullPointerException()).printStackTrace();
            return false;
        }

        @Override
        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
            view.setTag(url);
            return false;
        }
    }).into(view);
}
Also used : Context(android.content.Context) Target(com.bumptech.glide.request.target.Target) RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(androidx.annotation.Nullable) DataSource(com.bumptech.glide.load.DataSource)

Example 25 with GlideException

use of com.bumptech.glide.load.engine.GlideException in project bugzy by cpunq.

the class OrganisationFrgment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mLoginViewModel = ViewModelProviders.of(getActivity(), mViewModelFactory).get(LoginViewModel.class);
    mLogoProgressBar.setVisibility(View.GONE);
    mOrgNameView.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            mOrgImageView.setVisibility(View.GONE);
            mLoginViewModel.organisationNameChanged(charSequence.toString());
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    mLoginViewModel.getOrganisationLogoResource().observe(this, resourceState -> {
        if (resourceState.status == Status.LOADING) {
            mLogoProgressBar.setVisibility(View.VISIBLE);
        }
        if (resourceState.status == Status.ERROR) {
            mLogoProgressBar.setVisibility(View.GONE);
        }
        if (TextUtils.isEmpty(resourceState.data)) {
            return;
        }
        mOrgImageView.setVisibility(View.VISIBLE);
        Glide.with(getContext()).load(resourceState.data).listener(new RequestListener<Drawable>() {

            @Override
            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                mLogoProgressBar.setVisibility(View.GONE);
                return false;
            }

            @Override
            public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                mLogoProgressBar.setVisibility(View.GONE);
                return false;
            }
        }).into(mOrgImageView);
    });
}
Also used : RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) DataSource(com.bumptech.glide.load.DataSource) Target(com.bumptech.glide.request.target.Target) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(android.support.annotation.Nullable)

Aggregations

GlideException (com.bumptech.glide.load.engine.GlideException)34 DataSource (com.bumptech.glide.load.DataSource)21 Drawable (android.graphics.drawable.Drawable)18 RequestListener (com.bumptech.glide.request.RequestListener)16 Target (com.bumptech.glide.request.target.Target)16 Nullable (android.support.annotation.Nullable)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Test (org.junit.Test)8 Bitmap (android.graphics.Bitmap)6 Nullable (androidx.annotation.Nullable)6 View (android.view.View)5 ImageView (android.widget.ImageView)5 RequestOptions (com.bumptech.glide.request.RequestOptions)5 Context (android.content.Context)4 ColorDrawable (android.graphics.drawable.ColorDrawable)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 GradientDrawable (android.graphics.drawable.GradientDrawable)2 Handler (android.os.Handler)2 CircleGradientDrawable (com.amaze.filemanager.ui.views.CircleGradientDrawable)2