本文整理汇总了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();
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
示例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");
}
}
示例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;
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例12: ActivityModule
import com.squareup.picasso.Downloader; //导入依赖的package包/类
public ActivityModule(Activity activity, Downloader okHttpDownloader) {
this.activity = activity;
this.okHttpDownloader = okHttpDownloader;
}
示例13: TracedPicassoDownloader
import com.squareup.picasso.Downloader; //导入依赖的package包/类
public TracedPicassoDownloader(Tracer tracer, Downloader downloader) {
this.tracer = tracer;
this.downloader = downloader;
}
示例14: create
import com.squareup.picasso.Downloader; //导入依赖的package包/类
static Downloader create(Context context) {
return new OkHttpDownloader(context);
}
示例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);
}