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

The following examples show how to use com.bumptech.glide.request.target.Target. 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 File: ImageFragment.java    From MoeGallery with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onResourceReady(final V resource, T model, Target<V> target,
        boolean isFromMemoryCache,
        boolean isFirstResource) {
    width = resource.getIntrinsicWidth();
    height = resource.getIntrinsicHeight();

    if (isVisibleToUser) {
        updateOrientation();

        if (getActivity() != null) {
            ((MainActivity) getActivity()).setTouchEventListener(ImageFragment.this);
        }
    }

    if (resource instanceof Animatable) {
        mHandler.removeCallbacks(mUpdateGifRunnable);
        mHandler.postDelayed(mUpdateGifRunnable, 10);
    }
    mProgressBar.setVisibility(View.GONE);
    return false;
}
 
Example #2
Source File: PlayService.java    From music_player with Open Software License 3.0 6 votes vote down vote up
private void updateMetaDataAndBuildNotification() {
    musicInfo musicNow = MyApplication.getMusicListNow().get(MyApplication.getPositionNow());
    singerNow = musicNow.getMusicArtist();
    titleNow = musicNow.getMusicTitle();
    if (!musicNow.getMusicLink().equals("")) {//网络
        Glide.with(this).load(musicNow.getMusicMediumAlbum()).asBitmap().listener(listener).into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
    } else {//本地
        if (musicNow.getAlbumLink() != null) {
            Glide.with(this)
                    .load(musicNow.getAlbumLink())
                    .asBitmap()
                    .placeholder(R.drawable.default_album)
                    .listener(listener)
                    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
        } else {
            Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
            Uri uri = ContentUris.withAppendedId(sArtworkUri, musicNow.getMusicAlbumId());
            Glide.with(this).load(uri).asBitmap().listener(listener).into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
        }
    }
}
 
Example #3
Source File: ImageBrowseActivity.java    From YiZhi with Apache License 2.0 6 votes vote down vote up
/**
 * 保存图片到本地
 *
 * @param fileName 文件名
 */
private void saveImageToLocal(final String fileName) {
    Observable.create(new ObservableOnSubscribe<File>() {
        @Override
        public void subscribe(ObservableEmitter<File> e) throws Exception {
            e.onNext(Glide.with(ImageBrowseActivity.this)
                    .load(mImageUrl)
                    .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                    .get());
            e.onComplete();
        }
    }).compose(RxHelper.<File>rxSchedulerHelper()).subscribe(new Consumer<File>() {
        @Override
        public void accept(File file) throws Exception {
            saveImage(fileName, file);
        }
    });
}
 
Example #4
Source File: TestFragment.java    From glide-support with The Unlicense 6 votes vote down vote up
private void load(final ImageView imageView) {
	if (imageView.getHeight() == 0) {
		// wait for layout, same as glide SizeDeterminer does
		imageView.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
			@Override public boolean onPreDraw() {
				imageView.getViewTreeObserver().removeOnPreDrawListener(this);
				load(imageView); // call the same method, but we can be sure now getHeight() is a value
				return true;
			}
		});
	} else {
		Glide
				.with(imageView.getContext())
				.load("whatever")
				.fitCenter()
				.override(Target.SIZE_ORIGINAL, imageView.getHeight())
				.into(imageView);
	}
}
 
