Java 类com.bumptech.glide.RequestManager 实例源码

项目:Moment    文件:RxDownload.java   
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());

}
项目:OSchina_resources_android    文件:TweetSelectImageAdapter.java   
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);
    }
}
项目:GitHub    文件:RequestManagerRetriever.java   
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;
}
项目:GitHub    文件:RecyclerViewPreloader.java   
/**
 * 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);
}
项目:OSchina_resources_android    文件:TweetPicturesPreviewer.java   
@Override
public RequestManager getImgLoader() {
    if (mCurImageLoader == null) {
        mCurImageLoader = Glide.with(getContext());
    }
    return mCurImageLoader;
}
项目:RetroMusicPlayer    文件:ArtistGlideRequest.java   
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));
    }
}
项目:RxUploader    文件:UploadViewHolder.java   
@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);
}
项目:GitHub    文件:RequestManagerRetriever.java   
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;
}
项目:GitHub    文件:RequestManagerRetriever.java   
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;
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@Test
public void testReturnsExistingRequestManagerIfExists() {
  for (RetrieverHarness harness : harnesses) {
    RequestManager requestManager = mock(RequestManager.class);

    harness.addFragmentWithTag(RequestManagerRetriever.FRAGMENT_TAG, requestManager);

    assertEquals(requestManager, harness.doGet());
  }
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@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);
  }
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@Test
public void testSupportCanGetRequestManagerFromActivity() {
  FragmentActivity fragmentActivity =
      Robolectric.buildActivity(FragmentActivity.class).create().start().get();
  RequestManager manager = retriever.get(fragmentActivity);
  assertEquals(manager, retriever.get(fragmentActivity));
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@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));
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@Test
public void testChecksIfContextIsFragmentActivity() {
  RetrieverHarness harness = new SupportRetrieverHarness();
  RequestManager requestManager = harness.doGet();

  assertEquals(requestManager, retriever.get((Context) harness.getController().get()));
}
项目:TPlayer    文件:ImageLoader.java   
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);
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@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();
}
项目:OSchina_resources_android    文件:ViewEventBanner.java   
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);
}
项目:GitHub    文件:RequestManagerFragmentTest.java   
@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());
    }
  });
}
项目:GitHub    文件:RequestManagerFragmentTest.java   
@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));
}
项目:Orin    文件:SongGlideRequest.java   
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));
    }
}
项目:FastAndroid    文件:RecyclerViewPreloader.java   
/**
 * 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);
}
项目:pipe    文件:PortraitView.java   
public void setup(RequestManager manager,int resourceId, String url) {
    if (url==null)  url="";
    manager.load(url)
            .placeholder(resourceId)
            .centerCrop()
            .dontAnimate() // CircleImageView 不能使用动画,会导致显示延迟
            .into(this);
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@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();
}
项目:filepicker    文件:ImageBrowserActivity.java   
@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);
        }
    });
}
项目:GitHub    文件:SupportRequestManagerFragment.java   
@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;
}
项目:GitHub    文件:RequestManagerRetriever.java   
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);
}
项目:GeekZone    文件:BaseAdapter.java   
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;
}
项目:GitHub    文件:RequestManagerRetriever.java   
@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);
  }
}
项目:GitHub    文件:RequestManagerRetriever.java   
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;
}
项目:GitHub    文件:RequestManagerRetriever.java   
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;
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@Test
public void testReturnsExistingRequestManagerIfExists() {
  for (RetrieverHarness harness : harnesses) {
    RequestManager requestManager = mock(RequestManager.class);

    harness.addFragmentWithTag(RequestManagerRetriever.FRAGMENT_TAG, requestManager);

    assertEquals(requestManager, harness.doGet());
  }
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@Test
public void testSupportCanGetRequestManagerFromActivity() {
  FragmentActivity fragmentActivity =
      Robolectric.buildActivity(FragmentActivity.class).create().start().get();
  RequestManager manager = retriever.get(fragmentActivity);
  assertEquals(manager, retriever.get(fragmentActivity));
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@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));
}
项目:OSchina_resources_android    文件:HeaderView.java   
public HeaderView(Context context, RequestManager loader, String api, String bannerCache) {
    super(context);
    mImageLoader = loader;
    this.mUrl = api;
    this.mBannerCache = bannerCache;
    init(context);
}
项目:GitHub    文件:RequestManagerRetrieverTest.java   
@Test
public void testHandlesContextWrappersForActivities() {
  RetrieverHarness harness = new DefaultRetrieverHarness();
  RequestManager requestManager = harness.doGet();
  ContextWrapper contextWrapper = new ContextWrapper(harness.getController().get());

  assertEquals(requestManager, retriever.get(contextWrapper));
}
项目:OSchina_resources_android    文件:BaseFragment.java   
/**
 * 获取一个图片加载管理器
 *
 * @return RequestManager
 */
public synchronized RequestManager getImgLoader() {
    if (mImgLoader == null)
        mImgLoader = Glide.with(this);
    return mImgLoader;
}
项目:AppCommonFrame    文件:GlideImageLoaderStrategy.java   
@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());
}
项目:GitHub    文件:RequestManagerFragment.java   
/**
 * Returns the current {@link com.bumptech.glide.RequestManager} or null if none exists.
 */
@Nullable
public RequestManager getRequestManager() {
  return requestManager;
}
项目:AndroidBasicLibs    文件:GlideLoader.java   
private RequestManager getRequestManager(Context context) {
    return Glide.with(context);
}
项目:GitHub    文件:EmptyRequestManagerTreeNode.java   
@Override
public Set<RequestManager> getDescendants() {
    return Collections.emptySet();
}