修改悬浮窗样式,添加悬浮设置
This commit is contained in:
parent
a09cbf4776
commit
217c5f3115
@ -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<FloatCallbacks.Builder, Unit> {
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user