Ejemplo n.º 1
0
 public void setImage(
     TLObject fileLocation,
     String filter,
     TLRPC.FileLocation thumbLocation,
     String thumbFilter,
     String ext,
     boolean cacheOnly) {
   setImage(fileLocation, null, filter, null, thumbLocation, thumbFilter, 0, ext, cacheOnly);
 }
Ejemplo n.º 2
0
 public void setMessageObject(MessageObject messageObject) {
   if (currentMessageObject == messageObject) {
     return;
   }
   currentMessageObject = messageObject;
   previousWidth = 0;
   if (currentMessageObject.type == 11) {
     int id = 0;
     if (messageObject.messageOwner.to_id != null) {
       if (messageObject.messageOwner.to_id.chat_id != 0) {
         id = messageObject.messageOwner.to_id.chat_id;
       } else {
         id = messageObject.messageOwner.to_id.user_id;
         if (id == UserConfig.getClientUserId()) {
           id = messageObject.messageOwner.from_id;
         }
       }
     }
     avatarDrawable.setInfo(id, null, null, false);
     if (currentMessageObject.messageOwner.action
         instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
       imageReceiver.setImage(
           currentMessageObject.messageOwner.action.newUserPhoto.photo_small,
           "50_50",
           avatarDrawable,
           null,
           false);
     } else {
       TLRPC.PhotoSize photo =
           FileLoader.getClosestPhotoSizeWithSize(
               currentMessageObject.photoThumbs, AndroidUtilities.dp(64));
       if (photo != null) {
         imageReceiver.setImage(photo.location, "50_50", avatarDrawable, null, false);
       } else {
         imageReceiver.setImageBitmap(avatarDrawable);
       }
     }
     imageReceiver.setVisible(
         !PhotoViewer.getInstance().isShowingImage(currentMessageObject), false);
   } else {
     imageReceiver.setImageBitmap((Bitmap) null);
   }
   requestLayout();
 }
Ejemplo n.º 3
0
 public boolean onAttachedToWindow() {
   NotificationCenter.getInstance()
       .addObserver(this, NotificationCenter.didReplacedPhotoInMemCache);
   if (setImageBackup != null
       && (setImageBackup.fileLocation != null
           || setImageBackup.httpUrl != null
           || setImageBackup.thumbLocation != null
           || setImageBackup.thumb != null)) {
     setImage(
         setImageBackup.fileLocation,
         setImageBackup.httpUrl,
         setImageBackup.filter,
         setImageBackup.thumb,
         setImageBackup.thumbLocation,
         setImageBackup.thumbFilter,
         setImageBackup.size,
         setImageBackup.ext,
         setImageBackup.cacheOnly);
     return true;
   }
   return false;
 }
