Java Code Examples for com.bumptech.glide.load.model.GlideUrl

The following are top voted examples for showing how to use com.bumptech.glide.load.model.GlideUrl. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: BaseGlideUrlLoaderTest.java   View source code 6 votes vote down vote up
@Test
public void testBuildsNewUrlIfNotPresentInCache() {
  int width = 10;
  int height = 11;

  urlLoader.resultUrl = "fakeUrl";
  when(wrapped.buildLoadData(any(GlideUrl.class), eq(width), eq(height), eq(options)))
      .thenAnswer(new Answer<ModelLoader.LoadData<InputStream>>() {
        @Override
        public ModelLoader.LoadData<InputStream> answer(InvocationOnMock invocationOnMock)
            throws Throwable {
          GlideUrl glideUrl = (GlideUrl) invocationOnMock.getArguments()[0];
          assertEquals(urlLoader.resultUrl, glideUrl.toStringUrl());
          return new ModelLoader.LoadData<>(mock(Key.class), fetcher);

        }
      });
  assertEquals(fetcher,
      urlLoader.buildLoadData(new GlideUrl(urlLoader.resultUrl), width, height, options).fetcher);
}
 
Example 2
Project: GitHub   File: HttpGlideUrlLoader.java   View source code 6 votes vote down vote up
@Override
public LoadData<InputStream> buildLoadData(GlideUrl model, int width, int height,
    Options options) {
  // GlideUrls memoize parsed URLs so caching them saves a few object instantiations and time
  // spent parsing urls.
  GlideUrl url = model;
  if (modelCache != null) {
    url = modelCache.get(model, 0, 0);
    if (url == null) {
      modelCache.put(model, 0, 0, model);
      url = model;
    }
  }
  int timeout = options.get(TIMEOUT);
  return new LoadData<>(url, new HttpUrlFetcher(url, timeout));
}
 
Example 3
Project: GitHub   File: BaseGlideUrlLoaderTest.java   View source code 6 votes vote down vote up
@Test
public void testBuildsNewUrlIfNotPresentInCache() {
  int width = 10;
  int height = 11;

  urlLoader.resultUrl = "fakeUrl";
  when(wrapped.buildLoadData(any(GlideUrl.class), eq(width), eq(height), eq(options)))
      .thenAnswer(new Answer<ModelLoader.LoadData<InputStream>>() {
        @Override
        public ModelLoader.LoadData<InputStream> answer(InvocationOnMock invocationOnMock)
            throws Throwable {
          GlideUrl glideUrl = (GlideUrl) invocationOnMock.getArguments()[0];
          assertEquals(urlLoader.resultUrl, glideUrl.toStringUrl());
          return new ModelLoader.LoadData<>(mock(Key.class), fetcher);

        }
      });
  assertEquals(
      fetcher,
      Preconditions.checkNotNull(
          urlLoader.buildLoadData(
              new GlideUrl(urlLoader.resultUrl), width, height, options)).fetcher);
}
 
Example 4
Project: GitHub   File: BaseGlideUrlLoaderTest.java   View source code 6 votes vote down vote up
@Test
public void testAddsNewUrlToCacheIfNotPresentInCache() {
  urlLoader.resultUrl = "fakeUrl";
  Object model = new Object();
  int width = 400;
  int height = 500;

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
      GlideUrl glideUrl = (GlideUrl) invocationOnMock.getArguments()[3];
      assertEquals(urlLoader.resultUrl, glideUrl.toStringUrl());
      return null;
    }
  }).when(modelCache).put(eq(model), eq(width), eq(height), any(GlideUrl.class));

  urlLoader.buildLoadData(model, width, height, options);

  verify(modelCache).put(eq(model), eq(width), eq(height), any(GlideUrl.class));
}
 
Example 5
Project: GitHub   File: BaseGlideUrlLoaderTest.java   View source code 6 votes vote down vote up
@Test
public void testDoesNotInteractWithModelCacheIfNull() {
  TestLoader urlLoader = new TestLoader(wrapped, null);
  urlLoader.resultUrl = "fakeUrl";

  int width = 456;
  int height = 789;

  when(wrapped.buildLoadData(any(GlideUrl.class), eq(width), eq(height), eq(options)))
      .thenReturn(new ModelLoader.LoadData<>(mock(Key.class), fetcher));

  assertEquals(
      fetcher,
      Preconditions.checkNotNull(
          urlLoader.buildLoadData(new Object(), width, height, options)).fetcher);
}
 
