com.bumptech.glide.request.target.ImageViewTarget Java Examples

The following examples show how to use com.bumptech.glide.request.target.ImageViewTarget. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: Melophile   Author: vpaliy   File: PersonFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void showAvatar(String avatarUrl) {
  this.avatarUrl = avatarUrl;
  Glide.with(getContext())
          .load(avatarUrl)
          .asBitmap()
          .priority(Priority.IMMEDIATE)
          .into(new ImageViewTarget<Bitmap>(avatar) {
            @Override
            protected void setResource(Bitmap resource) {
              avatar.setImageBitmap(resource);
              avatar.post(() -> {
                media.post(() -> {
                  View blank = adapter.getBlank();
                  ViewGroup.LayoutParams params = blank.getLayoutParams();
                  params.height = followers.getTop() + followers.getHeight()
                          + 2 * getResources().getDimensionPixelOffset(R.dimen.spacing_large);
                  blank.setLayoutParams(params);
                });
                media.setVisibility(View.INVISIBLE);
                getActivity().supportStartPostponedEnterTransition();
                presenter.start(id);
              });
            }
          });
}
 
Example #2
Source Project: Melophile   Author: vpaliy   File: AlbumAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public View instantiateItem(ViewGroup container, int position) {
  View view = inflater.inflate(R.layout.adapter_album, container, false);
  ImageView image = ButterKnife.findById(view, R.id.image);

  Glide.with(container.getContext())
          .load(albums.get(position).getArtworkUrl())
          .asBitmap()
          .priority(Priority.IMMEDIATE)
          .diskCacheStrategy(DiskCacheStrategy.RESULT)
          .into(new ImageViewTarget<Bitmap>(image) {
            @Override
            protected void setResource(Bitmap resource) {
              image.setImageBitmap(resource);
              if (position == current && !isLoaded) {
                isLoaded = true;
                if (callback != null) {
                  callback.onTransitionImageLoaded(image, resource);
                }
              }
            }
          });
  container.addView(view);
  return view;
}
 
Example #3
Source Project: Melophile   Author: vpaliy   File: TrackFragment.java    License: Apache License 2.0 6 votes vote down vote up
public void showArt(String artUrl) {
  if (!TextUtils.equals(lastArtUrl, artUrl)) {
    lastArtUrl = artUrl;
    Glide.with(getContext())
            .load(artUrl)
            .asBitmap()
            .priority(Priority.IMMEDIATE)
            .into(new ImageViewTarget<Bitmap>(smallImage) {
              @Override
              protected void setResource(Bitmap resource) {
                smallImage.setImageBitmap(resource);
                smallImage.post(() -> {
                  Blurry.with(getContext())
                          .async(bitmap -> {
                            background.setImageDrawable(bitmap);
                            getActivity().supportStartPostponedEnterTransition();
                          })
                          .from(resource)
                          .into(background);
                });
              }
            });
  }
}
 
Example #4
Source Project: Melophile   Author: vpaliy   File: PlaylistFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void showPlaylistArt(String artUrl) {
  if (!loaded) {
    loaded = true;
    Glide.with(getContext())
            .load(artUrl)
            .asBitmap()
            .priority(Priority.IMMEDIATE)
            .into(new ImageViewTarget<Bitmap>(playlistArt) {
              @Override
              protected void setResource(Bitmap resource) {
                final int imageHeight = playlistArt.getHeight();
                playlistArt.setImageBitmap(resource);
                parent.setStaticOffset(imageHeight);
                parent.setOffset(imageHeight);
                toggle.setStaticOffset(imageHeight - toggle.getHeight() / 2);
                toggle.setOffset(imageHeight - toggle.getHeight() / 2);
                toggle.setMinOffset(ViewCompat.getMinimumHeight(playlistArt) - toggle.getHeight() / 2);
                tracks.addOnScrollListener(listener);
                tracks.setOnFlingListener(flingListener);
                new Palette.Builder(resource).generate(PlaylistFragment.this::applyPalette);
                getActivity().supportStartPostponedEnterTransition();
              }
            });
  }
}
 
