예제 #1
0
  /**
   * Start an image load, attach the result to the specified CallerInfo object. Note, when the query
   * is started, we make the ImageView INVISIBLE if the placeholderImageResource value is -1. When
   * we're given a valid (!= -1) placeholderImageResource value, we make sure the image is visible.
   */
  public static final void updateImageViewWithContactPhotoAsync(
      int token,
      OnImageLoadCompleteListener listener,
      Object cookie,
      Context context,
      ImageView imageView,
      CallerInfo callerInfo,
      int placeholderImageResource) {
    if (sThreadHandler == null) {
      Log.d(THIS_FILE, "Update image view with contact async");
      new ContactsAsyncHelper();
    }

    // in case the source caller info is null, the URI will be null as well.
    // just update using the placeholder image in this case.
    if (callerInfo == null || callerInfo.contactContentUri == null) {
      defaultImage(imageView, placeholderImageResource);
      return;
    }

    // Check that the view is not already loading for same uri
    if (isAlreadyProcessed(imageView, callerInfo.contactContentUri)) {
      return;
    }

    // Added additional Cookie field in the callee to handle arguments
    // sent to the callback function.

    // setup arguments
    WorkerArgs args = new WorkerArgs();
    args.cookie = cookie;
    args.context = context;
    args.view = imageView;
    PhotoViewTag photoTag = new PhotoViewTag();
    photoTag.uri = callerInfo.contactContentUri;
    args.view.setTag(TAG_PHOTO_INFOS, photoTag);
    args.defaultResource = placeholderImageResource;
    args.listener = listener;

    // setup message arguments
    Message msg = sThreadHandler.obtainMessage(token);
    msg.arg1 = EVENT_LOAD_IMAGE;
    msg.obj = args;

    preloadImage(imageView, placeholderImageResource, msg);
  }