Java Code Examples for android.text.style.DynamicDrawableSpan#ALIGN_BASELINE

The following examples show how to use android.text.style.DynamicDrawableSpan#ALIGN_BASELINE . 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: CenteredImageSpan.java    From GSYRickText with MIT License 6 votes vote down vote up
@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();
}
 
Example 2
Source File: EmojiconSpan.java    From imsdk-android with MIT License 5 votes vote down vote up
public EmojiconSpan(Context context, int resourceId, int size, int textSize) {
    super(DynamicDrawableSpan.ALIGN_BASELINE);
    mContext = context;
    mResourceId = resourceId;
    mWidth = mHeight = mSize = size;
    mTextSize = textSize;
}
 
Example 3
Source File: EmojiconSpan.java    From imsdk-android with MIT License 5 votes vote down vote up
public EmojiconSpan(Context context, Drawable drawable, int size, int textSize) {
    super(DynamicDrawableSpan.ALIGN_BASELINE);
    mContext = context;
    mDrawable = drawable;
    mResourceId = 0;
    mWidth = mHeight = mSize = size;
    mTextSize = textSize;
}
 
Example 4
Source File: ChatAdapter.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 5 votes vote down vote up
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\\-\\._\\?\\,\\'\\/\\\\\\+&amp;%\\$#\\=~])*[^\\.\\,\\)\\(\\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));
}
 
Example 5
Source File: EmojiSpan.java    From umeng_community_android with MIT License 5 votes vote down vote up
public EmojiSpan(Context context, int resourceId, int size, int textSize) {
    super(DynamicDrawableSpan.ALIGN_BASELINE);
    mContext = context;
    mResourceId = resourceId;
    mWidth = mHeight = mSize = size;
    mTextSize = textSize;
}
 
Example 6
Source File: BetterImageSpan.java    From fresco with MIT License 5 votes vote down vote up
/**
 * 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;
  }
}