Example #5
Source Project: likequanmintv   Author: chenchengyin   File: VerFullLiveUI.java    License: Apache License 2.0 6 votes vote down vote up
private void initData() {
    if (mPlayBean!=null){
        livePlayerPresenterImpl.enterRoom(mPlayBean.uid);
    }

    Glide.with(this)
            .load(mPlayBean.love_cover)
            .into(new ImageViewTarget<GlideDrawable>(bgImg) {
                @Override
                protected void setResource(GlideDrawable resource) {
                    bgImg.setImageDrawable(resource);
                    Blurry.with(VerFullLiveUI.this)
                            .animate()
                            .radius(10)
                            .sampling(8)
                            .capture(bgImg)
                            .into(bgImg);
                }
            });
}
 
Example #6
Source Project: MeiZiNews   Author: qq137712630   File: ImageAdapter.java    License: MIT License 6 votes vote down vote up
@Override
    protected void convert(final BaseAdapterHelper helper, T item, int position) {
        final RadioImageView story_img = (RadioImageView) helper.getView(R.id.story_img);
        TextView story_title = helper.getTextView(R.id.story_item_title);

        story_title.setText(item.getStory_title());
        Glide.with(helper.itemView.getContext())
                .load(item.getImgUrl())
//                                //设置占位图或者加载错误图:
//                        .placeholder(R.drawable.ic_sun_smile)
//                        .error(R.drawable.ic_cloud_sad)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(new ImageViewTarget<GlideDrawable>(story_img) {
                    @Override
                    protected void setResource(GlideDrawable resource) {

                        story_img.setOriginalSize(resource.getIntrinsicWidth(), resource.getIntrinsicHeight());
                        story_img.setImageDrawable(resource);
                    }
                });

        helper.itemView.setTag(position);
    }
 
Example #7
Source Project: PowerFileExplorer   Author: PowerExplorer   File: SvgSoftwareLayerSetter.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onException(Exception e, T model, Target<PictureDrawable> target, boolean isFirstResource) {
    ImageView view = ((ImageViewTarget<?>) target).getView();
    if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) {
        view.setLayerType(ImageView.LAYER_TYPE_NONE, null);
    }
    return false;
}
 
Example #8
Source Project: PowerFileExplorer   Author: PowerExplorer   File: SvgSoftwareLayerSetter.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onResourceReady(PictureDrawable resource, T model, Target<PictureDrawable> target,
                               boolean isFromMemoryCache, boolean isFirstResource) {
    ImageView view = ((ImageViewTarget<?>) target).getView();
    if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) {
        view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null);
    }
    return false;
}
 
Example #9
Source Project: GlideToVectorYou   Author: corouteam   File: SvgSoftwareLayerSetter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onLoadFailed(GlideException e, Object model, Target<PictureDrawable> target,
                            boolean isFirstResource) {
    ImageView view = ((ImageViewTarget<?>) target).getView();
    view.setLayerType(ImageView.LAYER_TYPE_NONE, null);

    if (customListener != null) {
        customListener.onLoadFailed();
    }
    return false;
}
 
Example #10
Source Project: GlideToVectorYou   Author: corouteam   File: SvgSoftwareLayerSetter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onResourceReady(PictureDrawable resource, Object model,
                               Target<PictureDrawable> target, DataSource dataSource, boolean isFirstResource) {
    ImageView view = ((ImageViewTarget<?>) target).getView();
    view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null);

    if (customListener != null) {
        customListener.onResourceReady();
    }

    return false;
}
 
Example #11
Source Project: react-native-syan-image-picker   Author: syanbo   File: GlideEngine.java    License: MIT License 5 votes vote down vote up
/**
 * 加载网络图片适配长图方案
 * # 注意:此方法只有加载网络图片才会回调
 *
 * @param context
 * @param url
 * @param imageView
 * @param longImageView
 * @ 已废弃
 */
