diff --git a/common/src/main/java/com/yunbao/common/custom/LiveGuardScalePageTransformer.java b/common/src/main/java/com/yunbao/common/custom/LiveGuardScalePageTransformer.java index 34a6970f0..19850087d 100644 --- a/common/src/main/java/com/yunbao/common/custom/LiveGuardScalePageTransformer.java +++ b/common/src/main/java/com/yunbao/common/custom/LiveGuardScalePageTransformer.java @@ -2,7 +2,10 @@ package com.yunbao.common.custom; import android.view.View; +import androidx.core.view.ViewCompat; + import com.stx.xhb.androidx.transformers.BasePageTransformer; +import com.yunbao.common.manager.IMLoginManager; public class LiveGuardScalePageTransformer extends BasePageTransformer { /** @@ -12,23 +15,54 @@ public class LiveGuardScalePageTransformer extends BasePageTransformer { * github:https://github.com/xiaohaibin * describe: 适用于一屏显示多个模式 */ - private static final float MIN_SCALE = 0.8F; + 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) { - view.setScaleY(MIN_SCALE); + ViewCompat.setAlpha(view, 0); } @Override public void handleLeftPage(View view, float position) { - float scale = Math.max(MIN_SCALE, 1 - Math.abs(position)); - view.setScaleY(scale); + 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(MIN_SCALE, 1 - Math.abs(position)); - view.setScaleY(scale); + 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 d7a0bbd62..aca49e322 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveSwAnchorActivity.java @@ -124,6 +124,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; @@ -555,12 +556,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 f39ca7d03..9668838bf 100644 --- a/live/src/main/java/com/yunbao/live/dialog/LiveBuyGuardDialog.java +++ b/live/src/main/java/com/yunbao/live/dialog/LiveBuyGuardDialog.java @@ -30,9 +30,6 @@ 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; import com.yunbao.common.bean.CheckUpgradesModel; @@ -42,6 +39,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; @@ -52,6 +50,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; @@ -160,8 +159,8 @@ public class LiveBuyGuardDialog extends AbsDialogPopupWindow { buyGuardBannerModels.add(guardBannerModel); } buyGuardBanner.setBannerData(R.layout.banner_item_buy_guard, buyGuardBannerModels); - buyGuardBanner.setIsClipChildrenMode(true); buyGuardBanner.setCustomPageTransformer(new LiveGuardScalePageTransformer()); + buyGuardBanner.setIsClipChildrenMode(true); guardPrivilegeStrings = data.getGuardData().get(0).getGuardPrivilege(); buyGuardBanner.postDelayed(new Runnable() { @Override 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 331f1b262..c40d4f83d 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRyAnchorViewHolder.java @@ -92,20 +92,22 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { private TextView menuRed; 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); } } @@ -132,6 +134,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); @@ -153,9 +156,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()) @@ -217,9 +220,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 { @@ -245,7 +248,7 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { yaoqing.put(numinda, numinda); } - public void removeYaoqing(String numinda){ + public void removeYaoqing(String numinda) { yaoqing.remove(numinda); } @@ -295,9 +298,9 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { * 关闭直播 */ private void close() { - if(isSw){ + if (isSw) { ((LiveSwAnchorActivity) mContext).closeLive(); - }else{ + } else { ((LiveRyAnchorActivity) mContext).closeLive(); } } @@ -315,9 +318,9 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { if (mBtnFunction != null) { mBtnFunction.setImageDrawable(mDrawable1); } - if(isSw){ + if (isSw) { ((LiveSwAnchorActivity) mContext).showFunctionDialog(); - }else{ + } else { ((LiveRyAnchorActivity) mContext).showFunctionDialog(); } } @@ -352,9 +355,9 @@ public class LiveRyAnchorViewHolder extends AbsLiveViewHolder { * 发起主播连麦pk */ private void applyLinkMicPk() { - if(isSw){ + if (isSw) { ((LiveSwAnchorActivity) mContext).applyLinkMicPk(); - }else{ + } else { ((LiveRyAnchorActivity) mContext).applyLinkMicPk(); } } @@ -689,6 +692,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 aa591d939..c3d7058bf 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -672,6 +672,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(); @@ -700,7 +703,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++) { @@ -786,8 +789,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++) { @@ -2393,8 +2396,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"> +