Search in sources :

Example 21 with RequestListener

use of com.bumptech.glide.request.RequestListener in project LuaViewSDK by alibaba.

the class GlideImageProvider method preload.

@Override
public void preload(final Context context, String url, final DrawableLoadCallback callback) {
    if (callback != null) {
        Glide.with(context).load(url).listener(new RequestListener<String, GlideDrawable>() {

            @Override
            public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                if (callback != null) {
                    callback.onLoadResult(null);
                }
                return false;
            }

            @Override
            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                if (callback != null) {
                    Drawable r = resource instanceof GlideBitmapDrawable ? new BitmapDrawable(context.getResources(), ((GlideBitmapDrawable) resource).getBitmap()) : resource;
                    callback.onLoadResult(r);
                }
                return false;
            }
        }).preload();
    } else {
        Glide.with(context).load(url).preload();
    }
}
Also used : Target(com.bumptech.glide.request.target.Target) RequestListener(com.bumptech.glide.request.RequestListener) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) GlideBitmapDrawable(com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable) GlideBitmapDrawable(com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) GlideBitmapDrawable(com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Example 22 with RequestListener

use of com.bumptech.glide.request.RequestListener 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 23 with RequestListener

use of com.bumptech.glide.request.RequestListener 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)

Example 24 with RequestListener

use of com.bumptech.glide.request.RequestListener in project AndroidStudy by tinggengyan.

the class GlideMainActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_imageview);
    prescale_iamgeview = (ImageView) findViewById(R.id.prescale_iamgeview);
    RequestManager requestManager = Glide.with(this);
    requestManager.load(Constants.IMAGES[0]).placeholder(R.drawable.accept).diskCacheStrategy(DiskCacheStrategy.NONE).override(100, 100).listener(new RequestListener<String, GlideDrawable>() {

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            return false;
        }
    }).into(prescale_iamgeview);
    requestManager.load(Constants.IMAGES[1]).diskCacheStrategy(DiskCacheStrategy.SOURCE).preload();
    downloadImage(prescale_iamgeview);
}
Also used : Target(com.bumptech.glide.request.target.Target) FutureTarget(com.bumptech.glide.request.FutureTarget) RequestManager(com.bumptech.glide.RequestManager) RequestListener(com.bumptech.glide.request.RequestListener) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Example 25 with RequestListener

use of com.bumptech.glide.request.RequestListener in project drift-sdk-android by Driftt.

the class ImageViewerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drift_sdk_activity_image_viewer);
    StatusBarColorizer.setActivityColor(this);
    getSupportActionBar().setTitle("Attachment");
    imageView = findViewById(R.id.drift_sdk_image_viewer_image_view);
    progressBar = findViewById(R.id.drift_sdk_image_viewer_progress_view);
    Intent intent = getIntent();
    if (intent.getExtras() != null) {
        String imageUriAsString = intent.getExtras().getString(IMAGE_URI);
        if (imageUriAsString == null || imageUriAsString.isEmpty()) {
            finish();
            return;
        }
        imageUri = Uri.parse(imageUriAsString);
    }
    Glide.with(this).load(imageUri).listener(new RequestListener<Drawable>() {

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<Drawable> target, boolean b) {
            progressBar.setVisibility(View.GONE);
            Toast.makeText(ImageViewerActivity.this, "Failed to load Image", Toast.LENGTH_LONG).show();
            finish();
            return false;
        }

        @Override
        public boolean onResourceReady(Drawable drawable, Object o, Target<Drawable> target, DataSource dataSource, boolean b) {
            progressBar.setVisibility(View.GONE);
            return false;
        }
    }).into(imageView);
}
Also used : Target(com.bumptech.glide.request.target.Target) RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(android.support.annotation.Nullable) DataSource(com.bumptech.glide.load.DataSource)

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