com.bumptech.glide.RequestManager Java Examples

The following examples show how to use com.bumptech.glide.RequestManager. 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: GlideFilmstripManager.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
public GlideFilmstripManager(Context context)
{
    Glide glide = Glide.get(context);
    BitmapEncoder bitmapEncoder = new BitmapEncoder(Bitmap.CompressFormat.JPEG,
            JPEG_COMPRESS_QUALITY);
    GifBitmapWrapperResourceEncoder drawableEncoder = new GifBitmapWrapperResourceEncoder(
            bitmapEncoder,
            new GifResourceEncoder(glide.getBitmapPool()));
    RequestManager request = Glide.with(context);

    mTinyImageBuilder = request
            .fromMediaStore()
            .asBitmap() // This prevents gifs from animating at tiny sizes.
            .transcode(new BitmapToGlideDrawableTranscoder(context), GlideDrawable.class)
            .fitCenter()
            .placeholder(DEFAULT_PLACEHOLDER_RESOURCE)
            .dontAnimate();

    mLargeImageBuilder = request
            .fromMediaStore()
            .encoder(drawableEncoder)
            .fitCenter()
            .placeholder(DEFAULT_PLACEHOLDER_RESOURCE)
            .dontAnimate();
}
 
Example #2
Source File: GlideHelper.java    From hipda with GNU General Public License v2.0 6 votes vote down vote up
public static void loadAvatar(RequestManager glide, ImageView view, String avatarUrl) {
    avatarUrl = Utils.nullToText(avatarUrl);
    String cacheKey = AVATAR_CACHE_KEYS.get(avatarUrl);
    if (cacheKey == null) {
        cacheKey = avatarUrl;
    }
    if (HiSettingsHelper.getInstance().isCircleAvatar()) {
        glide.load(new AvatarModel(avatarUrl))
                .signature(new ObjectKey(cacheKey))
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .circleCrop()
                .error(DEFAULT_USER_ICON)
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(view);
    } else {
        glide.load(new AvatarModel(avatarUrl))
                .signature(new ObjectKey(cacheKey))
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .transform(new CenterCrop(), new RoundedCorners(Utils.dpToPx(4)))
                .error(DEFAULT_USER_ICON)
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(view);
    }
}
 
Example #3
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 #4
Source File: ImageLoader.java    From AccountBook with GNU General Public License v3.0 6 votes vote down vote up
private DrawableRequestBuilder load(Object object, RequestManager with){
    DrawableRequestBuilder builder = null;
    if(object instanceof String){
        String imageUrl = (String) object;
        if(!imageUrl.startsWith("http://")){
            imageUrl = Api.IMG_SERVER_URL.concat(imageUrl);
        }
        builder = with.load(imageUrl);
    }else if(object instanceof Integer){
        builder = with.load((Integer) object);
    }else if(object instanceof File){
        builder = with.load((File) object);
    }else if(object instanceof Uri){
        builder = with.load((Uri) object);
    }else if(object instanceof Byte[]){
        builder = with.load((Byte[]) object);
    }
    return builder;
}
 
Example #5
Source File: GalleryAdapter.java    From NClientV2 with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewRecycled(@NonNull ViewHolder holder) {
    final ImageView imgView=holder.master.findViewById(R.id.image);
    toDelete.add(map.remove(imgView));
    for (Iterator<BitmapTarget> iterator = toDelete.iterator(); iterator.hasNext();) {
        BitmapTarget target = iterator.next();
        if(context.isFinishing()||Global.isDestroyed(context))
            break;
        if(!map.containsValue(target)) {
            RequestManager manager = GlideX.with(context);
            if (manager != null) manager.clear(target);
        }
        iterator.remove();
    }
    super.onViewRecycled(holder);
}
 
