From e36fbdc6b8004f2bfcee7caea7230f35ab30aedf Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 22 May 2024 13:49:06 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E8=B0=83=E6=95=B4=E3=80=90=E6=88=91?= =?UTF-8?q?=E7=9A=84=E3=80=91=E4=B8=AA=E6=80=A7=E7=AD=BE=E5=90=8D=E4=B8=AD?= =?UTF-8?q?=E8=8B=B1=E6=96=87=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/yunbao/main/views/MainMeViewHolder.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/main/src/main/java/com/yunbao/main/views/MainMeViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainMeViewHolder.java index e2bf2ef92..6ff717a41 100644 --- a/main/src/main/java/com/yunbao/main/views/MainMeViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainMeViewHolder.java @@ -318,9 +318,7 @@ public class MainMeViewHolder extends AbsMainViewHolder implements OnItemClickLi } String singnature = u.getSignature(); if (TextUtils.equals(singnature, "這個人很懶,什麼也沒留下") || TextUtils.equals(singnature, "这家伙很懒,什么都没留下") || TextUtils.isEmpty(singnature)) { - String ct = Locale.getDefault().getCountry(); - ct = TextUtils.equals("CN", ct) ? "HK" : ct; - if (TextUtils.equals(ct, "CN")) { + if (WordUtil.isNewZh()) { singnature = "這個人很懶,什麼也沒留下"; } else { singnature = "The guy was lazy and didn't write anything."; From 24170d55e25fed53b85c515fc2aabef0c6f689c2 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 23 May 2024 12:53:07 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=BF=9B=E5=85=A5?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=E7=AD=89=E5=BE=85=E6=97=B6=E9=95=BF?= =?UTF-8?q?15=E2=86=924?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/yunbao/live/views/PortraitLiveManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index ab2b57248..92f1f4996 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -758,7 +758,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe AppManager.runDebugCode(() -> { // liveHandler.postDelayed(loadTimeoutRunnableGone, 1_000); }); - liveHandler.postDelayed(loadTimeoutRunnableGone, 15_000); + liveHandler.postDelayed(loadTimeoutRunnableGone, 4_000); if (TextUtils.equals(data.getEnterRoomInfo().getIsconnection(), "1")) { //通知心愿单位置换地方 EventBus.getDefault().post(new LiveAudienceEvent() From c033340aadc0e479a9cf13e8ef92791ef523ca5b Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 24 May 2024 14:49:14 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=8F=B3=E4=B8=8B=E8=A7=92=E6=82=AC=E6=B5=AE=E5=B1=82=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/views/PortraitLiveManager.java | 2 +- .../yunbao/main/activity/MainActivity.java | 66 ++++++++++++++----- .../yunbao/main/views/MainHomeViewHolder.java | 8 +-- 3 files changed, 55 insertions(+), 21 deletions(-) diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index 92f1f4996..f266f585b 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -323,7 +323,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe public void run() { loading.setVisibility(View.GONE); enterRoomLeaveHandler.post(enterRoomLeaveRunnable); - ToastUtil.show(mContext.getString(R.string.net_error) + " :500");//异常下播,等待加载时间过了后弹出 + //ToastUtil.show(mContext.getString(R.string.net_error) + " :500");//异常下播,等待加载时间过了后弹出 } }; diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index 60c1a7fa3..5a35b8efb 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -51,6 +51,7 @@ import com.tencent.imsdk.v2.V2TIMManager; import com.tencent.imsdk.v2.V2TIMSDKConfig; import com.tencent.imsdk.v2.V2TIMSDKListener; import com.tencent.imsdk.v2.V2TIMUserFullInfo; +import com.yunbao.common.dialog.DebugDialog; import com.yunbao.common.utils.MobclickAgent; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; @@ -517,8 +518,20 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene mTabButtonGroup.addTabButtonGroupChangeListener((view, index) -> { if (index == 0) { - isfloatBannernet = true; - initAnchorRecommendBanner(); + // isfloatBannernet = true; + // initAnchorRecommendBanner(); + if (floatEventShow) { + if (floatWarOrder.getTag() != null) { + floatWarOrder.setVisibility(View.VISIBLE); + } else { + floatWarOrder.setVisibility(View.GONE); + if (floatBanner.getTag() != null) { + floatBanner.setVisibility(View.VISIBLE); + } else { + floatBanner.setVisibility(View.GONE); + } + } + } } else if (index == 2) { floatBanner.setVisibility(View.GONE); floatRedPacket.setVisibility(View.GONE); @@ -621,30 +634,26 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene if (isFinishing()) return; if (data.getListShow() == 1 && data.getList().size() > 2) { floatBanner.setVisibility(View.VISIBLE); + floatBanner.setTag(data); findViewById(R.id.banner_click).setVisibility(View.VISIBLE); floatBanner.showBanner(data.getList()); } else { floatBanner.setVisibility(View.GONE); + floatBanner.setTag(null); findViewById(R.id.banner_click).setVisibility(View.GONE); } - if (data.getShowRedPacket() == 0) { - floatRedPacket.setVisibility(View.GONE); - } else { - floatRedPacket.setVisibility(View.VISIBLE); - ((ProgressBar) floatRedPacket.findViewById(R.id.progress)).setMax(data.getRedPacketTotal()); - ((ProgressBar) floatRedPacket.findViewById(R.id.progress)).setProgress(data.getRedPacketNum()); - ((TextView) floatRedPacket.findViewById(R.id.progressText)).setText(data.getRedPacketNum() + "/" + data.getRedPacketTotal()); - } if (data.getShowWarOrder() == 0) { floatWarOrder.setVisibility(View.GONE); floatWarOrder.setTag(null); //战令关闭情况下,在判断一次Banner是否足够 if (data.getListShow() == 1 && data.getList().size() > 2) { floatBanner.setVisibility(View.VISIBLE); + floatBanner.setTag(data); findViewById(R.id.banner_click).setVisibility(View.VISIBLE); floatBanner.showBanner(data.getList()); } else { floatBanner.setVisibility(View.GONE); + floatBanner.setTag(null); findViewById(R.id.banner_click).setVisibility(View.GONE); } } else { @@ -657,8 +666,17 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene } floatBanner.setVisibility(View.GONE); + floatBanner.setTag(null); findViewById(R.id.banner_click).setVisibility(View.GONE); } + if (data.getShowRedPacket() == 0) { + floatRedPacket.setVisibility(View.GONE); + } else if (floatWarOrder.getTag() == null && floatWarOrder.getTag() == null) { + floatRedPacket.setVisibility(View.VISIBLE); + ((ProgressBar) floatRedPacket.findViewById(R.id.progress)).setMax(data.getRedPacketTotal()); + ((ProgressBar) floatRedPacket.findViewById(R.id.progress)).setProgress(data.getRedPacketNum()); + ((TextView) floatRedPacket.findViewById(R.id.progressText)).setText(data.getRedPacketNum() + "/" + data.getRedPacketTotal()); + } } @@ -1499,18 +1517,34 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene } } + boolean floatEventShow = true; + @Subscribe(threadMode = ThreadMode.MAIN) public void onFloatWarOrderEvent(FloatWarOrderEvent event) { - /* if (event.isFloatWarOrder()) { - floatWarOrder.setVisibility(View.GONE); + System.out.println("FloatWarOrderEvent:事件" + event.isFloatWarOrder()); + System.out.println("战令:" + floatWarOrder.getTag()); + System.out.println("Banner:" + floatBanner.getTag()); + floatEventShow = event.isFloatWarOrder(); + if (event.isFloatWarOrder()) { + if (floatWarOrder.getTag() == null) { + floatWarOrder.setVisibility(View.GONE); + } else { + floatWarOrder.setVisibility(View.VISIBLE); + } + if (floatBanner.getTag() == null) { + floatBanner.setVisibility(View.GONE); + } else { + floatBanner.setVisibility(View.VISIBLE); + } } else { - floatWarOrder.setVisibility(View.VISIBLE); - }*/ - if(floatWarOrder.getTag()!=null){ + floatBanner.setVisibility(View.GONE); + floatWarOrder.setVisibility(View.GONE); + } + /* if(floatWarOrder.getTag()!=null){ floatWarOrder.setVisibility(View.VISIBLE); }else{ floatWarOrder.setVisibility(View.GONE); - } + }*/ } private void initRedPacket() { diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java index 39c8120e9..995c72a96 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeViewHolder.java @@ -85,22 +85,22 @@ public class MainHomeViewHolder extends AbsMainHomeParentViewHolder { case 0: floatWarOrder = false; MobclickAgent.onEvent(mContext, "home_page_follow", "首页关注列表按钮"); - EventBus.getDefault().post(new FloatWarOrderEvent().setFloatWarOrder(false)); + EventBus.getDefault().post(new FloatWarOrderEvent().setFloatWarOrder(true)); break; case 1: floatWarOrder = false; MobclickAgent.onEvent(mContext, "home_page_hot", "首页热门列表按钮"); - EventBus.getDefault().post(new FloatWarOrderEvent().setFloatWarOrder(false)); + EventBus.getDefault().post(new FloatWarOrderEvent().setFloatWarOrder(true)); break; case 2: floatWarOrder = false; MobclickAgent.onEvent(mContext, "home_page_recommend", "首页推荐列表按钮"); - EventBus.getDefault().post(new FloatWarOrderEvent().setFloatWarOrder(false)); + EventBus.getDefault().post(new FloatWarOrderEvent().setFloatWarOrder(true)); break; case 3: floatWarOrder = true; MobclickAgent.onEvent(mContext, "home_page_redpk", "首页红包列表按钮"); - EventBus.getDefault().post(new FloatWarOrderEvent().setFloatWarOrder(true)); + EventBus.getDefault().post(new FloatWarOrderEvent().setFloatWarOrder(false)); break; } if (mViewHolders == null) { From c33975fe67d6176cf3b8b37a6b681b11ca60526e Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 24 May 2024 15:45:06 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=8F=B3=E4=B8=8B=E8=A7=92=E6=82=AC=E6=B5=AE=E5=B1=82=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E7=9B=B4=E6=92=AD=E9=97=B4=E8=B4=AD=E4=B9=B0=E6=8E=A8?= =?UTF-8?q?=E8=8D=90=E7=9A=84UI=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=90=88?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom/LiveGuardScalePageTransformer.java | 34 +++++++++++++++++++ .../live/dialog/LiveBuyGuardDialog.java | 3 ++ .../yunbao/main/activity/MainActivity.java | 15 ++++++-- 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/custom/LiveGuardScalePageTransformer.java diff --git a/common/src/main/java/com/yunbao/common/custom/LiveGuardScalePageTransformer.java b/common/src/main/java/com/yunbao/common/custom/LiveGuardScalePageTransformer.java new file mode 100644 index 000000000..34a6970f0 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/custom/LiveGuardScalePageTransformer.java @@ -0,0 +1,34 @@ +package com.yunbao.common.custom; + +import android.view.View; + +import com.stx.xhb.androidx.transformers.BasePageTransformer; + +public class LiveGuardScalePageTransformer extends BasePageTransformer { + /** + * author: xiaohaibin. + * time: 2018/10/9 + * mail:xhb_199409@163.com + * github:https://github.com/xiaohaibin + * describe: 适用于一屏显示多个模式 + */ + private static final float MIN_SCALE = 0.8F; + + @Override + public void handleInvisiblePage(View view, float position) { + view.setScaleY(MIN_SCALE); + } + + @Override + public void handleLeftPage(View view, float position) { + float scale = Math.max(MIN_SCALE, 1 - Math.abs(position)); + view.setScaleY(scale); + } + + @Override + public void handleRightPage(View view, float position) { + float scale = Math.max(MIN_SCALE, 1 - Math.abs(position)); + view.setScaleY(scale); + } + +} diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveBuyGuardDialog.java b/live/src/main/java/com/yunbao/live/dialog/LiveBuyGuardDialog.java index 164dbd564..f39ca7d03 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveBuyGuardDialog.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveBuyGuardDialog.java @@ -30,6 +30,8 @@ import com.lxj.xpopup.XPopup; import com.lxj.xpopup.enums.PopupPosition; import com.makeramen.roundedimageview.RoundedImageView; import com.stx.xhb.androidx.XBanner; +import com.stx.xhb.androidx.transformers.ScalePageTransformer; +import com.yunbao.common.custom.LiveGuardScalePageTransformer; import com.yunbao.common.utils.MobclickAgent; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.adapter.LiveBuyGuardPrivilegeAdapter; @@ -159,6 +161,7 @@ public class LiveBuyGuardDialog extends AbsDialogPopupWindow { } buyGuardBanner.setBannerData(R.layout.banner_item_buy_guard, buyGuardBannerModels); buyGuardBanner.setIsClipChildrenMode(true); + buyGuardBanner.setCustomPageTransformer(new LiveGuardScalePageTransformer()); guardPrivilegeStrings = data.getGuardData().get(0).getGuardPrivilege(); buyGuardBanner.postDelayed(new Runnable() { @Override diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index 5a35b8efb..05d7a1ab9 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -529,6 +529,11 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene floatBanner.setVisibility(View.VISIBLE); } else { floatBanner.setVisibility(View.GONE); + if (floatRedPacket.getTag() == null) { + floatRedPacket.setVisibility(View.GONE); + } else { + floatRedPacket.setVisibility(View.VISIBLE); + } } } } @@ -673,6 +678,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene floatRedPacket.setVisibility(View.GONE); } else if (floatWarOrder.getTag() == null && floatWarOrder.getTag() == null) { floatRedPacket.setVisibility(View.VISIBLE); + floatRedPacket.setTag(data); ((ProgressBar) floatRedPacket.findViewById(R.id.progress)).setMax(data.getRedPacketTotal()); ((ProgressBar) floatRedPacket.findViewById(R.id.progress)).setProgress(data.getRedPacketNum()); ((TextView) floatRedPacket.findViewById(R.id.progressText)).setText(data.getRedPacketNum() + "/" + data.getRedPacketTotal()); @@ -1521,9 +1527,6 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene @Subscribe(threadMode = ThreadMode.MAIN) public void onFloatWarOrderEvent(FloatWarOrderEvent event) { - System.out.println("FloatWarOrderEvent:事件" + event.isFloatWarOrder()); - System.out.println("战令:" + floatWarOrder.getTag()); - System.out.println("Banner:" + floatBanner.getTag()); floatEventShow = event.isFloatWarOrder(); if (event.isFloatWarOrder()) { if (floatWarOrder.getTag() == null) { @@ -1536,9 +1539,15 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene } else { floatBanner.setVisibility(View.VISIBLE); } + if (floatRedPacket.getTag() == null) { + floatRedPacket.setVisibility(View.GONE); + } else { + floatRedPacket.setVisibility(View.VISIBLE); + } } else { floatBanner.setVisibility(View.GONE); floatWarOrder.setVisibility(View.GONE); + floatRedPacket.setVisibility(View.GONE); } /* if(floatWarOrder.getTag()!=null){ floatWarOrder.setVisibility(View.VISIBLE); From 5f3ebb4235e8a32bb3c25cea5489c92cbacf62a5 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 30 May 2024 15:52:34 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E9=97=B4=20=E7=94=A8=E6=88=B7=E7=AD=89=E7=BA=A7+=E8=B6=85?= =?UTF-8?q?=E7=9A=87+=E7=B2=89=E4=B8=9D=E7=89=8C+=E5=9B=BE=E6=A0=87+?= =?UTF-8?q?=E5=90=8D=E5=AD=97=EF=BC=8810=E5=AD=97=EF=BC=89=E4=BC=9A?= =?UTF-8?q?=E4=B8=A2=E5=A4=B1=E5=90=8D=E5=AD=97=E5=89=8D=E9=9D=A2=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.gradle | 2 +- .../com/yunbao/live/utils/LiveTextRender.java | 87 ++++++++++++++----- live/src/main/res/layout/item_live_chat.xml | 2 +- 3 files changed, 67 insertions(+), 24 deletions(-) diff --git a/config.gradle b/config.gradle index fd33bfeaf..882f01bd3 100644 --- a/config.gradle +++ b/config.gradle @@ -4,7 +4,7 @@ ext { buildToolsVersion: "29.0.2", minSdkVersion : 21, targetSdkVersion : 33, - versionCode : 473, + versionCode : 474, versionName : "6.6.8" ] manifestPlaceholders = [ 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 b220d8f07..f9f67b5ba 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java @@ -21,6 +21,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.MeasureSpec; +import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; @@ -263,7 +264,7 @@ public class LiveTextRender { } public interface CreatePrefixCallback { - void onPrefixCallback(SpannableStringBuilder builder); + void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth); } /** @@ -353,19 +354,20 @@ public class LiveTextRender { index = builder.length(); } } - createPrefixCallback.onPrefixCallback(builder); + createPrefixCallback.onPrefixCallback(builder, 0); } @Override public void onLoadFailed() { SpannableStringBuilder builder = new SpannableStringBuilder(); int index = 0; - + int prefixWidth = 0; if (levelDrawable != null) { builder.append(" "); levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += levelDrawable.getBounds().width(); } if (gzDrawablesMap.containsKey(bean)) {//贵族 @@ -373,6 +375,7 @@ public class LiveTextRender { 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); index = builder.length(); + prefixWidth += gzDrawablesMap.get(bean).getBounds().width(); } if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 @@ -380,6 +383,7 @@ public class LiveTextRender { 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); index = builder.length(); + prefixWidth += ryxzDrawablesMap.get(bean).getBounds().width(); } if (nhDrawablesMap.containsKey(bean)) {//靓号 @@ -387,6 +391,7 @@ public class LiveTextRender { 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); index = builder.length(); + prefixWidth += nhDrawablesMap.get(bean).getBounds().width(); } //在这里添加粉丝徽章的图片 if (!TextUtils.isEmpty(bean.getMedalNmae()) && !TextUtils.isEmpty(bean.getMedalLevelImageUrl()) @@ -397,6 +402,7 @@ public class LiveTextRender { drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += drawable.getBounds().width(); } } @@ -421,7 +427,7 @@ public class LiveTextRender { index = builder.length(); } } - createPrefixCallback.onPrefixCallback(builder); + createPrefixCallback.onPrefixCallback(builder, prefixWidth); } }); @@ -515,9 +521,9 @@ public class LiveTextRender { } public void getGuardImage(Context mContext, int guardType, ImgLoader.DrawableCallback callback) { - if (guardType==0){ + if (guardType == 0) { callback.onLoadFailed(); - }else { + } else { if (mContext instanceof Activity) { if (((Activity) mContext).isDestroyed()) { mContext = CommonAppContext.getTopActivity(); @@ -684,7 +690,7 @@ public class LiveTextRender { createPrefix(drawable, bean, new CreatePrefixCallback() { @Override - public void onPrefixCallback(SpannableStringBuilder builder) { + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { int color = Color.parseColor("#68F1F4"); if (bean.isAnchor()) { color = Color.parseColor("#FBEABF"); @@ -696,20 +702,20 @@ public class LiveTextRender { builder = renderGift(color, builder, bean); break; default: - builder = renderChat(color, builder, bean); + builder = renderChat(textView, color, builder, bean, prefixWidth); break; } textView.setText(builder); } }); - } + }// 123123123123123123123123 @Override public void onLoadFailed() { createPrefix(null, bean, new CreatePrefixCallback() { @Override - public void onPrefixCallback(SpannableStringBuilder builder) { + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { int color = 0; if (bean.isAnchor()) { color = 0xffffdd00; @@ -721,7 +727,7 @@ public class LiveTextRender { builder = renderGift(color, builder, bean); break; default: - builder = renderChat(color, builder, bean); + builder = renderChat(textView, color, builder, bean, prefixWidth); break; } textView.setText(builder); @@ -808,12 +814,31 @@ public class LiveTextRender { /** * 渲染普通聊天消息 */ - private SpannableStringBuilder renderChat(int color, SpannableStringBuilder builder, LiveChatBean bean) { + private SpannableStringBuilder renderChat(TextView textView, int color, SpannableStringBuilder builder, LiveChatBean bean, int prefixWidth) { int length = builder.length(); String name = bean.getUserNiceName(); if (bean.getType() != LiveChatBean.ENTER_ROOM) {//产品规定,进场消息不允许加冒号 name += ":"; } + SpannableStringBuilder sb = new SpannableStringBuilder(); + sb.append(builder).append(name).append(" "); + float measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + int width = ((ViewGroup) textView.getParent()).getWidth(); + //检测渲染后图标+名字是否超过父布局宽度,超过了就做换行处理 + if (measuredText > width) { + sb.clear(); + sb.append(builder); + for (int i = 0; i < name.length(); i++) { + sb.append(name.charAt(i)).append(" "); + measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + if (measuredText + 1 > width) { + name = name.substring(0, i+1) + "\n" + name.substring(i+1); + break; + } + } + sb.clear(); + } + // name=name.substring(0,7)+"\n"+name.substring(7); builder.append(name); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getStartColor())) { @@ -823,6 +848,24 @@ public class LiveTextRender { builder.setSpan(new ForegroundColorSpan(color), length, length + name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } int lengthContent = builder.length(); + //这一段先别删,万一后面要改内容换行呢 + /* sb.clear(); + sb.append(builder).append(bean.getContent()); + measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + if (measuredText > width) { + sb.clear(); + sb.append(builder); + for (int i = 0; i < bean.getContent().length(); i++) { + sb.append(bean.getContent().charAt(i)); + measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + if (measuredText + 3 > width) { + bean.setContent(bean.getContent().substring(0, i) + "\n"+ bean.getContent().substring(i)); + bean.setContent(""); + break; + } + } + } +*/ builder.append(bean.getContent()); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getContentColor())) { @@ -889,7 +932,7 @@ public class LiveTextRender { if (textView != null) { createPrefix(drawable, bean, new CreatePrefixCallback() { @Override - public void onPrefixCallback(SpannableStringBuilder builder) { + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { int start = builder.length(); String name = bean.getUserNiceName() + " "; builder.append(name); @@ -904,15 +947,15 @@ public class LiveTextRender { @Override public void onLoadFailed() { if (textView != null) { - createPrefix(null, bean, new CreatePrefixCallback() { - @Override - public void onPrefixCallback(SpannableStringBuilder builder) { - int start = builder.length(); - String name = bean.getUserNiceName() + " "; - builder.append(name); - textView.setText(builder); - } - }); + createPrefix(null, bean, new CreatePrefixCallback() { + @Override + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { + int start = builder.length(); + String name = bean.getUserNiceName() + " "; + builder.append(name); + textView.setText(builder); + } + }); } } diff --git a/live/src/main/res/layout/item_live_chat.xml b/live/src/main/res/layout/item_live_chat.xml index c4d360d8c..da2996682 100644 --- a/live/src/main/res/layout/item_live_chat.xml +++ b/live/src/main/res/layout/item_live_chat.xml @@ -10,7 +10,7 @@ Date: Mon, 3 Jun 2024 15:02:03 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E5=A0=86?= =?UTF-8?q?=E5=9B=BE=E6=A0=87+10=E5=AD=97=E5=90=8D=E5=AD=97=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E6=A1=86=E6=B2=A1=E6=9C=89=E5=9B=BE=E6=A0=87=E9=97=AE?= =?UTF-8?q?=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())) { From cb0772c9e357b29c050826a92e09baece972e6ae Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Wed, 5 Jun 2024 09:48:22 +0800 Subject: [PATCH 7/7] =?UTF-8?q?update=20=E6=9B=B4=E6=96=B0=E5=BC=B9?= =?UTF-8?q?=E5=B9=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/activity/LiveAudienceActivity.java | 25 +++- .../yunbao/live/adapter/LiveChatAdapter.java | 3 +- .../com/yunbao/live/utils/LiveTextRender.java | 122 ++++++++++++------ live/src/main/res/layout/item_live_chat.xml | 2 + 4 files changed, 111 insertions(+), 41 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 6d51d42b2..d093665b1 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -15,6 +15,7 @@ import android.text.TextUtils; import android.util.Log; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.ImageView; import androidx.annotation.IdRes; @@ -229,21 +230,37 @@ public class LiveAudienceActivity extends LiveActivity { fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "YoursystemisolderDialog"); IMLoginManager.get(mContext).setXiaJBG(true); } - /*new Handler(Looper.getMainLooper()) + /* 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(); + + 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() { @Override public void onItemClick(String bean, int position) { - dialog.setParams(bean.split("\\|")[0], bean.split("\\|")[1]); + dialog.setParams(bean.split("\\|")[0], bean.split("\\|")[1]+"|"+position); } }; } diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java index 9d515497e..bac417ed9 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java @@ -210,7 +210,8 @@ public class LiveChatAdapter extends RecyclerView.Adapter { class Vh extends RecyclerView.ViewHolder { 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; View v_chat_active_close; RecyclerView rv_chat_active; 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 c99006b84..c1014fa45 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java @@ -6,6 +6,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Rect; import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; @@ -23,6 +24,7 @@ import android.view.View; import android.view.View.MeasureSpec; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -296,34 +298,34 @@ public class LiveTextRender { int index = 0; if (levelDrawable != null) { - builder.append(" "); + builder.append("\uFFFC "); levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); } if (gzDrawablesMap.containsKey(bean)) {//贵族 - builder.append(" "); + builder.append("\uFFFC "); 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); index = builder.length(); } if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 - builder.append(" "); + builder.append("\uFFFC "); 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); index = builder.length(); } if (nhDrawablesMap.containsKey(bean)) {//靓号 - builder.append(" "); + builder.append("\uFFFC "); 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); index = builder.length(); } if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); 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(); @@ -333,7 +335,7 @@ public class LiveTextRender { && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("")) {//粉丝徽章图标 Drawable drawable2 = getMedalImage(bean); if (drawable2 != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable2.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable2), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -344,7 +346,7 @@ public class LiveTextRender { if (bean.isManager()) {//直播间管理员图标 Drawable drawable3 = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); if (drawable3 != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable3.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable3), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -354,7 +356,7 @@ public class LiveTextRender { if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 Drawable drawable4 = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); if (drawable4 != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable4.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable4), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // new add @@ -375,7 +377,7 @@ public class LiveTextRender { int index = 0; int prefixWidth = 0; if (levelDrawable != null) { - builder.append(" "); + builder.append("\uFFFC "); levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -383,7 +385,7 @@ public class LiveTextRender { } if (gzDrawablesMap.containsKey(bean)) {//贵族 - builder.append(" "); + builder.append("\uFFFC "); 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); index = builder.length(); @@ -391,7 +393,7 @@ public class LiveTextRender { } if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 - builder.append(" "); + builder.append("\uFFFC "); 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); index = builder.length(); @@ -399,14 +401,14 @@ public class LiveTextRender { } if (nhDrawablesMap.containsKey(bean)) {//靓号 - builder.append(" "); + builder.append("\uFFFC "); 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); index = builder.length(); prefixWidth += nhDrawablesMap.get(bean).getBounds().width(); } if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); 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(); @@ -417,7 +419,7 @@ public class LiveTextRender { && !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("")) {//粉丝徽章图标 drawable = getMedalImage(bean); if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); @@ -429,7 +431,7 @@ public class LiveTextRender { if (bean.isManager()) {//直播间管理员图标 drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m); if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); 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(); @@ -440,7 +442,7 @@ public class LiveTextRender { if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标 drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang); if (drawable != null) { - builder.append(" "); + builder.append("\uFFFC "); drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // new add @@ -832,13 +834,15 @@ public class LiveTextRender { return mNewBitmap; } - public static OnItemClickListener onItemClickListener=new OnItemClickListener() { + public static OnItemClickListener onItemClickListener = new OnItemClickListener() { @Override public void onItemClick(String bean, int position) { } }; 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) { int length = builder.length(); 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) {//产品规定,进场消息不允许加冒号 name += ":"; } SpannableStringBuilder sb = new SpannableStringBuilder(); - sb.append(builder).append(name).append(" "); + sb.append(name); 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); + // Rect mRect = new Rect(); + // textView.getPaint().getTextBounds(sb.toString(), 0, sb.length(), mRect); + int width = (int) (((ViewGroup) textView.getParent()).getMeasuredWidth() - prefixEmpty); + 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) { sb.clear(); - sb.append(builder); for (int i = 0; i < name.length(); i++) { sb.append(name.charAt(i)); measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; - onItemClickListener.onItemClick(i + "逐测算|" + measuredText, 0); - if (measuredText > width) { - name = name.substring(0, i - 1) + "\n" + name.substring(i -1); + Log.i(TAG, i + "逐测算|" + measuredText + "|" + textTemp); + if (measuredText > width) { + prefixName = name.substring(0, i + textTemp); + name = prefixName + "\n" + name.substring(i + textTemp); break; } } sb.clear(); + } else { + prefixName = name; } + sb.clear(); + sb.append(prefixName); // name=name.substring(0,7)+"\n"+name.substring(7); 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())) { @@ -882,26 +901,56 @@ public class LiveTextRender { } int lengthContent = builder.length(); //这一段先别删,万一后面要改内容换行呢 - /* sb.clear(); - sb.append(builder).append(bean.getContent()); + // TODO 试试 “空Unicode” + /*sb.clear(); + 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; + sb.clear(); + sb.append(prefixName); + prefixEmpty = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + StringBuilder stringBuilder = new StringBuilder(); if (measuredText > width) { sb.clear(); - sb.append(builder); - for (int i = 0; i < bean.getContent().length(); i++) { - sb.append(bean.getContent().charAt(i)); - measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; - if (measuredText + 3 > width) { - bean.setContent(bean.getContent().substring(0, i) + "\n"+ bean.getContent().substring(i)); - bean.setContent(""); - break; + sb.append(name); + float lineWidth = 0; + for (int i = 0; i < content.length(); i++) { + char charAt = content.charAt(i); + sb.append(charAt); + lineWidth += textView.getPaint().measureText(String.valueOf(charAt)) + prefixEmpty; + prefixEmpty = 0; + 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()); //超皇设置渐变色展示昵称 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); } if (bean.getType() == LiveChatBean.LIGHT) { @@ -913,6 +962,7 @@ public class LiveTextRender { builder.setSpan(new VerticalImageSpan(heartDrawable), length - 1, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } + //textView.setText(""); return builder; } diff --git a/live/src/main/res/layout/item_live_chat.xml b/live/src/main/res/layout/item_live_chat.xml index da2996682..a6e5fddfb 100644 --- a/live/src/main/res/layout/item_live_chat.xml +++ b/live/src/main/res/layout/item_live_chat.xml @@ -16,7 +16,9 @@ android:layout_marginRight="9dp" android:paddingBottom="7dp" android:textColor="#fff" + android:breakStrategy="simple" android:textSize="12sp" + tools:text="aaaaaaaaa111111111111111111111111111111111111111111111111111111111" android:visibility="visible" tools:ignore="RtlHardcoded" />