예제 #1
0
 public void setImageBitmap(Drawable bitmap) {
   ImageLoader.getInstance().cancelLoadingForImageReceiver(this, 0);
   recycleBitmap(null, false);
   recycleBitmap(null, true);
   staticThumb = bitmap;
   currentThumbLocation = null;
   currentKey = null;
   currentExt = null;
   currentThumbKey = null;
   currentImage = null;
   currentThumbFilter = null;
   currentImageLocation = null;
   currentHttpUrl = null;
   currentFilter = null;
   currentSize = 0;
   currentCacheOnly = false;
   bitmapShader = null;
   if (setImageBackup != null) {
     setImageBackup.fileLocation = null;
     setImageBackup.httpUrl = null;
     setImageBackup.thumbLocation = null;
     setImageBackup.thumb = null;
   }
   currentAlpha = 1;
   if (delegate != null) {
     delegate.didSetImage(
         this,
         currentImage != null || currentThumb != null || staticThumb != null,
         currentImage == null);
   }
   if (parentView != null) {
     if (invalidateAll) {
       parentView.invalidate();
     } else {
       parentView.invalidate(imageX, imageY, imageX + imageW, imageY + imageH);
     }
   }
 }
예제 #2
0
 public void onDetachedFromWindow() {
   if (currentImageLocation != null
       || currentHttpUrl != null
       || currentThumbLocation != null
       || staticThumb != null) {
     if (setImageBackup == null) {
       setImageBackup = new SetImageBackup();
     }
     setImageBackup.fileLocation = currentImageLocation;
     setImageBackup.httpUrl = currentHttpUrl;
     setImageBackup.filter = currentFilter;
     setImageBackup.thumb = staticThumb;
     setImageBackup.thumbLocation = currentThumbLocation;
     setImageBackup.thumbFilter = currentThumbFilter;
     setImageBackup.size = currentSize;
     setImageBackup.ext = currentExt;
     setImageBackup.cacheOnly = currentCacheOnly;
   }
   NotificationCenter.getInstance()
       .removeObserver(this, NotificationCenter.didReplacedPhotoInMemCache);
   clearImage();
 }
예제 #3
0
  public void setImage(
      TLObject fileLocation,
      String httpUrl,
      String filter,
      Drawable thumb,
      TLRPC.FileLocation thumbLocation,
      String thumbFilter,
      int size,
      String ext,
      boolean cacheOnly) {
    if (setImageBackup != null) {
      setImageBackup.fileLocation = null;
      setImageBackup.httpUrl = null;
      setImageBackup.thumbLocation = null;
      setImageBackup.thumb = null;
    }

    if ((fileLocation == null && httpUrl == null && thumbLocation == null)
        || (fileLocation != null
            && !(fileLocation instanceof TLRPC.TL_fileLocation)
            && !(fileLocation instanceof TLRPC.TL_fileEncryptedLocation)
            && !(fileLocation instanceof TLRPC.TL_document))) {
      recycleBitmap(null, false);
      recycleBitmap(null, true);
      currentKey = null;
      currentExt = ext;
      currentThumbKey = null;
      currentThumbFilter = null;
      currentImageLocation = null;
      currentHttpUrl = null;
      currentFilter = null;
      currentCacheOnly = false;
      staticThumb = thumb;
      currentAlpha = 1;
      currentThumbLocation = null;
      currentSize = 0;
      currentImage = null;
      bitmapShader = null;
      ImageLoader.getInstance().cancelLoadingForImageReceiver(this, 0);
      if (parentView != null) {
        if (invalidateAll) {
          parentView.invalidate();
        } else {
          parentView.invalidate(imageX, imageY, imageX + imageW, imageY + imageH);
        }
      }
      if (delegate != null) {
        delegate.didSetImage(
            this,
            currentImage != null || currentThumb != null || staticThumb != null,
            currentImage == null);
      }
      return;
    }

    if (!(thumbLocation instanceof TLRPC.TL_fileLocation)) {
      thumbLocation = null;
    }

    String key = null;
    if (fileLocation != null) {
      if (fileLocation instanceof TLRPC.FileLocation) {
        TLRPC.FileLocation location = (TLRPC.FileLocation) fileLocation;
        key = location.volume_id + "_" + location.local_id;
      } else if (fileLocation instanceof TLRPC.Document) {
        TLRPC.Document location = (TLRPC.Document) fileLocation;
        key = location.dc_id + "_" + location.id;
      }
    } else if (httpUrl != null) {
      key = Utilities.MD5(httpUrl);
    }
    if (key != null) {
      if (filter != null) {
        key += "@" + filter;
      }
    }

    if (currentKey != null && key != null && currentKey.equals(key)) {
      if (delegate != null) {
        delegate.didSetImage(
            this,
            currentImage != null || currentThumb != null || staticThumb != null,
            currentImage == null);
      }
      if (!canceledLoading && !forcePreview) {
        return;
      }
    }

    String thumbKey = null;
    if (thumbLocation != null) {
      thumbKey = thumbLocation.volume_id + "_" + thumbLocation.local_id;
      if (thumbFilter != null) {
        thumbKey += "@" + thumbFilter;
      }
    }

    recycleBitmap(key, false);
    recycleBitmap(thumbKey, true);

    currentThumbKey = thumbKey;
    currentKey = key;
    currentExt = ext;
    currentImageLocation = fileLocation;
    currentHttpUrl = httpUrl;
    currentFilter = filter;
    currentThumbFilter = thumbFilter;
    currentSize = size;
    currentCacheOnly = cacheOnly;
    currentThumbLocation = thumbLocation;
    staticThumb = thumb;
    bitmapShader = null;
    currentAlpha = 1.0f;

    if (delegate != null) {
      delegate.didSetImage(
          this,
          currentImage != null || currentThumb != null || staticThumb != null,
          currentImage == null);
    }

    ImageLoader.getInstance().loadImageForImageReceiver(this);
    if (parentView != null) {
      if (invalidateAll) {
        parentView.invalidate();
      } else {
        parentView.invalidate(imageX, imageY, imageX + imageW, imageY + imageH);
      }
    }
  }