当前位置: 首页>>代码示例>>Java>>正文


Java Downloader类代码示例

本文整理汇总了Java中com.squareup.picasso.Downloader的典型用法代码示例。如果您正苦于以下问题:Java Downloader类的具体用法?Java Downloader怎么用?Java Downloader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Downloader类属于com.squareup.picasso包,在下文中一共展示了Downloader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: networkPolicyNoCache

import com.squareup.picasso.Downloader; //导入依赖的package包/类
@Test public void networkPolicyNoCache() throws Exception {
  MockResponse response =
      new MockResponse().setHeader("Cache-Control", "max-age=31536000").setBody("Hi");
  server.enqueue(response);

  Downloader.Response response1 = downloader.load(uri, 0);
  assertThat((Boolean) cached.get(response1)).isFalse();
  // Exhaust input stream to ensure response is cached.
  Okio.buffer(Okio.source(response1.getInputStream())).readByteArray();

  // Enqueue the same response again but this time use NetworkPolicy.NO_CACHE.
  server.enqueue(response);

  Downloader.Response response2 = downloader.load(uri, NO_CACHE);
  // Response should not be coming from cache even if it was cached previously.
  assertThat((Boolean) cached.get(response2)).isFalse();
}
 
开发者ID:JakeWharton,项目名称:picasso2-okhttp3-downloader,代码行数:18,代码来源:OkHttp3DownloaderTest.java

示例2: build

import com.squareup.picasso.Downloader; //导入依赖的package包/类
/**
 * 构建Picasso Downloader
 *
 * @param context
 * @param downloader
 */
public static void build(Context context, Downloader downloader) {
    Picasso picasso = new Picasso.Builder(context)
            .downloader(downloader)
            .build();
    Picasso.setSingletonInstance(picasso);
}
 
开发者ID:Jay-Y,项目名称:yApp,代码行数:13,代码来源:ImageLoader.java

示例3: setUp

import com.squareup.picasso.Downloader; //导入依赖的package包/类
@Before public void setUp() throws Exception {
  downloader = new OkHttp3Downloader(temporaryFolder.getRoot());
  uri = Uri.parse(server.url("/").toString());

  cached = Downloader.Response.class.getDeclaredField("cached");
  cached.setAccessible(true);
}
 
开发者ID:JakeWharton,项目名称:picasso2-okhttp3-downloader,代码行数:8,代码来源:OkHttp3DownloaderTest.java

示例4: cachedResponse

import com.squareup.picasso.Downloader; //导入依赖的package包/类
@Test public void cachedResponse() throws Exception {
  server.enqueue(new MockResponse()
      .setHeader("Cache-Control", "max-age=31536000")
      .setBody("Hi"));

  Downloader.Response response1 = downloader.load(uri, 0);
  assertThat((Boolean) cached.get(response1)).isFalse();
  // Exhaust input stream to ensure response is cached.
  Okio.buffer(Okio.source(response1.getInputStream())).readByteArray();

  Downloader.Response response2 = downloader.load(uri, OFFLINE);
  assertThat((Boolean) cached.get(response2)).isTrue();
}
 
开发者ID:JakeWharton,项目名称:picasso2-okhttp3-downloader,代码行数:14,代码来源:OkHttp3DownloaderTest.java

示例5: offlineStaleResponse

import com.squareup.picasso.Downloader; //导入依赖的package包/类
@Test public void offlineStaleResponse() throws Exception {
  server.enqueue(new MockResponse()
      .setHeader("Cache-Control", "max-age=1")
      .setHeader("Expires", "Mon, 29 Dec 2014 21:44:55 GMT")
      .setBody("Hi"));

  Downloader.Response response1 = downloader.load(uri, 0);
  assertThat((Boolean) cached.get(response1)).isFalse();
  // Exhaust input stream to ensure response is cached.
  Okio.buffer(Okio.source(response1.getInputStream())).readByteArray();

  Downloader.Response response2 = downloader.load(uri, OFFLINE);
  assertThat((Boolean) cached.get(response2)).isTrue();
}
 
开发者ID:JakeWharton,项目名称:picasso2-okhttp3-downloader,代码行数:15,代码来源:OkHttp3DownloaderTest.java

示例6: throwsResponseException

import com.squareup.picasso.Downloader; //导入依赖的package包/类
@Test public void throwsResponseException() throws Exception {
  server.enqueue(new MockResponse().setStatus("HTTP/1.1 401 Not Authorized"));

  try {
    downloader.load(uri, 0);
    fail("Expected ResponseException.");
  } catch (Downloader.ResponseException e) {
    assertThat(e).hasMessage("401 Not Authorized");
  }
}
 
