小游戏:狼人杀接入

This commit is contained in:
huangjian
2022-05-06 16:49:11 +08:00
parent 01a8329401
commit c20225bbe8
19 changed files with 205 additions and 170 deletions

View File

@@ -7,12 +7,14 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.GridLayoutManager import androidx.core.view.updateLayoutParams
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.netease.nim.uikit.common.util.sys.ScreenUtil
import com.yizhuan.erban.R import com.yizhuan.erban.R
import com.yizhuan.xchat_android_core.bean.RoomQueueInfo import com.yizhuan.xchat_android_core.bean.RoomQueueInfo
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager import com.yizhuan.xchat_android_core.manager.AvRoomDataManager
import kotlin.math.max
/** /**
@@ -25,8 +27,8 @@ class GameMicroViewAdapter(context: Context?) : BaseMicroViewAdapter(context) {
* Set LayoutManager and bind this to RecyclerView * Set LayoutManager and bind this to RecyclerView
*/ */
override fun bindToRecyclerView(recyclerView: RecyclerView) { override fun bindToRecyclerView(recyclerView: RecyclerView) {
val layoutManager = GridLayoutManager(context, 6) val layoutManager = LinearLayoutManager(context)
layoutManager.orientation = LinearLayoutManager.VERTICAL layoutManager.orientation = LinearLayoutManager.HORIZONTAL
recyclerView.layoutManager = layoutManager recyclerView.layoutManager = layoutManager
recyclerView.adapter = this recyclerView.adapter = this
} }
@@ -47,6 +49,14 @@ class GameMicroViewAdapter(context: Context?) : BaseMicroViewAdapter(context) {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
public override fun bind(info: RoomQueueInfo, position: Int) { public override fun bind(info: RoomQueueInfo, position: Int) {
itemView.updateLayoutParams<RecyclerView.LayoutParams> {
width = when (itemCount) {
6 -> ScreenUtil.screenWidth / 6
7 -> ScreenUtil.screenWidth / 7
else -> (ScreenUtil.screenWidth / 7.5f).toInt()
}
}
super.bind(info, position) super.bind(info, position)
info.mChatRoomMember?.let { info.mChatRoomMember?.let {
if (it.gameStatus == 0 && !AvRoomDataManager.get().isRoomOwner(it.account)) { if (it.gameStatus == 0 && !AvRoomDataManager.get().isRoomOwner(it.account)) {
@@ -82,7 +92,7 @@ class GameMicroViewAdapter(context: Context?) : BaseMicroViewAdapter(context) {
} }
override fun getItemCount(): Int { override fun getItemCount(): Int {
return 6 return max(AvRoomDataManager.get().mCurrentRoomInfo?.mgMicNum ?: 6, 6)
} }
} }

View File

@@ -10,6 +10,8 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.yizhuan.erban.R import com.yizhuan.erban.R
import com.yizhuan.xchat_android_core.bean.RoomQueueInfo import com.yizhuan.xchat_android_core.bean.RoomQueueInfo
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager
import kotlin.math.max
/** /**
@@ -61,7 +63,7 @@ class GameMiniMicroViewAdapter(context: Context?) : BaseMicroViewAdapter(context
} }
override fun getItemCount(): Int { override fun getItemCount(): Int {
return 6 return max(AvRoomDataManager.get().mCurrentRoomInfo?.mgMicNum ?: 6, 6)
} }

View File

@@ -751,7 +751,6 @@ open class BaseRoomFragment<V : IBaseRoomView?, P : BaseRoomPresenter<V>?> :
private fun onDownMicro(micPosition: Int) { private fun onDownMicro(micPosition: Int) {
showBottomViewForDifRole() showBottomViewForDifRole()
updateMicBtn() updateMicBtn()
microView.removeDragonBar(micPosition)
microView.adapter.notifyDataSetChanged() microView.adapter.notifyDataSetChanged()
//下麦时更新最高最低头饰 //下麦时更新最高最低头饰
GiftValueMrg.get().updateRoomGiftValue(false) GiftValueMrg.get().updateRoomGiftValue(false)

View File

@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.core.view.isInvisible
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
@@ -55,6 +56,7 @@ class GameRoomFragment : BaseRoomFragment<IGameRoomView?, GameRoomPresenter?>(),
private lateinit var gameBinding: FragmentGameRoomBinding private lateinit var gameBinding: FragmentGameRoomBinding
private lateinit var gameDelegate: GameDelegate private lateinit var gameDelegate: GameDelegate
private var isShowMiniMic = false
override fun getRootLayoutId(): Int { override fun getRootLayoutId(): Int {
return R.layout.fragment_game_room return R.layout.fragment_game_room
@@ -83,39 +85,30 @@ class GameRoomFragment : BaseRoomFragment<IGameRoomView?, GameRoomPresenter?>(),
PlayerModel.get().stop() PlayerModel.get().stop()
gameBinding.roomInfo = AvRoomDataManager.get().mCurrentRoomInfo gameBinding.roomInfo = AvRoomDataManager.get().mCurrentRoomInfo
mvpPresenter?.getBannerList() mvpPresenter?.getBannerList()
gameBinding.tvShowMiniMic.setOnClickListener { gameBinding.tvShowMiniMic.setOnClickListener { showMiniMic() }
gameBinding.microView.updateLayoutParams<LinearLayout.LayoutParams> { gameBinding.ivShowMic.setOnClickListener { showMic() }
width = LinearLayout.LayoutParams.WRAP_CONTENT }
marginStart = ScreenUtil.dip2px(2f)
marginEnd = ScreenUtil.dip2px(2f)
}
gameBinding.microView.bindAdapter(GameMiniMicroViewAdapter(context).apply {
setOnClick { gameBinding.ivShowMic.callOnClick() }
})
gameBinding.llMicView.updateLayoutParams<LinearLayout.LayoutParams> {
width = LinearLayout.LayoutParams.WRAP_CONTENT
}
gameBinding.tvShowMiniMic.isVisible = false
gameBinding.microView.postDelayed({
gameBinding.ivShowMic.isVisible = true
gameBinding.llMicView.setBackgroundResource(R.drawable.bg_mini_mic_entrance)
}, 100)
}
gameBinding.ivShowMic.setOnClickListener { private fun showMiniMic() {
gameBinding.microView.updateLayoutParams<LinearLayout.LayoutParams> { if (isShowMiniMic) return
width = LinearLayout.LayoutParams.MATCH_PARENT isShowMiniMic = true
marginStart = ScreenUtil.dip2px(10f) gameBinding.microView.bindAdapter(GameMiniMicroViewAdapter(context).apply {
marginEnd = ScreenUtil.dip2px(10f) setOnClick { showMic() }
} })
gameBinding.llMicView.updateLayoutParams<LinearLayout.LayoutParams> { gameBinding.tvShowMiniMic.isVisible = false
width = LinearLayout.LayoutParams.MATCH_PARENT gameBinding.microView.postDelayed({
} gameBinding.ivShowMic.isVisible = true
gameBinding.microView.bindAdapter(GameMicroViewAdapter(context)) gameBinding.llMicView.setBackgroundResource(R.drawable.bg_mini_mic_entrance)
gameBinding.tvShowMiniMic.isVisible = true }, 100)
gameBinding.llMicView.background = null }
gameBinding.ivShowMic.isVisible = false
} private fun showMic() {
if (!isShowMiniMic) return
isShowMiniMic = false
gameBinding.microView.bindAdapter(GameMicroViewAdapter(context))
gameBinding.tvShowMiniMic.isVisible = true
gameBinding.llMicView.background = null
gameBinding.ivShowMic.isVisible = false
} }
override fun onSetListener() { override fun onSetListener() {
@@ -127,15 +120,31 @@ class GameRoomFragment : BaseRoomFragment<IGameRoomView?, GameRoomPresenter?>(),
super.updateView() super.updateView()
gameDelegate.updateGame(AvRoomDataManager.get().mCurrentRoomInfo?.mgId) gameDelegate.updateGame(AvRoomDataManager.get().mCurrentRoomInfo?.mgId)
gameBinding.roomInfo = AvRoomDataManager.get().mCurrentRoomInfo gameBinding.roomInfo = AvRoomDataManager.get().mCurrentRoomInfo
if (isSixMic()) {
gameBinding.tvShowMiniMic.isVisible = !isShowMiniMic
gameBinding.ivShowMic.isVisible = isShowMiniMic
} else {
showMic()
gameBinding.tvShowMiniMic.isInvisible = true
gameBinding.ivShowMic.isVisible = false
}
gameBinding.microView.adapter.notifyDataSetChanged() gameBinding.microView.adapter.notifyDataSetChanged()
} }
override fun onGameStart() { override fun onGameStart() {
gameBinding.tvShowMiniMic.callOnClick() if (isSixMic()) {
showMiniMic()
}
} }
override fun onGameEnd() { override fun onGameEnd() {
gameBinding.ivShowMic.callOnClick() if (isSixMic()) {
showMic()
}
}
fun isSixMic(): Boolean {
return AvRoomDataManager.get().mCurrentRoomInfo?.mgMicNum == 6
} }
override fun onSendMsgSuccess(msg: String?) { override fun onSendMsgSuccess(msg: String?) {

View File

@@ -313,7 +313,7 @@ class GameDelegate(val activity: Activity, val container: FrameLayout, var mgId:
//游戏安全操作区域 //游戏安全操作区域
val viewGameRect = JSONObject() val viewGameRect = JSONObject()
viewGameRect.put("left", 0) viewGameRect.put("left", 0)
viewGameRect.put("top", ScreenUtil.dip2px(220f)) viewGameRect.put("top", ScreenUtil.dip2px(200f))
viewGameRect.put("right", 0) viewGameRect.put("right", 0)
viewGameRect.put("bottom", ScreenUtil.dip2px(200f)) viewGameRect.put("bottom", ScreenUtil.dip2px(200f))
jsonObject.put("view_game_rect", viewGameRect) jsonObject.put("view_game_rect", viewGameRect)

View File

@@ -205,7 +205,7 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
Point senderPoint = micViewPoint.get(senderPosition); Point senderPoint = micViewPoint.get(senderPosition);
Point receivePoint = micViewPoint.get(receivePosition); Point receivePoint = micViewPoint.get(receivePosition);
if (receivePoint == null) { //这种情况就是接收者已经不在麦上 if (receivePoint == null || isGameRoomMoreThan6People()) { //这种情况就是接收者已经不在麦上
//礼物送到上面中间的位置 //礼物送到上面中间的位置
receivePoint = new Point(UIUtil.getScreenWidth(context) / 2, receivePoint = new Point(UIUtil.getScreenWidth(context) / 2,
UIUtil.dip2px(context, 35)); UIUtil.dip2px(context, 35));
@@ -261,7 +261,7 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
Point senderPoint = micViewPoint.get(senderPosition); Point senderPoint = micViewPoint.get(senderPosition);
Point receivePoint = micViewPoint.get(receivePosition); Point receivePoint = micViewPoint.get(receivePosition);
if (receivePoint == null) { //这种情况就是接收者已经不在麦上 if (receivePoint == null || isGameRoomMoreThan6People()) { //这种情况就是接收者已经不在麦上
//礼物送到上面中间的位置 //礼物送到上面中间的位置
receivePoint = new Point(UIUtil.getScreenWidth(context) / 2, receivePoint = new Point(UIUtil.getScreenWidth(context) / 2,
UIUtil.dip2px(context, 35)); UIUtil.dip2px(context, 35));
@@ -344,7 +344,7 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
Point senderPoint = micViewPoint.get(senderPosition); Point senderPoint = micViewPoint.get(senderPosition);
Point receivePoint = micViewPoint.get(receivePosition); Point receivePoint = micViewPoint.get(receivePosition);
if (receivePoint == null) { //这种情况就是接收者已经不在麦上 if (receivePoint == null || isGameRoomMoreThan6People()) { //这种情况就是接收者已经不在麦上
//礼物送到上面中间的位置 //礼物送到上面中间的位置
receivePoint = new Point(UIUtil.getScreenWidth(context) / 2, receivePoint = new Point(UIUtil.getScreenWidth(context) / 2,
UIUtil.dip2px(context, 35)); UIUtil.dip2px(context, 35));
@@ -555,7 +555,7 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
Point senderPoint = micViewPoint.get(senderPosition); Point senderPoint = micViewPoint.get(senderPosition);
Point receivePoint = micViewPoint.get(receivePosition); Point receivePoint = micViewPoint.get(receivePosition);
if (receivePoint == null) { if (receivePoint == null || isGameRoomMoreThan6People()) {
//礼物送到上面中间的位置 //礼物送到上面中间的位置
receivePoint = new Point(UIUtil.getScreenWidth(context) / 2, receivePoint = new Point(UIUtil.getScreenWidth(context) / 2,
UIUtil.dip2px(context, 35)); UIUtil.dip2px(context, 35));
@@ -646,7 +646,7 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
return; return;
} }
if (senderPoint == null) if (senderPoint == null || isGameRoomMoreThan6People())
senderPoint = new Point(mScreenWidth - giftWidth, mScreenHeight - UIUtil.dip2px(context, 50)); senderPoint = new Point(mScreenWidth - giftWidth, mScreenHeight - UIUtil.dip2px(context, 50));
SVGAImageView imageView = mMagicViewPool.borrowMagicObject(senderPoint); SVGAImageView imageView = mMagicViewPool.borrowMagicObject(senderPoint);
String animationUrl = getValidPathAnimationUrl(magicReceivedInfo.getMagicId(), String animationUrl = getValidPathAnimationUrl(magicReceivedInfo.getMagicId(),
@@ -732,7 +732,7 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
final Point center = new Point(); final Point center = new Point();
center.x = context.getResources().getDisplayMetrics().widthPixels / 2; center.x = context.getResources().getDisplayMetrics().widthPixels / 2;
center.y = context.getResources().getDisplayMetrics().heightPixels / 2; center.y = context.getResources().getDisplayMetrics().heightPixels / 2;
if (senderPoint == null) { if (senderPoint == null || isGameRoomMoreThan6People()) {
senderPoint = new Point(mScreenWidth / 2 - giftWidth / 2, UIUtil.dip2px(context, 25)); senderPoint = new Point(mScreenWidth / 2 - giftWidth / 2, UIUtil.dip2px(context, 25));
} }
SVGAImageView imageView = mMagicViewPool.borrowGiftObject(senderPoint); SVGAImageView imageView = mMagicViewPool.borrowGiftObject(senderPoint);
@@ -761,6 +761,11 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
}); });
} }
private boolean isGameRoomMoreThan6People() {
RoomInfo roomInfo = AvRoomDataManager.get().mCurrentRoomInfo;
return AvRoomDataManager.get().isOpenGame() && roomInfo != null && roomInfo.getMgMicNum() > 6;
}
private Path getBezierCurvePath(Point sendPoint, Point receivePoint, boolean center) { private Path getBezierCurvePath(Point sendPoint, Point receivePoint, boolean center) {
Point endPoint = new Point(receivePoint.x - sendPoint.x, receivePoint.y - sendPoint.y); Point endPoint = new Point(receivePoint.x - sendPoint.x, receivePoint.y - sendPoint.y);

View File

@@ -7,11 +7,10 @@ import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.View; import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@@ -22,11 +21,9 @@ import com.opensource.svgaplayer.SVGAParser;
import com.opensource.svgaplayer.SVGAVideoEntity; import com.opensource.svgaplayer.SVGAVideoEntity;
import com.yizhuan.erban.R; import com.yizhuan.erban.R;
import com.yizhuan.erban.avroom.adapter.BaseMicroViewAdapter; import com.yizhuan.erban.avroom.adapter.BaseMicroViewAdapter;
import com.yizhuan.erban.avroom.adapter.CpMicroViewAdapter;
import com.yizhuan.erban.avroom.adapter.DatingMicroViewAdapter; import com.yizhuan.erban.avroom.adapter.DatingMicroViewAdapter;
import com.yizhuan.erban.avroom.adapter.GameMicroViewAdapter; import com.yizhuan.erban.avroom.adapter.GameMicroViewAdapter;
import com.yizhuan.erban.avroom.adapter.GameMiniMicroViewAdapter; import com.yizhuan.erban.avroom.adapter.GameMiniMicroViewAdapter;
import com.yizhuan.erban.avroom.adapter.MicroViewAdapter;
import com.yizhuan.erban.avroom.adapter.OnMicroItemClickListener; import com.yizhuan.erban.avroom.adapter.OnMicroItemClickListener;
import com.yizhuan.erban.ui.anim.AnimFactory; import com.yizhuan.erban.ui.anim.AnimFactory;
import com.yizhuan.erban.ui.widget.magicindicator.buildins.UIUtil; import com.yizhuan.erban.ui.widget.magicindicator.buildins.UIUtil;
@@ -58,11 +55,9 @@ import io.reactivex.disposables.Disposable;
* @author xiaoyu * @author xiaoyu
* @date 2017/12/20 * @date 2017/12/20
*/ */
public class MicroView extends FrameLayout implements View.OnLayoutChangeListener { public class MicroView extends LinearLayout implements View.OnLayoutChangeListener {
private static final String TAG = "MicroView"; private static final String TAG = "MicroView";
public RecyclerView recyclerView; public RecyclerView recyclerView;
private SparseArray<ImageView> faceImageViews;
private SparseArray<ImageView> dragonBarImageViews;
private Context mContext; private Context mContext;
private int giftWidth; private int giftWidth;
private int giftHeight; private int giftHeight;
@@ -99,25 +94,11 @@ public class MicroView extends FrameLayout implements View.OnLayoutChangeListene
inflate(mContext, R.layout.layout_micro_view, this); inflate(mContext, R.layout.layout_micro_view, this);
recyclerView = findViewById(R.id.recycler_view); recyclerView = findViewById(R.id.recycler_view);
recyclerView.addOnLayoutChangeListener(this); recyclerView.addOnLayoutChangeListener(this);
giftWidth = UIUtil.dip2px(mContext, 80); giftWidth = UIUtil.dip2px(mContext, 80);
giftHeight = UIUtil.dip2px(mContext, 80); giftHeight = UIUtil.dip2px(mContext, 80);
faceImageViews = new SparseArray<>(10);
dragonBarImageViews = new SparseArray<>(9);
} }
public void bindAdapter(@NonNull BaseMicroViewAdapter adapter) { public void bindAdapter(@NonNull BaseMicroViewAdapter adapter) {
if (adapter instanceof GameMicroViewAdapter) {
giftWidth = UIUtil.dip2px(mContext, 60);
giftHeight = UIUtil.dip2px(mContext, 60);
} else if (adapter instanceof GameMiniMicroViewAdapter) {
giftWidth = UIUtil.dip2px(mContext, 16);
giftHeight = UIUtil.dip2px(mContext, 16);
} else {
giftWidth = UIUtil.dip2px(mContext, 80);
giftHeight = UIUtil.dip2px(mContext, 80);
}
if (adapter instanceof DatingMicroViewAdapter) { if (adapter instanceof DatingMicroViewAdapter) {
if (datingItemDecoration == null) datingItemDecoration = new DatingItemDecoration(); if (datingItemDecoration == null) datingItemDecoration = new DatingItemDecoration();
recyclerView.addItemDecoration(datingItemDecoration); recyclerView.addItemDecoration(datingItemDecoration);
@@ -155,41 +136,11 @@ public class MicroView extends FrameLayout implements View.OnLayoutChangeListene
private void onReceiveRoomEvent(RoomEvent roomEvent) { private void onReceiveRoomEvent(RoomEvent roomEvent) {
if (roomEvent == null || roomEvent.getEvent() == RoomEvent.NONE) return; if (roomEvent == null || roomEvent.getEvent() == RoomEvent.NONE) return;
switch (roomEvent.getEvent()) { if (roomEvent.getEvent() == RoomEvent.SPEAK_STATE_CHANGE) {
case RoomEvent.SPEAK_STATE_CHANGE: onSpeakQueueUpdate(roomEvent.getMicPositionList());
onSpeakQueueUpdate(roomEvent.getMicPositionList());
break;
case RoomEvent.DRAGON_BAR_START:
onDragonBarOpen((FaceAttachment) roomEvent.getChatRoomMessage().getAttachment(), true, false, false);
break;
case RoomEvent.DRAGON_BAR_SELF_START:
onDragonBarOpen((FaceAttachment) roomEvent.getChatRoomMessage().getAttachment(), true, true, false);
break;
case RoomEvent.DRAGON_BAR_END:
onDragonBarOpen((FaceAttachment) roomEvent.getChatRoomMessage().getAttachment(), false, true, true);
break;
case RoomEvent.DRAGON_BAR_CANCEL:
onDragonBarCancel((FaceAttachment) roomEvent.getChatRoomMessage().getAttachment());
break;
default:
} }
} }
private void onDragonBarCancel(FaceAttachment attachment) {
int position = AvRoomDataManager.get().getMicPosition(attachment.getUid());
if (position < -1) return;
ImageView imageView = dragonBarImageViews.get(position);
if (imageView == null) return;
imageView.setImageDrawable(null);
imageView.clearAnimation();
}
private void onDragonBarOpen(FaceAttachment attachment, boolean needAnim, boolean needResult, boolean needGone) {
List<FaceReceiveInfo> faceReceiveInfos = attachment.getFaceReceiveInfos();
if (faceReceiveInfos == null || faceReceiveInfos.size() <= 0) return;
faceAnima(faceReceiveInfos, true, needAnim, needResult, needGone);
}
@Override @Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
//高度和位置都没发生变化,就没必要要reset了 //高度和位置都没发生变化,就没必要要reset了
@@ -200,35 +151,30 @@ public class MicroView extends FrameLayout implements View.OnLayoutChangeListene
isNeedResetMicCenterPoint = false; isNeedResetMicCenterPoint = false;
recyclerView.post(() -> { recyclerView.post(() -> {
isNeedResetMicCenterPoint = true; isNeedResetMicCenterPoint = true;
faceImageViews = setMicCenterPoint(faceImageViews); setMicCenterPoint();
if (AvRoomDataManager.get().hasDragonGame()) {
dragonBarImageViews = setMicCenterPoint(dragonBarImageViews);
}
}); });
} }
} }
public SparseArray<ImageView> setMicCenterPoint(SparseArray<ImageView> array) { private void setMicCenterPoint() {
if (array == null) array = new SparseArray<>(9);
SparseArray<Point> centerPoints = new SparseArray<>(); SparseArray<Point> centerPoints = new SparseArray<>();
// 算出每一个麦位的位置 // 算出每一个麦位的位置
int childCount = recyclerView.getChildCount(); int childCount = recyclerView.getChildCount();
View child; View child;
for (int i = 0; i < childCount; i++) { for (int i = 0; i < childCount; i++) {
child = recyclerView.getChildAt(i); child = recyclerView.getChildAt(i);
addFaceView(array, centerPoints, child, i - 1); addFaceView(centerPoints, child, i - 1);
if (i == 0) { if (i == 0) {
RecyclerView rvVip = child.findViewById(R.id.rv_vip); RecyclerView rvVip = child.findViewById(R.id.rv_vip);
if (rvVip != null && rvVip.getChildCount() > 0) { if (rvVip != null && rvVip.getChildCount() > 0) {
addFaceView(array, centerPoints, rvVip.getChildAt(0), AvRoomDataManager.POSITION_VIP_MIC); addFaceView(centerPoints, rvVip.getChildAt(0), AvRoomDataManager.POSITION_VIP_MIC);
} }
} }
} }
AvRoomDataManager.get().mMicPointMap = centerPoints; AvRoomDataManager.get().mMicPointMap = centerPoints;
return array;
} }
private void addFaceView(SparseArray<ImageView> array, SparseArray<Point> centerPoints, View child, int micPosition) { private void addFaceView(SparseArray<Point> centerPoints, View child, int micPosition) {
int[] location = new int[2]; int[] location = new int[2];
// 找到头像 // 找到头像
View view = child.findViewById(R.id.micro_layout); View view = child.findViewById(R.id.micro_layout);
@@ -236,23 +182,6 @@ public class MicroView extends FrameLayout implements View.OnLayoutChangeListene
child.getLocationInWindow(location); child.getLocationInWindow(location);
int x = (location[0] + child.getWidth() / 2) - giftWidth / 2; int x = (location[0] + child.getWidth() / 2) - giftWidth / 2;
int y = (location[1] + child.getHeight() / 2) - giftHeight / 2; int y = (location[1] + child.getHeight() / 2) - giftHeight / 2;
// 放置表情占位image view
ImageView face = array.get(micPosition);
LayoutParams params = new LayoutParams(giftWidth, giftHeight);
child.getLocationInWindow(location);
int[] containerLocation = new int[2];
this.getLocationInWindow(containerLocation);
params.leftMargin = ((location[0] - containerLocation[0] + child.getWidth() / 2) - giftHeight / 2);
params.topMargin = ((location[1] - containerLocation[1] + child.getHeight() / 2) - giftHeight / 2);
//如果不为空,只改变View的位置就行了
if (face == null) {
face = new ImageView(mContext);
array.put(micPosition, face);
face.setLayoutParams(params);
addView(face);
} else {
face.setLayoutParams(params);
}
Point point = new Point(x, y); Point point = new Point(x, y);
LogUtils.d("x= " + x + " y= " + y); LogUtils.d("x= " + x + " y= " + y);
centerPoints.put(micPosition, point); centerPoints.put(micPosition, point);
@@ -264,7 +193,8 @@ public class MicroView extends FrameLayout implements View.OnLayoutChangeListene
@SuppressLint("CheckResult") @SuppressLint("CheckResult")
public void onSpeakQueueUpdate(List<Integer> positions) { public void onSpeakQueueUpdate(List<Integer> positions) {
int count = recyclerView.getChildCount(); if (recyclerView == null || getAdapter() == null) return;
int count = getAdapter().getItemCount();
for (int i = 0; i < positions.size(); i++) { for (int i = 0; i < positions.size(); i++) {
int pos = positions.get(i) + 1; int pos = positions.get(i) + 1;
if (pos >= count && pos != AvRoomDataManager.POSITION_VIP_MIC + 1) continue; if (pos >= count && pos != AvRoomDataManager.POSITION_VIP_MIC + 1) continue;
@@ -272,10 +202,10 @@ public class MicroView extends FrameLayout implements View.OnLayoutChangeListene
final SVGAImageView speakState; final SVGAImageView speakState;
//相亲模式VIP位置光圈 //相亲模式VIP位置光圈
if (pos == AvRoomDataManager.POSITION_VIP_MIC + 1) { if (pos == AvRoomDataManager.POSITION_VIP_MIC + 1) {
speakState = ((RecyclerView) recyclerView.getChildAt(0).findViewById(R.id.rv_vip)) speakState = ((RecyclerView) findItemView(pos).findViewById(R.id.rv_vip))
.getChildAt(0).findViewById(R.id.iv_halo); .getChildAt(0).findViewById(R.id.iv_halo);
} else { } else {
speakState = recyclerView.getChildAt(pos).findViewById(R.id.iv_halo); speakState = findItemView(pos).findViewById(R.id.iv_halo);
} }
if (speakState != null) { if (speakState != null) {
@@ -341,6 +271,14 @@ public class MicroView extends FrameLayout implements View.OnLayoutChangeListene
} }
} }
private View findItemView(int pos) {
RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForLayoutPosition(pos);
if (viewHolder != null) {
return viewHolder.itemView;
}
return recyclerView.getChildAt(pos);
}
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onReceiveFace(ReceiveFaceEvent event) { public void onReceiveFace(ReceiveFaceEvent event) {
List<FaceReceiveInfo> faceReceiveInfos = event.getFaceReceiveInfos(); List<FaceReceiveInfo> faceReceiveInfos = event.getFaceReceiveInfos();
@@ -357,33 +295,24 @@ public class MicroView extends FrameLayout implements View.OnLayoutChangeListene
((BaseMicroViewAdapter.NormalMicroViewHolder) holder).clear(); ((BaseMicroViewAdapter.NormalMicroViewHolder) holder).clear();
} }
} }
//key 是从[-1, 7],9个key
// 移除所有的表情动画
for (int i = -1; i < faceImageViews.size() - 1; i++) {
ImageView imageView = faceImageViews.get(i);
if (imageView == null) continue;
imageView.setImageDrawable(null);
imageView.clearAnimation();
}
// 移除龙珠的动画
for (int i = -1; i < dragonBarImageViews.size() - 1; i++) {
ImageView imageView = dragonBarImageViews.get(i);
if (imageView == null) continue;
imageView.setImageDrawable(null);
imageView.clearAnimation();
}
} }
//开始表情动画和龙珠动画 //开始表情动画和龙珠动画
@SuppressLint("CheckResult")
private void faceAnima(List<FaceReceiveInfo> faceReceiveInfos, boolean isDragon, boolean needAnim, boolean needResult, boolean needGone) { private void faceAnima(List<FaceReceiveInfo> faceReceiveInfos, boolean isDragon, boolean needAnim, boolean needResult, boolean needGone) {
for (FaceReceiveInfo faceReceiveInfo : faceReceiveInfos) { for (FaceReceiveInfo faceReceiveInfo : faceReceiveInfos) {
int position = AvRoomDataManager.get().getMicPosition(faceReceiveInfo.getUid()); int position = AvRoomDataManager.get().getMicPosition(faceReceiveInfo.getUid());
if (position < -1) continue; if (position < -1) continue;
ImageView imageView; ImageView imageView;
if (isDragon) { if (isDragon) {
imageView = dragonBarImageViews.get(position); return;
} else { } else {
imageView = faceImageViews.get(position); if (position == AvRoomDataManager.POSITION_VIP_MIC + 1) {
imageView = ((RecyclerView) findItemView(position + 1).findViewById(R.id.rv_vip))
.getChildAt(0).findViewById(R.id.iv_face);
} else {
imageView = findItemView(position + 1).findViewById(R.id.iv_face);
}
} }
if (imageView == null) continue; if (imageView == null) continue;
AnimFactory.getFaceAnimation(faceReceiveInfo, mContext, imageView.getWidth(), imageView.getHeight(), needAnim, needResult, needGone) AnimFactory.getFaceAnimation(faceReceiveInfo, mContext, imageView.getWidth(), imageView.getHeight(), needAnim, needResult, needGone)
@@ -402,12 +331,4 @@ public class MicroView extends FrameLayout implements View.OnLayoutChangeListene
}); });
} }
} }
public void removeDragonBar(int micPosition) {
ImageView imageView = dragonBarImageViews.get(micPosition);
if (imageView == null) return;
imageView.setImageDrawable(null);
imageView.clearAnimation();
}
} }

