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); } } }
protected void setImageBitmapByKey( BitmapDrawable bitmap, String key, boolean thumb, boolean memCache) { if (bitmap == null || key == null) { return; } if (!thumb) { if (currentKey == null || !key.equals(currentKey)) { return; } ImageLoader.getInstance().incrementUseCount(currentKey); currentImage = bitmap; if (roundRadius != 0 && bitmap instanceof BitmapDrawable) { Bitmap object = bitmap.getBitmap(); bitmapShader = new BitmapShader(object, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); roundPaint.setShader(bitmapShader); bitmapRect.set(0, 0, object.getWidth(), object.getHeight()); } if (!memCache && !forcePreview) { if (currentThumb == null && staticThumb == null || currentAlpha == 1.0f) { currentAlpha = 0.0f; lastUpdateAlphaTime = System.currentTimeMillis(); crossfadeWithThumb = currentThumb != null || staticThumb != null; } } else { currentAlpha = 1.0f; } if (parentView != null) { if (invalidateAll) { parentView.invalidate(); } else { parentView.invalidate(imageX, imageY, imageX + imageW, imageY + imageH); } } } else if (currentThumb == null && (currentImage == null || forcePreview)) { if (currentThumbKey == null || !key.equals(currentThumbKey)) { return; } ImageLoader.getInstance().incrementUseCount(currentThumbKey); currentThumb = bitmap; if (!memCache && crossfadeAlpha != 2) { currentAlpha = 0.0f; lastUpdateAlphaTime = System.currentTimeMillis(); crossfadeWithThumb = staticThumb != null && currentKey == null; } else { currentAlpha = 1.0f; } if (!(staticThumb instanceof BitmapDrawable) && 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); } }
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); } } }