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()); }
public void bind(int position, TweetSelectImageAdapter.Model model, RequestManager loader) { mDelete.setTag(model); // In this we need clear before load Glide.clear(mImage); // Load image if (model.path.toLowerCase().endsWith("gif")) { loader.load(model.path) .asBitmap() .centerCrop() .error(R.mipmap.ic_split_graph) .into(mImage); // Show gif mask mGifMask.setVisibility(View.VISIBLE); } else { loader.load(model.path) .centerCrop() .error(R.mipmap.ic_split_graph) .into(mImage); mGifMask.setVisibility(View.GONE); } }
private RequestManager getApplicationManager(Context context) { // Either an application context or we're on a background thread. if (applicationManager == null) { synchronized (this) { if (applicationManager == null) { // Normally pause/resume is taken care of by the fragment we add to the fragment or // activity. However, in this case since the manager attached to the application will not // receive lifecycle events, we must force the manager to start resumed using // ApplicationLifecycle. // TODO(b/27524013): Factor out this Glide.get() call. Glide glide = Glide.get(context.getApplicationContext()); applicationManager = factory.build( glide, new ApplicationLifecycle(), new EmptyRequestManagerTreeNode(), context.getApplicationContext()); } } } return applicationManager; }
/** * Constructor that accepts interfaces for providing the dimensions of images to preload, the list * of models to preload for a given position, and the request to use to load images. * * @param preloadModelProvider Provides models to load and requests capable of loading them. * @param preloadDimensionProvider Provides the dimensions of images to load. * @param maxPreload Maximum number of items to preload. */ public RecyclerViewPreloader(RequestManager requestManager, PreloadModelProvider<T> preloadModelProvider, PreloadSizeProvider<T> preloadDimensionProvider, int maxPreload) { ListPreloader<T> listPreloader = new ListPreloader<>(requestManager, preloadModelProvider, preloadDimensionProvider, maxPreload); recyclerScrollListener = new RecyclerToListViewScrollListener(listPreloader); }
@Override public RequestManager getImgLoader() { if (mCurImageLoader == null) { mCurImageLoader = Glide.with(getContext()); } return mCurImageLoader; }
static DrawableTypeRequest createBaseRequest(RequestManager requestManager, Artist artist, boolean noCustomImage, boolean forceDownload) { boolean hasCustomImage = CustomArtistImageUtil.getInstance(RetroApplication.getInstance()).hasCustomArtistImage(artist); if (noCustomImage || !hasCustomImage) { return requestManager.load(new ArtistImage(artist.getName(), forceDownload)); } else { return requestManager.load(CustomArtistImageUtil.getFile(artist)); } }
@NonNull public static UploadViewHolder create(@NonNull ViewGroup parent, @NonNull RequestManager glide) { final LayoutInflater inflater = LayoutInflater.from(parent.getContext()); final View itemView = inflater.inflate(R.layout.upload_item, parent, false); final ImageView thumbnail = (ImageView) itemView.findViewById(R.id.image_thumbnail); final TextView filename = (TextView) itemView.findViewById(R.id.text_filename); final TextView status = (TextView) itemView.findViewById(R.id.text_status); return new UploadViewHolder(itemView, thumbnail, filename, status, glide); }
private RequestManager fragmentGet(Context context, android.app.FragmentManager fm, android.app.Fragment parentHint) { RequestManagerFragment current = getRequestManagerFragment(fm, parentHint); RequestManager requestManager = current.getRequestManager(); if (requestManager == null) { // TODO(b/27524013): Factor out this Glide.get() call. Glide glide = Glide.get(context); requestManager = factory.build(glide, current.getLifecycle(), current.getRequestManagerTreeNode()); current.setRequestManager(requestManager); } return requestManager; }
private RequestManager supportFragmentGet(Context context, FragmentManager fm, Fragment parentHint) { SupportRequestManagerFragment current = getSupportRequestManagerFragment(fm, parentHint); RequestManager requestManager = current.getRequestManager(); if (requestManager == null) { // TODO(b/27524013): Factor out this Glide.get() call. Glide glide = Glide.get(context); requestManager = factory.build(glide, current.getLifecycle(), current.getRequestManagerTreeNode()); current.setRequestManager(requestManager); } return requestManager; }
@Test public void testReturnsExistingRequestManagerIfExists() { for (RetrieverHarness harness : harnesses) { RequestManager requestManager = mock(RequestManager.class); harness.addFragmentWithTag(RequestManagerRetriever.FRAGMENT_TAG, requestManager); assertEquals(requestManager, harness.doGet()); } }
@Test public void testSavesNewRequestManagerToFragmentIfCreatesRequestManagerForExistingFragment() { for (RetrieverHarness harness : harnesses) { harness.addFragmentWithTag(RequestManagerRetriever.FRAGMENT_TAG, null); RequestManager first = harness.doGet(); RequestManager second = harness.doGet(); assertEquals(first, second); } }
@Test public void testSupportCanGetRequestManagerFromActivity() { FragmentActivity fragmentActivity = Robolectric.buildActivity(FragmentActivity.class).create().start().get(); RequestManager manager = retriever.get(fragmentActivity); assertEquals(manager, retriever.get(fragmentActivity)); }
@Test public void testSupportCanGetRequestManagerFromFragment() { FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).create().start().resume().get(); Fragment fragment = new Fragment(); activity.getSupportFragmentManager().beginTransaction().add(fragment, PARENT_TAG).commit(); activity.getSupportFragmentManager().executePendingTransactions(); RequestManager manager = retriever.get(fragment); assertEquals(manager, retriever.get(fragment)); }
@Test public void testChecksIfContextIsFragmentActivity() { RetrieverHarness harness = new SupportRetrieverHarness(); RequestManager requestManager = harness.doGet(); assertEquals(requestManager, retriever.get((Context) harness.getController().get())); }
public static void loadImage(RequestManager loader, ImageView view, String url, int placeholder, int error) { boolean isCenterCrop = false; if (view instanceof CircleImageView) { isCenterCrop = true; } loadImage(loader, view, url, placeholder, error, isCenterCrop); }
@Override public void addFragmentWithTag(String tag, RequestManager requestManager) { RequestManagerFragment fragment = new RequestManagerFragment(); fragment.setRequestManager(requestManager); controller.get().getFragmentManager().beginTransaction() .add(fragment, RequestManagerRetriever.FRAGMENT_TAG).commitAllowingStateLoss(); controller.get().getFragmentManager().executePendingTransactions(); }
public void initData(RequestManager manager, Banner banner) { this.banner = banner; manager.load(banner.getImg()) .placeholder(R.mipmap.event_cover_default) .error(R.mipmap.event_cover_default) .into(mImageEnent); }
@Test public void testSupportCanSetAndGetRequestManager() { runTest(new TestCase() { @Override public void runTest(Harness harness) { RequestManager manager = mock(RequestManager.class); harness.setRequestManager(manager); assertEquals(manager, harness.getManager()); } }); }
@Test public void testNonSupportFragmentCallsOnTrimMemory() { RequestManagerHarness requestManagerHarness = new RequestManagerHarness(); int level = 100; RequestManager requestManager = mock(RequestManager.class); requestManagerHarness.setRequestManager(requestManager); requestManagerHarness.onTrimMemory(level); verify(requestManager).onTrimMemory(eq(level)); }
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)); } }
public void setup(RequestManager manager,int resourceId, String url) { if (url==null) url=""; manager.load(url) .placeholder(resourceId) .centerCrop() .dontAnimate() // CircleImageView 不能使用动画,会导致显示延迟 .into(this); }
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) { ImageThumbnailHolder viewHolder = (ImageThumbnailHolder) holder; ImageFile file = mSelectedThumbnailList.get(position); RequestManager requestManager = Glide.with(ImageBrowserActivity.this); DrawableRequestBuilder requestBuilder; if (file.getEditCount() > 0) { requestBuilder = requestManager.load(file.getEditedPath()) .signature(new StringSignature(file.getEditCount() + "")); } else { requestBuilder = requestManager.load(file.getPath()); } requestBuilder.centerCrop() .crossFade() .placeholder(R.mipmap.ic_place_holder).into(viewHolder.imageView); if (mList.get(mCurrentIndex).getId() == file.getId()) { viewHolder.ivBlock.setVisibility(View.VISIBLE); } else { viewHolder.ivBlock.setVisibility(View.GONE); } if (mIsPreview) { viewHolder.shadow.setVisibility(file.isSelected() ? View.GONE : View.VISIBLE); } viewHolder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mViewPager.setCurrentItem(Integer.valueOf(mSelectedPosition.get(position)), false); mRecyclerView.scrollToPosition(position); } }); }
@Override public Set<RequestManager> getDescendants() { Set<SupportRequestManagerFragment> descendantFragments = getDescendantRequestManagerFragments(); HashSet<RequestManager> descendants = new HashSet<>(descendantFragments.size()); for (SupportRequestManagerFragment fragment : descendantFragments) { if (fragment.getRequestManager() != null) { descendants.add(fragment.getRequestManager()); } } return descendants; }
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); }
private RequestManager getRequestManager() { RequestManager requestManager = null; if (mContext instanceof Activity) { requestManager = Glide.with((Activity) mContext); } else if (mContext instanceof Fragment) { requestManager = Glide.with((Fragment) mContext); } else { requestManager = Glide.with((Context) mContext); } return requestManager; }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public RequestManager get(android.app.Fragment fragment) { if (fragment.getActivity() == null) { throw new IllegalArgumentException( "You cannot start a load on a fragment before it is attached"); } if (Util.isOnBackgroundThread() || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { return get(fragment.getActivity().getApplicationContext()); } else { android.app.FragmentManager fm = fragment.getChildFragmentManager(); return fragmentGet(fragment.getActivity(), fm, fragment); } }
private RequestManager fragmentGet(Context context, android.app.FragmentManager fm, android.app.Fragment parentHint) { RequestManagerFragment current = getRequestManagerFragment(fm, parentHint); RequestManager requestManager = current.getRequestManager(); if (requestManager == null) { // TODO(b/27524013): Factor out this Glide.get() call. Glide glide = Glide.get(context); requestManager = factory.build( glide, current.getGlideLifecycle(), current.getRequestManagerTreeNode(), context); current.setRequestManager(requestManager); } return requestManager; }
private RequestManager supportFragmentGet(Context context, FragmentManager fm, Fragment parentHint) { SupportRequestManagerFragment current = getSupportRequestManagerFragment(fm, parentHint); RequestManager requestManager = current.getRequestManager(); if (requestManager == null) { // TODO(b/27524013): Factor out this Glide.get() call. Glide glide = Glide.get(context); requestManager = factory.build( glide, current.getGlideLifecycle(), current.getRequestManagerTreeNode(), context); current.setRequestManager(requestManager); } return requestManager; }
@Test public void testCanGetRequestManagerFromFragment() { Activity activity = Robolectric.buildActivity(Activity.class).create().start().resume().get(); android.app.Fragment fragment = new android.app.Fragment(); activity.getFragmentManager().beginTransaction().add(fragment, PARENT_TAG).commit(); activity.getFragmentManager().executePendingTransactions(); RequestManager manager = retriever.get(fragment); assertEquals(manager, retriever.get(fragment)); }
public HeaderView(Context context, RequestManager loader, String api, String bannerCache) { super(context); mImageLoader = loader; this.mUrl = api; this.mBannerCache = bannerCache; init(context); }
@Test public void testHandlesContextWrappersForActivities() { RetrieverHarness harness = new DefaultRetrieverHarness(); RequestManager requestManager = harness.doGet(); ContextWrapper contextWrapper = new ContextWrapper(harness.getController().get()); assertEquals(requestManager, retriever.get(contextWrapper)); }
/** * 获取一个图片加载管理器 * * @return RequestManager */ public synchronized RequestManager getImgLoader() { if (mImgLoader == null) mImgLoader = Glide.with(this); return mImgLoader; }
@Override public void loadImage(Context ctx, GlideImageConfig config) { RequestManager manager; if (ctx instanceof Activity)//如果是activity则可以使用Activity的生命周期 manager = Glide.with((Activity) ctx); else manager = Glide.with(ctx); DrawableRequestBuilder<String> requestBuilder = manager.load(config.getUrl()) .crossFade() .centerCrop(); switch (config.getCacheStrategy()) {//缓存策略 case 0: requestBuilder.diskCacheStrategy(DiskCacheStrategy.ALL); break; case 1: requestBuilder.diskCacheStrategy(DiskCacheStrategy.NONE); break; case 2: requestBuilder.diskCacheStrategy(DiskCacheStrategy.SOURCE); break; case 3: requestBuilder.diskCacheStrategy(DiskCacheStrategy.RESULT); break; } if (config.getTransformation() != null) {//glide用它来改变图形的形状 requestBuilder.transform(config.getTransformation()); } if (config.getPlaceholder() != 0)//设置占位符 requestBuilder.placeholder(config.getPlaceholder()); if (config.getErrorPic() != 0)//设置错误的图片 requestBuilder.error(config.getErrorPic()); requestBuilder .into(config.getImageView()); }
/** * Returns the current {@link com.bumptech.glide.RequestManager} or null if none exists. */ @Nullable public RequestManager getRequestManager() { return requestManager; }
private RequestManager getRequestManager(Context context) { return Glide.with(context); }
@Override public Set<RequestManager> getDescendants() { return Collections.emptySet(); }