Java Code Examples for com.facebook.imagepipeline.request.ImageRequest#getSourceUri()

The following examples show how to use com.facebook.imagepipeline.request.ImageRequest#getSourceUri() . 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: ProducerSequenceFactory.java    From fresco with MIT License 6 votes vote down vote up
/**
 * Returns a sequence that can be used for a prefetch request for an encoded image.
 *
 * <p>Guaranteed to return the same sequence as {@code getEncodedImageProducerSequence(request)},
 * except that it is pre-pended with a {@link SwallowResultProducer}.
 *
 * @param imageRequest the request that will be submitted
 * @return the sequence that should be used to process the request
 */
public Producer<Void> getEncodedImagePrefetchProducerSequence(ImageRequest imageRequest) {
  validateEncodedImageRequest(imageRequest);

  switch (imageRequest.getSourceUriType()) {
    case SOURCE_TYPE_NETWORK:
      return getNetworkFetchToEncodedMemoryPrefetchSequence();
    case SOURCE_TYPE_LOCAL_VIDEO_FILE:
    case SOURCE_TYPE_LOCAL_IMAGE_FILE:
      return getLocalFileFetchToEncodedMemoryPrefetchSequence();
    default:
      final Uri uri = imageRequest.getSourceUri();
      throw new IllegalArgumentException(
          "Unsupported uri scheme for encoded image fetch! Uri is: "
              + getShortenedUriString(uri));
  }
}
 
Example 2
Source File: LocalContentUriFetchProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected InputStream getInputStream(ImageRequest imageRequest) throws IOException {
  Uri uri = imageRequest.getSourceUri();
  if (isContactUri(uri)) {
    // If a Contact URI is provided, use the special helper to open that contact's photo.
    return ContactsContract.Contacts.openContactPhotoInputStream(mContentResolver, uri);
  }
  return mContentResolver.openInputStream(uri);
}
 
Example 3
Source File: ProducerSequenceFactory.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private Producer<CloseableReference<CloseableImage>> getBasicDecodedImageSequence(
    ImageRequest imageRequest) {
  Preconditions.checkNotNull(imageRequest);
  ImageRequest.RequestLevel lowestPermittedRequestLevel =
      imageRequest.getLowestPermittedRequestLevel();
  Preconditions.checkState(
      lowestPermittedRequestLevel.equals(ImageRequest.RequestLevel.FULL_FETCH) ||
          lowestPermittedRequestLevel.equals(
              ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE),
      "Only support bitmap memory cache or full fetch at present, request level is %s ",
      lowestPermittedRequestLevel);

  if (lowestPermittedRequestLevel.equals(ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE)) {
    return getBitmapCacheGetOnlySequence();
  }

  Uri uri = imageRequest.getSourceUri();
  if (UriUtil.isNetworkUri(uri)) {
    return getNetworkFetchSequence();
  } else if (UriUtil.isLocalFileUri(uri)) {
    if (MediaUtils.isVideo(MediaUtils.extractMime(uri.getPath()))) {
      return getLocalVideoFileFetchSequence();
    } else {
      return getLocalImageFileFetchSequence();
    }
  } else if (UriUtil.isLocalContentUri(uri)) {
    return getLocalContentUriFetchSequence();
  } else if (UriUtil.isLocalAssetUri(uri)) {
    return getLocalAssetFetchSequence();
  } else if (UriUtil.isLocalResourceUri(uri)) {
    return getLocalResourceFetchSequence();
  } else {
    throw new RuntimeException(
        "Unsupported image type! Uri is: " + uri.toString().substring(0, 30));
  }
}
 
Example 4
Source File: LocalContentUriFetchProducer.java    From fresco with MIT License 5 votes vote down vote up
@Override
protected EncodedImage getEncodedImage(ImageRequest imageRequest) throws IOException {
  Uri uri = imageRequest.getSourceUri();
  if (UriUtil.isLocalContactUri(uri)) {
    final InputStream inputStream;
    if (uri.toString().endsWith("/photo")) {
      inputStream = mContentResolver.openInputStream(uri);
    } else if (uri.toString().endsWith("/display_photo")) {
      try {
        AssetFileDescriptor fd = mContentResolver.openAssetFileDescriptor(uri, "r");
        inputStream = fd.createInputStream();
      } catch (IOException e) {
        throw new IOException("Contact photo does not exist: " + uri);
      }
    } else {
      inputStream = ContactsContract.Contacts.openContactPhotoInputStream(mContentResolver, uri);
      if (inputStream == null) {
        throw new IOException("Contact photo does not exist: " + uri);
      }
    }
    // If a Contact URI is provided, use the special helper to open that contact's photo.
    return getEncodedImage(inputStream, EncodedImage.UNKNOWN_STREAM_SIZE);
  }

  if (UriUtil.isLocalCameraUri(uri)) {
    EncodedImage cameraImage = getCameraImage(uri);
    if (cameraImage != null) {
      return cameraImage;
    }
  }

  return getEncodedImage(mContentResolver.openInputStream(uri), EncodedImage.UNKNOWN_STREAM_SIZE);
}
 
