Java Code Examples for com.facebook.imagepipeline.request.ImageRequest#RequestLevel

The following examples show how to use com.facebook.imagepipeline.request.ImageRequest#RequestLevel . 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: ImagePipeline.java    From fresco with MIT License 6 votes vote down vote up
/**
 * Submits a request for execution and returns a DataSource representing the pending decoded
 * image(s).
 *
 * <p>The returned DataSource must be closed once the client has finished with it.
 *
 * @param imageRequest the request to submit
 * @param callerContext the caller context for image request
 * @param lowestPermittedRequestLevelOnSubmit the lowest request level permitted for image reques
 * @param requestListener additional image request listener independent of ImageRequest listeners
 * @param uiComponentId optional UI component ID that is requesting the image
 * @return a DataSource representing the pending decoded image(s)
 */
public DataSource<CloseableReference<CloseableImage>> fetchDecodedImage(
    ImageRequest imageRequest,
    Object callerContext,
    ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit,
    @Nullable RequestListener requestListener,
    @Nullable String uiComponentId) {
  try {
    Producer<CloseableReference<CloseableImage>> producerSequence =
        mProducerSequenceFactory.getDecodedImageProducerSequence(imageRequest);
    return submitFetchRequest(
        producerSequence,
        imageRequest,
        lowestPermittedRequestLevelOnSubmit,
        callerContext,
        requestListener,
        uiComponentId);
  } catch (Exception exception) {
    return DataSources.immediateFailedDataSource(exception);
  }
}
 
Example 2
Source File: ImagePipelineMultiUriHelper.java    From fresco with MIT License 6 votes vote down vote up
private static Supplier<DataSource<CloseableReference<CloseableImage>>>
    getImageRequestDataSourceSupplier(
        final ImagePipeline imagePipeline,
        final ImageRequest imageRequest,
        final Object callerContext,
        final ImageRequest.RequestLevel requestLevel,
        final RequestListener requestListener,
        final @Nullable String uiComponentId) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      return getImageRequestDataSource(
          imagePipeline, imageRequest, callerContext, requestListener, uiComponentId);
    }
  };
}
 
Example 3
Source File: ImagePipeline.java    From fresco with MIT License 6 votes vote down vote up
/**
 * Returns a DataSource supplier that will on get submit the request for execution and return a
 * DataSource representing the pending results of the task.
 *
 * @param imageRequest the request to submit (what to execute).
 * @param callerContext the caller context of the caller of data source supplier
 * @param requestLevel which level to look down until for the image
 * @param requestListener additional image request listener independent of ImageRequest listeners
 * @param uiComponentId optional UI component ID requesting the image
 * @return a DataSource representing pending results and completion of the request
 */
public Supplier<DataSource<CloseableReference<CloseableImage>>> getDataSourceSupplier(
    final ImageRequest imageRequest,
    final Object callerContext,
    final ImageRequest.RequestLevel requestLevel,
    final @Nullable RequestListener requestListener,
    final @Nullable String uiComponentId) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      return fetchDecodedImage(
          imageRequest, callerContext, requestLevel, requestListener, uiComponentId);
    }

    @Override
    public String toString() {
      return Objects.toStringHelper(this).add("uri", imageRequest.getSourceUri()).toString();
    }
  };
}
 
Example 4
Source File: ImagePipeline.java    From fresco with MIT License 6 votes vote down vote up
/**
 * Returns a DataSource supplier that will on get submit the request for execution and return a
 * DataSource representing the pending results of the task.
 *
 * @param imageRequest the request to submit (what to execute).
 * @param callerContext the caller context of the caller of data source supplier
 * @param requestLevel which level to look down until for the image
 * @param requestListener additional image request listener independent of ImageRequest listeners
 * @return a DataSource representing pending results and completion of the request
 */
public Supplier<DataSource<CloseableReference<CloseableImage>>> getDataSourceSupplier(
    final ImageRequest imageRequest,
    final Object callerContext,
    final ImageRequest.RequestLevel requestLevel,
    final @Nullable RequestListener requestListener) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      return fetchDecodedImage(imageRequest, callerContext, requestLevel, requestListener);
    }

    @Override
    public String toString() {
      return Objects.toStringHelper(this).add("uri", imageRequest.getSourceUri()).toString();
    }
  };
}
 
