本文整理汇总了Java中android.text.style.DynamicDrawableSpan.ALIGN_BASELINE属性的典型用法代码示例。如果您正苦于以下问题:Java DynamicDrawableSpan.ALIGN_BASELINE属性的具体用法?Java DynamicDrawableSpan.ALIGN_BASELINE怎么用?Java DynamicDrawableSpan.ALIGN_BASELINE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.text.style.DynamicDrawableSpan
的用法示例。
在下文中一共展示了DynamicDrawableSpan.ALIGN_BASELINE属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EmojiconSpan
public EmojiconSpan(Context context, Drawable drawable,
int textSize) {
super(DynamicDrawableSpan.ALIGN_BASELINE);
mContext = context;
mDrawable = drawable;
mWidth = mHeight = mSize = 2 * textSize;
mTextSize = textSize;
if (mDrawable != null) {
mHeight = mSize;
mWidth = mHeight * mDrawable.getIntrinsicWidth()
/ mDrawable.getIntrinsicHeight();
mTop = (mTextSize - mHeight) / 2;
mDrawable.setBounds(0, mTop, mWidth, mTop + mHeight);
}
}
示例2: draw
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom,
Paint paint) {
if (mVerticalAlignment == DynamicDrawableSpan.ALIGN_BASELINE || mVerticalAlignment == DynamicDrawableSpan.ALIGN_BOTTOM) {
super.draw(canvas, text, start, end, x, top, y, bottom, paint);
return;
}
Drawable b = getDrawable();
canvas.save();
int transY = 0;
//获得将要显示的文本高度-图片高度除2等居中位置+top(换行情况)
transY = ((bottom - top) - b.getBounds().bottom) / 2 + top;
//偏移画布后开始绘制
canvas.translate(x, transY);
b.draw(canvas);
canvas.restore();
}
示例3: normalizeAlignment
/**
* A helper function to allow dropping in BetterImageSpan as a replacement to ImageSpan,
* and allowing for center alignment if passed in.
*/
public static final @BetterImageSpanAlignment
int normalizeAlignment(int alignment) {
switch (alignment) {
case DynamicDrawableSpan.ALIGN_BOTTOM:
return ALIGN_BOTTOM;
case ALIGN_CENTER:
return ALIGN_CENTER;
case DynamicDrawableSpan.ALIGN_BASELINE:
default:
return ALIGN_BASELINE;
}
}
示例4: EmojiconSpan
public EmojiconSpan(Context context, int resourceId, int size, int textSize) {
super(DynamicDrawableSpan.ALIGN_BASELINE);
mContext = context;
mResourceId = resourceId;
mWidth = mHeight = mSize = size;
mTextSize = textSize;
}
示例5: ChatAdapter
public ChatAdapter(ChatRecyclerView aRecyclerView, Activity aContext, ChatAdapterCallback aCallback) {
messages = new ArrayList<>();
mRecyclerView = aRecyclerView;
context = aContext;
mCallback = aCallback;
settings = new Settings(context);
linkPattern = Pattern.compile("((http|https|ftp)\\:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?\\/?([a-zA-Z0\u200C123456789\\-\\._\\?\\,\\'\\/\\\\\\+&%\\$#\\=~])*[^\\.\\,\\)\\(\\s])");
emoteAlignment = DynamicDrawableSpan.ALIGN_BASELINE;
imageMod = new ImageSpan(context, R.drawable.ic_moderator, emoteAlignment);
imageTurbo = new ImageSpan(context, R.drawable.ic_twitch_turbo, emoteAlignment);
isNightTheme = settings.getTheme().equals(context.getString(R.string.night_theme_name)) || settings.getTheme().equals(context.getString(R.string.true_night_theme_name));
}
示例6: EmojiSpan
public EmojiSpan(Context context, int resourceId, int size, int textSize) {
super(DynamicDrawableSpan.ALIGN_BASELINE);
mContext = context;
mResourceId = resourceId;
mWidth = mHeight = mSize = size;
mTextSize = textSize;
}
示例7: setSpanBubbles
/**
* Outputs span bubbles to ss based on text wrapped in token
*/
public static void setSpanBubbles(final SpannableStringBuilder ss,
String text,
String token, final TextPaint p, final int borderColor,
final int textColor, final int fillColor,
@Nullable final SpanBubbleListener listener) {
if (ss.length() > 0) {
// hack so ensure descent is always added by TextView
ss.append("\u200B");
}
// Start and end refer to the points where the span will apply
int tokenLen = token.length();
int base = 0;
int index = 0;
while (true) {
int start = text.indexOf(token, base);
int end = text.indexOf(token, start + tokenLen);
if (start < 0 || end < 0) {
break;
}
base = end + tokenLen;
final String word = text.substring(start + tokenLen, end);
final int finalIndex = index;
Drawable imgDrawable = new MyDrawable(finalIndex, word, p, fillColor,
borderColor, textColor, listener);
float w = p.measureText(word + "__");
float bottom = -p.ascent() + p.descent();
int y = 0;
imgDrawable.setBounds(0, y, (int) w, (int) (bottom + p.descent()));
ImageSpan imageSpan = new ImageSpan(imgDrawable,
DynamicDrawableSpan.ALIGN_BASELINE);
ss.setSpan(imageSpan, start, end + tokenLen, 0);
if (listener != null) {
ClickableSpan clickSpan = new ClickableSpan() {
@Override
public void onClick(View widget) {
listener.spanBubbleClicked(finalIndex, word);
if (AndroidUtils.hasTouchScreen()) {
Selection.removeSelection(ss);
}
widget.invalidate();
}
};
ss.setSpan(clickSpan, start, end + tokenLen, 0);
}
index++;
}
}