com.facebook.common.util.UriUtil Java Examples

The following examples show how to use com.facebook.common.util.UriUtil. 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: ImageUriRequest.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
private String parseLastFMNetworkImageUrl(UriRequest request, ResponseBody body)
    throws IOException {
  String imageUrl = null;
  String bodyString = body.string();
  if (request.getSearchType() == ImageUriRequest.URL_ALBUM) {
    LastFmAlbum lastFmAlbum = new Gson().fromJson(bodyString, LastFmAlbum.class);
    if (lastFmAlbum.getAlbum() != null) {
      imageUrl = ImageUriUtil.getLargestAlbumImageUrl(lastFmAlbum.getAlbum().getImage());
    }
  } else if (request.getSearchType() == ImageUriRequest.URL_ARTIST) {
    LastFmArtist lastFmArtist = new Gson().fromJson(bodyString, LastFmArtist.class);
    if (lastFmArtist.getArtist() != null) {
      imageUrl = ImageUriUtil.getLargestArtistImageUrl(lastFmArtist.getArtist().getImage());
    }
  }
  if (BLACKLIST.contains(imageUrl)) {
    imageUrl = null;
  }
  if (!TextUtils.isEmpty(imageUrl) && UriUtil.isNetworkUri(Uri.parse(imageUrl))) {
    SPUtil.putValue(App.getContext(), SPUtil.COVER_KEY.NAME, request.getLastFMKey(), imageUrl);
  }
  return imageUrl;
}
 
Example #2
Source File: NoteReelArray.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
public String getUriString(){
	int [] bannerResArray = new int[]{
			R.drawable.banner,
			R.drawable.banner3
	};
	Uri uri = new Uri.Builder()
			.scheme(UriUtil.LOCAL_RESOURCE_SCHEME) // "res"
			.path(String.valueOf(
					bannerResArray[(int)(id%2)]
				//	R.drawable.banner
			))
			.build();
	String uriString;
	uriString = uri.toString();
	if(reel_title_pic.startsWith("http") ){
		uriString = reel_title_pic;
	}else if(!TextUtils.isEmpty(reel_title_pic)){
		uriString  = Uri.fromFile(new File(reel_title_pic)).toString();
	}
	return uriString;
}
 
Example #3
Source File: NoteReelArray.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
public static String getUriString(String reel_title_pic){
	int [] bannerResArray = new int[]{
			R.drawable.banner,
			R.drawable.banner3
	};
	Uri uri = new Uri.Builder()
			.scheme(UriUtil.LOCAL_RESOURCE_SCHEME) // "res"
			.path(String.valueOf(
					bannerResArray[(int)(Math.random()*2)]
					//	R.drawable.banner
			))
			.build();
	String uriString;
	uriString = uri.toString();
	if(!reel_title_pic.endsWith("http") &&!TextUtils.isEmpty(reel_title_pic)){
		uriString  = Uri.fromFile(new File(reel_title_pic)).toString();
	}
	return uriString;
}
 
Example #4
Source File: PersonSettingNewActivity.java    From FimiX8-RE with MIT License 6 votes vote down vote up
private void handleUserType(UserType userType, String fimiId) {
    switch (userType) {
        case Guest:
            this.mIvHead.setImageURI(new Builder().scheme(UriUtil.LOCAL_RESOURCE_SCHEME).path(String.valueOf(R.drawable.icon_person_setting_head_unlogin)).build());
            this.mBtnBack.setVisibility(8);
            this.rlLoginNow.setVisibility(0);
            return;
        case Register:
            String name = HostConstants.getUserDetail().getNickName();
            TextView textView = this.mTvName;
            if (TextUtils.isEmpty(name)) {
                name = "";
            }
            textView.setText(name);
            this.mTvId.setText(getString(R.string.person_setting_fimi_id, new Object[]{fimiId}));
            FrescoImageLoader.display(this.mIvHead, HostConstants.getUserDetail().getUserImgUrl());
            this.mBtnBack.setVisibility(0);
            this.rlLoginNow.setVisibility(8);
            return;
        default:
            return;
    }
}
 
