use MultiSourceHelper in PhotoViewer

Reviewed By: andreicoman11

Differential Revision: D3509011

fbshipit-source-id: 96fe96f28da24efb00b98589cea28e6c9cfc7180
This commit is contained in:
Felix Oghina 2016-07-01 10:46:11 -07:00 committed by Facebook Github Bot 8
parent 2ce76771b5
commit adea8d5fc9
1 changed files with 13 additions and 2 deletions

View File

@ -51,17 +51,28 @@ public class MultiSourceHelper {
} }
} }
public static MultiSourceResult getBestSourceForSize(
int width,
int height,
List<ImageSource> sources) {
return getBestSourceForSize(width, height, sources, 1.0d);
}
/** /**
* Chooses the image source with the size closest to the target image size. * Chooses the image source with the size closest to the target image size.
* *
* @param width the width of the view that will be used to display this image * @param width the width of the view that will be used to display this image
* @param height the height of the view that will be used to display this image * @param height the height of the view that will be used to display this image
* @param sources the list of potential image sources to choose from * @param sources the list of potential image sources to choose from
* @param multiplier the area of the view will be multiplied by this number before calculating the
* best source; this is useful if the image will be displayed bigger than the view
* (e.g. zoomed)
*/ */
public static MultiSourceResult getBestSourceForSize( public static MultiSourceResult getBestSourceForSize(
int width, int width,
int height, int height,
List<ImageSource> sources) { List<ImageSource> sources,
double multiplier) {
// no sources // no sources
if (sources.isEmpty()) { if (sources.isEmpty()) {
return new MultiSourceResult(null, null); return new MultiSourceResult(null, null);
@ -81,7 +92,7 @@ public class MultiSourceHelper {
ImagePipeline imagePipeline = ImagePipelineFactory.getInstance().getImagePipeline(); ImagePipeline imagePipeline = ImagePipelineFactory.getInstance().getImagePipeline();
ImageSource best = null; ImageSource best = null;
ImageSource bestCached = null; ImageSource bestCached = null;
final double viewArea = width * height; final double viewArea = width * height * multiplier;
double bestPrecision = Double.MAX_VALUE; double bestPrecision = Double.MAX_VALUE;
double bestCachePrecision = Double.MAX_VALUE; double bestCachePrecision = Double.MAX_VALUE;
for (ImageSource source : sources) { for (ImageSource source : sources) {