ImageLoader.java 文件源码

java
阅读 34 收藏 0 点赞 0 评论 0

项目:mc_backup 作者:
/**
 * 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");
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号