Example 5
Source File: SettableProducerContext.java    From fresco with MIT License 6 votes vote down vote up
public SettableProducerContext(
    ImageRequest imageRequest,
    String id,
    ProducerListener2 producerListener,
    Object callerContext,
    ImageRequest.RequestLevel lowestPermittedRequestLevel,
    boolean isPrefetch,
    boolean isIntermediateResultExpected,
    Priority priority,
    ImagePipelineConfig imagePipelineConfig) {
  super(
      imageRequest,
      id,
      producerListener,
      callerContext,
      lowestPermittedRequestLevel,
      isPrefetch,
      isIntermediateResultExpected,
      priority,
      imagePipelineConfig);
}
 
Example 6
Source File: SettableProducerContext.java    From fresco with MIT License 6 votes vote down vote up
public SettableProducerContext(
    ImageRequest imageRequest,
    String id,
    @Nullable String uiComponentId,
    ProducerListener2 producerListener,
    Object callerContext,
    ImageRequest.RequestLevel lowestPermittedRequestLevel,
    boolean isPrefetch,
    boolean isIntermediateResultExpected,
    Priority priority,
    ImagePipelineConfig imagePipelineConfig) {
  super(
      imageRequest,
      id,
      uiComponentId,
      producerListener,
      callerContext,
      lowestPermittedRequestLevel,
      isPrefetch,
      isIntermediateResultExpected,
      priority,
      imagePipelineConfig);
}
 
Example 7
Source File: ImagePipeline.java    From fresco with MIT License 6 votes vote down vote up
/**
 * Returns a DataSource supplier that will on get submit the request for execution and return a
 * DataSource representing the pending results of the task.
 *
 * @param imageRequest the request to submit (what to execute).
 * @param callerContext the caller context of the caller of data source supplier
 * @param requestLevel which level to look down until for the image
 * @return a DataSource representing pending results and completion of the request
 */
public Supplier<DataSource<CloseableReference<CloseableImage>>> getDataSourceSupplier(
    final ImageRequest imageRequest,
    final Object callerContext,
    final ImageRequest.RequestLevel requestLevel) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      return fetchDecodedImage(imageRequest, callerContext, requestLevel);
    }

    @Override
    public String toString() {
      return Objects.toStringHelper(this).add("uri", imageRequest.getSourceUri()).toString();
    }
  };
}
 
Example 8
Source File: BaseProducerContext.java    From fresco with MIT License 6 votes vote down vote up
public BaseProducerContext(
    ImageRequest imageRequest,
    String id,
    ProducerListener2 producerListener,
    Object callerContext,
    ImageRequest.RequestLevel lowestPermittedRequestLevel,
    boolean isPrefetch,
    boolean isIntermediateResultExpected,
    Priority priority,
    ImagePipelineConfig imagePipelineConfig) {
  this(
      imageRequest,
      id,
      null,
      producerListener,
      callerContext,
      lowestPermittedRequestLevel,
      isPrefetch,
      isIntermediateResultExpected,
      priority,
      imagePipelineConfig);
}
 
Example 9
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 10
Source File: ImagePipeline.java    From fresco with MIT License 5 votes vote down vote up
private DataSource<Void> submitPrefetchRequest(
    Producer<Void> producerSequence,
    ImageRequest imageRequest,
    ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit,
    Object callerContext,
    Priority priority) {
  final RequestListener2 requestListener =
      new InternalRequestListener(
          getRequestListenerForRequest(imageRequest, null), mRequestListener2);

  if (mCallerContextVerifier != null) {
    mCallerContextVerifier.verifyCallerContext(callerContext, true);
  }
  try {
    ImageRequest.RequestLevel lowestPermittedRequestLevel =
        ImageRequest.RequestLevel.getMax(
            imageRequest.getLowestPermittedRequestLevel(), lowestPermittedRequestLevelOnSubmit);
    SettableProducerContext settableProducerContext =
        new SettableProducerContext(
            imageRequest,
            generateUniqueFutureId(),
            requestListener,
            callerContext,
            lowestPermittedRequestLevel,
            /* isPrefetch */ true,
            /* isIntermediateResultExpected */ false,
            priority,
            mConfig);
    return ProducerToDataSourceAdapter.create(
        producerSequence, settableProducerContext, requestListener);
  } catch (Exception exception) {
    return DataSources.immediateFailedDataSource(exception);
  }
}
 
