送礼物动画位置计算方式修改

This commit is contained in:
huangjian
2021-01-26 19:03:04 +08:00
parent 6b077cc39a
commit 2153648abb
9 changed files with 210 additions and 175 deletions

View File

@@ -477,9 +477,6 @@ public abstract class BaseMicroViewAdapter extends RecyclerView.Adapter<Recycler
TextView tvLabelLeaveMode;
CircleImageView ivLeaveMode;
View inOfficialMask;
TextView tvOfficialMask;
ImageView ivOfficialMask;
ImageView ivRedPackage;
BossMicroViewHolder(View itemView) {
@@ -494,12 +491,6 @@ public abstract class BaseMicroViewAdapter extends RecyclerView.Adapter<Recycler
tvRoomType.setOnClickListener(this);
ivRoomCanEdit.setOnClickListener(this);
inOfficialMask = itemView.findViewById(R.id.in_official_mask);
if (inOfficialMask != null) {
tvOfficialMask = inOfficialMask.findViewById(R.id.tv_official_mask);
ivOfficialMask = inOfficialMask.findViewById(R.id.iv_official_mask);
}
ivRedPackage = itemView.findViewById(R.id.iv_red_package);
ivRedPackage.setOnClickListener(this);
}
@@ -518,8 +509,6 @@ public abstract class BaseMicroViewAdapter extends RecyclerView.Adapter<Recycler
// 新版房主位优先判断麦序是否有人,麦序没人再判断是否是离开模式(防止新版展示离开模式,实际麦位有人)
MicMemberInfo chatRoomMember = info.mChatRoomMember;
if (chatRoomMember == null) {
inOfficialMask.setVisibility(View.GONE);
if (roomInfo.isLeaveMode()) {
tvLabelLeaveMode.setVisibility(View.VISIBLE);
ivLeaveMode.setVisibility(View.VISIBLE);
@@ -541,16 +530,6 @@ public abstract class BaseMicroViewAdapter extends RecyclerView.Adapter<Recycler
} else {
ivLeaveMode.setVisibility(View.GONE);
tvLabelLeaveMode.setVisibility(View.GONE);
String fixedWord = NobleUtil.getLevel(UserInfo.OAC_NAME, chatRoomMember);
String iconPic = NobleUtil.getLevel(UserInfo.OAC_ICON, chatRoomMember);
if (!TextUtils.isEmpty(fixedWord) && !TextUtils.isEmpty(iconPic)) {
inOfficialMask.setVisibility(View.VISIBLE);
tvOfficialMask.setText(fixedWord);
NobleUtil.loadResource(iconPic, ivOfficialMask);
} else {
inOfficialMask.setVisibility(View.GONE);
}
}
tvNick.setBackgroundColor(context.getResources().getColor(R.color.transparent));

View File

@@ -91,7 +91,6 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
private Context context;
private int mScreenWidth;
private int mScreenHeight;
private int mGiftSendY;
private Keyframe[] keyScale;
private Keyframe[] keyTrans;
private SvgaObjectPool mMagicViewPool;
@@ -118,7 +117,6 @@ public class GiftV2View extends FrameLayout implements GiftEffectView.GiftEffect
LayoutInflater.from(getContext()).inflate(R.layout.layout_gift_v2_view, this, true);
mScreenWidth = ResolutionUtils.getScreenWidth(getContext());
mScreenHeight = ResolutionUtils.getScreenHeight(getContext());
mGiftSendY = UIUtil.dip2px(context, 90);
giftWidth = UIUtil.dip2px(context, 80);
giftHeight = UIUtil.dip2px(context, 80);

View File

@@ -2,13 +2,18 @@ package com.yizhuan.erban.avroom.widget;
import android.annotation.SuppressLint;
import android.content.Context;
import androidx.databinding.DataBindingUtil;
import android.graphics.Point;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
@@ -39,6 +44,7 @@ import com.yizhuan.xchat_android_core.noble.NobleUtil;
import com.yizhuan.xchat_android_core.room.bean.RoomInfo;
import com.yizhuan.xchat_android_core.room.event.ReceiveFaceEvent;
import com.yizhuan.xchat_android_core.room.face.FaceReceiveInfo;
import com.yizhuan.xchat_android_core.utils.LogUtils;
import com.yizhuan.xchat_android_library.utils.config.BasicConfig;
@@ -56,7 +62,7 @@ import io.reactivex.disposables.Disposable;
* @author xiaoyu
* @date 2017/12/20
*/
public class MicroView extends RelativeLayout {
public class MicroView extends RelativeLayout implements View.OnLayoutChangeListener {
private static final String TAG = "MicroView";
public RecyclerView recyclerView;
private SparseArray<ImageView> faceImageViews;
@@ -72,8 +78,8 @@ public class MicroView extends RelativeLayout {
private KtvView ktvView;
private LayoutMicroViewBinding mBinding;
/**状态栏高度*/
private int statusBarHeight = 0;
private boolean isNeedResetMicCenterPoint = true;
public MicroView(Context context) {
this(context, null);
@@ -102,8 +108,6 @@ public class MicroView extends RelativeLayout {
super.onAttachedToWindow();
EventBus.getDefault().register(this);
subMsg();
/*mDisposable.add(CoreManager.getCore(IFaceCore.class).getChatRoomMsgFlowable()
.subscribe(this::onReceiveFace));*/
}
private void subMsg() {
@@ -160,37 +164,30 @@ public class MicroView extends RelativeLayout {
faceAnima(faceReceiveInfos, true, needAnim, needResult, needGone);
}
/**
* 根据位置获取想要的表情view的宽高
*/
private int getFaceSize(int i) {
int dp;
if (isKtvMode) {
if (i == 4) {//ktv模式boss麦位置
dp = 55;
} else {
dp = 45;
}
} else {
if (i == 0) {//普通模式boss麦位置
dp = 65;
} else {
dp = 55;
}
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
//高度和位置都没发生变化,就没必要要reset了
if (top == oldTop && bottom == oldBottom) return;
if (isNeedResetMicCenterPoint) {//这里有时候会重复调用,简单处理下(都是在500毫秒内重复调用的)
isNeedResetMicCenterPoint = false;
recyclerView.post(() -> {
isNeedResetMicCenterPoint = true;
faceImageViews = setMicCenterPoint(faceImageViews);
if (AvRoomDataManager.get().hasDragonGame()) {
dragonBarImageViews = setMicCenterPoint(dragonBarImageViews);
}
});
}
//放大4/3倍
return UIUtil.dip2px(mContext, dp * 4 / 3);
}
public SparseArray<ImageView> setMicCenterPoint() {
SparseArray<ImageView> array = new SparseArray<>(9);
public SparseArray<ImageView> setMicCenterPoint(SparseArray<ImageView> array) {
if (array == null) array = new SparseArray<>(9);
SparseArray<Point> centerPoints = new SparseArray<>();
// 算出每一个麦位的位置
int childCount = recyclerView.getChildCount();
View child;
for (int i = 0; i < childCount; i++) {
child = recyclerView.getChildAt(i);
int position = getRealPosition(i);
int[] location = new int[2];
// 找到头像
View view = child.findViewById(R.id.micro_layout);
@@ -198,26 +195,25 @@ public class MicroView extends RelativeLayout {
child.getLocationInWindow(location);
int x = (location[0] + child.getWidth() / 2) - giftWidth / 2;
int y = (location[1] + child.getHeight() / 2) - giftHeight / 2;
//修复礼物落点偏下的问题减去状态栏高度沉浸式版本开始的bug
//原因是因为这个位置计算出来是屏幕最开始0开始的
//但是giftV2View的位置是相对于状态栏高度开始的
y = y - statusBarHeight;
// 放置表情占位image view
int faceSize = getFaceSize(i);
if (array.get(position - 1) == null) {
LayoutParams params = new LayoutParams(faceSize, faceSize);
child.getLocationInWindow(location);
int[] containerLocation = new int[2];
this.getLocationInWindow(containerLocation);
params.leftMargin = ((location[0] - containerLocation[0] + child.getWidth() / 2) - faceSize / 2);
params.topMargin = ((location[1] - containerLocation[1] + child.getHeight() / 2) - faceSize / 2);
ImageView face = new ImageView(mContext);
ImageView face = array.get(i - 1);
LayoutParams params = new LayoutParams(giftHeight, 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(i - 1, face);
face.setLayoutParams(params);
array.put(position - 1, face);
addView(face);
} else {
face.setLayoutParams(params);
}
Point point = new Point(x, y);
centerPoints.put(position - 1, point);
centerPoints.put(i - 1, point);
}
AvRoomDataManager.get().mMicPointMap = centerPoints;
return array;
@@ -232,6 +228,7 @@ public class MicroView extends RelativeLayout {
inflate(mContext, R.layout.layout_micro_view, this);
mBinding = DataBindingUtil.bind(findViewById(R.id.container));
recyclerView = findViewById(R.id.recycler_view);
recyclerView.addOnLayoutChangeListener(this);
if (AvRoomDataManager.get().isCpRoom()) {
bindAdapter(new CpMicroViewAdapter(mContext));
} else {
@@ -241,20 +238,6 @@ public class MicroView extends RelativeLayout {
ViewGroup.LayoutParams ktvParam = ktvView.getLayoutParams();
ktvParam.height = (UIUtil.getScreenWidth(context) - UIUtil.dip2px(context, 24)) * 198 / 352;
// recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
// @Override
// public void onGlobalLayout() {
// recyclerView.postDelayed(() -> {
// dragonBarImageViews = setMicCenterPoint();
// faceImageViews = setMicCenterPoint();
// }, 500);
// recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
// }
// });
//
// MicroViewAdapter adapter = new MicroViewAdapter(mContext);
// adapter.bindToRecyclerView(recyclerView);
giftWidth = UIUtil.dip2px(mContext, 80);
giftHeight = UIUtil.dip2px(mContext, 80);
@@ -263,8 +246,6 @@ public class MicroView extends RelativeLayout {
mBinding.setRoomInfo(AvRoomDataManager.get().mCurrentRoomInfo);
statusBarHeight = TitleBar.getStatusBarHeight();
}
public void updateRoomInfo() {
@@ -412,46 +393,21 @@ public class MicroView extends RelativeLayout {
}
public void resetPoint() {
recyclerView.postDelayed(() -> {
removeFaceAndDragonView(faceImageViews);
removeFaceAndDragonView(dragonBarImageViews);
faceImageViews = setMicCenterPoint();
dragonBarImageViews = setMicCenterPoint();
}, 500);
}
private void removeFaceAndDragonView(SparseArray<ImageView> array) {
if (array == null) {
return;
}
for (int i = 0; i < array.size(); i++) {
int key = array.keyAt(i);
ImageView view = array.get(key);
if (view == null) {
continue;
}
view.setImageDrawable(null);
view.clearAnimation();
if (this == view.getParent()) {
removeView(view);
}
}
/* recyclerView.postDelayed(() -> {
faceImageViews = setMicCenterPoint(faceImageViews);
dragonBarImageViews = setMicCenterPoint(dragonBarImageViews);
}, 500);*/
}
public void bindAdapter(BaseMicroViewAdapter adapter) {
adapter.bindToRecyclerView(recyclerView);
adapter.setOnMicroItemClickListener(onMicroItemClickListener);
recyclerView.postDelayed(() -> {
removeFaceAndDragonView(faceImageViews);
removeFaceAndDragonView(dragonBarImageViews);
faceImageViews = setMicCenterPoint();
dragonBarImageViews = setMicCenterPoint();
}, 500);
resetPoint();
}
public void closeKtvMode() {
isKtvMode = false;
mBinding.setKtvModel(isKtvMode);
mBinding.setKtvModel(false);
ktvView.setVisibility(GONE);
if (AvRoomDataManager.get().isCpRoom()) {
bindAdapter(new CpMicroViewAdapter(mContext));

View File

@@ -324,10 +324,12 @@
<com.coorchice.library.SuperTextView
android:id="@+id/tv_select_him"
android:layout_width="130dp"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_gravity="center_horizontal"
android:layout_marginStart="70dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="70dp"
android:layout_marginBottom="15dp"
android:gravity="center"
android:text="选择心动"

View File

@@ -58,19 +58,19 @@
android:layout_height="65dp"
android:layout_gravity="center"
android:visibility="gone"
tools:visibility="visible"/>
tools:visibility="visible" />
<TextView
android:id="@+id/tv_label_leave_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="离开"
android:textColor="#E6FFFFFF"
android:textSize="16dp"
android:text="离开"
android:visibility="gone"
android:gravity="center"
tools:visibility="visible"/>
tools:visibility="visible" />
<RelativeLayout
android:layout_width="@dimen/dp_room_boss_mic_radius"
@@ -100,60 +100,44 @@
android:gravity="center"
android:textColor="@color/color_FFFFFF"
android:textSize="9dp"
tools:text="红队"
android:visibility="visible" />
android:visibility="visible"
tools:text="红队" />
<LinearLayout
android:id="@+id/rl_nick"
android:id="@+id/ll_nick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/micro_layout"
android:layout_centerHorizontal="true"
android:layout_below="@+id/micro_layout" >
android:gravity="center_vertical">
<include
android:id="@+id/in_official_mask"
<ImageView
android:id="@+id/iv_tag"
android:layout_width="wrap_content"
android:layout_height="@dimen/dp_20"
android:layout_marginEnd="5.5dp"
android:layout_gravity="center"
android:visibility="visible"
layout="@layout/layout_official_mask" />
android:layout_height="15dp"
android:layout_marginRight="5dp" />
<LinearLayout
android:id="@+id/ll_nick"
<TextView
android:id="@+id/nick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageView
android:id="@+id/iv_tag"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:layout_marginRight="5dp" />
<TextView
android:id="@+id/nick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxWidth="120dp"
android:maxLines="1"
android:singleLine="true"
android:text=""
android:textColor="@color/white"
android:textSize="13sp"
tools:text="我是名字"
tools:textColor="#000" />
</LinearLayout>
android:ellipsize="end"
android:gravity="center_vertical"
android:maxWidth="120dp"
android:maxLines="1"
android:singleLine="true"
android:text=""
android:textColor="@color/white"
android:textSize="13sp"
tools:text="我是名字"
tools:textColor="#000" />
</LinearLayout>
<LinearLayout
android:id="@+id/desc_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rl_nick"
android:layout_below="@+id/ll_nick"
android:layout_marginTop="7dp"
android:layout_marginBottom="@dimen/dp_10"
android:gravity="center"
@@ -166,13 +150,13 @@
android:layout_height="wrap_content"
android:background="@drawable/shape_bg_room_tag"
android:gravity="center"
android:visibility="gone"
android:paddingStart="6dp"
android:paddingTop="2dp"
android:paddingEnd="6dp"
android:paddingBottom="2dp"
android:paddingTop="2dp"
android:textColor="@color/appColor"
android:textSize="@dimen/sp_9"
android:visibility="gone"
tools:text="交友" />
<TextView
@@ -224,15 +208,15 @@
<LinearLayout
android:id="@+id/ll_charm_click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="@dimen/dp_5"
android:paddingBottom="@dimen/dp_5"
app:layout_constraintBottom_toBottomOf="@id/view_center_of_charm"
app:layout_constraintEnd_toEndOf="@id/view_center_of_charm"
app:layout_constraintStart_toStartOf="@id/view_center_of_charm"
app:layout_constraintTop_toTopOf="@id/view_center_of_charm"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
app:layout_constraintTop_toTopOf="@id/view_center_of_charm">
<LinearLayout
android:layout_width="wrap_content"
@@ -269,10 +253,10 @@
android:id="@+id/iv_red_package"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="15dp"
android:scaleType="centerInside"
android:src="@drawable/room_red_package_in"
android:visibility="gone"
android:layout_centerVertical="true"
tools:visibility="visible" />
</RelativeLayout>

View File

@@ -123,15 +123,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/micro_layout">
<include
android:id="@+id/in_official_mask"
layout="@layout/layout_official_mask"
android:layout_width="wrap_content"
android:layout_height="@dimen/dp_20"
android:layout_gravity="center"
android:layout_marginEnd="5.5dp"
android:visibility="visible" />
<LinearLayout
android:id="@+id/ll_nick"
android:layout_width="wrap_content"

View File

@@ -368,6 +368,6 @@ public class UriProvider {
* @return
*/
public static String getDatingRule() {
return JAVA_WEB_URL.concat("/accompany/modules/rules/dating-rule.html");
return JAVA_WEB_URL.concat("/accompany/modules/rule/dating.html");
}
}

View File

@@ -156,6 +156,7 @@ import com.yizhuan.xchat_android_core.team.bean.TeamInfo;
import com.yizhuan.xchat_android_core.user.UserModel;
import com.yizhuan.xchat_android_core.user.bean.BaseInfo;
import com.yizhuan.xchat_android_core.user.bean.UserInfo;
import com.yizhuan.xchat_android_core.utils.LogUtils;
import com.yizhuan.xchat_android_core.utils.SharedPreferenceUtils;
import com.yizhuan.xchat_android_core.utils.net.DontWarnObserver;
import com.yizhuan.xchat_android_library.net.rxnet.callback.CallBack;
@@ -1587,7 +1588,7 @@ public final class IMNetEaseManager {
// 1----房间信息更新 2-----麦序信息更新
// 3----更新房间信息和麦序信息(排麦模式)
int type = (int) extension.get("type");
LogUtil.print("chatRoomInfoUpdate type =" + type);
LogUtils.d("chatRoomInfoUpdate type =" + type);
if (type == 2) {
roomQueueMicUpdate(extension);
} else if (type == 1) {
@@ -1608,7 +1609,7 @@ public final class IMNetEaseManager {
private void roomInfoUpdate(Map<String, Object> extension) {
String roomInfoStr = (String) extension.get("roomInfo");
if (!TextUtils.isEmpty(roomInfoStr)) {
LogUtil.print(roomInfoStr);
LogUtils.d(roomInfoStr);
RoomInfo roomInfo = gson.fromJson(roomInfoStr, RoomInfo.class);
if (roomInfo != null) {
AvRoomDataManager.get().mCurrentRoomInfo = roomInfo;
@@ -1621,7 +1622,7 @@ public final class IMNetEaseManager {
ChatRoomQueueChangeAttachment roomQueueChangeAttachment = (ChatRoomQueueChangeAttachment) msg.getAttachment();
//麦上成员信息uid... key:坑位 content:{"nick":"行走的老者","uid":90972,"gender":1,"avatar":"https://image.zhongjialx.com/Fmtbprx5cGc3KABKjDxs_udJZb3O?imageslim"}
String content = roomQueueChangeAttachment.getContent();
LogUtil.print(content);
LogUtils.d(content);
String key = roomQueueChangeAttachment.getKey();
switch (roomQueueChangeAttachment.getChatRoomQueueChangeType()) {
case DROP:

View File

@@ -0,0 +1,124 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.yizhuan.xchat_android_core.utils;
import android.util.Log;
import com.yizhuan.xchat_android_core.BuildConfig;
import java.util.Locale;
public class LogUtils {
public static boolean DEBUG = BuildConfig.DEBUG;
private static final int INDEX = 4;
public LogUtils() {
}
private static String getPrefix() {
StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[4];
String className = stackTraceElement.getClassName();
int classNameStartIndex = className.lastIndexOf(".") + 1;
className = className.substring(classNameStartIndex);
String methodName = stackTraceElement.getMethodName();
int methodLine = stackTraceElement.getLineNumber();
String format = "%s-%s(L:%d)";
return String.format(Locale.CHINESE, format, className, methodName, methodLine);
}
public static void v(String content) {
if (DEBUG) {
Log.v(getPrefix(), content);
}
}
public static void v(String content, Throwable tr) {
if (DEBUG) {
Log.v(getPrefix(), content, tr);
}
}
public static void d(String content) {
if (DEBUG) {
Log.d(getPrefix(), content);
}
}
public static void d(String tag, String content) {
if (DEBUG) {
Log.d(tag, content);
}
}
public static void d(String content, Throwable tr) {
if (DEBUG) {
Log.d(getPrefix(), content, tr);
}
}
public static void i(String content) {
if (DEBUG) {
Log.i(getPrefix(), content);
}
}
public static void i(String content, Throwable tr) {
if (DEBUG) {
Log.i(getPrefix(), content, tr);
}
}
public static void w(String content) {
if (DEBUG) {
Log.e(getPrefix(), content);
}
}
public static void w(String content, Throwable tr) {
if (DEBUG) {
Log.w(getPrefix(), content, tr);
}
}
public static void e(String content) {
if (DEBUG) {
Log.e(getPrefix(), content);
}
}
public static void e(String content, Throwable tr) {
if (DEBUG) {
Log.e(getPrefix(), content, tr);
}
}
public static String showAllElementsInfo() {
String print = "";
int count = 0;
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
StackTraceElement[] var3 = stackTraceElements;
int var4 = stackTraceElements.length;
for(int var5 = 0; var5 < var4; ++var5) {
StackTraceElement stackTraceElement = var3[var5];
++count;
print = print + String.format("ClassName:%s \nMethodName:%s \nMethodLine:%d \n当前是第%d个 \n---------------------------- \n ", stackTraceElement.getClassName(), stackTraceElement.getMethodName(), stackTraceElement.getLineNumber(), count);
}
return print;
}
}