Ejemplo n.º 4
0
  private void drawDrawable(Canvas canvas, Drawable drawable, int alpha) {
    if (drawable instanceof BitmapDrawable) {
      BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;

      Paint paint = bitmapDrawable.getPaint();
      boolean hasFilter = paint != null && paint.getColorFilter() != null;
      if (hasFilter && !isPressed) {
        bitmapDrawable.setColorFilter(null);
      } else if (!hasFilter && isPressed) {
        bitmapDrawable.setColorFilter(
            new PorterDuffColorFilter(0xffdddddd, PorterDuff.Mode.MULTIPLY));
      }
      if (colorFilter != null) {
        bitmapDrawable.setColorFilter(colorFilter);
      }
      if (bitmapShader != null) {
        drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
        if (isVisible) {
          roundRect.set(drawRegion);
          shaderMatrix.reset();
          shaderMatrix.setRectToRect(bitmapRect, roundRect, Matrix.ScaleToFit.FILL);
          bitmapShader.setLocalMatrix(shaderMatrix);
          roundPaint.setAlpha(alpha);
          canvas.drawRoundRect(roundRect, roundRadius, roundRadius, roundPaint);
        }
      } else {
        int bitmapW;
        int bitmapH;
        if (orientation == 90 || orientation == 270) {
          bitmapW = bitmapDrawable.getIntrinsicHeight();
          bitmapH = bitmapDrawable.getIntrinsicWidth();
        } else {
          bitmapW = bitmapDrawable.getIntrinsicWidth();
          bitmapH = bitmapDrawable.getIntrinsicHeight();
        }
        float scaleW = bitmapW / (float) imageW;
        float scaleH = bitmapH / (float) imageH;

        if (isAspectFit) {
          float scale = Math.max(scaleW, scaleH);
          canvas.save();
          bitmapW /= scale;
          bitmapH /= scale;
          drawRegion.set(
              imageX + (imageW - bitmapW) / 2,
              imageY + (imageH - bitmapH) / 2,
              imageX + (imageW + bitmapW) / 2,
              imageY + (imageH + bitmapH) / 2);
          bitmapDrawable.setBounds(drawRegion);
          try {
            bitmapDrawable.setAlpha(alpha);
            bitmapDrawable.draw(canvas);
          } catch (Exception e) {
            if (bitmapDrawable == currentImage && currentKey != null) {
              ImageLoader.getInstance().removeImage(currentKey);
              currentKey = null;
            } else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
              ImageLoader.getInstance().removeImage(currentThumbKey);
              currentThumbKey = null;
            }
            setImage(
                currentImageLocation,
                currentHttpUrl,
                currentFilter,
                currentThumb,
                currentThumbLocation,
                currentThumbFilter,
                currentSize,
                currentExt,
                currentCacheOnly);
            FileLog.e("tmessages", e);
          }
          canvas.restore();
        } else {
          if (Math.abs(scaleW - scaleH) > 0.00001f) {
            canvas.save();
            canvas.clipRect(imageX, imageY, imageX + imageW, imageY + imageH);

            if (orientation != 0) {
              if (centerRotation) {
                canvas.rotate(orientation, imageW / 2, imageH / 2);
              } else {
                canvas.rotate(orientation, 0, 0);
              }
            }

            if (bitmapW / scaleH > imageW) {
              bitmapW /= scaleH;
              drawRegion.set(
                  imageX - (bitmapW - imageW) / 2,
                  imageY,
                  imageX + (bitmapW + imageW) / 2,
                  imageY + imageH);
            } else {
              bitmapH /= scaleW;
              drawRegion.set(
                  imageX,
                  imageY - (bitmapH - imageH) / 2,
                  imageX + imageW,
                  imageY + (bitmapH + imageH) / 2);
            }
            if (orientation == 90 || orientation == 270) {
              int width = (drawRegion.right - drawRegion.left) / 2;
              int height = (drawRegion.bottom - drawRegion.top) / 2;
              int centerX = (drawRegion.right + drawRegion.left) / 2;
              int centerY = (drawRegion.top + drawRegion.bottom) / 2;
              bitmapDrawable.setBounds(
                  centerX - height, centerY - width, centerX + height, centerY + width);
            } else {
              bitmapDrawable.setBounds(drawRegion);
            }
            if (isVisible) {
              try {
                bitmapDrawable.setAlpha(alpha);
                bitmapDrawable.draw(canvas);
              } catch (Exception e) {
                if (bitmapDrawable == currentImage && currentKey != null) {
                  ImageLoader.getInstance().removeImage(currentKey);
                  currentKey = null;
                } else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
                  ImageLoader.getInstance().removeImage(currentThumbKey);
                  currentThumbKey = null;
                }
                setImage(
                    currentImageLocation,
                    currentHttpUrl,
                    currentFilter,
                    currentThumb,
                    currentThumbLocation,
                    currentThumbFilter,
                    currentSize,
                    currentExt,
                    currentCacheOnly);
                FileLog.e("tmessages", e);
              }
            }

            canvas.restore();
          } else {
            canvas.save();
            if (orientation != 0) {
              if (centerRotation) {
                canvas.rotate(orientation, imageW / 2, imageH / 2);
              } else {
                canvas.rotate(orientation, 0, 0);
              }
            }
            drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
            if (orientation == 90 || orientation == 270) {
              int width = (drawRegion.right - drawRegion.left) / 2;
              int height = (drawRegion.bottom - drawRegion.top) / 2;
              int centerX = (drawRegion.right + drawRegion.left) / 2;
              int centerY = (drawRegion.top + drawRegion.bottom) / 2;
              bitmapDrawable.setBounds(
                  centerX - height, centerY - width, centerX + height, centerY + width);
            } else {
              bitmapDrawable.setBounds(drawRegion);
            }
            if (isVisible) {
              try {
                bitmapDrawable.setAlpha(alpha);
                bitmapDrawable.draw(canvas);
              } catch (Exception e) {
                if (bitmapDrawable == currentImage && currentKey != null) {
                  ImageLoader.getInstance().removeImage(currentKey);
                  currentKey = null;
                } else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
                  ImageLoader.getInstance().removeImage(currentThumbKey);
                  currentThumbKey = null;
                }
                setImage(
                    currentImageLocation,
                    currentHttpUrl,
                    currentFilter,
                    currentThumb,
                    currentThumbLocation,
                    currentThumbFilter,
                    currentSize,
                    currentExt,
                    currentCacheOnly);
                FileLog.e("tmessages", e);
              }
            }
            canvas.restore();
          }
        }
      }
    } else {
      drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
      drawable.setBounds(drawRegion);
      if (isVisible) {
        try {
          drawable.setAlpha(alpha);
          drawable.draw(canvas);
        } catch (Exception e) {
          FileLog.e("tmessages", e);
        }
      }
    }
  }
Ejemplo n.º 5
0
 public void setImage(String httpUrl, String filter, Drawable thumb, String ext, int size) {
   setImage(null, httpUrl, filter, thumb, null, null, size, ext, true);
 }
Ejemplo n.º 6
0
 public void setImage(
     TLObject path, String filter, Drawable thumb, int size, String ext, boolean cacheOnly) {
   setImage(path, null, filter, thumb, null, null, size, ext, cacheOnly);
 }