Java 类com.facebook.react.views.imagehelper.ImageSource 实例源码

项目:Ironman    文件:ReactImageView.java   
public void setSource(@Nullable ReadableArray sources) {
  mSources.clear();
  if (sources != null && sources.size() != 0) {
    // Optimize for the case where we have just one uri, case in which we don't need the sizes
    if (sources.size() == 1) {
      mSources.add(new ImageSource(getContext(), sources.getMap(0).getString("uri")));
    } else {
      for (int idx = 0; idx < sources.size(); idx++) {
        ReadableMap source = sources.getMap(idx);
        mSources.add(new ImageSource(
          getContext(),
          source.getString("uri"),
          source.getDouble("width"),
          source.getDouble("height")));
      }
    }
  }
  mIsDirty = true;
}
项目:RNLearn_Project1    文件:RCTTextInlineImage.java   
@ReactProp(name = "src")
public void setSource(@Nullable ReadableArray sources) {
  final String source =
      (sources == null || sources.size() == 0) ? null : sources.getMap(0).getString("uri");
  final ImageSource imageSource = source == null ? null :
      new ImageSource(getThemedContext(), source);
  getMutableSpan().setImageRequest(imageSource == null ? null :
      ImageRequestBuilder.newBuilderWithSource(imageSource.getUri()).build());
}
项目:RNLearn_Project1    文件:DrawImageWithDrawee.java   
private static boolean shouldResize(ImageSource imageSource) {
  // Resizing is inferior to scaling. See http://frescolib.org/docs/resizing-rotating.html
  // We resize here only for images likely to be from the device's camera, where the app developer
  // has no control over the original size
  Uri uri = imageSource.getUri();
  String type = uri == null ? null : uri.getScheme();
  // one day, we can replace this with what non-Nodes does, which is:
  // UriUtil.isLocalContentUri || UriUtil.isLocalFileUri
  // not doing this just to save including eyt another BUCK dependency
  return LOCAL_FILE_SCHEME.equals(type) || LOCAL_CONTENT_SCHEME.equals(type);
}
项目:RNLearn_Project1    文件:ReactImageView.java   
private boolean shouldResize(ImageSource imageSource) {
  // Resizing is inferior to scaling. See http://frescolib.org/docs/resizing-rotating.html#_
  // We resize here only for images likely to be from the device's camera, where the app developer
  // has no control over the original size
  if (mResizeMethod == ImageResizeMethod.AUTO) {
    return
      UriUtil.isLocalContentUri(imageSource.getUri()) ||
      UriUtil.isLocalFileUri(imageSource.getUri());
  } else if (mResizeMethod == ImageResizeMethod.RESIZE) {
    return true;
  } else {
    return false;
  }
}
项目:RNLearn_Project1    文件:RCTTextInlineImage.java   
@ReactProp(name = "src")
public void setSource(@Nullable ReadableArray sources) {
  final String source =
      (sources == null || sources.size() == 0) ? null : sources.getMap(0).getString("uri");
  final ImageSource imageSource = source == null ? null :
      new ImageSource(getThemedContext(), source);
  getMutableSpan().setImageRequest(imageSource == null ? null :
      ImageRequestBuilder.newBuilderWithSource(imageSource.getUri()).build());
}
项目:RNLearn_Project1    文件:DrawImageWithDrawee.java   
private static boolean shouldResize(ImageSource imageSource) {
  // Resizing is inferior to scaling. See http://frescolib.org/docs/resizing-rotating.html
  // We resize here only for images likely to be from the device's camera, where the app developer
  // has no control over the original size
  Uri uri = imageSource.getUri();
  String type = uri == null ? null : uri.getScheme();
  // one day, we can replace this with what non-Nodes does, which is:
  // UriUtil.isLocalContentUri || UriUtil.isLocalFileUri
  // not doing this just to save including eyt another BUCK dependency
  return LOCAL_FILE_SCHEME.equals(type) || LOCAL_CONTENT_SCHEME.equals(type);
}
项目:RNLearn_Project1    文件:ReactImageView.java   
private boolean shouldResize(ImageSource imageSource) {
  // Resizing is inferior to scaling. See http://frescolib.org/docs/resizing-rotating.html#_
  // We resize here only for images likely to be from the device's camera, where the app developer
  // has no control over the original size
  if (mResizeMethod == ImageResizeMethod.AUTO) {
    return
      UriUtil.isLocalContentUri(imageSource.getUri()) ||
      UriUtil.isLocalFileUri(imageSource.getUri());
  } else if (mResizeMethod == ImageResizeMethod.RESIZE) {
    return true;
  } else {
    return false;
  }
}
项目:react-native-sparkbutton    文件:RNSparkButton.java   
public void setActiveImageSource(@Nullable ReadableMap source) {
    this.activeImageSource = null;

    if (source != null) {
        String uri = source.getString("uri");
        this.activeImageSource = new ImageSource(getContext(), uri);
    }

    this.isDirty = true;
}
项目:react-native-sparkbutton    文件:RNSparkButton.java   
public void setInactiveImageSource(@Nullable ReadableMap source) {
    this.inactiveImageSource = null;

    if (source != null) {
        String uri = source.getString("uri");
        this.inactiveImageSource = new ImageSource(getContext(), uri);
    }

    this.isDirty = true;
}
项目:Ironman    文件:ReactImageView.java   
private boolean shouldResize(ImageSource imageSource) {
  // Resizing is inferior to scaling. See http://frescolib.org/docs/resizing-rotating.html#_
  // We resize here only for images likely to be from the device's camera, where the app developer
  // has no control over the original size
  if (mResizeMethod == ImageResizeMethod.AUTO) {
    return
      UriUtil.isLocalContentUri(imageSource.getUri()) ||
      UriUtil.isLocalFileUri(imageSource.getUri());
  } else if (mResizeMethod == ImageResizeMethod.RESIZE) {
    return true;
  } else {
    return false;
  }
}
项目:RNLearn_Project1    文件:MultiSourceHelper.java   
private MultiSourceResult(
  @Nullable ImageSource bestResult,
  @Nullable ImageSource bestResultInCache) {
  this.bestResult = bestResult;
  this.bestResultInCache = bestResultInCache;
}
项目:RNLearn_Project1    文件:MultiSourceHelper.java   
public static MultiSourceResult getBestSourceForSize(
  int width,
  int height,
  List<ImageSource> sources) {
  return getBestSourceForSize(width, height, sources, 1.0d);
}
项目:RNLearn_Project1    文件:MultiSourceHelper.java   
/**
 * 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 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 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(
  int width,
  int height,
  List<ImageSource> sources,
  double multiplier) {
  // no sources
  if (sources.isEmpty()) {
    return new MultiSourceResult(null, null);
  }

  // single source
  if (sources.size() == 1) {
    return new MultiSourceResult(sources.get(0), null);
  }

  // For multiple sources, we first need the view's size in order to determine the best source to
  // load. If we haven't been measured yet, return null and wait for onSizeChanged.
  if (width <= 0 || height <= 0) {
    return new MultiSourceResult(null, null);
  }

  ImagePipeline imagePipeline = ImagePipelineFactory.getInstance().getImagePipeline();
  ImageSource best = null;
  ImageSource bestCached = null;
  final double viewArea = width * height * multiplier;
  double bestPrecision = Double.MAX_VALUE;
  double bestCachePrecision = Double.MAX_VALUE;
  for (ImageSource source : sources) {
    double precision = Math.abs(1.0 - source.getSize() / viewArea);
    if (precision < bestPrecision) {
      bestPrecision = precision;
      best = source;
    }
    if (precision < bestCachePrecision &&
      (imagePipeline.isInBitmapMemoryCache(source.getUri()) ||
        imagePipeline.isInDiskCacheSync(source.getUri()))) {
      bestCachePrecision = precision;
      bestCached = source;
    }
  }
  if (bestCached != null && best != null && bestCached.getSource().equals(best.getSource())) {
    bestCached = null;
  }
  return new MultiSourceResult(best, bestCached);
}
项目:RNLearn_Project1    文件:MultiSourceHelper.java   
private MultiSourceResult(
  @Nullable ImageSource bestResult,
  @Nullable ImageSource bestResultInCache) {
  this.bestResult = bestResult;
  this.bestResultInCache = bestResultInCache;
}
项目:RNLearn_Project1    文件:MultiSourceHelper.java   
public static MultiSourceResult getBestSourceForSize(
  int width,
  int height,
  List<ImageSource> sources) {
  return getBestSourceForSize(width, height, sources, 1.0d);
}
项目:RNLearn_Project1    文件:MultiSourceHelper.java   
/**
 * 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 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 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(
  int width,
  int height,
  List<ImageSource> sources,
  double multiplier) {
  // no sources
  if (sources.isEmpty()) {
    return new MultiSourceResult(null, null);
  }

  // single source
  if (sources.size() == 1) {
    return new MultiSourceResult(sources.get(0), null);
  }

  // For multiple sources, we first need the view's size in order to determine the best source to
  // load. If we haven't been measured yet, return null and wait for onSizeChanged.
  if (width <= 0 || height <= 0) {
    return new MultiSourceResult(null, null);
  }

  ImagePipeline imagePipeline = ImagePipelineFactory.getInstance().getImagePipeline();
  ImageSource best = null;
  ImageSource bestCached = null;
  final double viewArea = width * height * multiplier;
  double bestPrecision = Double.MAX_VALUE;
  double bestCachePrecision = Double.MAX_VALUE;
  for (ImageSource source : sources) {
    double precision = Math.abs(1.0 - source.getSize() / viewArea);
    if (precision < bestPrecision) {
      bestPrecision = precision;
      best = source;
    }
    if (precision < bestCachePrecision &&
      (imagePipeline.isInBitmapMemoryCache(source.getUri()) ||
        imagePipeline.isInDiskCacheSync(source.getUri()))) {
      bestCachePrecision = precision;
      bestCached = source;
    }
  }
  if (bestCached != null && best != null && bestCached.getSource().equals(best.getSource())) {
    bestCached = null;
  }
  return new MultiSourceResult(best, bestCached);
}
项目:Ironman    文件:MultiSourceHelper.java   
private MultiSourceResult(
  @Nullable ImageSource bestResult,
  @Nullable ImageSource bestResultInCache) {
  this.bestResult = bestResult;
  this.bestResultInCache = bestResultInCache;
}
项目:Ironman    文件:MultiSourceHelper.java   
public static MultiSourceResult getBestSourceForSize(
  int width,
  int height,
  List<ImageSource> sources) {
  return getBestSourceForSize(width, height, sources, 1.0d);
}
项目:Ironman    文件:MultiSourceHelper.java   
/**
 * 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 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 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(
  int width,
  int height,
  List<ImageSource> sources,
  double multiplier) {
  // no sources
  if (sources.isEmpty()) {
    return new MultiSourceResult(null, null);
  }

  // single source
  if (sources.size() == 1) {
    return new MultiSourceResult(sources.get(0), null);
  }

  // For multiple sources, we first need the view's size in order to determine the best source to
  // load. If we haven't been measured yet, return null and wait for onSizeChanged.
  if (width <= 0 || height <= 0) {
    return new MultiSourceResult(null, null);
  }

  ImagePipeline imagePipeline = ImagePipelineFactory.getInstance().getImagePipeline();
  ImageSource best = null;
  ImageSource bestCached = null;
  final double viewArea = width * height * multiplier;
  double bestPrecision = Double.MAX_VALUE;
  double bestCachePrecision = Double.MAX_VALUE;
  for (ImageSource source : sources) {
    double precision = Math.abs(1.0 - source.getSize() / viewArea);
    if (precision < bestPrecision) {
      bestPrecision = precision;
      best = source;
    }
    if (precision < bestCachePrecision &&
      (imagePipeline.isInBitmapMemoryCache(source.getUri()) ||
        imagePipeline.isInDiskCacheSync(source.getUri()))) {
      bestCachePrecision = precision;
      bestCached = source;
    }
  }
  if (bestCached != null && best != null && bestCached.getSource().equals(best.getSource())) {
    bestCached = null;
  }
  return new MultiSourceResult(best, bestCached);
}
项目:RNLearn_Project1    文件:MultiSourceHelper.java   
/**
 * Get the best result overall (closest in size to the view's size). Can be null if there were
 * no sources to choose from, or if there were more than 1 sources but width/height were 0.
 */