Example 5
Source File: QualifiedResourceFetchProducer.java    From fresco with MIT License 5 votes vote down vote up
@Override
protected EncodedImage getEncodedImage(final ImageRequest imageRequest) throws IOException {
  final Uri uri = imageRequest.getSourceUri();
  final InputStream inputStream = mContentResolver.openInputStream(uri);

  return getEncodedImage(inputStream, EncodedImage.UNKNOWN_STREAM_SIZE);
}
 
Example 6
Source File: LocalVideoThumbnailProducer.java    From fresco with MIT License 5 votes vote down vote up
@Nullable
private String getLocalFilePath(ImageRequest imageRequest) {
  Uri uri = imageRequest.getSourceUri();
  if (UriUtil.isLocalFileUri(uri)) {
    return imageRequest.getSourceFile().getPath();
  } else if (UriUtil.isLocalContentUri(uri)) {
    String selection = null;
    String[] selectionArgs = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
        && "com.android.providers.media.documents".equals(uri.getAuthority())) {
      String documentId = DocumentsContract.getDocumentId(uri);
      uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
      selection = MediaStore.Video.Media._ID + "=?";
      selectionArgs = new String[] {documentId.split(":")[1]};
    }
    Cursor cursor =
        mContentResolver.query(
            uri, new String[] {MediaStore.Video.Media.DATA}, selection, selectionArgs, null);
    try {
      if (cursor != null && cursor.moveToFirst()) {
        return cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
      }
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
  }
  return null;
}
 
Example 7
Source File: LocalContentUriThumbnailFetchProducer.java    From fresco with MIT License 5 votes vote down vote up
@Override
protected @Nullable EncodedImage getEncodedImage(ImageRequest imageRequest) throws IOException {
  Uri uri = imageRequest.getSourceUri();

  if (UriUtil.isLocalCameraUri(uri)) {
    return getCameraImage(uri, imageRequest.getResizeOptions());
  }

  return null;
}
 
Example 8
Source File: ProducerSequenceFactory.java    From fresco with MIT License 5 votes vote down vote up
/**
 * Returns a sequence that can be used for a request for an encoded image from either network or
 * local files.
 *
 * @param imageRequest the request that will be submitted
 * @return the sequence that should be used to process the request
 */
public Producer<CloseableReference<PooledByteBuffer>> getEncodedImageProducerSequence(
    ImageRequest imageRequest) {
  try {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.beginSection("ProducerSequenceFactory#getEncodedImageProducerSequence");
    }
    validateEncodedImageRequest(imageRequest);
    final Uri uri = imageRequest.getSourceUri();

    switch (imageRequest.getSourceUriType()) {
      case SOURCE_TYPE_NETWORK:
        return getNetworkFetchEncodedImageProducerSequence();
      case SOURCE_TYPE_LOCAL_VIDEO_FILE:
      case SOURCE_TYPE_LOCAL_IMAGE_FILE:
        return getLocalFileFetchEncodedImageProducerSequence();
      case SOURCE_TYPE_LOCAL_CONTENT:
        return getLocalContentUriFetchEncodedImageProducerSequence();
      default:
        throw new IllegalArgumentException(
            "Unsupported uri scheme for encoded image fetch! Uri is: "
                + getShortenedUriString(uri));
    }
  } finally {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.endSection();
    }
  }
}
 
Example 9
Source File: ProducerSequenceFactory.java    From fresco with MIT License 4 votes vote down vote up
private Producer<CloseableReference<CloseableImage>> getBasicDecodedImageSequence(
    ImageRequest imageRequest) {
  try {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.beginSection("ProducerSequenceFactory#getBasicDecodedImageSequence");
    }
    Preconditions.checkNotNull(imageRequest);

    Uri uri = imageRequest.getSourceUri();
    Preconditions.checkNotNull(uri, "Uri is null.");

    switch (imageRequest.getSourceUriType()) {
      case SOURCE_TYPE_NETWORK:
        return getNetworkFetchSequence();
      case SOURCE_TYPE_LOCAL_VIDEO_FILE:
        return getLocalVideoFileFetchSequence();
      case SOURCE_TYPE_LOCAL_IMAGE_FILE:
        return getLocalImageFileFetchSequence();
      case SOURCE_TYPE_LOCAL_CONTENT:
        if (MediaUtils.isVideo(mContentResolver.getType(uri))) {
          return getLocalVideoFileFetchSequence();
        }
        return getLocalContentUriFetchSequence();
      case SOURCE_TYPE_LOCAL_ASSET:
        return getLocalAssetFetchSequence();
      case SOURCE_TYPE_LOCAL_RESOURCE:
        return getLocalResourceFetchSequence();
      case SOURCE_TYPE_QUALIFIED_RESOURCE:
        return getQualifiedResourceFetchSequence();
      case SOURCE_TYPE_DATA:
        return getDataFetchSequence();
      default:
        throw new IllegalArgumentException(
            "Unsupported uri scheme! Uri is: " + getShortenedUriString(uri));
    }
  } finally {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.endSection();
    }
  }
}