From 6656aebff977ec1934476494544cd9e5b8322b51 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Fri, 4 Nov 2022 14:58:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=82=AC=E6=B5=AE=E7=AA=97=E5=92=8C=E5=BC=80?= =?UTF-8?q?=E6=92=AD=E7=A6=BB=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/utils/BitmapUtil.java | 22 ++++ .../common/views/weight/LiveFloatView.java | 23 +++- .../src/main/res/layout/view_flaot_live.xml | 3 +- .../live/activity/LiveRyAnchorActivity.java | 120 +++++++----------- 4 files changed, 95 insertions(+), 73 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/utils/BitmapUtil.java b/common/src/main/java/com/yunbao/common/utils/BitmapUtil.java index 9ea112281..6884368b4 100644 --- a/common/src/main/java/com/yunbao/common/utils/BitmapUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/BitmapUtil.java @@ -6,9 +6,11 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; +import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; +import android.graphics.Rect; import android.provider.MediaStore; import com.bumptech.glide.Glide; @@ -195,4 +197,24 @@ public class BitmapUtil { canvas.drawBitmap(bitmap, 0, 0, paint); return bm; } + + /** + * 镜像Bitmap + * + * @param bitmap + * @return + */ + public Bitmap convertMirror(Bitmap bitmap) { + int w = bitmap.getWidth(); + int h = bitmap.getHeight(); + Bitmap newb = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);// 创建一个新的和SRC长度宽度一样的位图 + Canvas cv = new Canvas(newb); + Matrix m = new Matrix(); + //m.postScale(1, -1); //镜像垂直翻转 + m.postScale(-1, 1); //镜像水平翻转 + //m.postRotate(-90); //旋转-90度 + Bitmap new2 = Bitmap.createBitmap(bitmap, 0, 0, w, h, m, true); + cv.drawBitmap(new2, new Rect(0, 0, new2.getWidth(), new2.getHeight()), new Rect(0, 0, w, h), null); + return newb; + } } diff --git a/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java b/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java index aa75d767e..5005387ea 100644 --- a/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java +++ b/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java @@ -7,7 +7,9 @@ import android.text.TextUtils; import android.util.Log; import android.view.Gravity; import android.view.View; +import android.widget.RelativeLayout; +import androidx.cardview.widget.CardView; import androidx.fragment.app.FragmentActivity; import com.lzf.easyfloat.EasyFloat; @@ -24,6 +26,7 @@ import com.yunbao.common.dialog.HintDialog; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpClient; import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.RouteUtil; import com.yunbao.common.views.floatingview.APPEasyFloat; import com.yunbao.common.views.floatingview.FloatingMagnetView; @@ -68,6 +71,15 @@ public class LiveFloatView implements Function1 { .setMagnetViewListener(new MagnetViewListener() { @Override public void invoke(FloatingMagnetView magnetView) { + CardView layout = magnetView.findViewById(R.id.layout); + RelativeLayout.LayoutParams cardParams = (RelativeLayout.LayoutParams) layout.getLayoutParams(); + if (mLiveBean.getLandscape() == 1) { + cardParams.height = DpUtil.dp2px(130); + cardParams.width = DpUtil.dp2px(230); + } else { + cardParams.height = DpUtil.dp2px(224); + cardParams.width = DpUtil.dp2px(126); + } TXCloudVideoView videoView = magnetView.findViewById(R.id.video_view); mPlayer = new V2TXLivePlayerImpl(mContext); mPlayer.setRenderView(videoView); @@ -182,10 +194,19 @@ public class LiveFloatView implements Function1 { @Override public void invoke(View view) { TXCloudVideoView videoView = view.findViewById(R.id.video_view); + CardView layout = view.findViewById(R.id.layout); mPlayer = new V2TXLivePlayerImpl(mContext); mPlayer.setRenderView(videoView); mPlayer.startPlay(url); - + RelativeLayout.LayoutParams cardParams = (RelativeLayout.LayoutParams) layout.getLayoutParams(); + if (mLiveBean.getLandscape() == 1) { + cardParams.height = DpUtil.dp2px(130); + cardParams.width = DpUtil.dp2px(230); + } else { + cardParams.height = DpUtil.dp2px(224); + cardParams.width = DpUtil.dp2px(126); + } + layout.setLayoutParams(cardParams); ViewClicksAntiShake.clicksAntiShake(view.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() { @Override public void onViewClicks() { diff --git a/common/src/main/res/layout/view_flaot_live.xml b/common/src/main/res/layout/view_flaot_live.xml index e97d21e66..5b1d2d4db 100644 --- a/common/src/main/res/layout/view_flaot_live.xml +++ b/common/src/main/res/layout/view_flaot_live.xml @@ -1,10 +1,11 @@ () { - @Override - public void onStart(Request request) { - - } - - @Override - public void onSuccess(Response response) { - - } - - @Override - public void onCacheSuccess(Response response) { - - } - - @Override - public void onError(Response response) { - - } - - @Override - public void onFinish() { - - } - - @Override - public void uploadProgress(Progress progress) { - - } - - @Override - public void downloadProgress(Progress progress) { - - } - - @Override - public JsonBean convertResponse(okhttp3.Response response) throws Throwable { - return null; - } - }); + leaveLive(); break; case Constants.LIVE_FUNC_WKS: String url = CommonAppConfig.HOST + "/h5/activity/weekStar/index.html?&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&anchorUid=" + mLiveUid; @@ -428,6 +371,45 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl } } + /** + * 主播展示离开直播间 + */ + private void leaveLive() { + RCRTCRect rect = new RCRTCRect(0f, 0f, 1.0f); + if (leave == 0) { + leave = 1; + Glide.with(mContext).asBitmap().load(R.mipmap.zslk).into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + + boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(BitmapUtil.getInstance().convertMirror(resource), rect); + sendSystemMessage(WordUtil.getString(R.string.live_anchor_leave)); + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); + } else if (leave == 1) { + leave = 0; + // 清除水印 + boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(null, rect); + sendSystemMessage(WordUtil.getString(R.string.live_anchor_come_back)); + } + + HttpClient.getInstance().get("Live.isLeave", "Live.isLeave") + .params("uid", CommonAppConfig.getInstance().getUid()) + .params("isleave", leave) + .params("token", CommonAppConfig.getInstance().getToken()) + .execute(new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + + } + }); + } + /** * 打开心愿单窗口 @@ -475,9 +457,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl if (mLiveRoomViewHolder != null) { mLiveRoomViewHolder.changeFaceUnityView(); } - /* LiveBeautyDialogFragment fragment = new LiveBeautyDialogFragment(); - fragment.setiBeautyModule(BeautyManager.iBeautyModule, BeautyManager.iLookupModule, BeautyManager.iBeautyBodyModule); - fragment.show(getSupportFragmentManager(), "LiveBeautyDialogFragment");*/ } /** @@ -485,7 +464,6 @@ public class LiveRyAnchorActivity extends LiveActivity implements LiveFunctionCl */ public void light() { if (mLiveRoomViewHolder != null) { -// mLiveRoomViewHolder.playLightAnim(); } }