Java 类com.bumptech.glide.load.model.GlideUrl 实例源码

项目:GitHub    文件:BaseGlideUrlLoaderTest.java   
@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);
}
项目:GitHub    文件:HttpGlideUrlLoader.java   
@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));
}
项目:GitHub    文件:BaseGlideUrlLoaderTest.java   
@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);
}
项目:GitHub    文件:BaseGlideUrlLoaderTest.java   
@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));
}
项目:GitHub    文件:BaseGlideUrlLoaderTest.java   
@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);
}
项目:react-native-fast-image    文件:OkHttpProgressGlideModule.java   
@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));
}
项目:OSchina_resources_android    文件:AppOperator.java   
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);
    }
}
项目:youkes_browser    文件:GlideUtil.java   
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);

}
项目:GitHub    文件:GlideTest.java   
@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);
}
项目:GitHub    文件:BaseGlideUrlLoaderTest.java   
@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);
}
项目:garras    文件:GlideProgressSupport.java   
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()));
}
项目:GitHub    文件:HttpUriLoaderTest.java   
@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));
}
项目:GitHub    文件:HttpUriLoaderTest.java   
@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));
}
项目:GitHub    文件:HttpUriLoaderTest.java   
@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));
}
项目:RetroMusicPlayer    文件:ArtistImageFetcher.java   
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;
}
项目:GitHub    文件:BaseGlideUrlLoader.java   
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;
}
项目:GitHub    文件:HttpUriLoaderTest.java   
@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));
}
项目:GitHub    文件:OkHttpUrlLoader.java   
@Override
public boolean handles(GlideUrl url) {
  return true;
}
项目:GitHub    文件:OkHttpUrlLoader.java   
@Override
public LoadData<InputStream> buildLoadData(GlideUrl model, int width, int height,
    Options options) {
  return new LoadData<>(model, new OkHttpStreamFetcher(client, model));
}
项目:garras    文件:PixelsModelLoader.java   
@Override
public ModelLoader<String, InputStream> build(MultiModelLoaderFactory multiFactory) {
    return new PixelsModelLoader(multiFactory.build(GlideUrl.class, InputStream.class), urlCache);
}
项目:GitHub    文件:OkHttpStreamFetcher.java   
public OkHttpStreamFetcher(OkHttpClient client, GlideUrl url) {
  this.client = client;
  this.url = url;
}
项目:GitHub    文件:OkHttpGlideModule.java   
@Override
public void registerComponents(Context context, Registry registry) {
  registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
}
项目:FastAndroid    文件:OkHttpUrlLoader.java   
@Override
public boolean handles(GlideUrl url) {
    return true;
}
项目:FastAndroid    文件:OkHttpUrlLoader.java   
@Override
public LoadData<InputStream> buildLoadData(GlideUrl model, int width, int height,Options options) {
    return new LoadData<>(model, new OkHttpStreamFetcher(client, model));
}
项目:GitHub    文件:OkHttpUrlLoader.java   
@Override
public LoadData<InputStream> buildLoadData(GlideUrl model, int width, int height,
    Options options) {
  return new LoadData<>(model, new OkHttpStreamFetcher(client, model));
}
项目:GitHub    文件:OkHttpUrlLoader.java   
@Override
public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory multiFactory) {
  return new OkHttpUrlLoader(client);
}
项目:NeiHanDuanZiTV    文件:OkHttpUrlLoader.java   
@Override
public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory multiFactory) {
    return new OkHttpUrlLoader(client);
}
项目:GitHub    文件:OkHttpGlideModule.java   
@Override
public void registerComponents(Context context, Registry registry) {
  registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
}
项目:GitHub    文件:OkHttpLibraryGlideModule.java   
@Override
public void registerComponents(Context context, Registry registry) {
  registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
}
项目:GitHub    文件:VolleyUrlLoader.java   
@Override
public boolean handles(GlideUrl url) {
  return true;
}
项目:lrs_android    文件:MyGlideModuleConfig.java   
@Override
public void registerComponents(Context context, Glide glide) {
    //glide.clearDiskCache();
    glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
    glide.setMemoryCategory(MemoryCategory.NORMAL);
}
项目:GitHub    文件:VolleyLibraryGlideModule.java   
@Override
public void registerComponents(Context context, Registry registry) {
  registry.replace(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(context));
}
项目:GitHub    文件:VolleyGlideModule.java   
@Override
public void registerComponents(Context context, Registry registry) {
  registry.replace(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(context));
}
项目:GitHub    文件:VolleyStreamFetcher.java   
@SuppressWarnings("unused")
public VolleyStreamFetcher(RequestQueue requestQueue, GlideUrl url) {
  this(requestQueue, url, DEFAULT_REQUEST_FACTORY);
}
项目:GitHub    文件:VolleyStreamFetcher.java   
public VolleyStreamFetcher(RequestQueue requestQueue, GlideUrl url,
    VolleyRequestFactory requestFactory) {
  this.requestQueue = requestQueue;
  this.url = url;
  this.requestFactory = requestFactory;
}
项目:GitHub    文件:VolleyStreamFetcherServerTest.java   
private DataFetcher<InputStream> getFetcher(Headers headers) {
  URL url = mockWebServer.url(DEFAULT_PATH).url();
  return new VolleyStreamFetcher(requestQueue, new GlideUrl(url.toString(), headers));
}
项目:MoligyMvpArms    文件:OkHttpStreamFetcher.java   
public OkHttpStreamFetcher(Call.Factory client, GlideUrl url) {
    this.client = client;
    this.url = url;
}
项目:GitHub    文件:FlickrModelLoader.java   
@Override
public ModelLoader<Photo, InputStream> build(MultiModelLoaderFactory multiFactory) {
  return new FlickrModelLoader(multiFactory.build(GlideUrl.class, InputStream.class),
      modelCache);
}
项目:AndroidModulePattern    文件:OkHttpStreamFetcher.java   
public OkHttpStreamFetcher(OkHttpClient client, GlideUrl url) {
    this.client = client;
    this.url = url;
}
项目:ProgressManager    文件:GlideConfiguration.java   
@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()));
}