com.facebook.react.views.imagehelper.ImageSource Java Examples

The following examples show how to use com.facebook.react.views.imagehelper.ImageSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuxCache.java    From react-native-image-filter-kit with MIT License 6 votes vote down vote up
@Nonnull
static CacheKey auxKey(
  final @Nonnull JSONObject config,
  final @Nonnull List<ReactImageView> images
) {
  final List<Integer> imageIndexes = imageIndexes(config);
  final ArrayList<CacheKey> keys = new ArrayList<>();

  keys.add(new SimpleCacheKey(config.toString()));

  for (Integer index : imageIndexes) {
    final ImageSource source = ReactImageViewUtils.getImageSource(images.get(index));

    keys.add(new SimpleCacheKey(source != null ? source.getSource() : "null"));
  }

  return new MultiCacheKey(keys);
}
 
Example #2
Source File: ImageViewerAdapter.java    From photo-viewer with Apache License 2.0 6 votes vote down vote up
private void setController(String url, ReadableMap headers) {
			PipelineDraweeControllerBuilder controllerBuilder = Fresco.newDraweeControllerBuilder();
//			controllerBuilder.setUri(url);
			controllerBuilder.setOldController(drawee.getController());
			controllerBuilder.setControllerListener(getDraweeControllerListener(drawee));
			controllerBuilder.setAutoPlayAnimations(true);
			if (imageRequestBuilder != null) {
				imageRequestBuilder.setSource(Uri.parse(url));
				controllerBuilder.setImageRequest(imageRequestBuilder.build());
			}
//			support load local image just like React Native do

			ImageSource imageSource = new ImageSource(getContext(), url);
			ImageRequestBuilder imageRequestBuilder1 = ImageRequestBuilder.newBuilderWithSource(imageSource.getUri());
//			support headers
			ImageRequest imageRequest = ReactNetworkImageRequest.fromBuilderWithHeaders(imageRequestBuilder1, headers);

			controllerBuilder.setImageRequest(imageRequest);


			drawee.setController(controllerBuilder.build());
		}
 
Example #3
Source File: ReactImageView.java    From react-native-GPay with MIT License 5 votes vote down vote up
private void setSourceImage() {
  mImageSource = null;
  if (mSources.isEmpty()) {
    ImageSource imageSource = new ImageSource(getContext(), REMOTE_TRANSPARENT_BITMAP_URI);
    mSources.add(imageSource);
  } else if (hasMultipleSources()) {
    MultiSourceResult multiSource =
      MultiSourceHelper.getBestSourceForSize(getWidth(), getHeight(), mSources);
    mImageSource = multiSource.getBestResult();
    mCachedImageSource = multiSource.getBestResultInCache();
    return;
  }

  mImageSource = mSources.get(0);
}
 
Example #4
Source File: ReactImageView.java    From react-native-GPay with MIT License 5 votes vote down vote up
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;
  }
}
 
Example #5
Source File: ApplicationActivity.java    From react-native-turbolinks with MIT License 5 votes vote down vote up
private void bitmapFor(Bundle image, Context context, BaseBitmapDataSubscriber baseBitmapDataSubscriber) {
    ImageSource source = new ImageSource(context, image.getString("uri"));
    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(source.getUri()).build();

    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);

    dataSource.subscribe(baseBitmapDataSubscriber, UiThreadImmediateExecutorService.getInstance());
}
 
Example #6
Source File: MerryPhotoView.java    From photo-viewer with Apache License 2.0 5 votes vote down vote up
private ImageRequestBuilder getLocalImage() {
    final Context context = getContext();

    ImageSource imageSource = new ImageSource(context, "cat-2575694_1920");

    ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(imageSource.getUri());
    return imageRequestBuilder;
}
 
Example #7
Source File: ReactImageViewUtils.java    From react-native-image-filter-kit with MIT License 4 votes vote down vote up
@Nullable
static ImageSource getImageSource(@Nullable ReactImageView target) {
  return target != null
    ? ReflectUtils.getFieldValue(target, "mImageSource")
    : null;
}
 
Example #8
Source File: MultiSourceHelper.java    From react-native-GPay with MIT License 4 votes vote down vote up
private MultiSourceResult(
  @Nullable ImageSource bestResult,
  @Nullable ImageSource bestResultInCache) {
  this.bestResult = bestResult;
  this.bestResultInCache = bestResultInCache;
}
 
Example #9
Source File: MultiSourceHelper.java    From react-native-GPay with MIT License 4 votes vote down vote up
public static MultiSourceResult getBestSourceForSize(
  int width,
  int height,
  List<ImageSource> sources) {
  return getBestSourceForSize(width, height, sources, 1.0d);
}
 
Example #10
Source File: MultiSourceHelper.java    From react-native-GPay with MIT License 4 votes vote down vote up
/**
 * 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);
}
 
Example #11
Source File: MultiSourceHelper.java    From react-native-GPay with MIT License 2 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: MultiSourceHelper.java    From react-native-GPay with MIT License 2 votes vote down vote up
/**
 * 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;
}