Search in sources :

Example 26 with RequestListener

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);
}
Also used : ClipboardManager(android.content.ClipboardManager) RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) Gson(com.google.gson.Gson) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) ImageView(android.widget.ImageView) View(android.view.View) DataSource(com.bumptech.glide.load.DataSource) Target(com.bumptech.glide.request.target.Target) ImageView(android.widget.ImageView) ClipData(android.content.ClipData) GlideException(com.bumptech.glide.load.engine.GlideException)

Example 27 with RequestListener

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;
}
Also used : RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) TouchImageView(com.dante.custom.TouchImageView) PhotoView(com.github.chrisbanes.photoview.PhotoView) View(android.view.View) DataSource(com.bumptech.glide.load.DataSource) PhotoView(com.github.chrisbanes.photoview.PhotoView) DrawableTransitionOptions(com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions) Target(com.bumptech.glide.request.target.Target) ProgressBar(android.widget.ProgressBar) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(android.support.annotation.Nullable) NonNull(android.support.annotation.NonNull)

Example 28 with RequestListener

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;
}
Also used : SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Target(com.bumptech.glide.request.target.Target) Bitmap(android.graphics.Bitmap) RequestListener(com.bumptech.glide.request.RequestListener) GenericRequestBuilder(com.bumptech.glide.GenericRequestBuilder)

Example 29 with RequestListener

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));
}
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)

Aggregations

RequestListener (com.bumptech.glide.request.RequestListener)29 Target (com.bumptech.glide.request.target.Target)29 DataSource (com.bumptech.glide.load.DataSource)18 GlideException (com.bumptech.glide.load.engine.GlideException)18 Drawable (android.graphics.drawable.Drawable)16 Nullable (android.support.annotation.Nullable)9 GlideDrawable (com.bumptech.glide.load.resource.drawable.GlideDrawable)9 Bitmap (android.graphics.Bitmap)8 Nullable (androidx.annotation.Nullable)8 View (android.view.View)6 ImageView (android.widget.ImageView)5 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)4 BlurTransformation (jp.wasabeef.glide.transformations.BlurTransformation)4 Animator (android.animation.Animator)3 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)3 ObjectAnimator (android.animation.ObjectAnimator)3 ValueAnimator (android.animation.ValueAnimator)3 Context (android.content.Context)3 RecyclerView (android.support.v7.widget.RecyclerView)3 CustomTarget (com.bumptech.glide.request.target.CustomTarget)3