View File

@@ -102,6 +102,14 @@
</RelativeLayout> </RelativeLayout>
<ImageView
android:id="@+id/iv_face"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
tools:visibility="visible" />
</FrameLayout> </FrameLayout>
<TextView <TextView

View File

@@ -161,6 +161,17 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible" /> tools:visibility="visible" />
<ImageView
android:id="@+id/iv_face"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -190,6 +190,16 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible" /> tools:visibility="visible" />
<ImageView
android:id="@+id/iv_face"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -2,13 +2,12 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="56dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clipChildren="false" android:clipChildren="false"
android:clipToPadding="false" android:clipToPadding="false"
android:paddingTop="5dp" android:paddingTop="5dp"
tools:background="@color/color_activity_blue_bg" tools:background="@color/color_activity_blue_bg">
tools:layout_width="60dp">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/micro_layout" android:id="@+id/micro_layout"
@@ -74,6 +73,7 @@
app:layout_constraintWidth_percent="0.76" app:layout_constraintWidth_percent="0.76"
tools:visibility="visible" /> tools:visibility="visible" />
<ImageView <ImageView
android:id="@+id/iv_head_wear" android:id="@+id/iv_head_wear"
android:layout_width="0dp" android:layout_width="0dp"
@@ -128,6 +128,16 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible" /> tools:visibility="visible" />
<ImageView
android:id="@+id/iv_face"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -6,8 +6,7 @@
android:layout_height="16dp" android:layout_height="16dp"
android:layout_marginStart="1dp" android:layout_marginStart="1dp"
android:layout_marginEnd="1dp" android:layout_marginEnd="1dp"
tools:background="@color/color_activity_blue_bg" tools:background="@color/color_activity_blue_bg">
>
<FrameLayout <FrameLayout
android:id="@+id/micro_layout" android:id="@+id/micro_layout"
@@ -20,10 +19,10 @@
<com.opensource.svgaplayer.SVGAImageView <com.opensource.svgaplayer.SVGAImageView
android:id="@+id/iv_halo" android:id="@+id/iv_halo"
android:visibility="gone"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center" /> android:layout_gravity="center"
android:visibility="gone" />
<ImageView <ImageView
android:id="@+id/up_image" android:id="@+id/up_image"
@@ -63,16 +62,23 @@
android:visibility="visible" android:visibility="visible"
tools:visibility="visible" /> tools:visibility="visible" />
<ImageView
android:id="@+id/iv_face"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
tools:visibility="gone" />
</FrameLayout> </FrameLayout>
<LinearLayout <LinearLayout
android:id="@+id/ll_nick" android:id="@+id/ll_nick"
android:layout_width="0dp" android:layout_width="0dp"
android:visibility="gone"
android:layout_height="15dp" android:layout_height="15dp"
android:layout_marginLeft="@dimen/dp_5" android:layout_marginLeft="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5" android:layout_marginRight="@dimen/dp_5"
android:gravity="center" android:gravity="center"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/micro_layout"> app:layout_constraintTop_toBottomOf="@id/micro_layout">