Example #6
Source File: ImageLoadMnanger.java    From star-zone-android with Apache License 2.0 6 votes vote down vote up
RequestBuilder getGlide(Object o, ImageView iv) {
    RequestManager manager = Glide.with(getImageContext(iv));
    if (o instanceof String) {
        try {
            int t = Integer.parseInt(String.valueOf(o));
            return getGlideInteger(manager, t, iv);
        } catch (Exception e) {
            return getGlideString(manager, (String) o, iv);
        }
    } else if (o instanceof Integer) {
        return getGlideInteger(manager, (Integer) o, iv);
    } else if (o instanceof Uri) {
        return getGlideUri(manager, (Uri) o, iv);
    } else if (o instanceof File) {
        return getGlideFile(manager, (File) o, iv);
    }
    return getGlideString(manager, "", iv);
}
 
Example #7
Source File: AFGlideUtil.java    From AFBaseLibrary with Apache License 2.0 6 votes vote down vote up
@Nullable
private static DrawableTypeRequest getDrawableTypeRequest(Object obj, View img) {
    if (img == null || obj == null) return null;
    Context context = img.getContext();
    RequestManager manager = Glide.with(context);
    DrawableTypeRequest drawableTypeRequest = null;
    if (obj instanceof String) {
        drawableTypeRequest = manager.load((String) obj);
    } else if (obj instanceof Integer) {
        drawableTypeRequest = manager.load((Integer) obj);
    } else if (obj instanceof Uri) {
        drawableTypeRequest = manager.load((Uri) obj);
    } else if (obj instanceof File) {
        drawableTypeRequest = manager.load((File) obj);
    }
    return drawableTypeRequest;
}
 
Example #8
Source File: GlideImagesPlugin.java    From Markwon with Apache License 2.0 5 votes vote down vote up
@NonNull
public static GlideImagesPlugin create(@NonNull final RequestManager requestManager) {
    return create(new GlideStore() {
        @NonNull
        @Override
        public RequestBuilder<Drawable> load(@NonNull AsyncDrawable drawable) {
            return requestManager.load(drawable.getDestination());
        }

        @Override
        public void cancel(@NonNull Target<?> target) {
            requestManager.clear(target);
        }
    });
}
 
Example #9
Source File: UploadViewHolder.java    From RxUploader with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
UploadViewHolder(@NonNull View itemView, @NonNull ImageView thumbnail,
        @NonNull TextView filename, @NonNull TextView status, @NonNull RequestManager glide) {
    super(itemView);
    this.thumbnail = thumbnail;
    this.filename = filename;
    this.status = status;
    this.glide = glide;
}
 
Example #10
Source File: SongGlideRequest.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
public static DrawableTypeRequest createBaseRequest(RequestManager requestManager, Song song, boolean ignoreMediaStore) {
    if (ignoreMediaStore) {
        return requestManager.load(new AudioFileCover(song.data));
    } else {
        return requestManager.loadFromMediaStore(MusicUtil.getMediaStoreAlbumCoverUri(song.albumId));
    }
}
 
Example #11
Source File: CatsAdapter.java    From android-aop-analytics with Apache License 2.0 5 votes vote down vote up
@Inject
public CatsAdapter(LayoutInflater layoutInflater, RequestManager glideRequestManager,
                   EventBus eventBus) {
    this.layoutInflater = layoutInflater;
    this.glideRequestManager = glideRequestManager;
    this.eventBus = eventBus;
    this.catImages = new ArrayList<>();
}
 
Example #12
Source File: RequestManagerRetriever.java    From giffun with Apache License 2.0 5 votes vote down vote up
public RequestManager get(FragmentActivity activity) {
    if (Util.isOnBackgroundThread()) {
        return get(activity.getApplicationContext());
    } else {
        assertNotDestroyed(activity);
        FragmentManager fm = activity.getSupportFragmentManager();
        return supportFragmentGet(activity, fm);
    }
}
 
Example #13
Source File: MainModule.java    From MoeGallery with GNU General Public License v3.0 5 votes vote down vote up
@Singleton
@Provides
GenericRequestBuilder<GlideUrl, InputStream, byte[], GifDrawable> provideGifRequestBuilder(
        RequestManager requestManager, OkHttpClient okHttpClient) {

    return requestManager.using(new OkHttpUrlLoader(okHttpClient), InputStream.class)
            .from(GlideUrl.class)
            .as(byte[].class)
            .transcode(new GifDrawableBytesTranscoder(), GifDrawable.class)
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .decoder(new StreamByteArrayResourceDecoder())
            .sourceEncoder(new StreamEncoder())
            .cacheDecoder(new FileToStreamDecoder<>(new StreamByteArrayResourceDecoder()));
}
 