开发者ID:JakeWharton,项目名称:picasso2-okhttp3-downloader,代码行数:11,代码来源:OkHttp3DownloaderTest.java

示例7: doInBackground

import com.squareup.picasso.Downloader; //导入依赖的package包/类
@Override
protected byte[] doInBackground(Void... params) {
    try {
        // Grab an input stream to the image
        OkHttpDownloader downloader = new OkHttpDownloader(getContext());
        Downloader.Response response = downloader.load(Uri.parse(url), 0);

        // Read the image into a byte array
        return Okio.buffer(Okio.source(response.getInputStream())).readByteArray();
    } catch (Exception e) {
        Log.d(ImageFragment.class.getSimpleName(), "Error fetching image", e);
        return null;
    }
}
 
开发者ID:SteamGifts,项目名称:SteamGifts,代码行数:15,代码来源:ImageFragment.java

示例8: createCacheDownloader

import com.squareup.picasso.Downloader; //导入依赖的package包/类
public static Downloader createCacheDownloader(Context context) {
    try {
        Class.forName("com.squareup.okhttp.OkHttpClient");
        File cacheDir = createDefaultCacheDir(context, CACHE_PATH);
        long cacheSize = calculateDiskCacheSize(cacheDir);
        return new OkHttpDownloader(cacheDir, cacheSize);
    } catch (ClassNotFoundException e) {
        return new UrlConnectionDownloader(context);
    }
}
 
开发者ID:lkorth,项目名称:photo-paper,代码行数:11,代码来源:Cache.java

示例9: createDefaultDownloader

import com.squareup.picasso.Downloader; //导入依赖的package包/类
private static Downloader createDefaultDownloader(Context context) {
  try {
    Class.forName("com.squareup.okhttp.OkHttpClient");
    return OkHttpLoaderCreator.create(context);
  } catch (ClassNotFoundException e) {
    return new UrlConnectionDownloader(context);
  }
}
 
开发者ID:dpreussler,项目名称:android-gluten,代码行数:9,代码来源:TracedPicassoDownloader.java

示例10: onError

import com.squareup.picasso.Downloader; //导入依赖的package包/类
@Override
public void onError() {
	if (SadPandaApp.getLastException() instanceof Downloader.ResponseException) {
		mFailureText.setText(R.string.image_not_found);
	}
	else {
		mFailureText.setText(R.string.image_loading_failed);
	}

	mFailureText.setVisibility(View.VISIBLE);

	mLoadingBar.setVisibility(View.GONE);
}
 
开发者ID:Ecchilon,项目名称:SadPanda,代码行数:14,代码来源:ScreenSlidePageFragment.java

示例11: readsContentLengthHeader

import com.squareup.picasso.Downloader; //导入依赖的package包/类
@Test public void readsContentLengthHeader() throws Exception {
  server.enqueue(new MockResponse().addHeader("Content-Length", 1024));

  Downloader.Response response = downloader.load(uri, 0);
  assertThat(response.getContentLength()).isEqualTo(1024);
}
 
开发者ID:JakeWharton,项目名称:picasso2-okhttp3-downloader,代码行数:7,代码来源:OkHttp3DownloaderTest.java

示例12: ActivityModule

import com.squareup.picasso.Downloader; //导入依赖的package包/类
public ActivityModule(Activity activity, Downloader okHttpDownloader) {
    this.activity = activity;
    this.okHttpDownloader = okHttpDownloader;
}
 
开发者ID:pakoito,项目名称:SongkickInterview,代码行数:5,代码来源:ActivityModule.java

示例13: TracedPicassoDownloader

import com.squareup.picasso.Downloader; //导入依赖的package包/类
public TracedPicassoDownloader(Tracer tracer, Downloader downloader) {
    this.tracer = tracer;
    this.downloader = downloader;
}
 
开发者ID:dpreussler,项目名称:android-gluten,代码行数:5,代码来源:TracedPicassoDownloader.java

示例14: create

import com.squareup.picasso.Downloader; //导入依赖的package包/类
static Downloader create(Context context) {
  return new OkHttpDownloader(context);
}
 
开发者ID:dpreussler,项目名称:android-gluten,代码行数:4,代码来源:TracedPicassoDownloader.java

示例15: setup

import com.squareup.picasso.Downloader; //导入依赖的package包/类
@Before
public void setup() {
    tracer = mock(Tracer.class);
    downloader = mock(Downloader.class);
    tested = new TracedPicassoDownloader(tracer, downloader);
}
 
开发者ID:dpreussler,项目名称:android-gluten,代码行数:7,代码来源:TracedPicassoDownloaderTest.java


注:本文中的com.squareup.picasso.Downloader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。