Example #5
Source File: ImagePipeline.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
private <T> DataSource<CloseableReference<T>> submitFetchRequest(
    Producer<CloseableReference<T>> producerSequence,
    ImageRequest imageRequest,
    Object callerContext) {
  SettableProducerContext settableProducerContext = new SettableProducerContext(
      imageRequest,
      generateUniqueFutureId(),
      mRequestListener,
      callerContext,
      /* isPrefetch */ false,
      imageRequest.getProgressiveRenderingEnabled() ||
          !UriUtil.isNetworkUri(imageRequest.getSourceUri()),
      Priority.HIGH);
  return CloseableProducerToDataSourceAdapter.create(
      producerSequence,
      settableProducerContext,
      mRequestListener);
}
 
Example #6
Source File: DecodeProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void produceResults(
    final Consumer<CloseableReference<CloseableImage>> consumer,
    final ProducerContext context) {
  final ImageRequest imageRequest = context.getImageRequest();
  ProgressiveDecoder progressiveDecoder;
  if (!UriUtil.isNetworkUri(imageRequest.getSourceUri())) {
    progressiveDecoder = new LocalImagesProgressiveDecoder(consumer, context);
  } else {
    ProgressiveJpegParser jpegParser = new ProgressiveJpegParser(mByteArrayPool);
    progressiveDecoder = new NetworkImagesProgressiveDecoder(
        consumer,
        context,
        jpegParser,
        mProgressiveJpegConfig);
  }
  mNextProducer.produceResults(progressiveDecoder, context);
}
 
Example #7
Source File: ImageUriRequest.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
private Observable<String> getNeteaseNetworkThumbObservable(UriRequest request) {
  return Observable.concat(Observable.create(new ObservableOnSubscribe<String>() {
    @Override
    public void subscribe(ObservableEmitter<String> emitter) throws Exception {
      String imageUrl = SPUtil
          .getValue(App.getContext(), SPUtil.COVER_KEY.NAME, request.getNeteaseCacheKey(), "");
      if (!TextUtils.isEmpty(imageUrl) && UriUtil.isNetworkUri(Uri.parse(imageUrl))) {
        emitter.onNext(imageUrl);
      }
      emitter.onComplete();
    }
  }), Observable.just(isAutoDownloadCover() && !TextUtils.isEmpty(request.getNeteaseSearchKey()))
      .filter(aBoolean -> aBoolean)
      .flatMap(aBoolean -> HttpClient.getInstance()
          .getNeteaseSearch(request.getNeteaseSearchKey(), 0, 1, request.getNeteaseType())
          .map(responseBody -> parseNeteaseNetworkImageUrl(request, responseBody))
          .firstElement().toObservable()));
}
 
Example #8
Source File: HomeViewModel.java    From demo4Fish with MIT License 6 votes vote down vote up
@Override
public void loadBanner() {
    Uri[] bannerList = {
            UriUtil.getUriForResourceId(R.drawable.banner_1),
            UriUtil.getUriForResourceId(R.drawable.banner_2),
            UriUtil.getUriForResourceId(R.drawable.banner_3),
            UriUtil.getUriForResourceId(R.drawable.banner_4)
    };

    List<BannerEntity> banners = new ArrayList<>();
    for (int i = 0; i < bannerList.length; i++) {
        BannerEntity entity = new BannerEntity();
        entity.setImageUrl(bannerList[i].toString());
        banners.add(entity);
    }

    mBannerList.clear();
    mBannerList.addAll(banners);

    mEntity.setBannerCount(mBannerList.size());
}
 