@Override
public void loadImage(@NonNull Context context, @NonNull String url,
                      @NonNull ImageView imageView,
                      SubsamplingScaleImageView longImageView) {
    Glide.with(context)
            .asBitmap()
            .load(url)
            .into(new ImageViewTarget<Bitmap>(imageView) {
                @Override
                protected void setResource(@Nullable Bitmap resource) {
                    if (resource != null) {
                        boolean eqLongImage = MediaUtils.isLongImg(resource.getWidth(),
                                resource.getHeight());
                        longImageView.setVisibility(eqLongImage ? View.VISIBLE : View.GONE);
                        imageView.setVisibility(eqLongImage ? View.GONE : View.VISIBLE);
                        if (eqLongImage) {
                            // 加载长图
                            longImageView.setQuickScaleEnabled(true);
                            longImageView.setZoomEnabled(true);
                            longImageView.setPanEnabled(true);
                            longImageView.setDoubleTapZoomDuration(100);
                            longImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP);
                            longImageView.setDoubleTapZoomDpi(SubsamplingScaleImageView.ZOOM_FOCUS_CENTER);
                            longImageView.setImage(ImageSource.bitmap(resource),
                                    new ImageViewState(0, new PointF(0, 0), 0));
                        } else {
                            // 普通图片
                            imageView.setImageBitmap(resource);
                        }
                    }
                }
            });
}
 
Example #12
Source Project: PictureSelector   Author: LuckSiege   File: GlideEngine.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 加载网络图片适配长图方案
 * # 注意:此方法只有加载网络图片才会回调
 *
 * @param context
 * @param url
 * @param imageView
 * @param longImageView
 * @ 已废弃
 */
@Override
public void loadImage(@NonNull Context context, @NonNull String url,
                      @NonNull ImageView imageView,
                      SubsamplingScaleImageView longImageView) {
    Glide.with(context)
            .asBitmap()
            .load(url)
            .into(new ImageViewTarget<Bitmap>(imageView) {
                @Override
                protected void setResource(@Nullable Bitmap resource) {
                    if (resource != null) {
                        boolean eqLongImage = MediaUtils.isLongImg(resource.getWidth(),
                                resource.getHeight());
                        longImageView.setVisibility(eqLongImage ? View.VISIBLE : View.GONE);
                        imageView.setVisibility(eqLongImage ? View.GONE : View.VISIBLE);
                        if (eqLongImage) {
                            // 加载长图
                            longImageView.setQuickScaleEnabled(true);
                            longImageView.setZoomEnabled(true);
                            longImageView.setPanEnabled(true);
                            longImageView.setDoubleTapZoomDuration(100);
                            longImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP);
                            longImageView.setDoubleTapZoomDpi(SubsamplingScaleImageView.ZOOM_FOCUS_CENTER);
                            longImageView.setImage(ImageSource.bitmap(resource),
                                    new ImageViewState(0, new PointF(0, 0), 0));
                        } else {
                            // 普通图片
                            imageView.setImageBitmap(resource);
                        }
                    }
                }
            });
}
 
Example #13
Source Project: MeiZiNews   Author: qq137712630   File: XmTvClassificationAdapter.java    License: MIT License 5 votes vote down vote up
@Override
protected void convert(BaseAdapterHelper helper, final Items item, int position) {
    final RadioImageView story_img = (RadioImageView) helper.getView(R.id.story_img);
    TextView story_title = helper.getTextView(R.id.story_item_title);

    story_title.setText(item.getName());
    Glide.with(helper.itemView.getContext())
            .load(item.getPictures().getImg())
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .into(new ImageViewTarget<GlideDrawable>(story_img) {
                @Override
                protected void setResource(GlideDrawable resource) {

                    story_img.setOriginalSize(resource.getIntrinsicWidth(), resource.getIntrinsicHeight());
                    story_img.setImageDrawable(resource);
                }
            });

    helper.itemView.setTag(position);

    helper.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();

            intent.putExtra("title", item.getName());

            intent.setClass(context, M3u8VideoActivity.class);
            intent.putExtra("type", VideoApi.TYPE_XM);
            intent.putExtra("roomid", item.getId());

            context.startActivity(intent);
        }
    });
}
 
Example #14
Source Project: LoyalNativeSlider   Author: jjhesk   File: LoyalUtil.java    License: MIT License 5 votes vote down vote up
public static void hybridImplementation(String u, final ImageView target, Context context, final Runnable callback) {
    if (u.contains(".gif")) {
        Glide.with(context).asGif().load(u)
                .apply(getOpt())
                .into(new ImageViewTarget<GifDrawable>(target) {
                    @Override
                    protected void setResource(GifDrawable resource) {
                        target.setImageDrawable(resource);
                        callback.run();
                    }
                });
    } else {
        picassoImplementation(u, target, context, callback);
    }
}
 
