Java 类com.squareup.picasso.Downloader.Response 实例源码

项目:mc_backup    文件:ImageLoader.java   
@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);
}
项目:mc_backup    文件:ImageLoader.java   
/**
 * 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");
}
项目:android-gluten    文件:TracedPicassoDownloaderTest.java   
@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());
}
项目:android-gluten    文件:TracedPicassoDownloaderTest.java   
@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());
}