Example 6
Project: react-native-fast-image   File: OkHttpProgressGlideModule.java   View source code 5 votes vote down vote up
@Override
public void registerComponents(Context context, Glide glide) {
    OkHttpClient client = new OkHttpClient
            .Builder()
            .addInterceptor(createInterceptor(new DispatchingProgressListener()))
            .build();
    glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
}
 
Example 7
Project: OSchina_resources_android   File: AppOperator.java   View source code 5 votes vote down vote up
public static GlideUrl getGlideUrlByUser(String url) {
    if (AccountHelper.isLogin()) {
        return new GlideUrl(url,
                new LazyHeaders
                        .Builder()
                        .addHeader("Cookie", AccountHelper.getCookie())
                        .build());
    } else {
        return new GlideUrl(url);
    }
}
 
Example 8
Project: youkes_browser   File: GlideUtil.java   View source code 5 votes vote down vote up
public static void displayImageReferer(String url,ImageView imageView,String referer) {
    if(url==null){
        return;
    }
    LazyHeaders.Builder builder=new LazyHeaders.Builder().addHeader("User-Agent", UserAgent);
    if(referer!=null){
        builder.addHeader("Referer", referer);
    }

    /*
            .addHeader("key2", new LazyHeaderFactory() {
                @Override
                public String buildHeader() {
                    String expensiveAuthHeader = computeExpensiveAuthHeader();
                    return expensiveAuthHeader;
                }
            })
            */

    GlideUrl glideUrl = new GlideUrl(url,builder.build());

    Glide.with(MainApp.getContext())
            .load(glideUrl)
            .placeholder(R.drawable.pictures_no)
            .thumbnail(0.2f)
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .into(imageView);

}
 
Example 9
Project: GitHub   File: GlideTest.java   View source code 5 votes vote down vote up
@Override
public void registerComponents(Context context, Registry registry) {
  registerMockModelLoader(GlideUrl.class, InputStream.class,
      new ByteArrayInputStream(new byte[0]), registry);
  registerMockModelLoader(File.class, InputStream.class,
      new ByteArrayInputStream(new byte[0]), registry);
  registerMockModelLoader(File.class, ParcelFileDescriptor.class,
      mock(ParcelFileDescriptor.class), registry);
  registerMockModelLoader(File.class, ByteBuffer.class,
      ByteBuffer.allocate(10), registry);
}
 
Example 10
Project: GitHub   File: BaseGlideUrlLoaderTest.java   View source code 5 votes vote down vote up
@Test
public void testReturnsUrlFromCacheIfPresent() {
  Object model = new Object();
  int width = 100;
  int height = 200;
  GlideUrl expectedUrl = mock(GlideUrl.class);
  when(modelCache.get(eq(model), eq(width), eq(height))).thenReturn(expectedUrl);

  when(wrapped.buildLoadData(eq(expectedUrl), eq(width), eq(height), eq(options)))
      .thenReturn(new ModelLoader.LoadData<>(mock(Key.class), fetcher));

  assertEquals(fetcher, urlLoader.buildLoadData(model, width, height, options).fetcher);
}
 
Example 11
Project: garras   File: GlideProgressSupport.java   View source code 5 votes vote down vote up
public static void init(Glide glide, OkHttpClient okHttpClient) {
    OkHttpClient.Builder builder;
    if (okHttpClient != null) {
        builder = okHttpClient.newBuilder();
    } else {
        builder = new OkHttpClient.Builder();
    }
    builder.addNetworkInterceptor(createInterceptor(new DispatchingProgressListener()));
    glide.getRegistry().replace(GlideUrl.class, InputStream.class,
            new OkHttpUrlLoader.Factory(builder.build()));
}
 
Example 12
Project: GitHub   File: HttpUriLoaderTest.java   View source code 5 votes vote down vote up
@Test
public void testHandlesHttpUris() throws MalformedURLException {
  Uri httpUri = Uri.parse("http://www.google.com");
  loader.buildLoadData(httpUri, IMAGE_SIDE, IMAGE_SIDE, OPTIONS);

  assertTrue(loader.handles(httpUri));
  verify(urlLoader)
      .buildLoadData(eq(new GlideUrl(httpUri.toString())), eq(IMAGE_SIDE), eq(IMAGE_SIDE),
          eq(OPTIONS));
}
 
