TestImageLoader.java 2.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
package com.yidianling.consultant.preview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
fengquan committed
15
import com.yidianling.consultant.R;
16 17 18 19 20 21 22 23 24

import org.jetbrains.annotations.NotNull;

/**
 * @author rainb
 */
public class TestImageLoader implements IZoomMediaLoader {
    @Override
    public void displayImage(@NonNull Fragment context, @NonNull String path, final ImageView imageView, @NonNull final MySimpleTarget simpleTarget) {
fengquan committed
25
        Glide.with(context).asBitmap().load(path).placeholder(R.drawable.consultant_bg_black).error(R.drawable.consultant_bg_black)
26 27 28 29 30 31 32 33 34

                //  .placeholder(android.R.color.darker_gray)
                .fitCenter()
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(@NonNull @NotNull Bitmap resource, @Nullable @org.jetbrains.annotations.Nullable Transition<? super Bitmap> transition) {
                        simpleTarget.onResourceReady();
                        imageView.setImageBitmap(resource);
                    }
35 36 37 38

                    @Override
                    public void onLoadFailed(@Nullable @org.jetbrains.annotations.Nullable Drawable errorDrawable) {
                        simpleTarget.onLoadFailed(errorDrawable);
fengquan committed
39
                        imageView.setImageDrawable(errorDrawable);
40
                    }
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
                });

    }

    @Override
    public void displayGifImage(@NonNull Fragment context, @NonNull String path, ImageView imageView, @NonNull final MySimpleTarget simpleTarget) {

    }

    @Override
    public void onStop(@NonNull Fragment context) {
        Glide.with(context).onStop();

    }

    @Override
    public void clearMemory(@NonNull Context c) {
        Glide.get(c).clearMemory();
    }
}