private void drawPlaceHolder(Canvas canvas) { placeholderPaint.setColor(layout.placeHolderColor); placeholderTextPaint.setAlpha(255); placeholderPaint.setAlpha(255); avatarPaint.setAlpha(255); rect.set( layout.layoutAvatarLeft, layout.layoutAvatarTop, layout.layoutAvatarLeft + layout.layoutAvatarWidth, layout.layoutAvatarTop + layout.layoutAvatarWidth); canvas.drawRect(rect, placeholderPaint); if (layout.usePlaceholder) { canvas.drawText( layout.placeHolderName, layout.placeholderLeft, layout.placeholderTop, placeholderTextPaint); } else { rect2.set(0, 0, placeholder.getWidth(), placeholder.getHeight()); canvas.drawBitmap(placeholder, rect2, rect, avatarPaint); } }
public void setDescription(DialogWireframe description, Object preparedLayouts) { this.preparedLayouts = (DialogLayout[]) preparedLayouts; this.description = description; this.state = description.getMessageState(); if (description.getPeerType() == PeerType.PEER_CHAT) { this.typingUids = application.getTypingStates().getChatTypes(description.getPeerId()); } else { this.userTypes = application.getTypingStates().isUserTyping(description.getPeerId()); } photo = description.getDialogAvatar(); if (description.getPeerType() == PeerType.PEER_USER_ENCRYPTED) { EncryptedChat encryptedChat = application.getEngine().getEncryptedChat(description.getPeerId()); avatarBgPaint.setColor(Placeholders.getBgColor(encryptedChat.getUserId())); placeholder = userPlaceHolder; } else if (description.getPeerType() == PeerType.PEER_USER) { avatarBgPaint.setColor(Placeholders.getBgColor(description.getPeerId())); placeholder = userPlaceHolder; } else if (description.getPeerType() == PeerType.PEER_CHAT) { avatarBgPaint.setColor(Placeholders.getBgColor(description.getPeerId())); placeholder = groupPlaceHolder; } else { throw new UnsupportedOperationException("Unknown peer type #" + description.getPeerType()); } if (photo instanceof TLLocalAvatarPhoto) { if (!loader.requestAvatar( ((TLLocalAvatarPhoto) photo).getPreviewLocation(), IS_LARGE ? AvatarLoader.TYPE_MEDIUM2 : AvatarLoader.TYPE_MEDIUM, this)) { releaseAvatar(); } } else { releaseAvatar(); loader.cancelRequest(this); } if (getMeasuredHeight() != 0 || getMeasuredWidth() != 0) { buildLayout(); invalidate(); } else { requestLayout(); } needNewUpdateTyping = true; }
public DialogView(Context context) { super(context); checkResources(context); this.application = (TelegramApplication) context.getApplicationContext(); this.loader = application.getUiKernel().getAvatarLoader(); this.currentUserUid = application.getCurrentUid(); application.getTypingStates().registerListener(this); avatarBgPaint = new Paint(); avatarBgPaint.setStyle(Paint.Style.FILL); statePending = getResources().getDrawable(R.drawable.st_dialogs_clock); stateSent = getResources().getDrawable(R.drawable.st_dialogs_check); stateHalfCheck = getResources().getDrawable(R.drawable.st_dialogs_halfcheck); stateFailure = getResources().getDrawable(R.drawable.st_dialogs_warning); secureIcon = getResources().getDrawable(R.drawable.st_dialogs_lock); userPlaceHolder = ((BitmapDrawable) getResources().getDrawable(R.drawable.st_user_placeholder_dialog)) .getBitmap(); groupPlaceHolder = ((BitmapDrawable) getResources().getDrawable(R.drawable.st_group_placeholder)).getBitmap(); }
protected void init() { super.init(); checkResources(getContext()); clockIconPaint = new Paint(); clockIconPaint.setStyle(Paint.Style.STROKE); clockIconPaint.setColor(0xff12C000); clockIconPaint.setStrokeWidth(getPx(1)); clockIconPaint.setAntiAlias(true); clockIconPaint.setFlags(Paint.ANTI_ALIAS_FLAG); statePending = getResources().getDrawable(R.drawable.st_bubble_ic_clock); stateSent = getResources().getDrawable(R.drawable.st_bubble_ic_check); stateHalfCheck = getResources().getDrawable(R.drawable.st_bubble_ic_halfcheck); stateFailure = getResources().getDrawable(R.drawable.st_bubble_ic_warning); }
@Override protected void onDraw(Canvas canvas) { if (layout == null) { requestLayout(); return; } if (description == null) { return; } if (needNewUpdateTyping) { updateTyping(); } if (layout.isEncrypted) { bounds(secureIcon, layout.layoutEncryptedLeft, layout.layoutEncryptedTop); secureIcon.draw(canvas); } if (layout.titleLayout != null) { canvas.save(); canvas.translate(layout.layoutTitleLeft, layout.layoutTitleLayoutTop); layout.titleLayout.draw(canvas); canvas.restore(); } else if (layout.titleString != null) { TextPaint paint = layout.isEncrypted ? titleEncryptedPaint : (layout.isHighlighted ? titleHighlightPaint : titlePaint); canvas.drawText(layout.titleString, layout.layoutTitleLeft, layout.layoutTitleTop, paint); } if (state != MessageState.FAILURE && description.getSenderId() == currentUserUid) { switch (state) { default: case MessageState.PENDING: bound(statePending, layout.layoutClockLeft, layout.layoutClockTop); statePending.draw(canvas); break; case MessageState.SENT: bound(stateSent, layout.layoutStateLeft, layout.layoutStateTop); stateSent.draw(canvas); break; case MessageState.READED: bound(stateSent, layout.layoutStateLeftDouble, layout.layoutStateTop); stateSent.draw(canvas); bound(stateHalfCheck, layout.layoutStateLeft, layout.layoutStateTop); stateHalfCheck.draw(canvas); break; } } TextPaint timePaint = HIGHLIGHT_UNDEAD ? (layout.isUnreadIn ? unreadClockPaint : readClockPaint) : readClockPaint; canvas.drawText(layout.time, layout.layoutTimeLeft, layout.layoutTimeTop, timePaint); if (typingLayout != null) { canvas.save(); canvas.translate(layout.layoutMainLeft, layout.layoutMainContentTop); typingLayout.draw(canvas); canvas.restore(); } else if (layout.bodyLayout != null) { canvas.save(); canvas.translate(layout.layoutMainLeft, layout.layoutMainContentTop); layout.bodyLayout.draw(canvas); canvas.restore(); } else if (layout.bodyString != null) { // canvas.save(); // canvas.translate(layout.layoutMainLeft, layout.layoutMainTop); // layout.bodyLayout.draw(canvas); // canvas.restore(); canvas.drawText(layout.bodyString, layout.layoutMainLeft, layout.layoutMainTop, bodyPaint); } if (avatarHolder != null) { long time = SystemClock.uptimeMillis() - avatarAppearTime; if (time > AVATAR_FADE_TIME || !AVATAR_FADE) { avatarPaint.setAlpha(255); canvas.drawBitmap( avatarHolder.getBitmap(), layout.layoutAvatarLeft, layout.layoutAvatarTop, avatarPaint); } else { drawPlaceHolder(canvas); float alpha = time / (float) AVATAR_FADE_TIME; avatarPaint.setAlpha((int) (255 * alpha)); canvas.drawBitmap( avatarHolder.getBitmap(), layout.layoutAvatarLeft, layout.layoutAvatarTop, avatarPaint); inavalidateForAnimation(); } } else { drawPlaceHolder(canvas); } if (description.isErrorState() || (state == MessageState.FAILURE && description.getSenderId() == currentUserUid)) { bound(stateFailure, layout.layoutMarkLeft, layout.layoutMarkTop); stateFailure.draw(canvas); } else if (description.getUnreadCount() > 0) { canvas.drawRoundRect( layout.layoutMarkRect, layout.layoutMarkRadius, layout.layoutMarkRadius, counterPaint); canvas.drawText( layout.unreadCountText, layout.layoutMarkLeft + layout.layoutMarkTextLeft, layout.layoutMarkTextTop, counterTitlePaint); } }
private static void checkResources(Context context) { if (!isLoaded) { TelegramApplication application = (TelegramApplication) context.getApplicationContext(); IS_LARGE = application.getUserSettings().getDialogItemSize() == UserSettings.DIALOG_SIZE_LARGE; avatarPaint = new Paint(); if (FontController.USE_SUBPIXEL) { titlePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); } else { titlePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); } titlePaint.setColor(0xff222222); if (IS_LARGE) { titlePaint.setTextSize(sp(20f)); titlePaint.setTypeface(FontController.loadTypeface(context, "medium")); } else { titlePaint.setTextSize(sp(18f)); titlePaint.setTypeface(FontController.loadTypeface(context, "medium")); } if (FontController.USE_SUBPIXEL) { titleHighlightPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); } else { titleHighlightPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); } titleHighlightPaint.setColor(0xff006FC8); if (IS_LARGE) { titleHighlightPaint.setTextSize(sp(20f)); titleHighlightPaint.setTypeface(FontController.loadTypeface(context, "medium")); } else { titleHighlightPaint.setTextSize(sp(18f)); titleHighlightPaint.setTypeface(FontController.loadTypeface(context, "medium")); } if (FontController.USE_SUBPIXEL) { titleEncryptedPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); } else { titleEncryptedPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); } titleEncryptedPaint.setColor(0xff368c3e); if (IS_LARGE) { titleEncryptedPaint.setTextSize(sp(20f)); titleEncryptedPaint.setTypeface(FontController.loadTypeface(context, "medium")); } else { titleEncryptedPaint.setTextSize(sp(18f)); titleEncryptedPaint.setTypeface(FontController.loadTypeface(context, "medium")); } if (FontController.USE_SUBPIXEL) { unreadClockPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); } else { unreadClockPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); } unreadClockPaint.setColor(UNREAD_TIME_COLOR); unreadClockPaint.setTextSize(sp(14)); unreadClockPaint.setTypeface(FontController.loadTypeface(context, "regular")); if (FontController.USE_SUBPIXEL) { readClockPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); } else { readClockPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); } readClockPaint.setColor(READ_TIME_COLOR); readClockPaint.setTextSize(sp(14)); readClockPaint.setTypeface(FontController.loadTypeface(context, "regular")); if (FontController.USE_SUBPIXEL) { bodyPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); } else { bodyPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); } bodyPaint.setColor(READ_COLOR); bodyPaint.setTextSize(sp(17f)); bodyPaint.setTypeface(FontController.loadTypeface(context, "regular")); if (FontController.USE_SUBPIXEL) { bodyUnreadPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); } else { bodyUnreadPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); } bodyUnreadPaint.setColor(UNREAD_COLOR); bodyUnreadPaint.setTextSize(sp(17f)); bodyUnreadPaint.setTypeface(FontController.loadTypeface(context, "regular")); if (FontController.USE_SUBPIXEL) { bodyHighlightPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); } else { bodyHighlightPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); } bodyHighlightPaint.setColor(HIGHLIGHT_COLOR); bodyHighlightPaint.setTextSize(sp(17f)); bodyHighlightPaint.setTypeface(FontController.loadTypeface(context, "regular")); if (FontController.USE_SUBPIXEL) { typingPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); } else { typingPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); } typingPaint.setColor(0xff006FC8); typingPaint.setTextSize(sp(16f)); typingPaint.setTypeface(FontController.loadTypeface(context, "regular")); if (FontController.USE_SUBPIXEL) { counterTitlePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); } else { counterTitlePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); } counterTitlePaint.setColor(0xffffffff); if (IS_LARGE) { counterTitlePaint.setTextSize(sp(15.5f)); } else { counterTitlePaint.setTextSize(sp(14f)); } counterTitlePaint.setTypeface(FontController.loadTypeface(context, "regular")); counterPaint = new Paint(); counterPaint.setColor(0xff8fc478); counterPaint.setAntiAlias(true); placeholderPaint = new Paint(); placeholderPaint.setAntiAlias(true); if (FontController.USE_SUBPIXEL) { placeholderTextPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); } else { placeholderTextPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); } placeholderTextPaint.setColor(0xffffffff); placeholderTextPaint.setTextSize(px(28f)); placeholderTextPaint.setTypeface(FontController.loadTypeface(context, "regular")); placeholderTextPaint.setTextAlign(Paint.Align.CENTER); isLoaded = true; } }