java类com.squareup.picasso.Downloader.Response的实例源码

ImageLoader.java 文件源码 项目:mc_backup 阅读 30 收藏 0 点赞 0 评论 0
@Override
public Response load(Uri uri, boolean localCacheOnly) throws IOException {
    final String scheme = uri.getScheme();
    if (DISTRIBUTION_SCHEME.equals(scheme)) {
        return loadDistributionImage(uri);
    }

    return super.load(uri, localCacheOnly);
}
ImageLoader.java 文件源码 项目:mc_backup 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Handle distribution URIs in Picasso. The expected format is:
 *
 *   gecko.distribution://<basepath>/<imagename>
 *
 * Which will look for the following file in the distribution:
 *
 *   <distribution-root-dir>/<basepath>/<device-density>/<imagename>.png
 */
private Response loadDistributionImage(Uri uri) throws IOException {
    // Eliminate the leading '//'
    final String ssp = uri.getSchemeSpecificPart().substring(2);

    final String filename;
    final String basePath;

    final int slashIndex = ssp.lastIndexOf('/');
    if (slashIndex == -1) {
        filename = ssp;
        basePath = "";
    } else {
        filename = ssp.substring(slashIndex + 1);
        basePath = ssp.substring(0, slashIndex);
    }

    Set<Density> triedDensities = EnumSet.noneOf(Density.class);

    for (int i = 0; i < densityFactors.length; i++) {
        final Density density = getDensity(densityFactors[i]);
        if (!triedDensities.add(density)) {
            continue;
        }

        final String path = getPathForDensity(basePath, density, filename);
        Log.d(LOGTAG, "Trying to load image from distribution " + path);

        final File f = distribution.getDistributionFile(path);
        if (f != null) {
            return new Response(new FileInputStream(f), true);
        }
    }

    throw new ResponseException("Couldn't find suggested site image in distribution");
}
TracedPicassoDownloaderTest.java 文件源码 项目:android-gluten 阅读 20 收藏 0 点赞 0 评论 0
@Test
public void should_report_time_spent() throws IOException {
    when(downloader.load(any(Uri.class), anyBoolean())).thenReturn(mock(Response.class));
    long before = new Date().getTime();
    tested.load(mock(Uri.class), false);
    verify(tracer).trace(anyString(), anyInt(), longThat(greaterThanOrEqualTo(before)), anyLong(), anyLong(), anyLong());
}
TracedPicassoDownloaderTest.java 文件源码 项目:android-gluten 阅读 18 收藏 0 点赞 0 评论 0
@Test
public void should_report_status_code_and_url() throws IOException {
    when(downloader.load(any(Uri.class), anyBoolean())).thenReturn(mock(Response.class));
    tested.load(Uri.parse("http://jodamob.de"), false);
    verify(tracer).trace(eq("http://jodamob.de"), eq(200), anyLong(), anyLong(), anyLong(), anyLong());
}


问题


面经


文章

微信
公众号

扫码关注公众号