update 更新弹幕

This commit is contained in:
zlzw 2024-06-05 09:48:22 +08:00
parent edc738d80b
commit cb0772c9e3
4 changed files with 111 additions and 41 deletions

View File

@ -15,6 +15,7 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.annotation.IdRes; import androidx.annotation.IdRes;
@ -233,17 +234,33 @@ public class LiveAudienceActivity extends LiveActivity {
.postDelayed(new Runnable() { .postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
System.out.println("------------------------初始化弹窗------------------------");
DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() {
@Override @Override
public void run(DebugDialog dialog) { public void run(DebugDialog dialog) {
System.out.println("------------------------显示弹窗------------------------");
dialog.setShowPattern(ShowPattern.ALL_TIME); dialog.setShowPattern(ShowPattern.ALL_TIME);
dialog.show(); dialog.show();
dialog.setView("+",new Button(mContext),view -> LiveTextRender.textTemp++);
dialog.setView("-",new Button(mContext),view -> LiveTextRender.textTemp--);
dialog.setView("+",new Button(mContext),view -> LiveTextRender.textTemp++);
dialog.setView("中/英",new Button(mContext),view ->{
if(LiveTextRender.userName.startsWith("")){
LiveTextRender.userName="英文34567890";
}else{
LiveTextRender.userName="中文测试中文测试中文";
}
});
dialog.setView("长/短",new Button(mContext),view ->{
if(LiveTextRender.userName.length()>5){
LiveTextRender.userName="abcdefg";
}else{
LiveTextRender.userName="中文中文";
}
});
LiveTextRender.onItemClickListener = new OnItemClickListener<String>() { LiveTextRender.onItemClickListener = new OnItemClickListener<String>() {
@Override @Override
public void onItemClick(String bean, int position) { public void onItemClick(String bean, int position) {
dialog.setParams(bean.split("\\|")[0], bean.split("\\|")[1]); dialog.setParams(bean.split("\\|")[0], bean.split("\\|")[1]+"|"+position);
} }
}; };
} }

View File

@ -210,7 +210,8 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
class Vh extends RecyclerView.ViewHolder { class Vh extends RecyclerView.ViewHolder {
LinearLayout mBg, view_follow, view_action_game, view_zg, xydComplete; LinearLayout mBg, view_follow, view_action_game, view_zg, xydComplete;
TextView mTextView, tv_chat_active_into, tv_chat_avtive_name, tv_zg_anchorname, textTxt2, automatic_chat; TextView tv_chat_active_into, tv_chat_avtive_name, tv_zg_anchorname, textTxt2, automatic_chat;
TextView mTextView;
RoundedImageView avatar; RoundedImageView avatar;
View v_chat_active_close; View v_chat_active_close;
RecyclerView rv_chat_active; RecyclerView rv_chat_active;

View File

@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -23,6 +24,7 @@ import android.view.View;
import android.view.View.MeasureSpec; import android.view.View.MeasureSpec;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -296,34 +298,34 @@ public class LiveTextRender {
int index = 0; int index = 0;
if (levelDrawable != null) { if (levelDrawable != null) {
builder.append(" "); builder.append("\uFFFC ");
levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17));
builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
} }
if (gzDrawablesMap.containsKey(bean)) {//贵族 if (gzDrawablesMap.containsKey(bean)) {//贵族
builder.append(" "); builder.append("\uFFFC ");
gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20)); gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20));
builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
} }
if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章
builder.append(" "); builder.append("\uFFFC ");
ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18)); ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18));
builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
} }
if (nhDrawablesMap.containsKey(bean)) {//靓号 if (nhDrawablesMap.containsKey(bean)) {//靓号
builder.append(" "); builder.append("\uFFFC ");
nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17));
builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
} }
if (drawable != null) { if (drawable != null) {
builder.append(" "); builder.append("\uFFFC ");
drawable.setBounds(0, 0, DpUtil.dp2px(34), DpUtil.dp2px(17)); drawable.setBounds(0, 0, DpUtil.dp2px(34), DpUtil.dp2px(17));
builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
@ -333,7 +335,7 @@ public class LiveTextRender {
&& !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("<null>")) {//粉丝徽章图标 && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("<null>")) {//粉丝徽章图标
Drawable drawable2 = getMedalImage(bean); Drawable drawable2 = getMedalImage(bean);
if (drawable2 != null) { if (drawable2 != null) {
builder.append(" "); builder.append("\uFFFC ");
drawable2.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); drawable2.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17));
builder.setSpan(new VerticalImageSpan(drawable2), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(drawable2), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
@ -344,7 +346,7 @@ public class LiveTextRender {
if (bean.isManager()) {//直播间管理员图标 if (bean.isManager()) {//直播间管理员图标
Drawable drawable3 = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); Drawable drawable3 = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m);
if (drawable3 != null) { if (drawable3 != null) {
builder.append(" "); builder.append("\uFFFC ");
drawable3.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); drawable3.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14));
builder.setSpan(new VerticalImageSpan(drawable3), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(drawable3), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
@ -354,7 +356,7 @@ public class LiveTextRender {
if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标
Drawable drawable4 = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); Drawable drawable4 = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang);
if (drawable4 != null) { if (drawable4 != null) {
builder.append(" "); builder.append("\uFFFC ");
drawable4.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); drawable4.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14));
builder.setSpan(new VerticalImageSpan(drawable4), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(drawable4), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// new add // new add
@ -375,7 +377,7 @@ public class LiveTextRender {
int index = 0; int index = 0;
int prefixWidth = 0; int prefixWidth = 0;
if (levelDrawable != null) { if (levelDrawable != null) {
builder.append(" "); builder.append("\uFFFC ");
levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17));
builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
@ -383,7 +385,7 @@ public class LiveTextRender {
} }
if (gzDrawablesMap.containsKey(bean)) {//贵族 if (gzDrawablesMap.containsKey(bean)) {//贵族
builder.append(" "); builder.append("\uFFFC ");
gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20)); gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20));
builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
@ -391,7 +393,7 @@ public class LiveTextRender {
} }
if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章
builder.append(" "); builder.append("\uFFFC ");
ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18)); ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18));
builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
@ -399,14 +401,14 @@ public class LiveTextRender {
} }
if (nhDrawablesMap.containsKey(bean)) {//靓号 if (nhDrawablesMap.containsKey(bean)) {//靓号
builder.append(" "); builder.append("\uFFFC ");
nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17));
builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
prefixWidth += nhDrawablesMap.get(bean).getBounds().width(); prefixWidth += nhDrawablesMap.get(bean).getBounds().width();
} }
if (drawable != null) { if (drawable != null) {
builder.append(" "); builder.append("\uFFFC ");
drawable.setBounds(0, 0, DpUtil.dp2px(34), DpUtil.dp2px(17)); drawable.setBounds(0, 0, DpUtil.dp2px(34), DpUtil.dp2px(17));
builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
@ -417,7 +419,7 @@ public class LiveTextRender {
&& !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("<null>")) {//粉丝徽章图标 && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("<null>")) {//粉丝徽章图标
drawable = getMedalImage(bean); drawable = getMedalImage(bean);
if (drawable != null) { if (drawable != null) {
builder.append(" "); builder.append("\uFFFC ");
drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17));
builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
@ -429,7 +431,7 @@ public class LiveTextRender {
if (bean.isManager()) {//直播间管理员图标 if (bean.isManager()) {//直播间管理员图标
drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m);
if (drawable != null) { if (drawable != null) {
builder.append(" "); builder.append("\uFFFC ");
drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14));
builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length(); index = builder.length();
@ -440,7 +442,7 @@ public class LiveTextRender {
if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标
drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang);
if (drawable != null) { if (drawable != null) {
builder.append(" "); builder.append("\uFFFC ");
drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14));
builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// new add // new add
@ -839,6 +841,8 @@ public class LiveTextRender {
} }
}; };
private static boolean isInit = false; private static boolean isInit = false;
public static int textTemp = 0;
public static String userName = "";
/** /**
* 渲染普通聊天消息 * 渲染普通聊天消息
@ -846,33 +850,48 @@ public class LiveTextRender {
private SpannableStringBuilder renderChat(TextView textView, int color, SpannableStringBuilder builder, LiveChatBean bean, int prefixWidth) { private SpannableStringBuilder renderChat(TextView textView, int color, SpannableStringBuilder builder, LiveChatBean bean, int prefixWidth) {
int length = builder.length(); int length = builder.length();
String name = bean.getUserNiceName(); String name = bean.getUserNiceName();
float prefixEmpty = textView.getPaint().measureText(builder, 0, builder.length()) / 2;
if (!StringUtil.isEmpty(userName)) {
// name = userName;
}
if (bean.getType() != LiveChatBean.ENTER_ROOM) {//产品规定进场消息不允许加冒号 if (bean.getType() != LiveChatBean.ENTER_ROOM) {//产品规定进场消息不允许加冒号
name += ""; name += "";
} }
SpannableStringBuilder sb = new SpannableStringBuilder(); SpannableStringBuilder sb = new SpannableStringBuilder();
sb.append(builder).append(name).append(" "); sb.append(name);
float measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; float measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth;
int width = ((ViewGroup) textView.getParent()).getWidth(); // Rect mRect = new Rect();
onItemClickListener.onItemClick("测算|" + measuredText, 0); // textView.getPaint().getTextBounds(sb.toString(), 0, sb.length(), mRect);
onItemClickListener.onItemClick("控件宽度|" + width, 0); int width = (int) (((ViewGroup) textView.getParent()).getMeasuredWidth() - prefixEmpty);
onItemClickListener.onItemClick("前缀预留宽度|" + prefixWidth, 0); String TAG = "文字渲染";
// Log.i(TAG, "测算|" + measuredText + "|" + mRect.width() + "|" + sb.toString());
//|810|810|810|786|786
// Log.i(TAG, "控件宽度|" + width + "|" + ((ViewGroup) textView.getParent()).getWidth() + "|" + ((ViewGroup) textView.getParent()).getMeasuredWidth() + "|" + textView.getWidth() + "|" + textView.getMeasuredWidth());
// Log.i(TAG, "前缀预留宽度|" + prefixWidth + "|" + prefixEmpty);
// Log.i(TAG, "renderChat: " + textView.getCompoundPaddingLeft() + "|" + textView.getCompoundPaddingRight() + "|");
//检测渲染后图标+名字是否超过父布局宽度超过了就做换行处理 //检测渲染后图标+名字是否超过父布局宽度超过了就做换行处理
String prefixName = "";
if (measuredText > width) { if (measuredText > width) {
sb.clear(); sb.clear();
sb.append(builder);
for (int i = 0; i < name.length(); i++) { for (int i = 0; i < name.length(); i++) {
sb.append(name.charAt(i)); sb.append(name.charAt(i));
measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth;
onItemClickListener.onItemClick(i + "逐测算|" + measuredText, 0); Log.i(TAG, i + "逐测算|" + measuredText + "|" + textTemp);
if (measuredText > width) { if (measuredText > width) {
name = name.substring(0, i - 1) + "\n" + name.substring(i -1); prefixName = name.substring(0, i + textTemp);
name = prefixName + "\n" + name.substring(i + textTemp);
break; break;
} }
} }
sb.clear(); sb.clear();
} else {
prefixName = name;
} }
sb.clear();
sb.append(prefixName);
// name=name.substring(0,7)+"\n"+name.substring(7); // name=name.substring(0,7)+"\n"+name.substring(7);
builder.append(name); builder.append(name);
Log.i(TAG, "再测算|" + (textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth) + "|" + textTemp + "|" + sb.toString());
//超皇设置渐变色展示昵称 //超皇设置渐变色展示昵称
if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getStartColor())) { if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getStartColor())) {
@ -882,26 +901,56 @@ public class LiveTextRender {
} }
int lengthContent = builder.length(); int lengthContent = builder.length();
//这一段先别删万一后面要改内容换行呢 //这一段先别删万一后面要改内容换行呢
// TODO 试试 空Unicode
/*sb.clear(); /*sb.clear();
sb.append(builder).append(bean.getContent()); TAG = "文字渲染2";
String content = bean.getContent();
Log.i(TAG, "renderChat: " + content);
sb.append(name).append(content);
SpannableStringBuilder csb = null;
measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth;
sb.clear();
sb.append(prefixName);
prefixEmpty = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth;
StringBuilder stringBuilder = new StringBuilder();
if (measuredText > width) { if (measuredText > width) {
sb.clear(); sb.clear();
sb.append(builder); sb.append(name);
for (int i = 0; i < bean.getContent().length(); i++) { float lineWidth = 0;
sb.append(bean.getContent().charAt(i)); for (int i = 0; i < content.length(); i++) {
measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; char charAt = content.charAt(i);
if (measuredText + 3 > width) { sb.append(charAt);
bean.setContent(bean.getContent().substring(0, i) + "\n"+ bean.getContent().substring(i)); lineWidth += textView.getPaint().measureText(String.valueOf(charAt)) + prefixEmpty;
bean.setContent(""); prefixEmpty = 0;
break; textView.setText(sb);
Log.i(TAG, "renderChat: TextView是否换行:" + textView.getText().toString().split("\n").length);
Log.i(TAG, "逐测算|" + lineWidth + " width|" + width + "|" + sb.toString());
if (lineWidth > width) {
Log.i(TAG, "renderChat: 换行:" + charAt);
if (!stringBuilder.toString().endsWith("\n")) {
stringBuilder.append("\n");
} }
lineWidth = 0;
--i;
} else {
Log.i(TAG, "renderChat: 直接加入:" + charAt);
stringBuilder.append(content.charAt(i));
} }
}
if (stringBuilder.toString().endsWith("\n")) {
Log.i(TAG, "需要删除回车");
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
}
Log.i(TAG, "分行后内容:" + stringBuilder.toString());
bean.setContent(stringBuilder.toString());
} }
*/ */
builder.append(bean.getContent()); builder.append(bean.getContent());
//超皇设置渐变色展示昵称 //超皇设置渐变色展示昵称
if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getContentColor())) { if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getContentColor())) {
Log.i(TAG, "lengthContent: " + lengthContent + "|content: " + bean.getContent().length() + "|max: " + (lengthContent + bean.getContent().length()));
builder.setSpan(new ForegroundColorSpan(Color.parseColor(bean.getContentColor())), lengthContent, lengthContent + bean.getContent().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new ForegroundColorSpan(Color.parseColor(bean.getContentColor())), lengthContent, lengthContent + bean.getContent().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} }
if (bean.getType() == LiveChatBean.LIGHT) { if (bean.getType() == LiveChatBean.LIGHT) {
@ -913,6 +962,7 @@ public class LiveTextRender {
builder.setSpan(new VerticalImageSpan(heartDrawable), length - 1, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(heartDrawable), length - 1, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} }
} }
//textView.setText("");
return builder; return builder;
} }

View File

@ -16,7 +16,9 @@
android:layout_marginRight="9dp" android:layout_marginRight="9dp"
android:paddingBottom="7dp" android:paddingBottom="7dp"
android:textColor="#fff" android:textColor="#fff"
android:breakStrategy="simple"
android:textSize="12sp" android:textSize="12sp"
tools:text="aaaaaaaaa111111111111111111111111111111111111111111111111111111111"
android:visibility="visible" android:visibility="visible"
tools:ignore="RtlHardcoded" /> tools:ignore="RtlHardcoded" />