Example 13
Project: GitHub   File: HttpUriLoaderTest.java   View source code 5 votes vote down vote up
@Test
public void testHandlesHttpsUris() throws MalformedURLException {
  Uri httpsUri = Uri.parse("https://www.google.com");
  loader.buildLoadData(httpsUri, IMAGE_SIDE, IMAGE_SIDE, OPTIONS);

  assertTrue(loader.handles(httpsUri));
  verify(urlLoader)
      .buildLoadData(eq(new GlideUrl(httpsUri.toString())), eq(IMAGE_SIDE), eq(IMAGE_SIDE),
          eq(OPTIONS));
}
 
Example 14
Project: GitHub   File: HttpUriLoaderTest.java   View source code 5 votes vote down vote up
@Test
public void testHandlesMostlyInvalidHttpUris() {
  Uri mostlyInvalidHttpUri = Uri.parse(
      "http://myserver_url.com:80http://myserver_url.com/webapp/images/no_image.png?size=100");

  assertTrue(loader.handles(mostlyInvalidHttpUri));
  loader.buildLoadData(mostlyInvalidHttpUri, IMAGE_SIDE, IMAGE_SIDE, OPTIONS);
  verify(urlLoader)
      .buildLoadData(eq(new GlideUrl(mostlyInvalidHttpUri.toString())), eq(IMAGE_SIDE),
          eq(IMAGE_SIDE), eq(OPTIONS));
}
 
Example 15
Project: RetroMusicPlayer   File: ArtistImageFetcher.java   View source code 5 votes vote down vote up
public ArtistImageFetcher(Context context, LastFMRestClient lastFMRestClient, ArtistImage model, ModelLoader<GlideUrl, InputStream> urlLoader, int width, int height) {
    this.context = context;
    this.lastFMRestClient = lastFMRestClient;
    this.model = model;
    this.urlLoader = urlLoader;
    this.width = width;
    this.height = height;
}
 
Example 16
Project: GitHub   File: BaseGlideUrlLoader.java   View source code 5 votes vote down vote up
private static List<Key> getAlternateKeys(List<String> alternateUrls) {
  List<Key> result = new ArrayList<>(alternateUrls.size());
  for (String alternate : alternateUrls) {
    result.add(new GlideUrl(alternate));
  }
  return result;
}
 
Example 17
Project: GitHub   File: HttpUriLoaderTest.java   View source code 5 votes vote down vote up
@Test
public void testHandlesHttpUris() throws MalformedURLException {
  Uri httpUri = Uri.parse("http://www.google.com");
  loader.buildLoadData(httpUri, IMAGE_SIDE, IMAGE_SIDE, OPTIONS);

  assertTrue(loader.handles(httpUri));
  verify(urlLoader)
      .buildLoadData(eq(new GlideUrl(httpUri.toString())), eq(IMAGE_SIDE), eq(IMAGE_SIDE),
          eq(OPTIONS));
}
 
Example 18
Project: GitHub   File: OkHttpUrlLoader.java   View source code 4 votes vote down vote up
@Override
public boolean handles(GlideUrl url) {
  return true;
}
 
Example 19
Project: GitHub   File: OkHttpUrlLoader.java   View source code 4 votes vote down vote up
@Override
public LoadData<InputStream> buildLoadData(GlideUrl model, int width, int height,
    Options options) {
  return new LoadData<>(model, new OkHttpStreamFetcher(client, model));
}
 
Example 20
Project: garras   File: PixelsModelLoader.java   View source code 4 votes vote down vote up
@Override
public ModelLoader<String, InputStream> build(MultiModelLoaderFactory multiFactory) {
    return new PixelsModelLoader(multiFactory.build(GlideUrl.class, InputStream.class), urlCache);
}
 
Example 21
Project: GitHub   File: OkHttpStreamFetcher.java   View source code 4 votes vote down vote up
public OkHttpStreamFetcher(OkHttpClient client, GlideUrl url) {
  this.client = client;
  this.url = url;
}
 
Example 22
Project: GitHub   File: OkHttpGlideModule.java   View source code 4 votes vote down vote up
@Override
public void registerComponents(Context context, Registry registry) {
  registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
}
 
Example 23
Project: FastAndroid   File: OkHttpUrlLoader.java   View source code 4 votes vote down vote up
@Override
public boolean handles(GlideUrl url) {
    return true;
}
 
Example 24
Project: FastAndroid   File: OkHttpUrlLoader.java   View source code 4 votes vote down vote up
@Override
public LoadData<InputStream> buildLoadData(GlideUrl model, int width, int height,Options options) {
    return new LoadData<>(model, new OkHttpStreamFetcher(client, model));
}
 