Example #15
Source Project: incubator-taverna-mobile   Author: apache   File: SvgSoftwareLayerSetter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onException(Exception e, T model, Target<PictureDrawable> target,
                           boolean isFirstResource) {
    ImageView view = ((ImageViewTarget<?>) target).getView();
    if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) {
        view.setLayerType(ImageView.LAYER_TYPE_NONE, null);
    }
    return false;
}
 
Example #16
Source Project: incubator-taverna-mobile   Author: apache   File: SvgSoftwareLayerSetter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onResourceReady(PictureDrawable resource, T model
        , Target<PictureDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
    ImageView view = ((ImageViewTarget<?>) target).getView();
    if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT) {
        view.setLayerType(ImageView.LAYER_TYPE_SOFTWARE, null);
    }
    return false;
}
 
Example #17
Source Project: GalleryFinal   Author: pengjianbo   File: GlideImageLoader.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void displayImage(Activity activity, String path, final GFImageView imageView, Drawable defaultDrawable, int width, int height) {
    Glide.with(activity)
            .load("file://" + path)
            .placeholder(defaultDrawable)
            .error(defaultDrawable)
            .override(width, height)
            .diskCacheStrategy(DiskCacheStrategy.NONE) //不缓存到SD卡
            .skipMemoryCache(true)
            //.centerCrop()
            .into(new ImageViewTarget<GlideDrawable>(imageView) {
                @Override
                protected void setResource(GlideDrawable resource) {
                    imageView.setImageDrawable(resource);
                }

                @Override
                public void setRequest(Request request) {
                    imageView.setTag(R.id.adapter_item_tag_key,request);
                }

                @Override
                public Request getRequest() {
                    return (Request) imageView.getTag(R.id.adapter_item_tag_key);
                }
            });
}
 
Example #18
Source Project: react-native-syan-image-picker   Author: syanbo   File: GlideEngine.java    License: MIT License 4 votes vote down vote up
/**
 * 加载网络图片适配长图方案
 * # 注意:此方法只有加载网络图片才会回调
 *
 * @param context
 * @param url
 * @param imageView
 * @param longImageView
 * @param callback      网络图片加载回调监听 {link after version 2.5.1 Please use the #OnImageCompleteCallback#}
 */
@Override
public void loadImage(@NonNull Context context, @NonNull String url,
                      @NonNull ImageView imageView,
                      SubsamplingScaleImageView longImageView, OnImageCompleteCallback callback) {
    Glide.with(context)
            .asBitmap()
            .load(url)
            .into(new ImageViewTarget<Bitmap>(imageView) {
                @Override
                public void onLoadStarted(@Nullable Drawable placeholder) {
                    super.onLoadStarted(placeholder);
                    if (callback != null) {
                        callback.onShowLoading();
                    }
                }

                @Override
                public void onLoadFailed(@Nullable Drawable errorDrawable) {
                    super.onLoadFailed(errorDrawable);
                    if (callback != null) {
                        callback.onHideLoading();
                    }
                }

                @Override
                protected void setResource(@Nullable Bitmap resource) {
                    if (callback != null) {
                        callback.onHideLoading();
                    }
                    if (resource != null) {
                        boolean eqLongImage = MediaUtils.isLongImg(resource.getWidth(),
                                resource.getHeight());
                        longImageView.setVisibility(eqLongImage ? View.VISIBLE : View.GONE);
                        imageView.setVisibility(eqLongImage ? View.GONE : View.VISIBLE);
                        if (eqLongImage) {
                            // 加载长图
                            longImageView.setQuickScaleEnabled(true);
                            longImageView.setZoomEnabled(true);
                            longImageView.setPanEnabled(true);
                            longImageView.setDoubleTapZoomDuration(100);
                            longImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP);
                            longImageView.setDoubleTapZoomDpi(SubsamplingScaleImageView.ZOOM_FOCUS_CENTER);
                            longImageView.setImage(ImageSource.bitmap(resource),
                                    new ImageViewState(0, new PointF(0, 0), 0));
                        } else {
                            // 普通图片
                            imageView.setImageBitmap(resource);
                        }
                    }
                }
            });
}
 
