From 6841f47ac321f31a404b377c30903f8128b5b1c7 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Tue, 1 Nov 2022 14:46:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BB=E6=92=AD=E7=AD=89?= =?UTF-8?q?=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/glide/ImgLoader.java | 24 ++- .../yunbao/live/activity/LiveActivity.java | 4 - .../live/activity/LiveAudienceActivity.java | 5 +- .../yunbao/live/adapter/LiveChatAdapter.java | 10 +- .../live/adapter/UserMoreInfoAdapter.java | 14 +- .../live/dialog/LiveUserDialogFragment.java | 8 +- .../presenter/LiveEnterRoomAnimPresenter.java | 2 +- .../com/yunbao/live/utils/LiveTextRender.java | 193 ++++++++++++------ .../yunbao/live/views/LiveGiftViewHolder.java | 6 +- .../live/views/LuckLiveGiftViewHolder.java | 9 +- .../main/res/layout/item_user_more_info.xml | 1 + live/src/main/res/layout/live_medal_icon.xml | 12 +- main/src/main/res/layout/view_homemain.xml | 9 +- 13 files changed, 201 insertions(+), 96 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/glide/ImgLoader.java b/common/src/main/java/com/yunbao/common/glide/ImgLoader.java index 3c26b148e..7d29c0623 100644 --- a/common/src/main/java/com/yunbao/common/glide/ImgLoader.java +++ b/common/src/main/java/com/yunbao/common/glide/ImgLoader.java @@ -70,7 +70,7 @@ public class ImgLoader { } RequestBuilder builder = Glide.with(context) .load(url) - + .thumbnail(thumbnail) .dontAnimate() .placeholder(imageView.getDrawable()); @@ -87,7 +87,21 @@ public class ImgLoader { Glide.with(context) .asDrawable() .load(url) - + + .thumbnail(thumbnail) + .placeholder(imageView.getDrawable()) + .dontAnimate() + .skipMemoryCache(SKIP_MEMORY_CACHE) + .into(imageView); + } + + public static void display2(Context context, Drawable drawable, ImageView imageView) { + if (!contextIsExist(context)) { + return; + } + Glide.with(context) + .asDrawable() + .load(drawable) .thumbnail(thumbnail) .placeholder(imageView.getDrawable()) .dontAnimate() @@ -142,7 +156,7 @@ public class ImgLoader { RequestBuilder builder = Glide.with(context) .load(url) .thumbnail(thumbnail) - + .error(R.mipmap.icon_avatar_placeholder); if (width != -1 && height != -1) { builder = builder.override(width, height); @@ -165,7 +179,7 @@ public class ImgLoader { Glide.with(context) .asDrawable() .load(file) - + .thumbnail(thumbnail) .skipMemoryCache(SKIP_MEMORY_CACHE) .into(imageView); @@ -178,7 +192,7 @@ public class ImgLoader { Glide.with(context) .asDrawable() .load(res) - + .thumbnail(thumbnail) .skipMemoryCache(SKIP_MEMORY_CACHE) .into(imageView); diff --git a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java index 22538594a..80aa7c7d5 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveActivity.java @@ -77,7 +77,6 @@ import com.yunbao.live.socket.SocketClient; import com.yunbao.live.socket.SocketMessageListener; import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyClient; -import com.yunbao.live.utils.LiveTextRender; import com.yunbao.live.utils.LoadDian9TuUtil; import com.yunbao.live.utils.UnzipFromAssets; import com.yunbao.live.views.AbsLiveViewHolder; @@ -1522,12 +1521,9 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL mLiveContributeViewHolder = null; mLiveMedalRankViewHolder = null; mLiveLuckGiftTipViewHolder = null; -// mMobShareUtil = null; mImageUtil = null; SVGAViewUtils.clearSVGA(); - LiveTextRender.clear(); L.e("LiveActivity--------release------>"); - Constants.isSend = "0"; } 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 46127b6ef..450bf2ab2 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -62,6 +62,7 @@ import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.pay.PayCallback; import com.yunbao.common.pay.PayPresenter; import com.yunbao.common.utils.Bus; +import com.yunbao.common.utils.DeviceUtils; import com.yunbao.common.utils.DialogUitl; import com.yunbao.common.utils.GiftCacheUtil; import com.yunbao.common.utils.L; @@ -657,7 +658,7 @@ public class LiveAudienceActivity extends LiveActivity { super.onResume(); manager.onResume(); GiftCacheUtil.getInstance().restart(); - + Log.e(TAG, "Memory:" + DeviceUtils.getAvailMemory(mContext)); } @Override @@ -874,7 +875,7 @@ public class LiveAudienceActivity extends LiveActivity { + "&stream=" + mStream + "&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken(); - LiveHDDialogFragment liveHDDialogFragment = new LiveHDDialogFragment(); + LiveHDDialogFragment liveHDDialogFragment = new LiveHDDialogFragment(); bundle.putString("url", url); bundle.putInt("show_type", 0); liveHDDialogFragment.setArguments(bundle); 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 1c76f89bf..a2ad2f0c1 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java @@ -333,23 +333,23 @@ public class LiveChatAdapter extends RecyclerView.Adapter { } else if (bean.getType() == RECOMMEND_CARD_NOTIFY) { //加载.9图聊天气泡 LoadDian9TuUtil.loadDian9Tu(mContext, mBg, bean.getBubble(), 1); - LiveTextRender.recommendCardNotify(mContext, mTextView, bean); + new LiveTextRender().recommendCardNotify(mContext, mTextView, bean); } else if (bean.getType() == AI_AUTOMATIC_SPEECH) { //加载.9图聊天气泡 LoadDian9TuUtil.loadDian9Tu(mContext, mBg, bean.getAiAutomaticSpeechModel().getSystemBubble(), 1); - LiveTextRender.aiAutomaticSpeech(mContext, mTextView, bean.getAiAutomaticSpeechModel()); + new LiveTextRender().aiAutomaticSpeech(mContext, mTextView, bean.getAiAutomaticSpeechModel()); } else if (bean.getType() == STAR_CHALLENGE_UPGRADE_NOTIFY) { //加载.9图聊天气泡 if (!TextUtils.isEmpty(bean.getMsgModel().getSystemBubble())) { LoadDian9TuUtil.loadDian9Tu(mContext, mBg, bean.getMsgModel().getSystemBubble(), 1); - LiveTextRender.starChallengeUpgradeNotify(mContext, mTextView, bean.getMsgModel()); + new LiveTextRender().starChallengeUpgradeNotify(mContext, mTextView, bean.getMsgModel()); } } else if (bean.getType() == LUCKY_ANGEL) { if (!TextUtils.isEmpty(bean.getMsgModel().getSystem_bubble())) { bean.setId(bean.getMsgModel().getUserId()); itemView.setTag(bean); LoadDian9TuUtil.loadDian9Tu(mContext, mBg, bean.getMsgModel().getSystem_bubble(), 1); - LiveTextRender.luckyAngel(mContext, mTextView, bean.getMsgModel()); + new LiveTextRender().luckyAngel(mContext, mTextView, bean.getMsgModel()); } } else { @@ -365,7 +365,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter { mTextView.setTextColor(0xffffffff); } - LiveTextRender.render(mContext, mTextView, bean); + new LiveTextRender().render(mContext, mTextView, bean); } } } diff --git a/live/src/main/java/com/yunbao/live/adapter/UserMoreInfoAdapter.java b/live/src/main/java/com/yunbao/live/adapter/UserMoreInfoAdapter.java index 8ecf0e50a..566acd9ff 100644 --- a/live/src/main/java/com/yunbao/live/adapter/UserMoreInfoAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/UserMoreInfoAdapter.java @@ -37,6 +37,7 @@ import com.yunbao.live.R; import com.yunbao.live.activity.LiveActivity; import com.yunbao.live.bean.LiveUserGiftBean; import com.yunbao.live.dialog.LiveUserMoreDialogFragment; +import com.yunbao.live.utils.LiveTextRender; import java.net.MalformedURLException; import java.net.URL; @@ -279,7 +280,18 @@ public class UserMoreInfoAdapter extends RefreshAdapter { mSex.setImageResource(CommonIconUtil.getSexIcon(bean.getSex())); if (levelBean != null) { - ImgLoader.display(mContext, levelBean.getThumb(), mLevel); + new LiveTextRender().getLevelImage(mContext, levelBean.getLevel(), new ImgLoader.DrawableCallback() { + @Override + public void onLoadSuccess(Drawable drawable) { + ImgLoader.display2(mContext,drawable, mLevel); + } + + @Override + public void onLoadFailed() { + + } + }); + } if (bean.isHide() && (type.equals("5") || type.equals("4"))) { mName.setText(R.string.mystery_man); diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java index 989be5ac0..fc82e3358 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveUserDialogFragment.java @@ -460,10 +460,10 @@ public class LiveUserDialogFragment extends AbsDialogFragment implements View.On mLevelAnchorText.setText(String.valueOf(levelAnchor)); mLevelText.setText(String.valueOf(level)); mSex.setImageResource(CommonIconUtil.getSexIcon(obj.getIntValue("sex"))); - mFollow.setText(LiveTextRender.renderLiveUserDialogData(obj.getLongValue("follows"))); - mFans.setText(LiveTextRender.renderLiveUserDialogData(obj.getLongValue("fans"))); - mConsume.setText(LiveTextRender.renderLiveUserDialogData(obj.getLongValue("consumption"))); - mVotes.setText(LiveTextRender.renderLiveUserDialogData(obj.getLongValue("votestotal"))); + mFollow.setText(new LiveTextRender().renderLiveUserDialogData(obj.getLongValue("follows"))); + mFans.setText(new LiveTextRender().renderLiveUserDialogData(obj.getLongValue("fans"))); + mConsume.setText(new LiveTextRender().renderLiveUserDialogData(obj.getLongValue("consumption"))); + mVotes.setText(new LiveTextRender().renderLiveUserDialogData(obj.getLongValue("votestotal"))); mConsumeTip.setText(WordUtil.getString(R.string.live_user_send) + appConfig.getCoinName()); mVotesTip.setText(WordUtil.getString(R.string.live_user_get) + appConfig.getVotesName()); if (mType == TYPE_AUD_ANC) { diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveEnterRoomAnimPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveEnterRoomAnimPresenter.java index 565a570e0..61155f065 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveEnterRoomAnimPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveEnterRoomAnimPresenter.java @@ -431,7 +431,7 @@ public class LiveEnterRoomAnimPresenter { if (u.getVipType() != 0 || liveChatBean.getGuardType() != Constants.GUARD_TYPE_NONE) { needAnim = true; ImgLoader.displayAvatar(mContext, bean.getUserBean().getAvatar(), mAvatar); - LiveTextRender.renderEnterRoom(mContext, mName, liveChatBean); + new LiveTextRender().renderEnterRoom(mContext, mName, liveChatBean); mBgAnimator1.start(); mUserAnimator1.start(); } 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 eb360679d..e0efac38c 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java @@ -2,7 +2,9 @@ package com.yunbao.live.utils; import android.content.Context; import android.graphics.Bitmap; +import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.Paint; import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; @@ -20,8 +22,13 @@ import android.view.View.MeasureSpec; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; 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.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; @@ -45,19 +52,19 @@ import java.util.Map; public class LiveTextRender { - private static StyleSpan sBoldSpan; - private static StyleSpan sNormalSpan; - private static ForegroundColorSpan sWhiteColorSpan; - private static ForegroundColorSpan sGlobalColorSpan; - private static AbsoluteSizeSpan sFontSizeSpan; - private static AbsoluteSizeSpan sFontSizeSpan2; - private static AbsoluteSizeSpan sFontSizeSpan3; - private static final Map mDrawableMedalMap = new HashMap<>(); - private static final Map gzDrawablesMap = new HashMap<>(); - private static final Map ryxzDrawablesMap = new HashMap<>(); - private static final Map nhDrawablesMap = new HashMap<>(); + private StyleSpan sBoldSpan; + private StyleSpan sNormalSpan; + private ForegroundColorSpan sWhiteColorSpan; + private ForegroundColorSpan sGlobalColorSpan; + private AbsoluteSizeSpan sFontSizeSpan; + private AbsoluteSizeSpan sFontSizeSpan2; + private AbsoluteSizeSpan sFontSizeSpan3; + private final Map mDrawableMedalMap = new HashMap<>(); + private final Map gzDrawablesMap = new HashMap<>(); + private final Map ryxzDrawablesMap = new HashMap<>(); + private final Map nhDrawablesMap = new HashMap<>(); - static { + public LiveTextRender() { sBoldSpan = new StyleSpan(Typeface.BOLD); sNormalSpan = new StyleSpan(Typeface.NORMAL); sWhiteColorSpan = new ForegroundColorSpan(0xffffffff); @@ -73,7 +80,7 @@ public class LiveTextRender { * @param textView * @param bean */ - public static void recommendCardNotify(Context context, TextView textView, LiveChatBean bean) { + public void recommendCardNotify(Context context, TextView textView, LiveChatBean bean) { String recommend; Drawable drawable; if (TextUtils.equals(bean.getMsgModel().getRecommendCardType(), "1")) { @@ -107,7 +114,7 @@ public class LiveTextRender { * @param textView * @param model */ - public static void starChallengeUpgradeNotify(Context activity, TextView textView, MsgModel model) { + public void starChallengeUpgradeNotify(Context activity, TextView textView, MsgModel model) { String star = activity.getString(R.string.star); String starString = String.format(activity.getString(R.string.star_success), model.getAncherName(), model.getCompetitionArea(), model.getStar()); SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(); @@ -126,7 +133,7 @@ public class LiveTextRender { /** * 幸运天使 */ - public static void luckyAngel(Context mContext, TextView mTextView, MsgModel msgModel) { + public void luckyAngel(Context mContext, TextView mTextView, MsgModel msgModel) { String msg = mContext.getString(R.string.lucky_angel); msg = String.format(msg, msgModel.getUserName(), msgModel.getGiftName()); int unameIndexOf = msg.indexOf(msgModel.getUserName()); @@ -140,7 +147,7 @@ public class LiveTextRender { mTextView.setText(builder); } - public static void aiAutomaticSpeech(Context activity, TextView textView, AiAutomaticSpeechModel model) { + public void aiAutomaticSpeech(Context activity, TextView textView, AiAutomaticSpeechModel model) { ImgLoader.displayDrawable(activity, model.getIcon(), new ImgLoader.DrawableCallback() { @Override public void onLoadSuccess(Drawable drawable) { @@ -207,13 +214,13 @@ public class LiveTextRender { /** * 生成前缀 */ - private static SpannableStringBuilder createPrefix(Drawable levelDrawable, LiveChatBean bean) { + private SpannableStringBuilder createPrefix(Drawable levelDrawable, LiveChatBean bean) { SpannableStringBuilder builder = new SpannableStringBuilder(); int index = 0; if (levelDrawable != null) { builder.append(" "); - levelDrawable.setBounds(0, 0, DpUtil.dp2px(28), DpUtil.dp2px(14)); + levelDrawable.setBounds(0, 0, DpUtil.dp2px(32), DpUtil.dp2px(14)); builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index += 2; } @@ -264,7 +271,6 @@ public class LiveTextRender { if (drawable != null) { builder.append(" "); drawable.setBounds(0, 0, DpUtil.dp2px(42), DpUtil.dp2px(14)); -// drawable.setBounds(0, 0, DpUtil.dp2px(50), DpUtil.dp2px(20));//切图为138*38 builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index += 2; } @@ -296,22 +302,20 @@ public class LiveTextRender { return builder; } - private static Drawable getMedalImage(final LiveChatBean bean) { + private Drawable getMedalImage(final LiveChatBean bean) { View view = LayoutInflater.from(CommonAppContext.sInstance).inflate(R.layout.live_medal_icon, null, false); final ImageView iv = view.findViewById(R.id.ivIcon); if (mDrawableMedalMap.containsKey(bean)) iv.setImageDrawable(mDrawableMedalMap.get(bean)); TextView tv = view.findViewById(R.id.tvName); tv.setText(bean.getMedalNmae()); - //字体加粗 -// tv.setTextSize(TypedValue.COMPLEX_UNIT_SP,13); tv.setTypeface(Typeface.DEFAULT_BOLD); Bitmap bitmap = convertViewToBitmap(view); Drawable drawable = new BitmapDrawable(bitmap); return drawable; } - public static Bitmap convertViewToBitmap(View view) { + public Bitmap convertViewToBitmap(View view) { view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredWidth() / 3); // 153 72 @@ -321,7 +325,7 @@ public class LiveTextRender { return bitmap; } - public static void render(final Context context, final TextView textView, final LiveChatBean bean) { + public void render(final Context context, final TextView textView, final LiveChatBean bean) { ImgLoader.displayDrawable(context, bean.getMedalLevelImageUrl(), new ImgLoader.DrawableCallback() { @Override public void onLoadSuccess(Drawable drawable) { @@ -337,7 +341,7 @@ public class LiveTextRender { } - public static void ryxz(final Context context, final TextView textView, final LiveChatBean bean) { + public void ryxz(final Context context, final TextView textView, final LiveChatBean bean) { ImgLoader.displayDrawable(context, bean.getMedal_honor(), new ImgLoader.DrawableCallback() { @Override public void onLoadSuccess(Drawable drawable) { @@ -352,7 +356,7 @@ public class LiveTextRender { }); } - public static void nh(final Context context, final TextView textView, final LiveChatBean bean) { + public void nh(final Context context, final TextView textView, final LiveChatBean bean) { if (bean.getGood_nub() != null && !bean.getGood_nub().equals("")) { nhDrawablesMap.put(bean, ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.good_nub)); renderTMP(context, textView, bean); @@ -361,7 +365,7 @@ public class LiveTextRender { } } - public static void gz(final Context context, final TextView textView, final LiveChatBean bean) { + public void gz(final Context context, final TextView textView, final LiveChatBean bean) { ImgLoader.displayDrawable(context, TextUtils.isEmpty(bean.getMedal_new()) ? bean.getMedal() : bean.getMedal_new(), new ImgLoader.DrawableCallback() { @Override public void onLoadSuccess(Drawable drawable) { @@ -376,7 +380,61 @@ public class LiveTextRender { }); } - private static void renderTMP(Context context, final TextView textView, final LiveChatBean bean) { + /** + * 等级设置 + * + * @return + */ + public void getLevelImage(Context mContext, int userLevel, ImgLoader.DrawableCallback callback) { + + String imgUrl = "https://downs.yaoulive.com/level/user_lv1_bg.png"; + if (0 < userLevel && userLevel < 10) { + imgUrl = "https://downs.yaoulive.com/level/user_lv1_bg.png"; + } else if (9 < userLevel && userLevel < 20) { + imgUrl = "https://downs.yaoulive.com/level/user_lv10_bg.png"; + } else if (19 < userLevel && userLevel < 30) { + imgUrl = "https://downs.yaoulive.com/level/user_lv20_bg.png"; + } else if (29 < userLevel && userLevel < 40) { + imgUrl = "https://downs.yaoulive.com/level/user_lv30_bg.png"; + } else if (39 < userLevel && userLevel < 50) { + imgUrl = "https://downs.yaoulive.com/level/user_lv40_bg.png"; + } else if (49 < userLevel && userLevel < 60) { + imgUrl = "https://downs.yaoulive.com/level/user_lv50_bg.png"; + } else if (59 < userLevel && userLevel < 70) { + imgUrl = "https://downs.yaoulive.com/level/user_lv60_bg.png"; + } else if (69 < userLevel && userLevel < 80) { + imgUrl = "https://downs.yaoulive.com/level/user_lv70_bg.png"; + } else if (79 < userLevel && userLevel < 90) { + imgUrl = "https://downs.yaoulive.com/level/user_lv80_bg.png"; + } else if (89 < userLevel && userLevel < 100) { + imgUrl = "https://downs.yaoulive.com/level/user_lv90_bg.png"; + } else if (99 < userLevel && userLevel < 110) { + imgUrl = "https://downs.yaoulive.com/level/user_lv100_bg.png"; + } else if (109 < userLevel && userLevel < 120) { + imgUrl = "https://downs.yaoulive.com/level/user_lv110_bg.png"; + } else if (userLevel == 120) { + imgUrl = "https://downs.yaoulive.com/level/user_lv120_bg.png"; + } + Glide.with(mContext).asBitmap().load(imgUrl).into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + ; + BitmapDrawable drawable = new BitmapDrawable(AddTimeWatermark(resource, String.valueOf(userLevel))); + if (callback != null) { + callback.onLoadSuccess(drawable); + } + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + if (callback != null) { + callback.onLoadFailed(); + } + } + }); + } + + private void renderTMP(Context context, final TextView textView, final LiveChatBean bean) { final LevelBean levelBean = CommonAppConfig.getInstance().getLevel(bean.getLevel()); if (levelBean == null) { @@ -395,10 +453,10 @@ public class LiveTextRender { textView.setText(builder); } } else { - ImgLoader.displayDrawable(context, levelBean.getThumb(), new ImgLoader.DrawableCallback() { - @Override - public void onLoadSuccess(Drawable drawable) { - if (textView != null) { + if (textView != null) { + getLevelImage(context, bean.getLevel(), new ImgLoader.DrawableCallback() { + @Override + public void onLoadSuccess(Drawable drawable) { SpannableStringBuilder builder = createPrefix(drawable, bean); int color = 0; if (bean.isAnchor()) { @@ -420,17 +478,19 @@ public class LiveTextRender { } textView.setText(builder); } - } - @Override - public void onLoadFailed() { - if (textView != null) { + @Override + public void onLoadFailed() { SpannableStringBuilder builder = createPrefix(null, bean); int color = 0; if (bean.isAnchor()) { color = 0xffffdd00; } else { - color = Color.parseColor(levelBean.getColor()); + try { + color = Color.parseColor(levelBean.getColor()); + } catch (Exception e) { + color = Color.parseColor("#ffffff"); + } } switch (bean.getType()) { case LiveChatBean.GIFT: @@ -442,17 +502,43 @@ public class LiveTextRender { } textView.setText(builder); } - } - }); + }); + + } } + } - + /** + * bitmap添加文字 + * + * @param mBitmap + * @return + */ + private Bitmap AddTimeWatermark(Bitmap mBitmap, String level) { + //获取原始图片与水印图片的宽与高 + int mBitmapWidth = mBitmap.getWidth(); + int mBitmapHeight = mBitmap.getHeight(); + Bitmap mNewBitmap = Bitmap.createBitmap(mBitmapWidth, mBitmapHeight, Bitmap.Config.ARGB_8888); + Canvas mCanvas = new Canvas(mNewBitmap); + //向位图中开始画入MBitmap原始图片 + mCanvas.drawBitmap(mBitmap, 0, 0, null); + //添加文字 + Paint mPaint = new Paint(); + Typeface font = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD); + mPaint.setColor(Color.WHITE); + mPaint.setTextSize(50); + mPaint.setTypeface(font); + //水印的位置坐标 + mCanvas.drawText(level, 80, 53, mPaint); + mCanvas.save(); + mCanvas.restore(); + return mNewBitmap; } /** * 渲染普通聊天消息 */ - private static SpannableStringBuilder renderChat(int color, SpannableStringBuilder builder, LiveChatBean bean) { + private SpannableStringBuilder renderChat(int color, SpannableStringBuilder builder, LiveChatBean bean) { int length = builder.length(); String name = bean.getUserNiceName(); if (bean.getType() != LiveChatBean.ENTER_ROOM) {//产品规定,进场消息不允许加冒号 @@ -487,7 +573,7 @@ public class LiveTextRender { /** * 渲染送礼物消息 */ - private static SpannableStringBuilder renderGift(int color, SpannableStringBuilder builder, LiveChatBean bean) { + private SpannableStringBuilder renderGift(int color, SpannableStringBuilder builder, LiveChatBean bean) { int length = builder.length(); String name = bean.getUserNiceName() + ":"; builder.append(name); @@ -503,7 +589,7 @@ public class LiveTextRender { /** * 渲染用户进入房间消息 */ - public static void renderEnterRoom(final Context context, final TextView textView, final LiveChatBean bean) { + public void renderEnterRoom(final Context context, final TextView textView, final LiveChatBean bean) { ImgLoader.displayDrawable(context, bean.getMedalLevelImageUrl(), new ImgLoader.DrawableCallback() { @Override public void onLoadSuccess(Drawable drawable) { @@ -519,7 +605,7 @@ public class LiveTextRender { } - private static void renderEnterRoomTMP(Context context, final TextView textView, final LiveChatBean bean) { + private void renderEnterRoomTMP(Context context, final TextView textView, final LiveChatBean bean) { final LevelBean levelBean = CommonAppConfig.getInstance().getLevel(bean.getLevel()); if (levelBean == null) { return; @@ -532,10 +618,6 @@ public class LiveTextRender { int start = builder.length(); String name = bean.getUserNiceName() + " "; builder.append(name); - //int end = start + name.length(); - //builder.setSpan(sWhiteColorSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - //builder.setSpan(sFontSizeSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - //builder.setSpan(sBoldSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.append(bean.getContent()); textView.setText(builder); } @@ -548,11 +630,6 @@ public class LiveTextRender { int start = builder.length(); String name = bean.getUserNiceName() + " "; builder.append(name); -// int end = start + name.length(); -// builder.setSpan(sWhiteColorSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); -// builder.setSpan(sFontSizeSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); -// builder.setSpan(sBoldSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); -// builder.append(bean.getContent()); textView.setText(builder); } } @@ -561,7 +638,7 @@ public class LiveTextRender { } - public static SpannableStringBuilder renderGiftInfo2(String giftName) { + public SpannableStringBuilder renderGiftInfo2(String giftName) { SpannableStringBuilder builder = new SpannableStringBuilder(); String s1 = WordUtil.getString(R.string.live_send_gift_1); String content = s1 + " " + giftName; @@ -571,7 +648,7 @@ public class LiveTextRender { return builder; } - public static SpannableStringBuilder renderGiftInfo(int giftCount, String giftName) { + public SpannableStringBuilder renderGiftInfo(int giftCount, String giftName) { SpannableStringBuilder builder = new SpannableStringBuilder(); String s1 = WordUtil.getString(R.string.live_send_gift_1); String s2 = WordUtil.getString(R.string.live_send_gift_2) + giftName; @@ -585,7 +662,7 @@ public class LiveTextRender { } - public static SpannableStringBuilder renderGiftCount(int count) { + public SpannableStringBuilder renderGiftCount(int count) { SpannableStringBuilder builder = new SpannableStringBuilder(); String s = String.valueOf(count); builder.append(s); @@ -606,7 +683,7 @@ public class LiveTextRender { /** * 渲染直播间用户弹窗数据 */ - public static CharSequence renderLiveUserDialogData(long num) { + public CharSequence renderLiveUserDialogData(long num) { if (num < 10000) { return String.valueOf(num); } @@ -622,7 +699,7 @@ public class LiveTextRender { return builder; } - public static void clear() { + public void clear() { mDrawableMedalMap.clear(); gzDrawablesMap.clear(); ryxzDrawablesMap.clear(); diff --git a/live/src/main/java/com/yunbao/live/views/LiveGiftViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveGiftViewHolder.java index 476924bb9..65da01f37 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveGiftViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveGiftViewHolder.java @@ -83,7 +83,7 @@ public class LiveGiftViewHolder extends AbsViewHolder { } if (mGiftCount != null && mGiftCount.getVisibility() != View.VISIBLE) { mGiftCount.setVisibility(View.VISIBLE); - mGiftCount.setText(LiveTextRender.renderGiftCount(mLianCount)); + mGiftCount.setText(new LiveTextRender().renderGiftCount(mLianCount)); } if (mGiftCount != null) { mGiftCount.clearAnimation(); @@ -152,7 +152,7 @@ public class LiveGiftViewHolder extends AbsViewHolder { } if (TextUtils.isEmpty(mLastGiftKey) || !mLastGiftKey.equals(bean.getKey())) { ImgLoader.display(mContext, bean.getGiftIcon(), mGiftIcon); - mContent.setText(LiveTextRender.renderGiftInfo2(bean.getGiftName())); + mContent.setText(new LiveTextRender().renderGiftInfo2(bean.getGiftName())); if (bean.getGiftCount() > 1) { mGiftGroupCount.setText("x" + bean.getGiftCount()); mMulSign.setText(R.string.live_gift_send_lian_3); @@ -174,7 +174,7 @@ public class LiveGiftViewHolder extends AbsViewHolder { mLianCount = bean.getLianCount(); } if (mGiftCount != null && mGiftCount.getVisibility() == View.VISIBLE) { - mGiftCount.setText(LiveTextRender.renderGiftCount(mLianCount)); + mGiftCount.setText(new LiveTextRender().renderGiftCount(mLianCount)); } mLastGiftKey = bean.getKey(); if (lian && mGiftCount != null && mAnimation != null) { diff --git a/live/src/main/java/com/yunbao/live/views/LuckLiveGiftViewHolder.java b/live/src/main/java/com/yunbao/live/views/LuckLiveGiftViewHolder.java index 591e8aa25..0f3bda722 100644 --- a/live/src/main/java/com/yunbao/live/views/LuckLiveGiftViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LuckLiveGiftViewHolder.java @@ -96,12 +96,9 @@ public class LuckLiveGiftViewHolder extends AbsViewHolder { if (mBg != null) { mBg.setTranslationX(-mDp214); } -// if (mStar != null && mStar.getVisibility() == View.VISIBLE) { -// mStar.setVisibility(View.INVISIBLE); -// } if (mGiftCount != null && mGiftCount.getVisibility() != View.VISIBLE) { mGiftCount.setVisibility(View.VISIBLE); - mGiftCount.setText(LiveTextRender.renderGiftCount(mLianCount)); + mGiftCount.setText(new LiveTextRender().renderGiftCount(mLianCount)); } if (mGiftCount != null) { mGiftCount.clearAnimation(); @@ -204,7 +201,7 @@ public class LuckLiveGiftViewHolder extends AbsViewHolder { } if (TextUtils.isEmpty(mLastGiftKey) || !mLastGiftKey.equals(bean.getKey())) { ImgLoader.display(mContext, bean.getGiftIcon(), mGiftIcon); - mContent.setText(LiveTextRender.renderGiftInfo2(bean.getGiftName())); + mContent.setText(new LiveTextRender().renderGiftInfo2(bean.getGiftName())); if (bean.getGiftCount() > 1) { mGiftGroupCount.setText("x" + bean.getGiftCount()); mMulSign.setText(R.string.live_gift_send_lian_3); @@ -226,7 +223,7 @@ public class LuckLiveGiftViewHolder extends AbsViewHolder { mLianCount = bean.getLianCount(); } if (mGiftCount != null && mGiftCount.getVisibility() == View.VISIBLE) { - mGiftCount.setText(LiveTextRender.renderGiftCount(mLianCount)); + mGiftCount.setText(new LiveTextRender().renderGiftCount(mLianCount)); } mLastGiftKey = bean.getKey(); if (lian && mGiftCount != null && mAnimation != null) { diff --git a/live/src/main/res/layout/item_user_more_info.xml b/live/src/main/res/layout/item_user_more_info.xml index 2cc3cdca0..f0dcd474d 100644 --- a/live/src/main/res/layout/item_user_more_info.xml +++ b/live/src/main/res/layout/item_user_more_info.xml @@ -126,6 +126,7 @@ android:id="@+id/level" android:layout_width="30dp" android:layout_height="15dp" + android:scaleType="fitXY" android:layout_marginLeft="5dp" /> diff --git a/live/src/main/res/layout/live_medal_icon.xml b/live/src/main/res/layout/live_medal_icon.xml index 3bd0834ea..1feccd4e3 100644 --- a/live/src/main/res/layout/live_medal_icon.xml +++ b/live/src/main/res/layout/live_medal_icon.xml @@ -2,22 +2,22 @@ + + android:layout_gravity="center" /> + + android:textSize="10sp" /> \ No newline at end of file diff --git a/main/src/main/res/layout/view_homemain.xml b/main/src/main/res/layout/view_homemain.xml index e490effa3..8c50c73ad 100644 --- a/main/src/main/res/layout/view_homemain.xml +++ b/main/src/main/res/layout/view_homemain.xml @@ -92,10 +92,17 @@ + + + @@ -107,7 +114,7 @@ android:gravity="center" android:textColor="@color/white" android:textSize="10dp" - android:visibility="gone" /> + android:visibility="visible" />