Example 25
Project: GitHub   File: OkHttpUrlLoader.java   View source code 4 votes vote down vote up
@Override
public LoadData<InputStream> buildLoadData(GlideUrl model, int width, int height,
    Options options) {
  return new LoadData<>(model, new OkHttpStreamFetcher(client, model));
}
 
Example 26
Project: GitHub   File: OkHttpUrlLoader.java   View source code 4 votes vote down vote up
@Override
public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory multiFactory) {
  return new OkHttpUrlLoader(client);
}
 
Example 27
Project: NeiHanDuanZiTV   File: OkHttpUrlLoader.java   View source code 4 votes vote down vote up
@Override
public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory multiFactory) {
    return new OkHttpUrlLoader(client);
}
 
Example 28
Project: GitHub   File: OkHttpGlideModule.java   View source code 4 votes vote down vote up
@Override
public void registerComponents(Context context, Registry registry) {
  registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
}
 
Example 29
Project: GitHub   File: OkHttpLibraryGlideModule.java   View source code 4 votes vote down vote up
@Override
public void registerComponents(Context context, Registry registry) {
  registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
}
 
Example 30
Project: GitHub   File: VolleyUrlLoader.java   View source code 4 votes vote down vote up
@Override
public boolean handles(GlideUrl url) {
  return true;
}
 
Example 31
Project: lrs_android   File: MyGlideModuleConfig.java   View source code 4 votes vote down vote up
@Override
public void registerComponents(Context context, Glide glide) {
    //glide.clearDiskCache();
    glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
    glide.setMemoryCategory(MemoryCategory.NORMAL);
}
 
Example 32
Project: GitHub   File: VolleyLibraryGlideModule.java   View source code 4 votes vote down vote up
@Override
public void registerComponents(Context context, Registry registry) {
  registry.replace(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(context));
}
 
Example 33
Project: GitHub   File: VolleyGlideModule.java   View source code 4 votes vote down vote up
@Override
public void registerComponents(Context context, Registry registry) {
  registry.replace(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(context));
}
 
Example 34
Project: GitHub   File: VolleyStreamFetcher.java   View source code 4 votes vote down vote up
@SuppressWarnings("unused")
public VolleyStreamFetcher(RequestQueue requestQueue, GlideUrl url) {
  this(requestQueue, url, DEFAULT_REQUEST_FACTORY);
}
 
Example 35
Project: GitHub   File: VolleyStreamFetcher.java   View source code 4 votes vote down vote up
public VolleyStreamFetcher(RequestQueue requestQueue, GlideUrl url,
    VolleyRequestFactory requestFactory) {
  this.requestQueue = requestQueue;
  this.url = url;
  this.requestFactory = requestFactory;
}
 
Example 36
Project: GitHub   File: VolleyStreamFetcherServerTest.java   View source code 4 votes vote down vote up
private DataFetcher<InputStream> getFetcher(Headers headers) {
  URL url = mockWebServer.url(DEFAULT_PATH).url();
  return new VolleyStreamFetcher(requestQueue, new GlideUrl(url.toString(), headers));
}
 
Example 37
Project: MoligyMvpArms   File: OkHttpStreamFetcher.java   View source code 4 votes vote down vote up
public OkHttpStreamFetcher(Call.Factory client, GlideUrl url) {
    this.client = client;
    this.url = url;
}
 
Example 38
Project: GitHub   File: FlickrModelLoader.java   View source code 4 votes vote down vote up
@Override
public ModelLoader<Photo, InputStream> build(MultiModelLoaderFactory multiFactory) {
  return new FlickrModelLoader(multiFactory.build(GlideUrl.class, InputStream.class),
      modelCache);
}
 
Example 39
Project: AndroidModulePattern   File: OkHttpStreamFetcher.java   View source code 4 votes vote down vote up
public OkHttpStreamFetcher(OkHttpClient client, GlideUrl url) {
    this.client = client;
    this.url = url;
}
 
Example 40
Project: ProgressManager   File: GlideConfiguration.java   View source code 4 votes vote down vote up
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
    BaseApplication application = (BaseApplication) context.getApplicationContext();
    //Glide 底层默认使用 HttpConnection 进行网络请求,这里替换为 Okhttp 后才能使用本框架,进行 Glide 的加载进度监听
    registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(application.getOkHttpClient()));
}