Example #19
Source Project: PictureSelector   Author: LuckSiege   File: GlideEngine.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 加载网络图片适配长图方案
 * # 注意:此方法只有加载网络图片才会回调
 *
 * @param context
 * @param url
 * @param imageView
 * @param longImageView
 * @param callback      网络图片加载回调监听 {link after version 2.5.1 Please use the #OnImageCompleteCallback#}
 */
@Override
public void loadImage(@NonNull Context context, @NonNull String url,
                      @NonNull ImageView imageView,
                      SubsamplingScaleImageView longImageView, OnImageCompleteCallback callback) {
    Glide.with(context)
            .asBitmap()
            .load(url)
            .into(new ImageViewTarget<Bitmap>(imageView) {
                @Override
                public void onLoadStarted(@Nullable Drawable placeholder) {
                    super.onLoadStarted(placeholder);
                    if (callback != null) {
                        callback.onShowLoading();
                    }
                }

                @Override
                public void onLoadFailed(@Nullable Drawable errorDrawable) {
                    super.onLoadFailed(errorDrawable);
                    if (callback != null) {
                        callback.onHideLoading();
                    }
                }

                @Override
                protected void setResource(@Nullable Bitmap resource) {
                    if (callback != null) {
                        callback.onHideLoading();
                    }
                    if (resource != null) {
                        boolean eqLongImage = MediaUtils.isLongImg(resource.getWidth(),
                                resource.getHeight());
                        longImageView.setVisibility(eqLongImage ? View.VISIBLE : View.GONE);
                        imageView.setVisibility(eqLongImage ? View.GONE : View.VISIBLE);
                        if (eqLongImage) {
                            // 加载长图
                            longImageView.setQuickScaleEnabled(true);
                            longImageView.setZoomEnabled(true);
                            longImageView.setPanEnabled(true);
                            longImageView.setDoubleTapZoomDuration(100);
                            longImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP);
                            longImageView.setDoubleTapZoomDpi(SubsamplingScaleImageView.ZOOM_FOCUS_CENTER);
                            longImageView.setImage(ImageSource.bitmap(resource),
                                    new ImageViewState(0, new PointF(0, 0), 0));
                        } else {
                            // 普通图片
                            imageView.setImageBitmap(resource);
                        }
                    }
                }
            });
}
 
Example #20
Source Project: android-login   Author: vpaliy   File: LoginActivity.java    License: MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_login);
  ButterKnife.bind(this);
  final AnimatedViewPager pager = ButterKnife.findById(this, R.id.pager);
  final ImageView background = ButterKnife.findById(this, R.id.scrolling_background);
  int[] screenSize = screenSize();

  for (ImageView element : sharedElements) {
    @ColorRes int color = element.getId() != R.id.logo ? R.color.white_transparent : R.color.color_logo_log_in;
    DrawableCompat.setTint(element.getDrawable(), ContextCompat.getColor(this, color));
  }
  //load a very big image and resize it, so it fits our needs
  Glide.with(this)
          .load(R.drawable.busy)
          .asBitmap()
          .override(screenSize[0] * 2, screenSize[1])
          .diskCacheStrategy(DiskCacheStrategy.RESULT)
          .into(new ImageViewTarget<Bitmap>(background) {
            @Override
            protected void setResource(Bitmap resource) {
              background.setImageBitmap(resource);
              background.post(() -> {
                //we need to scroll to the very left edge of the image
                //fire the scale animation
                background.scrollTo(-background.getWidth() / 2, 0);
                ObjectAnimator xAnimator = ObjectAnimator.ofFloat(background, View.SCALE_X, 4f, background.getScaleX());
                ObjectAnimator yAnimator = ObjectAnimator.ofFloat(background, View.SCALE_Y, 4f, background.getScaleY());
                AnimatorSet set = new AnimatorSet();
                set.playTogether(xAnimator, yAnimator);
                set.setDuration(getResources().getInteger(R.integer.duration));
                set.start();
              });
              pager.post(() -> {
                AuthAdapter adapter = new AuthAdapter(getSupportFragmentManager(), pager, background, sharedElements);
                pager.setAdapter(adapter);
              });
            }
          });
}