Esempio n. 1
0
 RequestBuilder(
     GlideContext context, RequestManager requestManager, Class<TranscodeType> transcodeClass) {
   this.requestManager = requestManager;
   this.context = Preconditions.checkNotNull(context);
   this.transcodeClass = transcodeClass;
   requestOptions = context.getOptions().clone();
 }
Esempio n. 2
0
  /**
   * Sets the {@link ImageView} the resource will be loaded into, cancels any existing loads into
   * the view, and frees any resources Glide may have previously loaded into the view so they may be
   * reused.
   *
   * @see RequestManager#clear(Target)
   * @param view The view to cancel previous loads for and load the new resource into.
   * @return The {@link com.bumptech.glide.request.target.Target} used to wrap the given {@link
   *     ImageView}.
   */
  public Target<TranscodeType> into(ImageView view) {
    Util.assertMainThread();
    if (view == null) {
      throw new IllegalArgumentException("You must pass in a non null View");
    }

    if (!requestOptions.isTransformationSet() && view.getScaleType() != null) {
      if (requestOptions.isLocked()) {
        requestOptions = requestOptions.clone();
      }
      switch (view.getScaleType()) {
        case CENTER_CROP:
          requestOptions.optionalCenterCrop(context);
          break;
        case FIT_CENTER:
        case FIT_START:
        case FIT_END:
          requestOptions.optionalFitCenter(context);
          break;
          // $CASES-OMITTED$
        default:
          // Do nothing.
      }
    }

    return into(context.buildImageViewTarget(view, transcodeClass));
  }
Esempio n. 3
0
  /**
   * Returns a future that can be used to do a blocking get on a background thread.
   *
   * @param width The desired width in pixels, or {@link Target#SIZE_ORIGINAL}. This will be
   *     overridden by {@link com.bumptech.glide.request.BaseRequestOptions#override(int, int)} if
   *     previously called.
   * @param height The desired height in pixels, or {@link Target#SIZE_ORIGINAL}. This will be
   *     overridden by {@link com.bumptech.glide.request.BaseRequestOptions#override(int, int)}} if
   *     previously called).
   * @return An {@link com.bumptech.glide.request.FutureTarget} that can be used to obtain the
   *     resource in a blocking manner.
   * @see RequestManager#clear(Target)
   */
  public FutureTarget<TranscodeType> into(int width, int height) {
    final RequestFutureTarget<TranscodeType> target =
        new RequestFutureTarget<>(context.getMainHandler(), width, height);

    // TODO: Currently all loads must be started on the main thread...
    context
        .getMainHandler()
        .post(
            new Runnable() {
              @Override
              public void run() {
                if (!target.isCancelled()) {
                  into(target);
                }
              }
            });

    return target;
  }
Esempio n. 4
0
  private Request obtainRequest(
      Target<TranscodeType> target,
      BaseRequestOptions<?> requestOptions,
      RequestCoordinator requestCoordinator,
      TransitionOptions<?, ? super TranscodeType> transitionOptions,
      Priority priority,
      int overrideWidth,
      int overrideHeight) {
    requestOptions.lock();

    return SingleRequest.obtain(
        context,
        model,
        transcodeClass,
        requestOptions,
        overrideWidth,
        overrideHeight,
        priority,
        target,
        requestListener,
        requestCoordinator,
        context.getEngine(),
        transitionOptions.getTransitionFactory());
  }