Example #5
Source File: FavoritesFragment.java    From Easy_xkcd with Apache License 2.0 6 votes vote down vote up
@Override
protected Void doInBackground(Void... dummy) {
    DatabaseManager databaseManager = new DatabaseManager(getActivity());
    while (!favStack.isEmpty()) {
        try {
            //RealmComic comic = RealmComic.findNewestComic(Realm.getDefaultInstance(), getActivity());
            RealmComic comic = databaseManager.getRealmComic(favStack.pop());
            mBitmap = Glide
                    .with(getActivity())
                    .asBitmap()
                    .load(comic.getUrl())
                    //.diskCacheStrategy(DiskCacheStrategy.SOURCE)
                    .into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) //TODO replace all .into(-1,-1) with the simple target
                    .get();
            RealmComic.saveOfflineBitmap(mBitmap, prefHelper, comic.getComicNumber(), getActivity());
            Timber.d("comic %d saved...", comic.getComicNumber());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}
 
Example #6
Source File: DetailFragment.java    From glide-support with The Unlicense 6 votes vote down vote up
private void setupGlide() {
	thumb = Glide
			.with(this)
			.using(new NetworkDisablingLoader<>()) // make sure we're hitting some cache (optional)
			// everything has to match the grid's adapter to hit the memory cache
			.load(item.thumbUrl)
			.override(256, 256)
			.centerCrop()
			.listener(THUMB_LOGGER) // irrelevant for cache
	;
	int width = getActivity().getWindow().getDecorView().getWidth(); // this assumes that the fragment is created
	// from an existing fragment inside the same activity (list-detail), otherwise getWidth() may be 0
	full = Glide
			.with(this)
			.load(item.fullUrl)
			.override(width, Target.SIZE_ORIGINAL)
			.listener(FULL_LOGGER)
	;
}
 
Example #7
Source File: ImageLoader.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
public Target<Drawable> load(String url, ImageView imageView) {
  Context context = weakContext.get();
  if (context != null) {
    String newImageUrl = AptoideUtils.IconSizeU.getNewImageUrl(url, resources, windowManager);
    if (newImageUrl != null) {
      Uri uri = Uri.parse(newImageUrl);
      return Glide.with(context)
          .load(uri)
          .apply(getRequestOptions())
          .transition(DrawableTransitionOptions.withCrossFade())
          .into(imageView);
    } else {
      Log.e(TAG, "newImageUrl is null");
    }
  } else {
    Log.e(TAG, "::load() Context is null");
  }
  return null;
}
 
Example #8
Source File: RxDownload.java    From Moment with GNU General Public License v3.0 6 votes vote down vote up
public static Observable<File> get(RequestManager requestManager, String url) {
    return Observable.create(new Observable.OnSubscribe<File>() {
        @Override
        public void call(Subscriber<? super File> subscriber) {
            try {
                subscriber.onNext(requestManager.load(url)
                        .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                        .get());
            } catch (InterruptedException | ExecutionException e) {
                subscriber.onError(e);
            } finally {
                subscriber.onCompleted();
            }
        }
    }).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread());

}
 
Example #9
Source File: ImageHelper.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void loadImage(Context context, ImageView view,
                             @NonNull String url, @Nullable String thumbUrl,
                             @Size(2) @Px int[] size, @Nullable @Size(2) @Px int[] thumbSize,
                             @Nullable BitmapTransformation[] ts, @Nullable OnLoadImageListener l) {
    if (thumbSize == null) {
        thumbSize = new int[] {Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL};
    }
    DrawableRequestBuilder<String> thumb = TextUtils.isEmpty(thumbUrl) ? null : Glide.with(getValidContext(context))
            .load(ensureUrl(thumbUrl))
            .override(thumbSize[0], thumbSize[1])
            .diskCacheStrategy(
                    thumbSize[0] == Target.SIZE_ORIGINAL
                            ? DiskCacheStrategy.NONE
                            : DiskCacheStrategy.SOURCE
            ).listener(
                    new BaseRequestListener<>(() -> view.setTag(R.id.tag_item_image_fade_in_flag, false))
            );
    loadImage(context, view, url, thumb, size, ts, l);
}
 
Example #10
Source File: GenericRequestBuilder.java    From giffun with Apache License 2.0 6 votes vote down vote up
/**
 * Set the target the resource will be loaded into.
 *
 * @see Glide#clear(Target)
 *
 * @param target The target to load the resource into.
 * @return The given target.
 */
public <Y extends Target<TranscodeType>> Y into(Y target) {
    Util.assertMainThread();
    if (target == null) {
        throw new IllegalArgumentException("You must pass in a non null Target");
    }
    if (!isModelSet) {
        throw new IllegalArgumentException("You must first set a model (try #load())");
    }

    Request previous = target.getRequest();

    if (previous != null) {
        previous.clear();
        requestTracker.removeRequest(previous);
        previous.recycle();
    }

    Request request = buildRequest(target);
    target.setRequest(request);
    lifecycle.addListener(target);
    requestTracker.runRequest(request);

    return target;
}
 