Example #14
Source File: ImageDownloadUtility.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
public static void loadImage(Activity activity,String url,ImageView imageView){
    LogUtility.d("Requested url glide: "+ url);
    if(activity.isFinishing()||Global.isDestroyed(activity))return;
    if(Global.getDownloadPolicy()== Global.DataUsageType.NONE){loadLogo(imageView);return;}
    RequestManager glide=GlideX.with(activity);
    if(glide==null)return;
    int logo=Global.getLogo();
    glide.load(url)
            .placeholder(logo)
            .error(logo)
            .into(imageView);
}
 
Example #15
Source File: RequestManagerFragment.java    From giffun with Apache License 2.0 5 votes vote down vote up
@Override
public Set<RequestManager> getDescendants() {
    Set<RequestManagerFragment> descendantFragments = getDescendantRequestManagerFragments();
    HashSet<RequestManager> descendants =
        new HashSet<RequestManager>(descendantFragments.size());
    for (RequestManagerFragment fragment : descendantFragments) {
        if (fragment.getRequestManager() != null) {
            descendants.add(fragment.getRequestManager());
        }
    }
    return descendants;
}
 
Example #16
Source File: SongGlideRequest.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
public static DrawableTypeRequest createBaseRequest(RequestManager requestManager, Song song, boolean ignoreMediaStore) {
    if (ignoreMediaStore) {
        return requestManager.load(new AudioFileCover(song.data));
    } else {
        return requestManager.loadFromMediaStore(MusicUtil.getMediaStoreAlbumCoverUri(song.albumId));
    }
}
 
Example #17
Source File: RequestManagerRetriever.java    From giffun with Apache License 2.0 5 votes vote down vote up
public RequestManager get(Context context) {
    if (context == null) {
        throw new IllegalArgumentException("You cannot start a load on a null Context");
    } else if (Util.isOnMainThread() && !(context instanceof Application)) {
        if (context instanceof FragmentActivity) {
            return get((FragmentActivity) context);
        } else if (context instanceof Activity) {
            return get((Activity) context);
        } else if (context instanceof ContextWrapper) {
            return get(((ContextWrapper) context).getBaseContext());
        }
    }

    return getApplicationManager(context);
}
 
Example #18
Source File: MainActivity.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    Global.updateACRAReportStatus(this);
    com.dar.nclientv2.settings.Login.initUseAccountTag(this);

    loadStringLogin();
    onlineFavoriteManager.setVisible(com.dar.nclientv2.settings.Login.isLogged(true));
    if(setting!=null){
        Global.initFromShared(this);//restart all settings
        inspector=inspector.cloneInspector(this,resetDataset);
        inspector.start();//restart inspector
        if(setting.theme!=Global.getTheme()||!setting.locale.equals(Global.initLanguage(this))){
            RequestManager manager= GlideX.with(getApplicationContext());
            if(manager!=null)manager.pauseAllRequestsRecursive();
            recreate();
        }
        adapter.notifyDataSetChanged();//restart adapter
        showPageSwitcher(inspector.getPage(),inspector.getPageCount());//restart page switcher
        changeLayout(getResources().getConfiguration().orientation==Configuration.ORIENTATION_LANDSCAPE);
        setting=null;
    }else if(filteringTag){
        inspector=InspectorV3.basicInspector(this,1,resetDataset);
        inspector.start();
        filteringTag=false;
    }
    invalidateOptionsMenu();
}
 
Example #19
Source File: FeedEntryViewHolder.java    From glide-support with The Unlicense 5 votes vote down vote up
public FeedEntryViewHolder(View itemView, RequestManager glide) {
	super(itemView);
	this.glide = glide;
	this.image = (ImageView)itemView.findViewById(R.id.github_864_image);
	this.title = (TextView)itemView.findViewById(R.id.github_864_title);
	this.author = (ImageView)itemView.findViewById(R.id.github_864_author_icon);
}
 
