Esempio n. 1
0
 @Override
 protected void onDetachedFromWindow() {
   super.onDetachedFromWindow();
   if (avatarImage != null) {
     avatarImage.clearImage();
     lastAvatar = null;
   }
 }
Esempio n. 2
0
  @Override
  protected void onDraw(Canvas canvas) {
    if (user == null && chat == null && encryptedChat == null) {
      return;
    }

    if (cellLayout == null) {
      requestLayout();
      return;
    }

    if (drawAlpha != 1) {
      canvas.saveLayerAlpha(
          0,
          0,
          canvas.getWidth(),
          canvas.getHeight(),
          (int) (255 * drawAlpha),
          Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
    }

    if (cellLayout.drawNameLock) {
      setDrawableBounds(lockDrawable, cellLayout.nameLockLeft, cellLayout.nameLockTop);
      lockDrawable.draw(canvas);
    }

    canvas.save();
    canvas.translate(cellLayout.nameLeft, cellLayout.nameTop);
    cellLayout.nameLayout.draw(canvas);
    canvas.restore();

    if (cellLayout.onlineLayout != null) {
      canvas.save();
      canvas.translate(cellLayout.onlineLeft, cellLayout.onlineTop);
      cellLayout.onlineLayout.draw(canvas);
      canvas.restore();
    }

    avatarImage.draw(
        canvas, cellLayout.avatarLeft, cellLayout.avatarTop, Utilities.dp(50), Utilities.dp(50));

    if (useSeparator) {
      int h = getMeasuredHeight();
      if (!usePadding) {
        canvas.drawLine(0, h - 1, getMeasuredWidth(), h, linePaint);
      } else {
        canvas.drawLine(
            Utilities.dp(11), h - 1, getMeasuredWidth() - Utilities.dp(11), h, linePaint);
      }
    }
  }
Esempio n. 3
0
  private void init() {
    if (namePaint == null) {
      namePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      namePaint.setTextSize(Utilities.dp(18));
      namePaint.setColor(0xff222222);
    }

    if (nameEncryptedPaint == null) {
      nameEncryptedPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      nameEncryptedPaint.setTextSize(Utilities.dp(18));
      nameEncryptedPaint.setColor(0xff00a60e);
    }

    if (onlinePaint == null) {
      onlinePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      onlinePaint.setTextSize(Utilities.dp(15));
      onlinePaint.setColor(0xff316f9f);
    }

    if (offlinePaint == null) {
      offlinePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      offlinePaint.setTextSize(Utilities.dp(15));
      offlinePaint.setColor(0xff999999);
    }

    if (lockDrawable == null) {
      lockDrawable = getResources().getDrawable(R.drawable.ic_lock_green);
    }

    if (linePaint == null) {
      linePaint = new Paint();
      linePaint.setColor(0xffdcdcdc);
    }

    if (avatarImage == null) {
      avatarImage = new ImageReceiver();
      avatarImage.parentView = new WeakReference<View>(this);
    }

    if (cellLayout == null) {
      cellLayout = new ChatOrUserCellLayout();
    }
  }
Esempio n. 4
0
  public void update(int mask) {
    int placeHolderId = 0;
    TLRPC.FileLocation photo = null;
    if (user != null) {
      if (user.photo != null) {
        photo = user.photo.photo_small;
      }
      placeHolderId = Utilities.getUserAvatarForId(user.id);
    } else if (chat != null) {
      if (chat.photo != null) {
        photo = chat.photo.photo_small;
      }
      placeHolderId = Utilities.getGroupAvatarForId(chat.id);
    }

    if (mask != 0) {
      boolean continueUpdate = false;
      if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 && user != null
          || (mask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0 && chat != null) {
        if (lastAvatar != null && photo == null
            || lastAvatar == null
                && photo != null
                && lastAvatar != null
                && photo != null
                && (lastAvatar.volume_id != photo.volume_id
                    || lastAvatar.local_id != photo.local_id)) {
          continueUpdate = true;
        }
      }
      if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_STATUS) != 0 && user != null) {
        int newStatus = 0;
        if (user.status != null) {
          newStatus = user.status.expires;
        }
        if (newStatus != lastStatus) {
          continueUpdate = true;
        }
      }
      if (!continueUpdate && ((mask & MessagesController.UPDATE_MASK_NAME) != 0 && user != null)
          || (mask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0 && chat != null) {
        String newName;
        if (user != null) {
          newName = user.first_name + user.last_name;
        } else {
          newName = chat.title;
        }
        if (!newName.equals(lastName)) {
          continueUpdate = true;
        }
      }

      if (!continueUpdate) {
        return;
      }
    }

    if (user != null) {
      if (user.status != null) {
        lastStatus = user.status.expires;
      } else {
        lastStatus = 0;
      }
      lastName = user.first_name + user.last_name;
    } else if (chat != null) {
      lastName = chat.title;
    }

    lastAvatar = photo;
    avatarImage.setImage(
        photo, "50_50", placeHolderId == 0 ? null : getResources().getDrawable(placeHolderId));

    if (getMeasuredWidth() != 0 || getMeasuredHeight() != 0) {
      buildLayout();
    } else {
      requestLayout();
    }
    postInvalidate();
  }