Example #11
Source File: BitmapTransformation.java    From giffun with Apache License 2.0 6 votes vote down vote up
@Override
public final Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    if (!Util.isValidDimensions(outWidth, outHeight)) {
        throw new IllegalArgumentException("Cannot apply transformation on width: " + outWidth + " or height: "
                + outHeight + " less than or equal to zero and not Target.SIZE_ORIGINAL");
    }
    Bitmap toTransform = resource.get();
    int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth;
    int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight;
    Bitmap transformed = transform(bitmapPool, toTransform, targetWidth, targetHeight);

    final Resource<Bitmap> result;
    if (toTransform.equals(transformed)) {
        result = resource;
    } else {
        result = BitmapResource.obtain(transformed, bitmapPool);
    }

    return result;
}
 
Example #12
Source File: SvgSoftwareLayerSetter.java    From PowerFileExplorer with 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 #13
Source File: FullscreenImageActivity.java    From Anecdote with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                           boolean isFirstResource) {
    startPostponedEnterTransition(mPhotoView);
    return false;
}
 
Example #14
Source File: ArtistGlideRequest.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
public BitmapRequestBuilder<?, BitmapPaletteWrapper> build() {
    //noinspection unchecked
    return createBaseRequest(builder.requestManager, builder.artist, builder.noCustomImage)
            .asBitmap()
            .transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class)
            .diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
            .error(DEFAULT_ERROR_IMAGE)
            .animate(DEFAULT_ANIMATION)
            .priority(Priority.LOW)
            .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
            .signature(createSignature(builder.artist));
}
 
Example #15
Source File: SvgSoftwareLayerSetter.java    From GlideToVectorYou with 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 #16
Source File: GlideUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 图片加载
 * @param uri     Image Uri
 * @param target  {@link Target}
 * @param options {@link RequestOptions}
 */
public void loadImageFile(final String uri, final Target<File> target, final RequestOptions options) {
    if (mRequestManager != null) {
        if (options != null) {
            mRequestManager.asFile().load(uri).apply(options).into(target);
        } else {
            mRequestManager.asFile().load(uri).into(target);
        }
    }
}
 
Example #17
Source File: ImageLoader.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
public Target<Drawable> loadWithShadowCircleTransform(@DrawableRes int drawableId,
    ImageView imageView, @ColorInt int shadowColor) {
  Context context = weakContext.get();
  if (context != null) {
    return Glide.with(context)
        .load(drawableId)
        .apply(getRequestOptions().transform(
            new ShadowCircleTransformation(context, imageView, shadowColor)))
        .transition(DrawableTransitionOptions.withCrossFade())
        .into(imageView);
  } else {
    Log.e(TAG, "::loadWithShadowCircleTransform() Context is null");
  }
  return null;
}
 
Example #18
Source File: CommonUtil.java    From Yuan-SxMusic with Apache License 2.0 5 votes vote down vote up
public static Bitmap getImgBitmap(Context context,String imgUrl){
    SimpleTarget target = new SimpleTarget<Drawable>(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) {
        @Override
        public void onResourceReady(@Nullable Drawable resource, Transition<? super Drawable> transition) {
            Bitmap bitmap = ((BitmapDrawable) resource).getBitmap();
        }
    };
    Glide.with(context)
            .load(imgUrl)
            .apply(RequestOptions.placeholderOf(R.drawable.welcome))
            .apply(RequestOptions.errorOf(R.drawable.welcome))
            .into(target);
    return null;
}
 
Example #19
Source File: DemoGlideHelper.java    From GestureViews with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onResourceReady(T resource, Object model, Target<T> target,
        DataSource dataSource, boolean isFirstResource) {
    if (listener != null) {
        listener.onSuccess();
    }
    return false;
}
 
Example #20
Source File: RedBookPresenter.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
@Override
public void displayImage(View view, ImageItem item, int size, boolean isThumbnail) {
    Object object = item.getUri() != null ? item.getUri() : item.path;

    Glide.with(view.getContext()).load(object).apply(new RequestOptions()
            .format(isThumbnail ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888))
            .override(isThumbnail ? size : Target.SIZE_ORIGINAL)
            .into((ImageView) view);
}
 
Example #21
Source File: RedBookPresenter.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
@Override
public void displayImage(View view, ImageItem item, int size, boolean isThumbnail) {
    Object object = item.getUri() != null ? item.getUri() : item.path;

    Glide.with(view.getContext()).load(object).apply(new RequestOptions()
            .format(isThumbnail ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888))
            .override(isThumbnail ? size : Target.SIZE_ORIGINAL)
            .into((ImageView) view);
}
 