View File

@@ -76,6 +76,13 @@
android:layout_gravity="start|bottom" android:layout_gravity="start|bottom"
tools:visibility="visible" /> tools:visibility="visible" />
<ImageView
android:id="@+id/iv_face"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
tools:visibility="gone" />
</FrameLayout> </FrameLayout>
<LinearLayout <LinearLayout

View File

@@ -126,6 +126,18 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
tools:visibility="visible" /> tools:visibility="visible" />
<ImageView
android:id="@+id/iv_face"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<TextView <TextView

View File

@@ -120,6 +120,18 @@
app:layout_constraintEnd_toEndOf="@id/avatar" app:layout_constraintEnd_toEndOf="@id/avatar"
tools:visibility="visible" /> tools:visibility="visible" />
<ImageView
android:id="@+id/iv_face"
android:layout_width="100dp"
android:layout_height="100dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="@id/avatar"
app:layout_constraintEnd_toEndOf="@id/avatar"
app:layout_constraintStart_toStartOf="@id/avatar"
app:layout_constraintTop_toTopOf="@id/avatar"
tools:visibility="visible" />
<LinearLayout <LinearLayout
android:id="@+id/ll_nick" android:id="@+id/ll_nick"
android:layout_width="0dp" android:layout_width="0dp"

View File