Example #9
Source File: QualifiedResourceFetchProducerTest.java    From fresco with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);
  mExecutor = new TestExecutorService(new FakeClock());
  mQualifiedResourceFetchProducer =
      new QualifiedResourceFetchProducer(mExecutor, mPooledByteBufferFactory, mContentResolver);
  mContentUri = UriUtil.getUriForQualifiedResource(PACKAGE_NAME, RESOURCE_ID);

  mProducerContext =
      new SettableProducerContext(
          mImageRequest,
          REQUEST_ID,
          mProducerListener,
          CALLER_CONTEXT,
          ImageRequest.RequestLevel.FULL_FETCH,
          false,
          true,
          Priority.MEDIUM,
          mConfig);
  when(mImageRequest.getSourceUri()).thenReturn(mContentUri);
}
 
Example #10
Source File: FrescoHolder.java    From fresco with MIT License 6 votes vote down vote up
@Override
protected void onBind(String uriString) {
  Uri uri = Uri.parse(uriString);
  ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri);
  if (UriUtil.isNetworkUri(uri)) {
    imageRequestBuilder.setProgressiveRenderingEnabled(true);
  } else {
    imageRequestBuilder.setResizeOptions(
        new ResizeOptions(
            mImageView.getLayoutParams().width, mImageView.getLayoutParams().height));
  }
  DraweeController draweeController =
      Fresco.newDraweeControllerBuilder()
          .setImageRequest(imageRequestBuilder.build())
          .setOldController(mImageView.getController())
          .setControllerListener(mImageView.getListener())
          .setAutoPlayAnimations(true)
          .build();
  mImageView.setController(draweeController);
}
 
Example #11
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 #12
Source File: DecodeProducer.java    From fresco with MIT License 5 votes vote down vote up
@Override
public void produceResults(
    final Consumer<CloseableReference<CloseableImage>> consumer,
    final ProducerContext producerContext) {
  try {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.beginSection("DecodeProducer#produceResults");
    }
    final ImageRequest imageRequest = producerContext.getImageRequest();
    ProgressiveDecoder progressiveDecoder;
    if (!UriUtil.isNetworkUri(imageRequest.getSourceUri())) {
      progressiveDecoder =
          new LocalImagesProgressiveDecoder(
              consumer, producerContext, mDecodeCancellationEnabled, mMaxBitmapSize);
    } else {
      ProgressiveJpegParser jpegParser = new ProgressiveJpegParser(mByteArrayPool);
      progressiveDecoder =
          new NetworkImagesProgressiveDecoder(
              consumer,
              producerContext,
              jpegParser,
              mProgressiveJpegConfig,
              mDecodeCancellationEnabled,
              mMaxBitmapSize);
    }
    mInputProducer.produceResults(progressiveDecoder, producerContext);
  } finally {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.endSection();
    }
  }
}
 
Example #13
Source File: ImageManager.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
public SingleImageBuilder setImageFromRes(int resId, boolean progressive){
    Uri uri = new Uri.Builder()
            .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) // "res"
            .path(String.valueOf(resId))
            .build();
    ImageRequest request = getRequest(uri, progressive);
    mainImageRequest = request;
    controllerBuilder.setLowResImageRequest(request);
    return this;
}
 
Example #14
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 #15
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 #16
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 #17
Source File: ImageRequestBuilder.java    From fresco with MIT License 5 votes vote down vote up
/** Performs validation. */
protected void validate() {
  // make sure that the source uri is set correctly.
  if (mSourceUri == null) {
    throw new BuilderException("Source must be set!");
  }

  // For local resource we require caller to specify statically generated resource id as a path.
  if (UriUtil.isLocalResourceUri(mSourceUri)) {
    if (!mSourceUri.isAbsolute()) {
      throw new BuilderException("Resource URI path must be absolute.");
    }
    if (mSourceUri.getPath().isEmpty()) {
      throw new BuilderException("Resource URI must not be empty");
    }
    try {
      Integer.parseInt(mSourceUri.getPath().substring(1));
    } catch (NumberFormatException ignored) {
      throw new BuilderException("Resource URI path must be a resource id.");
    }
  }

  // For local asset we require caller to specify absolute path of an asset, which will be
  // resolved by AssetManager relative to configured asset folder of an app.
  if (UriUtil.isLocalAssetUri(mSourceUri) && !mSourceUri.isAbsolute()) {
    throw new BuilderException("Asset URI path must be absolute.");
  }
}
 