Example #22
Source File: ImageLoader.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onResourceReady(final Drawable resource, final Object model, final Target<Drawable> target,
        final DataSource dataSource, final boolean isFirstResource) {
    if (BuildConfig.DEBUG) {
        Log.i(TAG, String.format(Locale.ROOT,
                "GLIDE onResourceReady(%s, %s, %s, %s, %s)", resource, model,
                target, dataSource, isFirstResource));
    }

    return false;
}
 
Example #23
Source File: ConditionalAlbumListFragment.java    From PainlessMusicPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onResourceReady(
        @NonNull final Drawable resource,
        @NonNull final Object model,
        @NonNull final Target<Drawable> target,
        @NonNull final DataSource dataSource,
        final boolean isFirstResource) {
    final FragmentActivity activity = getActivity();
    if (activity != null) {
        activity.supportStartPostponedEnterTransition();
    }
    return false;
}
 
Example #24
Source File: SvgSoftwareLayerSetter.java    From PowerFileExplorer with 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 #25
Source File: QueueActivity.java    From PainlessMusicPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onLoadFailed(
        @Nullable final GlideException e,
        @NonNull final Object model,
        @NonNull final Target<Drawable> target,
        final boolean isFirstResource) {
    mCoverUri = null;
    showPlaceholderArt();
    onImageSet();
    return true;
}
 
Example #26
Source File: ProfileUtils.java    From imsdk-android with MIT License 5 votes vote down vote up
public static void displayEmojiconByImageSrc(final Activity context, final String imageSrc, final ImageView headView, final int w, final int h){

        if(context == null){
            return;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            if(context.isDestroyed()){
                return;
            }
        }
        if(TextUtils.isEmpty(imageSrc) || headView == null){
            return;
        }
        context.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                //glide
                Glide.with(context)
                        //配置上下文
                        .load(imageSrc)
//                        .load(new MyGlideUrl(imageSrc))      //设置图片路径(fix #8,文件名包含%符号 无法识别和显示)
                        .asBitmap()
//                        .error(defaultRes)
                        .centerCrop()
                        .thumbnail(0.1f)
                        .transform(new CenterCrop(context))
                        .placeholder(defaultRes)
                        .override(w > 0 ? w + 5 : Target.SIZE_ORIGINAL, h > 0 ? h + 5 : Target.SIZE_ORIGINAL)
                        .diskCacheStrategy(DiskCacheStrategy.SOURCE)//缓存全尺寸
                        .dontAnimate()
                        .into(headView);
            }
        });



    }
 
Example #27
Source File: GlideImagesPlugin.java    From Markwon with Apache License 2.0 5 votes vote down vote up
@Override
public void cancel(@NonNull AsyncDrawable drawable) {
    final Target<?> target = cache.remove(drawable);
    if (target != null) {
        glideStore.cancel(target);
    }
}
 
Example #28
Source File: ImageLoader.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
public Target<Drawable> loadWithShadowCircleTransformWithPlaceholder(String url,
    ImageView imageView, @DrawableRes int drawablePlaceholder) {
  Context context = weakContext.get();
  if (context != null) {
    return Glide.with(context)
        .load(url)
        .apply(getRequestOptions().transform(new ShadowCircleTransformation(context))
            .placeholder(drawablePlaceholder))
        .transition(DrawableTransitionOptions.withCrossFade())
        .into(imageView);
  } else {
    Log.e(TAG, "::loadWithShadowCircleTransform() Context is null");
  }
  return null;
}
 
Example #29
Source File: CustomImgPickerPresenter.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
@Override
public void displayImage(View view, ImageItem item, int size, boolean isThumbnail) {
    Object object = item.getUri() != null ? item.getUri() : item.path;

    Glide.with(view.getContext()).load(object).apply(new RequestOptions()
            .format(isThumbnail ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888))
            .override(isThumbnail ? size : Target.SIZE_ORIGINAL)
            .into((ImageView) view);
}
 
Example #30
Source File: ChannelActivity.java    From Twire with GNU General Public License v3.0 5 votes vote down vote up
private Target<Bitmap> getNightThemeTarget() {
    return new CustomTarget<Bitmap>() {
        @Override
        public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition<? super Bitmap> transition)  {
            streamerImage.setImageBitmap(bitmap);
        }

        @Override
        public void onLoadCleared(@Nullable Drawable placeholder) {

        }
    };
}