From a09cbf47765970d6003e3ba3fc56473267690dd7 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Thu, 20 Oct 2022 11:32:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=82=AC=E6=B5=AE?= =?UTF-8?q?=E7=AA=97=E6=A0=B7=E5=BC=8F=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=82=AC?= =?UTF-8?q?=E6=B5=AE=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/dialog/FloatSettingsDialog.java | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 common/src/main/java/com/yunbao/common/dialog/FloatSettingsDialog.java diff --git a/common/src/main/java/com/yunbao/common/dialog/FloatSettingsDialog.java b/common/src/main/java/com/yunbao/common/dialog/FloatSettingsDialog.java new file mode 100644 index 000000000..248d16f9a --- /dev/null +++ b/common/src/main/java/com/yunbao/common/dialog/FloatSettingsDialog.java @@ -0,0 +1,94 @@ +package com.yunbao.common.dialog; + +import android.os.Bundle; +import android.view.Gravity; +import android.view.Window; +import android.view.WindowManager; +import android.widget.ImageView; + +import com.lzf.easyfloat.interfaces.OnPermissionResult; +import com.lzf.easyfloat.permission.PermissionUtils; +import com.yunbao.common.R; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.manager.IMLoginManager; +import com.yunbao.common.views.weight.ViewClicksAntiShake; + +/** + * 悬浮窗设置页面 + */ +public class FloatSettingsDialog extends AbsDialogFragment { + private ImageView specialSwitch, specialMountSwitch; + private boolean isFloat; + + @Override + protected int getLayoutId() { + return R.layout.view_float_settings; + } + + @Override + protected int getDialogStyle() { + return R.style.dialog2; + } + + @Override + protected boolean canCancel() { + return true; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + specialSwitch = (ImageView) findViewById(R.id.special_switch); + specialMountSwitch = (ImageView) findViewById(R.id.special_mount_switch); + isFloat = IMLoginManager.get(getActivity()).isFloat(); + if (!isFloat) { + ImgLoader.display(getContext(), R.mipmap.special_icon_off, specialSwitch); + } else { + ImgLoader.display(getContext(), R.mipmap.special_icon_on, specialSwitch); + } + boolean floatPermission = PermissionUtils.checkPermission(mContext); + if (!floatPermission) { + ImgLoader.display(getContext(), R.mipmap.special_icon_off, specialMountSwitch); + } else { + ImgLoader.display(getContext(), R.mipmap.special_icon_on, specialMountSwitch); + } + //礼物特效开关 + ViewClicksAntiShake.clicksAntiShake(specialSwitch, () -> { + isFloat = !isFloat; + if (!isFloat) { + ImgLoader.display(getContext(), R.mipmap.special_icon_off, specialSwitch); + } else { + ImgLoader.display(getContext(), R.mipmap.special_icon_on, specialSwitch); + } + //更新特效开关 + IMLoginManager.get(getContext()).initFloat(isFloat); + + } + ); + //坐骑特效开关 + ViewClicksAntiShake.clicksAntiShake(specialMountSwitch, () -> { + dismiss(); + PermissionUtils.requestPermission(getActivity(), new OnPermissionResult() { + @Override + public void permissionResult(boolean isFloat) { + if (!isFloat) { + ImgLoader.display(getContext(), R.mipmap.special_icon_off, specialSwitch); + } else { + ImgLoader.display(getContext(), R.mipmap.special_icon_on, specialSwitch); + } + } + }); + } + ); + } + + @Override + protected void setWindowAttributes(Window window) { + window.setWindowAnimations(R.style.bottomToTopAnim); + WindowManager.LayoutParams params = window.getAttributes(); + params.width = WindowManager.LayoutParams.MATCH_PARENT; + params.height = WindowManager.LayoutParams.WRAP_CONTENT; + params.gravity = Gravity.BOTTOM; + window.setAttributes(params); + } +} From 217c5f31153aabe61d1cf26029ba7f3b7207e5d6 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Thu, 20 Oct 2022 11:33:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=82=AC=E6=B5=AE?= =?UTF-8?q?=E7=AA=97=E6=A0=B7=E5=BC=8F=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=82=AC?= =?UTF-8?q?=E6=B5=AE=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/views/weight/LiveFloatView.java | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java 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 new file mode 100644 index 000000000..e8b4a0422 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/views/weight/LiveFloatView.java @@ -0,0 +1,145 @@ +package com.yunbao.common.views.weight; + +import android.app.Activity; +import android.util.Log; +import android.view.Gravity; +import android.view.View; + +import com.lzf.easyfloat.EasyFloat; +import com.lzf.easyfloat.enums.ShowPattern; +import com.lzf.easyfloat.interfaces.FloatCallbacks; +import com.lzf.easyfloat.interfaces.OnInvokeView; +import com.tencent.live2.V2TXLivePlayer; +import com.tencent.live2.impl.V2TXLivePlayerImpl; +import com.tencent.rtmp.ui.TXCloudVideoView; +import com.yunbao.common.R; +import com.yunbao.common.bean.LiveBean; +import com.yunbao.common.utils.RouteUtil; + +import kotlin.Unit; +import kotlin.jvm.functions.Function1; + +/** + * 直播间悬浮窗管理 + */ +public class LiveFloatView implements Function1 { + + private static LiveFloatView instance; + private LiveOnInvokeView liveOnInvokeView = null; + private Activity mContext; + private String url; + private LiveBean mLiveBean; + private int mLiveType; + private int mLiveSDK; + private int mLiveTypeVal; + private FloatCallbacks.Builder builder; + private String TAG = "LiveFloatView"; + private V2TXLivePlayer mPlayer; + + public static LiveFloatView getInstance() { + if (instance == null) { + instance = new LiveFloatView(); + } + + return instance; + } + + public void builderFloat(Activity mContext, String url) { + liveOnInvokeView = new LiveOnInvokeView(); + this.mContext = mContext; + this.url = url; + EasyFloat.with(mContext) + .setTag(TAG) + .setLayout(R.layout.view_flaot_live, liveOnInvokeView) + .setShowPattern(ShowPattern.CURRENT_ACTIVITY) + .setGravity(Gravity.END | Gravity.CENTER_VERTICAL, 0, 200) + .registerCallback(this) + .show(); + } + + public void builderSystemFloat(Activity mContext, String url) { + liveOnInvokeView = new LiveOnInvokeView(); + this.mContext = mContext; + this.url = url; + EasyFloat.with(mContext) + .setTag(TAG) + .setLayout(R.layout.view_flaot_live, liveOnInvokeView) + .setShowPattern(ShowPattern.ALL_TIME) + .setGravity(Gravity.END | Gravity.CENTER_VERTICAL, 0, 200) + .registerCallback(this) + .show(); + } + + public LiveFloatView cacheLiveData(LiveBean mLiveBean, int mLiveType, int mLiveSDK, int mLiveTypeVal) { + this.mLiveBean = mLiveBean; + this.mLiveType = mLiveType; + this.mLiveSDK = mLiveSDK; + this.mLiveTypeVal = mLiveTypeVal; + return instance; + } + + @Override + public Unit invoke(FloatCallbacks.Builder builder) { + this.builder = builder; + builder.createResult((aBoolean, s, view) -> { + Log.e("LiveFloatView", "aBoolean:" + aBoolean + "---------------------s:" + s); + if (callback != null) { + callback.invoke(aBoolean); + } + builder.dismiss(() -> { + if (mPlayer != null && mPlayer.isPlaying() == 1) { + mPlayer.stopPlay(); + } + return null; + }); + builder.hide(view12 -> { + if (mPlayer != null && mPlayer.isPlaying() == 1) { + mPlayer.pauseAudio(); + mPlayer.pauseVideo(); + } + return null; + }); + + return null; + }); + return null; + } + + /** + * 悬浮窗布局管理 + */ + private class LiveOnInvokeView implements OnInvokeView { + + @Override + public void invoke(View view) { + TXCloudVideoView videoView = view.findViewById(R.id.video_view); + mPlayer = new V2TXLivePlayerImpl(mContext); + mPlayer.setRenderView(videoView); + mPlayer.startPlay(url); + ViewClicksAntiShake.clicksAntiShake(view.findViewById(R.id.btn_close), new ViewClicksAntiShake.ViewClicksCallBack() { + @Override + public void onViewClicks() { + mPlayer.stopPlay(); + EasyFloat.dismiss("LiveFloatView", true); + } + }); + ViewClicksAntiShake.clicksAntiShake(videoView, () -> { + mPlayer.stopPlay(); + RouteUtil.forwardLiveAudienceActivity(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal); + }); + } + } + + private LiveFloatViewCallback callback; + + public LiveFloatView setCallback(LiveFloatViewCallback callback) { + this.callback = callback; + return this; + } + + public interface LiveFloatViewCallback { + void invoke(Boolean aBoolean); + + } + +}