Java Code Examples for android.text.StaticLayout#getLineLeft()

The following examples show how to use android.text.StaticLayout#getLineLeft() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LetterDrawable.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void setTitle(String title) {
    stringBuilder.setLength(0);
    if (title != null && title.length() > 0) {
        stringBuilder.append(title.substring(0, 1));
    }

    if (stringBuilder.length() > 0) {
        String text = stringBuilder.toString().toUpperCase();
        try {
            textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (textLayout.getLineCount() > 0) {
                textLeft = textLayout.getLineLeft(0);
                textWidth = textLayout.getLineWidth(0);
                textHeight = textLayout.getLineBottom(0);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        textLayout = null;
    }
}
 
Example 2
Source File: LetterDrawable.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void setTitle(String title) {
    stringBuilder.setLength(0);
    if (title != null && title.length() > 0) {
        stringBuilder.append(title.substring(0, 1));
    }

    if (stringBuilder.length() > 0) {
        String text = stringBuilder.toString().toUpperCase();
        try {
            textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (textLayout.getLineCount() > 0) {
                textLeft = textLayout.getLineLeft(0);
                textWidth = textLayout.getLineWidth(0);
                textHeight = textLayout.getLineBottom(0);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        textLayout = null;
    }
}
 
Example 3
Source File: LetterDrawable.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void setTitle(String title) {
    stringBuilder.setLength(0);
    if (title != null && title.length() > 0) {
        stringBuilder.append(title.substring(0, 1));
    }

    if (stringBuilder.length() > 0) {
        String text = stringBuilder.toString().toUpperCase();
        try {
            textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (textLayout.getLineCount() > 0) {
                textLeft = textLayout.getLineLeft(0);
                textWidth = textLayout.getLineWidth(0);
                textHeight = textLayout.getLineBottom(0);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        textLayout = null;
    }
}
 
Example 4
Source File: LetterDrawable.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void setTitle(String title) {
    stringBuilder.setLength(0);
    if (title != null && title.length() > 0) {
        stringBuilder.append(title.substring(0, 1));
    }

    if (stringBuilder.length() > 0) {
        String text = stringBuilder.toString().toUpperCase();
        try {
            textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (textLayout.getLineCount() > 0) {
                textLeft = textLayout.getLineLeft(0);
                textWidth = textLayout.getLineWidth(0);
                textHeight = textLayout.getLineBottom(0);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        textLayout = null;
    }
}
 
Example 5
Source File: AvatarDrawable.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setInfo(int id, String firstName, String lastName, boolean isBroadcast, String custom) {
    if (isProfile) {
        color = getProfileColorForId(id);
    } else {
        color = getColorForId(id);
    }

    drawBrodcast = isBroadcast;
    savedMessages = 0;

    if (firstName == null || firstName.length() == 0) {
        firstName = lastName;
        lastName = null;
    }

    stringBuilder.setLength(0);
    if (custom != null) {
        stringBuilder.append(custom);
    } else {
        if (firstName != null && firstName.length() > 0) {
            stringBuilder.appendCodePoint(firstName.codePointAt(0));
        }
        if (lastName != null && lastName.length() > 0) {
            Integer lastch = null;
            for (int a = lastName.length() - 1; a >= 0; a--) {
                if (lastch != null && lastName.charAt(a) == ' ') {
                    break;
                }
                lastch = lastName.codePointAt(a);
            }
            if (Build.VERSION.SDK_INT > 17) {
                stringBuilder.append("\u200C");
            }
            stringBuilder.appendCodePoint(lastch);
        } else if (firstName != null && firstName.length() > 0) {
            for (int a = firstName.length() - 1; a >= 0; a--) {
                if (firstName.charAt(a) == ' ') {
                    if (a != firstName.length() - 1 && firstName.charAt(a + 1) != ' ') {
                        if (Build.VERSION.SDK_INT > 17) {
                            stringBuilder.append("\u200C");
                        }
                        stringBuilder.appendCodePoint(firstName.codePointAt(a + 1));
                        break;
                    }
                }
            }
        }
    }

    if (stringBuilder.length() > 0) {
        String text = stringBuilder.toString().toUpperCase();
        try {
            textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (textLayout.getLineCount() > 0) {
                textLeft = textLayout.getLineLeft(0);
                textWidth = textLayout.getLineWidth(0);
                textHeight = textLayout.getLineBottom(0);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        textLayout = null;
    }
}
 
Example 6
Source File: GroupCreateSpan.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public GroupCreateSpan(Context context, TLRPC.User user, ContactsController.Contact contact) {
    super(context);

    currentContact = contact;
    deleteDrawable = getResources().getDrawable(R.drawable.delete);
    textPaint.setTextSize(AndroidUtilities.dp(14));

    avatarDrawable = new AvatarDrawable();
    avatarDrawable.setTextSize(AndroidUtilities.dp(12));
    if (user != null) {
        avatarDrawable.setInfo(user);
        uid = user.id;
    } else {
        avatarDrawable.setInfo(0, contact.first_name, contact.last_name, false);
        uid = contact.contact_id;
        key = contact.key;
    }

    imageReceiver = new ImageReceiver();
    imageReceiver.setRoundRadius(AndroidUtilities.dp(16));
    imageReceiver.setParentView(this);
    imageReceiver.setImageCoords(0, 0, AndroidUtilities.dp(32), AndroidUtilities.dp(32));

    int maxNameWidth;
    if (AndroidUtilities.isTablet()) {
        maxNameWidth = AndroidUtilities.dp(530 - 32 - 18 - 57 * 2) / 2;
    } else {
        maxNameWidth = (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(32 + 18 + 57 * 2)) / 2;
    }
    String firstName;
    if (user != null) {
        firstName = UserObject.getFirstName(user);
    } else {
        if (!TextUtils.isEmpty(contact.first_name)) {
            firstName = contact.first_name;
        } else {
            firstName = contact.last_name;
        }
    }
    CharSequence name = TextUtils.ellipsize(firstName.replace('\n', ' '), textPaint, maxNameWidth, TextUtils.TruncateAt.END);
    nameLayout = new StaticLayout(name, textPaint, 1000, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    if (nameLayout.getLineCount() > 0) {
        textWidth = (int) Math.ceil(nameLayout.getLineWidth(0));
        textX = -nameLayout.getLineLeft(0);
    }

    TLRPC.FileLocation photo = null;
    if (user != null && user.photo != null) {
        photo = user.photo.photo_small;
    }
    imageReceiver.setImage(photo, null, "50_50", avatarDrawable, null, null, 0, null, 1);
    updateColors();
}
 
Example 7
Source File: AvatarDrawable.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setInfo(int id, String firstName, String lastName, boolean isBroadcast, String custom) {
    if (isProfile) {
        color = getProfileColorForId(id);
    } else {
        color = getColorForId(id);
    }

    drawBrodcast = isBroadcast;
    savedMessages = 0;

    if (firstName == null || firstName.length() == 0) {
        firstName = lastName;
        lastName = null;
    }

    stringBuilder.setLength(0);
    if (custom != null) {
        stringBuilder.append(custom);
    } else {
        if (firstName != null && firstName.length() > 0) {
            stringBuilder.appendCodePoint(firstName.codePointAt(0));
        }
        if (lastName != null && lastName.length() > 0) {
            Integer lastch = null;
            for (int a = lastName.length() - 1; a >= 0; a--) {
                if (lastch != null && lastName.charAt(a) == ' ') {
                    break;
                }
                lastch = lastName.codePointAt(a);
            }
            if (Build.VERSION.SDK_INT > 17) {
                stringBuilder.append("\u200C");
            }
            stringBuilder.appendCodePoint(lastch);
        } else if (firstName != null && firstName.length() > 0) {
            for (int a = firstName.length() - 1; a >= 0; a--) {
                if (firstName.charAt(a) == ' ') {
                    if (a != firstName.length() - 1 && firstName.charAt(a + 1) != ' ') {
                        if (Build.VERSION.SDK_INT > 17) {
                            stringBuilder.append("\u200C");
                        }
                        stringBuilder.appendCodePoint(firstName.codePointAt(a + 1));
                        break;
                    }
                }
            }
        }
    }

    if (stringBuilder.length() > 0) {
        String text = stringBuilder.toString().toUpperCase();
        try {
            textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (textLayout.getLineCount() > 0) {
                textLeft = textLayout.getLineLeft(0);
                textWidth = textLayout.getLineWidth(0);
                textHeight = textLayout.getLineBottom(0);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        textLayout = null;
    }
}
 
Example 8
Source File: GroupCreateSpan.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public GroupCreateSpan(Context context, TLRPC.User user, ContactsController.Contact contact) {
    super(context);

    currentContact = contact;
    deleteDrawable = getResources().getDrawable(R.drawable.delete);
    textPaint.setTextSize(AndroidUtilities.dp(14));

    avatarDrawable = new AvatarDrawable();
    avatarDrawable.setTextSize(AndroidUtilities.dp(12));
    if (user != null) {
        avatarDrawable.setInfo(user);
        uid = user.id;
    } else {
        avatarDrawable.setInfo(0, contact.first_name, contact.last_name, false);
        uid = contact.contact_id;
        key = contact.key;
    }

    imageReceiver = new ImageReceiver();
    imageReceiver.setRoundRadius(AndroidUtilities.dp(16));
    imageReceiver.setParentView(this);
    imageReceiver.setImageCoords(0, 0, AndroidUtilities.dp(32), AndroidUtilities.dp(32));

    int maxNameWidth;
    if (AndroidUtilities.isTablet()) {
        maxNameWidth = AndroidUtilities.dp(530 - 32 - 18 - 57 * 2) / 2;
    } else {
        maxNameWidth = (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(32 + 18 + 57 * 2)) / 2;
    }
    String firstName;
    if (user != null) {
        firstName = UserObject.getFirstName(user);
    } else {
        if (!TextUtils.isEmpty(contact.first_name)) {
            firstName = contact.first_name;
        } else {
            firstName = contact.last_name;
        }
    }
    CharSequence name = TextUtils.ellipsize(firstName.replace('\n', ' '), textPaint, maxNameWidth, TextUtils.TruncateAt.END);
    nameLayout = new StaticLayout(name, textPaint, 1000, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    if (nameLayout.getLineCount() > 0) {
        textWidth = (int) Math.ceil(nameLayout.getLineWidth(0));
        textX = -nameLayout.getLineLeft(0);
    }

    TLRPC.FileLocation photo = null;
    if (user != null && user.photo != null) {
        photo = user.photo.photo_small;
    }
    imageReceiver.setImage(photo, null, "50_50", avatarDrawable, null, null, 0, null, 1);
    updateColors();
}
 
Example 9
Source File: SubtitlePainter.java    From no-player with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("PMD.NPathComplexity")  // TODO break this method up
private void drawTextLayout(Canvas canvas) {
    StaticLayout layout = textLayout;
    if (layout == null) {
        // Nothing to draw.
        return;
    }

    int saveCount = canvas.save();
    canvas.translate(textLeft, textTop);

    if (Color.alpha(windowColor) > 0) {
        paint.setColor(windowColor);
        canvas.drawRect(-textPaddingX, 0, layout.getWidth() + textPaddingX, layout.getHeight(),
                paint);
    }

    if (Color.alpha(backgroundColor) > 0) {
        paint.setColor(backgroundColor);
        float previousBottom = layout.getLineTop(0);
        int lineCount = layout.getLineCount();
        for (int i = 0; i < lineCount; i++) {
            lineBounds.left = layout.getLineLeft(i) - textPaddingX;
            lineBounds.right = layout.getLineRight(i) + textPaddingX;
            lineBounds.top = previousBottom;
            lineBounds.bottom = layout.getLineBottom(i);
            previousBottom = lineBounds.bottom;
            canvas.drawRoundRect(lineBounds, cornerRadius, cornerRadius, paint);
        }
    }

    if (edgeType == CaptionStyleCompat.EDGE_TYPE_OUTLINE) {
        textPaint.setStrokeJoin(Join.ROUND);
        textPaint.setStrokeWidth(outlineWidth);
        textPaint.setColor(edgeColor);
        textPaint.setStyle(Style.FILL_AND_STROKE);
        layout.draw(canvas);
    } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_DROP_SHADOW) {
        textPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, edgeColor);
    } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED
            || edgeType == CaptionStyleCompat.EDGE_TYPE_DEPRESSED) {
        boolean raised = edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED;
        int colorUp = raised ? Color.WHITE : edgeColor;
        int colorDown = raised ? edgeColor : Color.WHITE;
        float offset = shadowRadius / 2;
        textPaint.setColor(foregroundColor);
        textPaint.setStyle(Style.FILL);
        textPaint.setShadowLayer(shadowRadius, -offset, -offset, colorUp);
        layout.draw(canvas);
        textPaint.setShadowLayer(shadowRadius, offset, offset, colorDown);
    }

    textPaint.setColor(foregroundColor);
    textPaint.setStyle(Style.FILL);
    layout.draw(canvas);
    textPaint.setShadowLayer(0, 0, 0, 0);

    canvas.restoreToCount(saveCount);
}
 
Example 10
Source File: SubtitlePainter.java    From K-Sonic with MIT License 4 votes vote down vote up
private void drawTextLayout(Canvas canvas) {
  StaticLayout layout = textLayout;
  if (layout == null) {
    // Nothing to draw.
    return;
  }

  int saveCount = canvas.save();
  canvas.translate(textLeft, textTop);

  if (Color.alpha(windowColor) > 0) {
    paint.setColor(windowColor);
    canvas.drawRect(-textPaddingX, 0, layout.getWidth() + textPaddingX, layout.getHeight(),
        paint);
  }

  if (Color.alpha(backgroundColor) > 0) {
    paint.setColor(backgroundColor);
    float previousBottom = layout.getLineTop(0);
    int lineCount = layout.getLineCount();
    for (int i = 0; i < lineCount; i++) {
      lineBounds.left = layout.getLineLeft(i) - textPaddingX;
      lineBounds.right = layout.getLineRight(i) + textPaddingX;
      lineBounds.top = previousBottom;
      lineBounds.bottom = layout.getLineBottom(i);
      previousBottom = lineBounds.bottom;
      canvas.drawRoundRect(lineBounds, cornerRadius, cornerRadius, paint);
    }
  }

  if (edgeType == CaptionStyleCompat.EDGE_TYPE_OUTLINE) {
    textPaint.setStrokeJoin(Join.ROUND);
    textPaint.setStrokeWidth(outlineWidth);
    textPaint.setColor(edgeColor);
    textPaint.setStyle(Style.FILL_AND_STROKE);
    layout.draw(canvas);
  } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_DROP_SHADOW) {
    textPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, edgeColor);
  } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED
      || edgeType == CaptionStyleCompat.EDGE_TYPE_DEPRESSED) {
    boolean raised = edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED;
    int colorUp = raised ? Color.WHITE : edgeColor;
    int colorDown = raised ? edgeColor : Color.WHITE;
    float offset = shadowRadius / 2f;
    textPaint.setColor(foregroundColor);
    textPaint.setStyle(Style.FILL);
    textPaint.setShadowLayer(shadowRadius, -offset, -offset, colorUp);
    layout.draw(canvas);
    textPaint.setShadowLayer(shadowRadius, offset, offset, colorDown);
  }

  textPaint.setColor(foregroundColor);
  textPaint.setStyle(Style.FILL);
  layout.draw(canvas);
  textPaint.setShadowLayer(0, 0, 0, 0);

  canvas.restoreToCount(saveCount);
}
 
Example 11
Source File: ChatBaseCell.java    From Yahala-Messenger with MIT License 4 votes vote down vote up
public void setMessageObject(MessageObject messageObject) {
    currentMessageObject = messageObject;
    isPressed = false;
    isCheckPressed = true;
    isAvatarVisible = false;
    wasLayout = false;

 /*  if (currentMessageObject.messageOwner.getId() < 0 && currentMessageObject.messageOwner.getSend_state() != MessagesController.MESSAGE_SEND_STATE_SEND_ERROR && currentMessageObject.messageOwner.getSend_state() != MessagesController.MESSAGE_SEND_STATE_SENT) {
       if (MessagesController.getInstance().sendingMessages.get(currentMessageObject.messageOwner.getId()) == null) {
            currentMessageObject.messageOwner.setSend_state(MessagesController.MESSAGE_SEND_STATE_SEND_ERROR);
        }
    }*/
    //FileLog.e("messageObject.messageOwner.getJid()",messageObject.messageOwner.getJid()+"");
    try {


        currentUser = ContactsController.getInstance().friendsDict.get(messageObject.messageOwner.getJid());

        if (isChat && currentMessageObject.isOut()) {
            isAvatarVisible = true;
            if (currentUser != null) {
                if (currentUser.photo != null) {
                    currentPhoto = currentUser.photo.photo_small;
                } else {
                    currentPhoto = null;
                }
                avatarImage.setImage(currentPhoto, "50_50", getResources().getDrawable(Utilities.getUserAvatarForId(currentUser.id)));
            } else {
                avatarImage.setImage((TLRPC.FileLocation) null, "50_50", null);
            }
        }

        if (!media) {
            if (currentMessageObject.isOut()) {
                currentTimePaint = timePaintOut;
            } else {
                currentTimePaint = timePaintIn;
            }
        } else {
            currentTimePaint = timeMediaPaint;
        }

        currentTimeString = LocaleController.formatterDay.format(currentMessageObject.messageOwner.getDate());
        timeWidth = (int) Math.ceil(currentTimePaint.measureText(currentTimeString));

        namesOffset = 0;

        if (drawName && isChat && currentUser != null && currentMessageObject.messageOwner.getOut() != 1) {
            currentNameString = Utilities.formatName(currentUser.first_name, currentUser.last_name);
            nameWidth = getMaxNameWidth();

            CharSequence nameStringFinal = TextUtils.ellipsize(currentNameString.replace("\n", " "), namePaint, nameWidth - OSUtilities.dp(12), TextUtils.TruncateAt.END);
            nameLayout = new StaticLayout(nameStringFinal, namePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (nameLayout.getLineCount() > 0) {
                nameWidth = (int) Math.ceil(nameLayout.getLineWidth(0));
                namesOffset += OSUtilities.dp(18);
                nameOffsetX = nameLayout.getLineLeft(0);
            } else {
                nameWidth = 0;
            }
        } else {
            currentNameString = null;
            nameLayout = null;
            nameWidth = 0;
        }

        //  if (drawForwardedName && messageObject.messageOwner.tl_message instanceof TLRPC.TL_messageForwarded) {
       /* currentForwardUser = MessagesController.getInstance().users.get(messageObject.messageOwner.fwd_from_id);
        if (currentForwardUser != null) {
            currentForwardNameString = Utilities.formatName(currentForwardUser.first_name, currentForwardUser.last_name);

            forwardedNameWidth = getMaxNameWidth();

            CharSequence str = TextUtils.ellipsize(currentForwardNameString.replace("\n", " "), forwardNamePaint, forwardedNameWidth - AndroidUtilities.dp(40), TextUtils.TruncateAt.END);
            str = Html.fromHtml(String.format("%s<br>%s <b>%s</b>", LocaleController.getString("ForwardedMessage", R.string.ForwardedMessage), LocaleController.getString("From", R.string.From), str));
            forwardedNameLayout = new StaticLayout(str, forwardNamePaint, forwardedNameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (forwardedNameLayout.getLineCount() > 1) {
                forwardedNameWidth = Math.max((int) Math.ceil(forwardedNameLayout.getLineWidth(0)), (int) Math.ceil(forwardedNameLayout.getLineWidth(1)));
                namesOffset += AndroidUtilities.dp(36);
                forwardNameOffsetX = Math.min(forwardedNameLayout.getLineLeft(0), forwardedNameLayout.getLineLeft(1));
            } else {
                forwardedNameWidth = 0;
            }
        } else {
            currentForwardNameString = null;
            forwardedNameLayout = null;
            forwardedNameWidth = 0;
        }*/
        //   } else {
        currentForwardNameString = null;
        forwardedNameLayout = null;
        forwardedNameWidth = 0;
        //   }

        requestLayout();
    } catch (Exception e) {
    }
}
 
Example 12
Source File: SubtitleView.java    From Exoplayer_VLC with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas c) {
  final StaticLayout layout = this.layout;
  if (layout == null) {
    return;
  }

  final int saveCount = c.save();
  final int innerPaddingX = this.innerPaddingX;
  c.translate(getPaddingLeft() + innerPaddingX, getPaddingTop());

  final int lineCount = layout.getLineCount();
  final Paint textPaint = this.textPaint;
  final Paint paint = this.paint;
  final RectF bounds = lineBounds;

  if (Color.alpha(backgroundColor) > 0) {
    final float cornerRadius = this.cornerRadius;
    float previousBottom = layout.getLineTop(0);

    paint.setColor(backgroundColor);
    paint.setStyle(Style.FILL);

    for (int i = 0; i < lineCount; i++) {
      bounds.left = layout.getLineLeft(i) - innerPaddingX;
      bounds.right = layout.getLineRight(i) + innerPaddingX;
      bounds.top = previousBottom;
      bounds.bottom = layout.getLineBottom(i);
      previousBottom = bounds.bottom;

      c.drawRoundRect(bounds, cornerRadius, cornerRadius, paint);
    }
  }

  if (edgeType == CaptionStyleCompat.EDGE_TYPE_OUTLINE) {
    textPaint.setStrokeJoin(Join.ROUND);
    textPaint.setStrokeWidth(outlineWidth);
    textPaint.setColor(edgeColor);
    textPaint.setStyle(Style.FILL_AND_STROKE);
    layout.draw(c);
  } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_DROP_SHADOW) {
    textPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, edgeColor);
  } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED
      || edgeType == CaptionStyleCompat.EDGE_TYPE_DEPRESSED) {
    boolean raised = edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED;
    int colorUp = raised ? Color.WHITE : edgeColor;
    int colorDown = raised ? edgeColor : Color.WHITE;
    float offset = shadowRadius / 2f;
    textPaint.setColor(foregroundColor);
    textPaint.setStyle(Style.FILL);
    textPaint.setShadowLayer(shadowRadius, -offset, -offset, colorUp);
    layout.draw(c);
    textPaint.setShadowLayer(shadowRadius, offset, offset, colorDown);
  }

  textPaint.setColor(foregroundColor);
  textPaint.setStyle(Style.FILL);
  layout.draw(c);
  textPaint.setShadowLayer(0, 0, 0, 0);
  c.restoreToCount(saveCount);
}
 
Example 13
Source File: AvatarDrawable.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void setInfo(int id, String firstName, String lastName, String custom) {
    if (isProfile) {
        color = getProfileColorForId(id);
    } else {
        color = getColorForId(id);
    }
    needApplyColorAccent = id == 5; // Tinting manually set blue color

    avatarType = AVATAR_TYPE_NORMAL;
    drawDeleted = false;

    if (firstName == null || firstName.length() == 0) {
        firstName = lastName;
        lastName = null;
    }

    stringBuilder.setLength(0);
    if (custom != null) {
        stringBuilder.append(custom);
    } else {
        if (firstName != null && firstName.length() > 0) {
            stringBuilder.appendCodePoint(firstName.codePointAt(0));
        }
        if (lastName != null && lastName.length() > 0) {
            Integer lastch = null;
            for (int a = lastName.length() - 1; a >= 0; a--) {
                if (lastch != null && lastName.charAt(a) == ' ') {
                    break;
                }
                lastch = lastName.codePointAt(a);
            }
            if (Build.VERSION.SDK_INT > 17) {
                stringBuilder.append("\u200C");
            }
            stringBuilder.appendCodePoint(lastch);
        } else if (firstName != null && firstName.length() > 0) {
            for (int a = firstName.length() - 1; a >= 0; a--) {
                if (firstName.charAt(a) == ' ') {
                    if (a != firstName.length() - 1 && firstName.charAt(a + 1) != ' ') {
                        if (Build.VERSION.SDK_INT > 17) {
                            stringBuilder.append("\u200C");
                        }
                        stringBuilder.appendCodePoint(firstName.codePointAt(a + 1));
                        break;
                    }
                }
            }
        }
    }

    if (stringBuilder.length() > 0) {
        String text = stringBuilder.toString().toUpperCase();
        try {
            textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (textLayout.getLineCount() > 0) {
                textLeft = textLayout.getLineLeft(0);
                textWidth = textLayout.getLineWidth(0);
                textHeight = textLayout.getLineBottom(0);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        textLayout = null;
    }
}
 
Example 14
Source File: AvatarDrawable.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void setInfo(int id, String firstName, String lastName, String custom) {
    if (isProfile) {
        color = getProfileColorForId(id);
    } else {
        color = getColorForId(id);
    }
    needApplyColorAccent = id == 5; // Tinting manually set blue color

    avatarType = AVATAR_TYPE_NORMAL;
    drawDeleted = false;

    if (firstName == null || firstName.length() == 0) {
        firstName = lastName;
        lastName = null;
    }

    stringBuilder.setLength(0);
    if (custom != null) {
        stringBuilder.append(custom);
    } else {
        if (firstName != null && firstName.length() > 0) {
            stringBuilder.appendCodePoint(firstName.codePointAt(0));
        }
        if (lastName != null && lastName.length() > 0) {
            Integer lastch = null;
            for (int a = lastName.length() - 1; a >= 0; a--) {
                if (lastch != null && lastName.charAt(a) == ' ') {
                    break;
                }
                lastch = lastName.codePointAt(a);
            }
            if (Build.VERSION.SDK_INT > 17) {
                stringBuilder.append("\u200C");
            }
            stringBuilder.appendCodePoint(lastch);
        } else if (firstName != null && firstName.length() > 0) {
            for (int a = firstName.length() - 1; a >= 0; a--) {
                if (firstName.charAt(a) == ' ') {
                    if (a != firstName.length() - 1 && firstName.charAt(a + 1) != ' ') {
                        if (Build.VERSION.SDK_INT > 17) {
                            stringBuilder.append("\u200C");
                        }
                        stringBuilder.appendCodePoint(firstName.codePointAt(a + 1));
                        break;
                    }
                }
            }
        }
    }

    if (stringBuilder.length() > 0) {
        String text = stringBuilder.toString().toUpperCase();
        try {
            textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (textLayout.getLineCount() > 0) {
                textLeft = textLayout.getLineLeft(0);
                textWidth = textLayout.getLineWidth(0);
                textHeight = textLayout.getLineBottom(0);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        textLayout = null;
    }
}