Example #18
Source File: ImageManager.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
public SingleImageBuilder setImageFromAsset(int assetId, boolean progressive){
    Uri uri = new Uri.Builder()
            .scheme(UriUtil.LOCAL_ASSET_SCHEME) // "asset"
            .path(String.valueOf(assetId))
            .build();
    ImageRequest request = getRequest(uri, progressive);
    mainImageRequest = request;
    controllerBuilder.setLowResImageRequest(request);
    return this;
}
 
Example #19
Source File: ProducerSequenceFactoryTest.java    From fresco with MIT License 5 votes vote down vote up
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  PowerMockito.mockStatic(UriUtil.class, MediaUtils.class);

  ProducerFactory producerFactory = mock(ProducerFactory.class, RETURNS_MOCKS);
  ImageTranscoder imageTranscoder = mock(ImageTranscoder.class);
  ImageTranscoderFactory imageTranscoderFactory = mock(ImageTranscoderFactory.class);
  when(imageTranscoderFactory.createImageTranscoder(any(ImageFormat.class), anyBoolean()))
      .thenReturn(imageTranscoder);

  mProducerSequenceFactory =
      new ProducerSequenceFactory(
          RuntimeEnvironment.application.getContentResolver(),
          producerFactory,
          null,
          true,
          false,
          null,
          false,
          false,
          false,
          true,
          imageTranscoderFactory,
          false,
          false);

  when(mImageRequest.getLowestPermittedRequestLevel())
      .thenReturn(ImageRequest.RequestLevel.FULL_FETCH);
  mUri = Uri.parse("http://dummy");
  when(mImageRequest.getSourceUri()).thenReturn(mUri);
  when(MediaUtils.extractMime(mUri.getPath())).thenReturn(mDummyMime);
  when(MediaUtils.isVideo(mDummyMime)).thenReturn(false);
}
 
Example #20
Source File: RCTResourceDrawableIdHelper.java    From react-native-image-sequence with MIT License 5 votes vote down vote up
public Uri getResourceDrawableUri(Context context, @Nullable String name) {
    int resId = getResourceDrawableId(context, name);
    return resId > 0 ? new Uri.Builder()
            .scheme(UriUtil.LOCAL_RESOURCE_SCHEME)
            .path(String.valueOf(resId))
            .build() : Uri.EMPTY;
}
 
Example #21
Source File: FrescoBasedReactTextInlineImageShadowNode.java    From react-native-GPay with MIT License 5 votes vote down vote up
private static @Nullable Uri getResourceDrawableUri(Context context, @Nullable String name) {
  if (name == null || name.isEmpty()) {
    return null;
  }
  name = name.toLowerCase(Locale.getDefault()).replace("-", "_");
  int resId = context.getResources().getIdentifier(
    name,
    "drawable",
    context.getPackageName());
  return new Uri.Builder()
    .scheme(UriUtil.LOCAL_RESOURCE_SCHEME)
    .path(String.valueOf(resId))
    .build();
}
 
Example #22
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 #23
Source File: HomeViewModel.java    From demo4Fish with MIT License 5 votes vote down vote up
private void initFunctionEntities() {
    mFunctionList = new ObservableArrayList<>();
    String iconUrl = UriUtil.getUriForResourceId(R.mipmap.ic_launcher).toString();
    for (int i = 0; i < 6; i++) {
        FunctionItemEntity entity = new FunctionItemEntity();
        entity.setIconUrl(iconUrl);
        entity.setTitle("测试标题" + i);
        entity.setDesc("测试描述" + i);
        mFunctionList.add(entity);
    }
}
 
Example #24
Source File: WindowImageView.java    From WindowImageView with MIT License 5 votes vote down vote up
public Uri getUri() {
    if (resUri == null) {
        if (resId == 0) {
            return null;
        }
        return UriUtil.getUriForResourceId(resId);
    }
    return resUri;
}
 
