From 96cfadd3358fdba5e93df1e7cea55a2be5b23734 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Sun, 16 Jun 2024 11:09:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5PD=EF=BC=9A=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=9A=82=E6=97=B6=E7=A6=BB=E5=BC=80=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=97=A0=E6=95=88=E9=97=AE=E9=A2=98=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E8=B4=AD=E4=B9=B0=E5=AE=88=E6=8A=A4=E7=9A=84=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom/LiveGuardScalePageTransformer.java | 67 ++++++++++++++++++ .../src/main/res/mipmap-mdpi/zslk.jpg | Bin .../beautyapi/faceunity/agora/SWManager.java | 33 ++++++++- .../live/activity/LiveSwAnchorActivity.java | 5 ++ .../live/dialog/LiveBuyGuardDialog.java | 3 + .../live/views/LiveRyAnchorViewHolder.java | 39 +++++----- .../live/views/PortraitLiveManager.java | 13 ++-- .../main/res/layout/activity_live_anchor.xml | 4 +- .../src/main/res/layout/view_live_play_sw.xml | 4 +- .../main/res/layout/view_ry_live_anchor.xml | 9 +++ 10 files changed, 152 insertions(+), 25 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/custom/LiveGuardScalePageTransformer.java rename {live => common}/src/main/res/mipmap-mdpi/zslk.jpg (100%) 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..713c30753 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/custom/LiveGuardScalePageTransformer.java @@ -0,0 +1,67 @@ +package com.yunbao.common.custom; + +import android.view.View; + +import androidx.core.view.ViewCompat; + +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 float mMinScale = 0.85f; + private float mMinAlpha = 1f; + + public LiveGuardScalePageTransformer() { + } + + public LiveGuardScalePageTransformer(float minAlpha, float minScale) { + setMinAlpha(minAlpha); + setMinScale(minScale); + } + + @Override + public void handleInvisiblePage(View view, float position) { + ViewCompat.setAlpha(view, 0); + } + + @Override + public void handleLeftPage(View view, float position) { + float scale = Math.max(mMinScale, 1 + position); + float vertMargin = view.getHeight() * (1 - scale) / 2; + float horzMargin = view.getWidth() * (1 - scale) / 2; + view.setTranslationX(horzMargin - vertMargin / 2); + view.setScaleX(scale); + view.setScaleY( scale); + view.setAlpha( mMinAlpha + (scale - mMinScale) / (1 - mMinScale) * (1 - mMinAlpha)); + } + + @Override + public void handleRightPage(View view, float position) { + float scale = Math.max(mMinScale, 1 - position); + float vertMargin = view.getHeight() * (1 - scale) / 2; + float horzMargin = view.getWidth() * (1 - scale) / 2; + view.setTranslationX( -horzMargin + vertMargin / 2); + view.setScaleX( scale); + + view.setScaleY( scale); + view.setAlpha( mMinAlpha + (scale - mMinScale) / (1 - mMinScale) * (1 - mMinAlpha)); + } + + public void setMinAlpha(float minAlpha) { + if (minAlpha >= 0.6f && minAlpha <= 1.0f) { + mMinAlpha = minAlpha; + } + } + + public void setMinScale(float minScale) { + if (minScale >= 0.6f && minScale <= 1.0f) { + mMinScale = minScale; + } + } +} diff --git a/live/src/main/res/mipmap-mdpi/zslk.jpg b/common/src/main/res/mipmap-mdpi/zslk.jpg similarity index 100% rename from live/src/main/res/mipmap-mdpi/zslk.jpg rename to common/src/main/res/mipmap-mdpi/zslk.jpg diff --git a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java index 80711372a..4271b4ec4 100644 --- a/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java +++ b/lib_faceunity/src/main/java/io/agora/beautyapi/faceunity/agora/SWManager.java @@ -1,10 +1,17 @@ package io.agora.beautyapi.faceunity.agora; import android.app.Activity; +import android.content.ContentResolver; import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.net.Uri; +import android.text.TextUtils; import android.view.SurfaceView; import android.widget.FrameLayout; +import androidx.core.content.res.ResourcesCompat; + import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.bean.SwTokenModel; @@ -17,6 +24,9 @@ import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.faceunity.utils.FURenderer; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.util.ArrayList; import java.util.List; @@ -27,13 +37,16 @@ import io.agora.beautyapi.faceunity.Config; import io.agora.beautyapi.faceunity.FaceUnityBeautyAPI; import io.agora.beautyapi.faceunity.FaceUnityBeautyAPIKt; import io.agora.beautyapi.faceunity.MirrorMode; +import io.agora.beautyapi.faceunity.R; import io.agora.rtc2.ChannelMediaOptions; import io.agora.rtc2.Constants; import io.agora.rtc2.IRtcEngineEventHandler; import io.agora.rtc2.RtcConnection; +import io.agora.rtc2.RtcEngine; import io.agora.rtc2.RtcEngineConfig; import io.agora.rtc2.RtcEngineEx; import io.agora.rtc2.video.ContentInspectConfig; +import io.agora.rtc2.video.ImageTrackOptions; import io.agora.rtc2.video.VideoCanvas; import io.agora.rtc2.video.VideoEncoderConfiguration; @@ -53,6 +66,7 @@ public class SWManager extends BaseCacheManager { private FrameLayout linkUserContainer;//连麦用户视图 private onRtcEngineListener onRtcEngineListener; private List drPkUserInfo = new ArrayList<>(); + private ImageTrackOptions imageTrackOptions = null; private onDrPkJoinSuccessListener onDrPkJoinSuccessListener; @@ -66,6 +80,17 @@ public class SWManager extends BaseCacheManager { public SWManager(Context context) { super(context); + + String filePath = context.getCacheDir() + File.separator + "zslk.png"; + if (!new File(filePath).exists()) { + Bitmap bitmap = ((BitmapDrawable) ResourcesCompat.getDrawable(context.getResources(), com.yunbao.common.R.mipmap.zslk, null)).getBitmap(); + try { + bitmap.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(filePath)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + imageTrackOptions = new ImageTrackOptions(filePath, 1); } /** @@ -80,6 +105,12 @@ public class SWManager extends BaseCacheManager { return manager; } + public void setLeaveFlag(boolean leave) { + if (mRtcEngine != null) { + mRtcEngine.enableVideoImageSource(leave, imageTrackOptions); + } + } + /** * 初始化声网SDK */ @@ -126,7 +157,6 @@ public class SWManager extends BaseCacheManager { cfg.orientationMode = VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_FIXED_PORTRAIT; - mRtcEngine.setVideoEncoderConfiguration(cfg); // 创建一个 SurfaceView 对象,并将其作为 FrameLayout 的子对象 @@ -497,6 +527,7 @@ public class SWManager extends BaseCacheManager { public interface onRtcEngineListener { void onOpenSuccess(String channel, int uid); + void onUserOffline(int uid); } diff --git a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java index 69622eee4..6cab519b9 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -125,6 +125,7 @@ import cn.rongcloud.rtc.api.callback.IRCRTCResultCallback; import cn.rongcloud.rtc.base.RCRTCRect; import cn.rongcloud.rtc.base.RTCErrorCode; import io.agora.beautyapi.faceunity.agora.SWManager; +import io.agora.rtc2.RtcEngine; import io.rong.imlib.IRongCallback; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; @@ -547,12 +548,16 @@ public class LiveSwAnchorActivity extends LiveActivity implements LiveFunctionCl } }); + SWManager.get().setLeaveFlag(true); + mLiveAnchorViewHolder.setLeaveFlag(true); } else if (leave == 1) { leave = 0; leave_img.setVisibility(View.GONE); // 清除水印 boolean ret = RCRTCEngine.getInstance().getDefaultVideoStream().setWatermark(null, rect); sendSystemMessageSw(mContext.getString(R.string.live_anchor_come_back)); + SWManager.get().setLeaveFlag(false); + mLiveAnchorViewHolder.setLeaveFlag(false); } HttpClient.getInstance().get("Live.isLeave", "Live.isLeave") 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..19e021350 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveBuyGuardDialog.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveBuyGuardDialog.java @@ -40,6 +40,7 @@ import com.yunbao.common.bean.GuardGetGuardUserInfoModel; import com.yunbao.common.bean.GuardPriceModel; import com.yunbao.common.bean.GuardUserInfoModel; import com.yunbao.common.bean.IMLoginModel; +import com.yunbao.common.custom.LiveGuardScalePageTransformer; import com.yunbao.common.dialog.AbsDialogPopupWindow; import com.yunbao.common.dialog.GuardBuyTipsDialog; import com.yunbao.common.dialog.GuardUpgradePopup; @@ -50,6 +51,7 @@ import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.utils.DeviceUtils; import com.yunbao.common.utils.DialogUitl; +import com.yunbao.common.utils.MobclickAgent; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.common.views.weight.ViewClicksAntiShake; @@ -158,6 +160,7 @@ public class LiveBuyGuardDialog extends AbsDialogPopupWindow { buyGuardBannerModels.add(guardBannerModel); } buyGuardBanner.setBannerData(R.layout.banner_item_buy_guard, buyGuardBannerModels); + buyGuardBanner.setCustomPageTransformer(new LiveGuardScalePageTransformer()); buyGuardBanner.setIsClipChildrenMode(true); guardPrivilegeStrings = data.getGuardData().get(0).getGuardPrivilege(); buyGuardBanner.postDelayed(new Runnable() { diff --git a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java index bf024bd45..be6be1142 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java @@ -91,20 +91,22 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { private LiveRoomHandler mLiveRoomHandler; private static LinearLayout btn_end_pk_dr; private String drpkRoomId; //多人 PK 房主 roomUid + private ImageView leaveImg; + public void setDrpkRoomId(String drpkRoomId) { this.drpkRoomId = drpkRoomId; } - public void showEndPkBt(){ - if(btn_end_pk_dr!=null){ - if(btn_start_dr_pk_view.getVisibility()==View.GONE){ + public void showEndPkBt() { + if (btn_end_pk_dr != null) { + if (btn_start_dr_pk_view.getVisibility() == View.GONE) { btn_end_pk_dr.setVisibility(View.VISIBLE); } } } - public void closeEndPkBt(){ - if(btn_end_pk_dr!=null){ + public void closeEndPkBt() { + if (btn_end_pk_dr != null) { btn_end_pk_dr.setVisibility(View.GONE); } } @@ -131,6 +133,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { mDrawable1 = ContextCompat.getDrawable(mContext, R.mipmap.icon_live_func_1); btn_end_pk_dr = (LinearLayout) findViewById(R.id.btn_end_pk_dr); mBtnFunction = (ImageView) findViewById(R.id.btn_function); + leaveImg = (ImageView) findViewById(R.id.leave_img); btn_dr = (TextView) findViewById(R.id.btn_dr); mBanner = (Banner) findViewById(R.id.banner); mBtnFunction.setImageDrawable(mDrawable0); @@ -152,9 +155,9 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { btn_start_dr_pk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if(pk_nub<= 0){ + if (pk_nub <= 0) { ToastUtil.show("多人PK次数已用完"); - }else{ + } else { //開始多人PK HttpClient.getInstance().get("live.startDRPK", "live.startDRPK") .params("roomid", CommonAppConfig.getInstance().getUid()) @@ -216,9 +219,9 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { if (yaoqing.size() < 3) { if (PKing == false) { - if(isSw){ + if (isSw) { ((LiveSwAnchorActivity) mContext).openLinkMicAnchorWindow(true); - }else{ + } else { ((LiveRyAnchorActivity) mContext).openLinkMicAnchorWindow(true); } } else { @@ -242,7 +245,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { yaoqing.put(numinda, numinda); } - public void removeYaoqing(String numinda){ + public void removeYaoqing(String numinda) { yaoqing.remove(numinda); } @@ -292,9 +295,9 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { * 关闭直播 */ private void close() { - if(isSw){ + if (isSw) { ((LiveSwAnchorActivity) mContext).closeLive(); - }else{ + } else { ((LiveRyAnchorActivity) mContext).closeLive(); } } @@ -312,9 +315,9 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { if (mBtnFunction != null) { mBtnFunction.setImageDrawable(mDrawable1); } - if(isSw){ + if (isSw) { ((LiveSwAnchorActivity) mContext).showFunctionDialog(); - }else{ + } else { ((LiveRyAnchorActivity) mContext).showFunctionDialog(); } } @@ -349,9 +352,9 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { * 发起主播连麦pk */ private void applyLinkMicPk() { - if(isSw){ + if (isSw) { ((LiveSwAnchorActivity) mContext).applyLinkMicPk(); - }else{ + } else { ((LiveRyAnchorActivity) mContext).applyLinkMicPk(); } } @@ -686,6 +689,10 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { private final int WHAT_ANCHOR_LIVE_TIME = 3;//直播间主播计时 + public void setLeaveFlag(boolean leave) { + leaveImg.setVisibility(leave ? View.VISIBLE : View.GONE); + } + private class LiveRoomHandler extends Handler { @Override public void handleMessage(Message msg) { 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 dc57dc37e..d7a53c46e 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -668,6 +668,9 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (LivePlaySwViewHolder.leave != null) { LivePlaySwViewHolder.leave.setVisibility(View.VISIBLE); } + if (LivePlayRyViewHolder.leave != null) { + LivePlayRyViewHolder.leave.setVisibility(View.VISIBLE); + } } //判断是否有连麦,要显示连麦窗口 String linkMicUid = data.getEnterRoomInfo().getLinkmicUid(); @@ -696,7 +699,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe if (mLivePlayViewHolder != null && data.getEnterRoomInfo().getIsconnection() != null && data.getEnterRoomInfo().getIsconnection().equals("1")) { JSONArray array = pkInfo.getJSONArray("userlist"); //判断是否是多人连麦 - if (array!=null&& !array.isEmpty()) {//多人連麥 + if (array != null && !array.isEmpty()) {//多人連麥 if (mLivePlayViewHolder != null) { List drPkbeans = new ArrayList<>(); for (int j = 0; j < array.size(); j++) { @@ -782,8 +785,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe } if (mLivePlayViewHolder != null) { JSONArray array = pkInfo.getJSONArray("userlist"); - if(array==null){ - array=new JSONArray(); + if (array == null) { + array = new JSONArray(); } List drPkbeans = new ArrayList<>(); for (int j = 0; j < array.size(); j++) { @@ -2382,8 +2385,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe * @param time */ public void upDataPkScore(JSONArray pkScores, int time) { - L.eSw("upDataPkScore" + time+"|"+pkScores); - if(pkScores==null){ + L.eSw("upDataPkScore" + time + "|" + pkScores); + if (pkScores == null) { return; } this.pkScores = pkScores; diff --git a/live/src/main/res/layout/activity_live_anchor.xml b/live/src/main/res/layout/activity_live_anchor.xml index 9af2c68cc..1083c0f18 100644 --- a/live/src/main/res/layout/activity_live_anchor.xml +++ b/live/src/main/res/layout/activity_live_anchor.xml @@ -1,6 +1,7 @@ + android:visibility="gone" + tools:visibility="visible" /> \ No newline at end of file diff --git a/live/src/main/res/layout/view_live_play_sw.xml b/live/src/main/res/layout/view_live_play_sw.xml index 64cb1c25f..b51101029 100644 --- a/live/src/main/res/layout/view_live_play_sw.xml +++ b/live/src/main/res/layout/view_live_play_sw.xml @@ -39,8 +39,8 @@ @@ -154,6 +155,14 @@ android:layout_height="45dp" android:layout_gravity="bottom"> +