Example #20
Source File: GlideX.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
@Nullable
public static RequestManager with(Context context) {
    try {
        return Glide.with(context);
    } catch (VerifyError | IllegalStateException ignore) {
        return null;
    }
}
 
Example #21
Source File: GlideX.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
@Nullable
public static RequestManager with(Fragment fragment) {
    try {
        return Glide.with(fragment);
    } catch (VerifyError | IllegalStateException ignore) {
        return null;
    }
}
 
Example #22
Source File: GlideX.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
@Nullable
public static RequestManager with(FragmentActivity fragmentActivity) {
    try {
        return Glide.with(fragmentActivity);
    } catch (VerifyError | IllegalStateException ignore) {
        return null;
    }
}
 
Example #23
Source File: GlideX.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
@Nullable
public static RequestManager with(Activity activity) {
    try {
        return Glide.with(activity);
    } catch (VerifyError | IllegalStateException ignore) {
        return null;
    }
}
 
Example #24
Source File: VideoGridViewAdapter.java    From SimpleVideoEdit with Apache License 2.0 5 votes vote down vote up
VideoGridViewAdapter(Context context, ArrayList<VideoInfo> dataList, RequestManager requestManager) {
    this.context = context;
    this.videoListData = dataList;
    this.requestBuilder = requestManager.asDrawable();
    /*this.setItemSelectCallback(new VideoGridViewAdapter.ItemSelectCallback(){
        @Override
        public void onItemSelectCallback(int position) {
            notifyItemChanged(selectedPos);
            selectedPos = position;
            notifyItemChanged(selectedPos);//刷新当前点击item
        }
    });*/
}
 
Example #25
Source File: MainAdapter.java    From mr-mantou-android with GNU General Public License v3.0 5 votes vote down vote up
public MainAdapter(Context context, ObservableList<Image> data, RequestManager requestManager,
                   Listener listener) {
    super(context, data);

    this.requestManager = requestManager;
    this.listener = listener;

    setHasStableIds(true);
}
 
Example #26
Source File: SongGlideRequest.java    From Orin with GNU General Public License v3.0 5 votes vote down vote up
public static DrawableTypeRequest createBaseRequest(RequestManager requestManager, Song song, boolean ignoreMediaStore) {
    if (ignoreMediaStore) {
        return requestManager.load(new AudioFileCover(song.data));
    } else {
        return requestManager.loadFromMediaStore(MusicUtil.getMediaStoreAlbumCoverUri(song.albumId));
    }
}
 
Example #27
Source File: AppInfoAdapter.java    From materialize with GNU General Public License v3.0 5 votes vote down vote up
public AppInfoAdapter(Context context, RequestManager requestManager,
                      FilteredSortedList.Filter<AppInfo> filter, OnItemClickListener listener) {
    super(AppInfo.class, filter);
    this.context = context;
    this.inflater = LayoutInflater.from(context);
    this.requestManager = requestManager;
    this.listener = listener;
}
 
Example #28
Source File: MainActivity.java    From BeFoot with Apache License 2.0 5 votes vote down vote up
@Override
public RequestManager getGlideManager() {
    if (mGlideManager == null) {
        synchronized (this) {
            if (mGlideManager == null) {
                mGlideManager = Glide.with(this);
            }
        }
    }
    return mGlideManager;
}
 
Example #29
Source File: UsageExampleNetworkDependent.java    From android-tutorials-glide with MIT License 5 votes vote down vote up
private void loadNetworkDependent() {
    RequestManager requestManager = Glide.with(context);
    DrawableTypeRequest<String> request;

    // if you need transformations or other options specific for the load, chain them here
    if (deviceOnWifi()) {
        request = requestManager.load("http://www.placehold.it/750x750");
    }
    else {
        request = requestManager.load("http://www.placehold.it/100x100");
    }

    request.into(imageView1);
}
 
Example #30
Source File: RxGlide.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
public static Observable<File> download(RequestManager rm, String url, int width, int height) {
    return Observable.defer(() -> {
        try {
            return Observable.just(rm.load(url).downloadOnly(width, height).get());
        } catch (Exception e) {
            return Observable.error(e);
        }
    });
}