@@ -94,6 +94,13 @@
</RelativeLayout> </RelativeLayout>
<ImageView
android:id="@+id/iv_face"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
tools:visibility="gone" />
</FrameLayout> </FrameLayout>
<TextView <TextView

View File

@@ -76,8 +76,9 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="75dp" android:layout_marginTop="75dp"
android:orientation="vertical"> android:orientation="vertical">
@@ -93,7 +94,7 @@
<LinearLayout <LinearLayout
android:id="@+id/ll_mic_view" android:id="@+id/ll_mic_view"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="end"
android:gravity="end|center_vertical" android:gravity="end|center_vertical"
@@ -111,10 +112,8 @@
<com.yizhuan.erban.avroom.widget.MicroView <com.yizhuan.erban.avroom.widget.MicroView
android:id="@+id/micro_view" android:id="@+id/micro_view"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content" />
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp" />
</LinearLayout> </LinearLayout>

View File

@@ -56,6 +56,7 @@ import com.netease.nimlib.sdk.util.Entry;
import com.netease.nimlib.sdk.util.api.RequestResult; import com.netease.nimlib.sdk.util.api.RequestResult;
import com.orhanobut.logger.Logger; import com.orhanobut.logger.Logger;
import com.yizhuan.xchat_android_constants.XChatConstants; import com.yizhuan.xchat_android_constants.XChatConstants;
import com.yizhuan.xchat_android_core.BuildConfig;
import com.yizhuan.xchat_android_core.Constants; import com.yizhuan.xchat_android_core.Constants;
import com.yizhuan.xchat_android_core.R; import com.yizhuan.xchat_android_core.R;
import com.yizhuan.xchat_android_core.auth.AuthModel; import com.yizhuan.xchat_android_core.auth.AuthModel;
@@ -180,6 +181,7 @@ import org.greenrobot.eventbus.EventBus;
import org.reactivestreams.Publisher; import org.reactivestreams.Publisher;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@@ -1602,7 +1604,10 @@ public final class IMNetEaseManager {
// 1----房间信息更新 2-----麦序信息更新 // 1----房间信息更新 2-----麦序信息更新
// 3----更新房间信息和麦序信息(排麦模式) // 3----更新房间信息和麦序信息(排麦模式)
int type = (int) extension.get("type"); int type = (int) extension.get("type");
LogUtils.d("chatRoomInfoUpdate type =" + type);
if (BuildConfig.DEBUG) {
LogUtils.d("chatRoomInfoUpdate type =" + type + " extension=" + Arrays.toString(extension.entrySet().toArray()));
}
if (type == 2) { if (type == 2) {
roomQueueMicUpdate(extension); roomQueueMicUpdate(extension);
} else if (type == 1) { } else if (type == 1) {

View File

@@ -195,6 +195,8 @@ public class RoomInfo implements Parcelable,Serializable {
private String mgName; private String mgName;
private int mgMicNum;
private long clearScreenTime; private long clearScreenTime;
// /** // /**
// * 房间角标 // * 房间角标