Java Code Examples for com.facebook.common.util.UriUtil#isLocalFileUri()

The following examples show how to use com.facebook.common.util.UriUtil#isLocalFileUri() . 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: 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 2
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 3
Source File: ImageRequest.java    From fresco with MIT License 5 votes vote down vote up
/**
 * This is a utility method which returns the type of Uri
 *
 * @param uri The Uri to test
 * @return The type of the given Uri if available or SOURCE_TYPE_UNKNOWN if not
 */
private static @SourceUriType int getSourceUriType(final Uri uri) {
  if (uri == null) {
    return SOURCE_TYPE_UNKNOWN;
  }
  if (UriUtil.isNetworkUri(uri)) {
    return SOURCE_TYPE_NETWORK;
  } else if (UriUtil.isLocalFileUri(uri)) {
    if (MediaUtils.isVideo(MediaUtils.extractMime(uri.getPath()))) {
      return SOURCE_TYPE_LOCAL_VIDEO_FILE;
    } else {
      return SOURCE_TYPE_LOCAL_IMAGE_FILE;
    }
  } else if (UriUtil.isLocalContentUri(uri)) {
    return SOURCE_TYPE_LOCAL_CONTENT;
  } else if (UriUtil.isLocalAssetUri(uri)) {
    return SOURCE_TYPE_LOCAL_ASSET;
  } else if (UriUtil.isLocalResourceUri(uri)) {
    return SOURCE_TYPE_LOCAL_RESOURCE;
  } else if (UriUtil.isDataUri(uri)) {
    return SOURCE_TYPE_DATA;
  } else if (UriUtil.isQualifiedResourceUri(uri)) {
    return SOURCE_TYPE_QUALIFIED_RESOURCE;
  } else {
    return SOURCE_TYPE_UNKNOWN;
  }
}
 
Example 4
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;
}