Example 11
Source File: BaseProducerContext.java    From fresco with MIT License 5 votes vote down vote up
public BaseProducerContext(
    ImageRequest imageRequest,
    String id,
    @Nullable String uiComponentId,
    ProducerListener2 producerListener,
    Object callerContext,
    ImageRequest.RequestLevel lowestPermittedRequestLevel,
    boolean isPrefetch,
    boolean isIntermediateResultExpected,
    Priority priority,
    ImagePipelineConfig imagePipelineConfig) {
  mImageRequest = imageRequest;
  mId = id;

  mExtras = new HashMap<>();
  mExtras.put("id", mId);
  mExtras.put("uri_source", imageRequest == null ? "null-request" : imageRequest.getSourceUri());

  mUiComponentId = uiComponentId;
  mProducerListener = producerListener;
  mCallerContext = callerContext;
  mLowestPermittedRequestLevel = lowestPermittedRequestLevel;

  mIsPrefetch = isPrefetch;
  mPriority = priority;
  mIsIntermediateResultExpected = isIntermediateResultExpected;

  mIsCancelled = false;
  mCallbacks = new ArrayList<>();

  mImagePipelineConfig = imagePipelineConfig;
}
 
Example 12
Source File: PipelineDraweeControllerBuilder.java    From fresco with MIT License 5 votes vote down vote up
public static ImageRequest.RequestLevel convertCacheLevelToRequestLevel(
    AbstractDraweeControllerBuilder.CacheLevel cacheLevel) {
  switch (cacheLevel) {
    case FULL_FETCH:
      return ImageRequest.RequestLevel.FULL_FETCH;
    case DISK_CACHE:
      return ImageRequest.RequestLevel.DISK_CACHE;
    case BITMAP_MEMORY_CACHE:
      return ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE;
    default:
      throw new RuntimeException("Cache level" + cacheLevel + "is not supported. ");
  }
}
 
Example 13
Source File: ProducerContext.java    From fresco with MIT License 4 votes vote down vote up
/** @return the lowest permitted {@link ImageRequest.RequestLevel} */
ImageRequest.RequestLevel getLowestPermittedRequestLevel();
 
Example 14
Source File: BaseProducerContext.java    From fresco with MIT License 4 votes vote down vote up
@Override
public ImageRequest.RequestLevel getLowestPermittedRequestLevel() {
  return mLowestPermittedRequestLevel;
}
 
Example 15
Source File: BitmapMemoryCacheKeyMultiplexProducer.java    From fresco with MIT License 4 votes vote down vote up
protected Pair<CacheKey, ImageRequest.RequestLevel> getKey(ProducerContext producerContext) {
  return Pair.create(
      mCacheKeyFactory.getBitmapCacheKey(
          producerContext.getImageRequest(), producerContext.getCallerContext()),
      producerContext.getLowestPermittedRequestLevel());
}
 
Example 16
Source File: EncodedCacheKeyMultiplexProducer.java    From fresco with MIT License 4 votes vote down vote up
protected Pair<CacheKey, ImageRequest.RequestLevel> getKey(ProducerContext producerContext) {
  return Pair.create(
      mCacheKeyFactory.getEncodedCacheKey(
          producerContext.getImageRequest(), producerContext.getCallerContext()),
      producerContext.getLowestPermittedRequestLevel());
}
 
