From edc738d80b52d2b9436fefc3a731ca0e08285e3e Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Mon, 3 Jun 2024 15:02:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E5=A0=86=E5=9B=BE?= =?UTF-8?q?=E6=A0=87+10=E5=AD=97=E5=90=8D=E5=AD=97=E8=81=8A=E5=A4=A9?= =?UTF-8?q?=E6=A1=86=E6=B2=A1=E6=9C=89=E5=9B=BE=E6=A0=87=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/activity/LiveAudienceActivity.java | 25 +++++++++ .../com/yunbao/live/utils/LiveTextRender.java | 51 +++++++++++++++---- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 15fd3aea4..6d51d42b2 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -36,6 +36,9 @@ import com.lxj.xpopup.core.BasePopupView; import com.lxj.xpopup.enums.PopupPosition; import com.lxj.xpopup.interfaces.XPopupCallback; import com.lzf.easyfloat.EasyFloat; +import com.lzf.easyfloat.enums.ShowPattern; +import com.yunbao.common.dialog.DebugDialog; +import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.utils.MobclickAgent; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; @@ -126,6 +129,7 @@ import com.yunbao.live.dialog.SignDialogFragment; import com.yunbao.live.event.LinkMicTxAccEvent; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.http.ImHttpUtil; +import com.yunbao.live.utils.LiveTextRender; import com.yunbao.live.views.LiveRoomPlayViewHolder; import com.yunbao.live.views.LiveRoomViewHolder; import com.yunbao.live.views.PortraitLiveManager; @@ -225,6 +229,27 @@ public class LiveAudienceActivity extends LiveActivity { fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "YoursystemisolderDialog"); IMLoginManager.get(mContext).setXiaJBG(true); } + /*new Handler(Looper.getMainLooper()) + .postDelayed(new Runnable() { + @Override + public void run() { + System.out.println("------------------------初始化弹窗------------------------"); + DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() { + @Override + public void run(DebugDialog dialog) { + System.out.println("------------------------显示弹窗------------------------"); + dialog.setShowPattern(ShowPattern.ALL_TIME); + dialog.show(); + LiveTextRender.onItemClickListener = new OnItemClickListener() { + @Override + public void onItemClick(String bean, int position) { + dialog.setParams(bean.split("\\|")[0], bean.split("\\|")[1]); + } + }; + } + }); + } + },1000);*/ } private final MicStatusManager.OnMicStatusListener onMicStatusListener = new MicStatusManager.OnMicStatusListener() { diff --git a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java index f9f67b5ba..c99006b84 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java @@ -32,13 +32,16 @@ import androidx.core.content.ContextCompat; import com.bumptech.glide.Glide; import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.transition.Transition; +import com.lzf.easyfloat.enums.ShowPattern; import com.yunbao.common.CommonAppContext; import com.yunbao.common.bean.AiAutomaticSpeechModel; import com.yunbao.common.bean.MsgModel; import com.yunbao.common.bean.NewGuardLevelModel; import com.yunbao.common.bean.NewLevelModel; import com.yunbao.common.custom.VerticalImageSpan; +import com.yunbao.common.dialog.DebugDialog; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.manager.NewLevelManager; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.StringUtil; @@ -84,6 +87,10 @@ public class LiveTextRender { sFontSizeSpan = new AbsoluteSizeSpan(17, true); sFontSizeSpan2 = new AbsoluteSizeSpan(12, true); sFontSizeSpan3 = new AbsoluteSizeSpan(14, true); + if (!isInit) { + isInit = true; + + } } public void blindBox(Context context, TextView textView, LiveChatBean bean) { @@ -285,7 +292,7 @@ public class LiveTextRender { getGuardImage(CommonAppContext.sInstance, bean.getGuardType(), new ImgLoader.DrawableCallback() { @Override public void onLoadSuccess(Drawable drawable) { - SpannableStringBuilder builder = new SpannableStringBuilder(); + /*SpannableStringBuilder builder = new SpannableStringBuilder(); int index = 0; if (levelDrawable != null) { @@ -354,11 +361,16 @@ public class LiveTextRender { index = builder.length(); } } - createPrefixCallback.onPrefixCallback(builder, 0); + createPrefixCallback.onPrefixCallback(builder, 0);*/ + show(drawable); } @Override public void onLoadFailed() { + show(null); + } + + void show(Drawable drawable) { SpannableStringBuilder builder = new SpannableStringBuilder(); int index = 0; int prefixWidth = 0; @@ -393,10 +405,17 @@ public class LiveTextRender { index = builder.length(); prefixWidth += nhDrawablesMap.get(bean).getBounds().width(); } + if (drawable != null) { + builder.append(" "); + drawable.setBounds(0, 0, DpUtil.dp2px(34), DpUtil.dp2px(17)); + builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + index = builder.length(); + prefixWidth += drawable.getBounds().width(); + } //在这里添加粉丝徽章的图片 if (!TextUtils.isEmpty(bean.getMedalNmae()) && !TextUtils.isEmpty(bean.getMedalLevelImageUrl()) && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("")) {//粉丝徽章图标 - Drawable drawable = getMedalImage(bean); + drawable = getMedalImage(bean); if (drawable != null) { builder.append(" "); drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); @@ -408,23 +427,25 @@ public class LiveTextRender { if (bean.isManager()) {//直播间管理员图标 - Drawable 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) { builder.append(" "); drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += drawable.getBounds().width(); } } if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 - Drawable 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) { builder.append(" "); drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // new add index = builder.length(); + prefixWidth += drawable.getBounds().width(); } } createPrefixCallback.onPrefixCallback(builder, prefixWidth); @@ -811,6 +832,14 @@ public class LiveTextRender { return mNewBitmap; } + public static OnItemClickListener onItemClickListener=new OnItemClickListener() { + @Override + public void onItemClick(String bean, int position) { + + } + }; + private static boolean isInit = false; + /** * 渲染普通聊天消息 */ @@ -824,21 +853,25 @@ public class LiveTextRender { sb.append(builder).append(name).append(" "); float measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; int width = ((ViewGroup) textView.getParent()).getWidth(); + onItemClickListener.onItemClick("测算|" + measuredText, 0); + onItemClickListener.onItemClick("控件宽度|" + width, 0); + onItemClickListener.onItemClick("前缀预留宽度|" + prefixWidth, 0); //检测渲染后图标+名字是否超过父布局宽度,超过了就做换行处理 if (measuredText > width) { sb.clear(); sb.append(builder); for (int i = 0; i < name.length(); i++) { - sb.append(name.charAt(i)).append(" "); + sb.append(name.charAt(i)); measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; - if (measuredText + 1 > width) { - name = name.substring(0, i+1) + "\n" + name.substring(i+1); + onItemClickListener.onItemClick(i + "逐测算|" + measuredText, 0); + if (measuredText > width) { + name = name.substring(0, i - 1) + "\n" + name.substring(i -1); break; } } sb.clear(); } - // name=name.substring(0,7)+"\n"+name.substring(7); + // name=name.substring(0,7)+"\n"+name.substring(7); builder.append(name); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getStartColor())) {