public @Nullable ImageSource getBestResult() {
  return bestResult;
}
项目:RNLearn_Project1    文件:MultiSourceHelper.java   
/**
 * Get the best result (closest in size to the view's size) that is also in cache. If this would
 * be the same as the source from {@link #getBestResult()}, this will return {@code null}
 * instead.
 */
public @Nullable ImageSource getBestResultInCache() {
  return bestResultInCache;
}
项目:RNLearn_Project1    文件:MultiSourceHelper.java   
/**
 * Get the best result overall (closest in size to the view's size). Can be null if there were
 * no sources to choose from, or if there were more than 1 sources but width/height were 0.
 */
public @Nullable ImageSource getBestResult() {
  return bestResult;
}
项目:RNLearn_Project1    文件:MultiSourceHelper.java   
/**
 * Get the best result (closest in size to the view's size) that is also in cache. If this would
 * be the same as the source from {@link #getBestResult()}, this will return {@code null}
 * instead.
 */
public @Nullable ImageSource getBestResultInCache() {
  return bestResultInCache;
}
项目:Ironman    文件:MultiSourceHelper.java   
/**
 * Get the best result overall (closest in size to the view's size). Can be null if there were
 * no sources to choose from, or if there were more than 1 sources but width/height were 0.
 */
public @Nullable ImageSource getBestResult() {
  return bestResult;
}
项目:Ironman    文件:MultiSourceHelper.java   
/**
 * Get the best result (closest in size to the view's size) that is also in cache. If this would
 * be the same as the source from {@link #getBestResult()}, this will return {@code null}
 * instead.
 */
public @Nullable ImageSource getBestResultInCache() {
  return bestResultInCache;
}