Example 17
Source File: FrescoControllerImpl.java    From fresco with MIT License 4 votes vote down vote up
/** Creates imagepipeline components and sets them to frescoState */
@VisibleForTesting
void prepareImagePipelineComponents(
    FrescoState frescoState, ImageRequest imageRequest, @Nullable Object callerContext) {
  if (FrescoSystrace.isTracing()) {
    FrescoSystrace.beginSection("FrescoControllerImpl#prepareImagePipelineComponents");
  }
  try {
    frescoState.setProducerSequence(
        mFrescoContext
            .getImagePipeline()
            .getProducerSequenceFactory()
            .getDecodedImageProducerSequence(imageRequest));

    ImageRequest.RequestLevel lowestPermittedRequestLevel =
        ImageRequest.RequestLevel.getMax(
            imageRequest.getLowestPermittedRequestLevel(), ImageRequest.RequestLevel.FULL_FETCH);

    setupRequestListener(frescoState, imageRequest);
    frescoState.setSettableProducerContext(
        new SettableProducerContext(
            imageRequest,
            mFrescoContext.getImagePipeline().generateUniqueFutureId(),
            frescoState.getStringId(),
            new InternalProducerListener(frescoState.getRequestListener(), null),
            callerContext,
            lowestPermittedRequestLevel,
            /* isPrefetch */ false,
            imageRequest.getProgressiveRenderingEnabled()
                || !UriUtil.isNetworkUri(imageRequest.getSourceUri()),
            imageRequest.getPriority(),
            mFrescoContext.getImagePipeline().getConfig()));
  } catch (Exception exception) {
    // This is how ImagePipeline handles the error case.
    // Something went wrong and we can't prepare components ahead of time.
  } finally {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.endSection();
    }
  }
}
 
Example 18
Source File: FrescoPlusFetcher.java    From FrescoPlus with Apache License 2.0 4 votes vote down vote up
public Builder withRequestLevel(ImageRequest.RequestLevel val) {
    requestLevel = val;
    return this;
}
 
Example 19
Source File: ImagePipeline.java    From fresco with MIT License 4 votes vote down vote up
private <T> DataSource<CloseableReference<T>> submitFetchRequest(
    Producer<CloseableReference<T>> producerSequence,
    ImageRequest imageRequest,
    ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit,
    Object callerContext,
    @Nullable RequestListener requestListener,
    @Nullable String uiComponentId) {
  if (FrescoSystrace.isTracing()) {
    FrescoSystrace.beginSection("ImagePipeline#submitFetchRequest");
  }
  final RequestListener2 requestListener2 =
      new InternalRequestListener(
          getRequestListenerForRequest(imageRequest, requestListener), mRequestListener2);

  if (mCallerContextVerifier != null) {
    mCallerContextVerifier.verifyCallerContext(callerContext, false);
  }

  try {
    ImageRequest.RequestLevel lowestPermittedRequestLevel =
        ImageRequest.RequestLevel.getMax(
            imageRequest.getLowestPermittedRequestLevel(), lowestPermittedRequestLevelOnSubmit);
    SettableProducerContext settableProducerContext =
        new SettableProducerContext(
            imageRequest,
            generateUniqueFutureId(),
            uiComponentId,
            requestListener2,
            callerContext,
            lowestPermittedRequestLevel,
            /* isPrefetch */ false,
            imageRequest.getProgressiveRenderingEnabled()
                || !UriUtil.isNetworkUri(imageRequest.getSourceUri()),
            imageRequest.getPriority(),
            mConfig);
    return CloseableProducerToDataSourceAdapter.create(
        producerSequence, settableProducerContext, requestListener2);
  } catch (Exception exception) {
    return DataSources.immediateFailedDataSource(exception);
  } finally {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.endSection();
    }
  }
}
 
Example 20
Source File: ImagePipeline.java    From fresco with MIT License 3 votes vote down vote up
/**
 * Submits a request for execution and returns a DataSource representing the pending decoded
 * image(s).
 *
 * <p>The returned DataSource must be closed once the client has finished with it.
 *
 * @param imageRequest the request to submit
 * @param callerContext the caller context for image request
 * @param lowestPermittedRequestLevelOnSubmit the lowest request level permitted for image reques
 * @param requestListener additional image request listener independent of ImageRequest listeners
 * @return a DataSource representing the pending decoded image(s)
 */
public DataSource<CloseableReference<CloseableImage>> fetchDecodedImage(
    ImageRequest imageRequest,
    Object callerContext,
    ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit,
    @Nullable RequestListener requestListener) {
  return fetchDecodedImage(
      imageRequest, callerContext, lowestPermittedRequestLevelOnSubmit, requestListener, null);
}