Example #25
Source File: LoadingDialogHeaderView.java    From Capstone-Project with MIT License 5 votes vote down vote up
private void setSuccessState() {
    Uri uri = new Uri.Builder()
            .scheme(UriUtil.LOCAL_RESOURCE_SCHEME)
            .path(String.valueOf(R.drawable.ic_done))
            .build();

    imgViewStatus.setImageURI(uri);
    imgViewStatus.setVisibility(View.VISIBLE);

    viewStatusBackground.setBackgroundColor(getStatusBackgroundColor(true));
    viewStatusBackground.setVisibility(View.VISIBLE);
}
 
Example #26
Source File: LoadingDialogHeaderView.java    From Capstone-Project with MIT License 5 votes vote down vote up
private void setFailureState() {
    Uri uri = new Uri.Builder()
            .scheme(UriUtil.LOCAL_RESOURCE_SCHEME)
            .path(String.valueOf(R.drawable.ic_error_alternative))
            .build();


    imgViewStatus.setImageURI(uri);
    imgViewStatus.setVisibility(View.VISIBLE);

    viewStatusBackground.setBackgroundColor(getStatusBackgroundColor(false));
    viewStatusBackground.setVisibility(View.VISIBLE);
}
 
Example #27
Source File: MainActivity.java    From ZoomableDraweeView-sample with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(ItemHolder holder, final int position) {
    holder.tvTitle.setText(menu[position]);
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Class cls;
            Uri data = null;

            switch (position) {
                case 0:
                    cls = ZoomableActivity.class;
                    data = new Uri.Builder()
                            .scheme(UriUtil.LOCAL_RESOURCE_SCHEME)
                            .path(String.valueOf(R.drawable.bbb_splash))
                            .build();
                    break;
                case 1:
                    cls = ZoomableActivity.class;
                    data = Uri.parse(
                            "http://upload.wikimedia.org/wikipedia/commons/3/31/Big.Buck.Bunny.-.Frank.Bunny.png");
                    break;
                case 2:
                    cls = ViewPagerActivity.class;
                    break;
                default:
                    throw new IllegalArgumentException("Invalid position: " + position);
            }

            Context ctx = v.getContext();
            ctx.startActivity(
                    new Intent(ctx, cls).setData(data)
                        .putExtra(ZoomableActivity.KEY_TITLE, menu[position]));
        }
    });

}
 
Example #28
Source File: ImageRequestBuilder.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/** Performs validation. */
protected void validate() {
  // make sure that the source uri is set correctly.
  if (mSourceUri == null) {
    throw new BuilderException("Source must be set!");
  }

  // For local resource we require caller to specify statically generated resource id as a path.
  if (UriUtil.isLocalResourceUri(mSourceUri)) {
    if (!mSourceUri.isAbsolute()) {
      throw new BuilderException("Resource URI path must be absolute.");
    }
    if (mSourceUri.getPath().isEmpty()) {
      throw new BuilderException("Resource URI must not be empty");
    }
    try {
      Integer.parseInt(mSourceUri.getPath().substring(1));
    } catch (NumberFormatException ignored) {
      throw new BuilderException("Resource URI path must be a resource id.");
    }
  }

  // For local asset we require caller to specify absolute path of an asset, which will be
  // resolved by AssetManager relative to configured asset folder of an app.
  if (UriUtil.isLocalAssetUri(mSourceUri) && !mSourceUri.isAbsolute()) {
    throw new BuilderException("Asset URI path must be absolute.");
  }
}
 
Example #29
Source File: ProducerSequenceFactory.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private static void validateEncodedImageRequest(ImageRequest imageRequest) {
  Preconditions.checkNotNull(imageRequest);
  Preconditions.checkArgument(UriUtil.isNetworkUri(imageRequest.getSourceUri()));
  Preconditions.checkArgument(
      imageRequest.getLowestPermittedRequestLevel() ==
          ImageRequest.RequestLevel.FULL_FETCH);
}
 
Example #30
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));
  }
}