use of carbon.view.TextAppearanceView in project Carbon by ZieIony.
the class Carbon method handleFontAttribute.
public static void handleFontAttribute(TextAppearanceView textView, TypedArray appearance, int textStyle, int fontWeight, int attributeId) {
WeakReference<TextAppearanceView> textViewWeak = new WeakReference<>(textView);
AtomicBoolean asyncFontPending = new AtomicBoolean();
ResourcesCompat.FontCallback replyCallback = new ResourcesCompat.FontCallback() {
@Override
public void onFontRetrieved(@NonNull Typeface typeface) {
if (asyncFontPending.get()) {
TextAppearanceView textView = textViewWeak.get();
if (textView != null)
textView.setTypeface(typeface, textStyle);
}
}
@Override
public void onFontRetrievalFailed(int reason) {
}
};
try {
int resourceId = appearance.getResourceId(attributeId, 0);
TypedValue mTypedValue = new TypedValue();
Typeface typeface = carbon.internal.ResourcesCompat.getFont(((View) textView).getContext(), resourceId, mTypedValue, textStyle, fontWeight, replyCallback);
if (typeface != null) {
asyncFontPending.set(true);
textView.setTypeface(typeface, textStyle);
}
} catch (UnsupportedOperationException | Resources.NotFoundException ignored) {
}
}
use of carbon.view.TextAppearanceView in project Carbon by ZieIony.
the class TextMarker method onMeasure.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (id != 0) {
TextAppearanceView textView = ((ViewGroup) getParent()).findViewById(id);
if (text == null)
text = textView.getText();
textPaint = textView.getPaint();
if (layout == null)
layout = new StaticLayout(text, textPaint, getMeasuredWidth(), Layout.Alignment.ALIGN_NORMAL, 1, 0, true);
String firstLine = text.subSequence(0, layout.getLineEnd(0)).toString();
textPaint.getTextBounds(firstLine, 0, firstLine.length(), rect);
baseline = Math.abs(rect.top);
rect.top = -layout.getLineAscent(0) + rect.top;
String lastLine = text.subSequence(layout.getLineStart(layout.getLineCount() - 1), layout.getLineEnd(layout.getLineCount() - 1)).toString();
textPaint.getTextBounds(lastLine, 0, lastLine.length(), rect2);
rect.bottom = layout.getHeight() - layout.getLineDescent(layout.getLineCount() - 1) + rect2.bottom;
setMeasuredDimension(getMeasuredWidth(), rect.height() + getPaddingTop() + getPaddingBottom());
}
}
Aggregations