添加了盲盒转盘抽奖功能

修改交友房中开始后,不能点击头像送礼的问题
This commit is contained in:
2025-08-27 19:58:05 +08:00
parent 994d98b515
commit 0b128f3d72
27 changed files with 1333 additions and 137 deletions

View File

@@ -103,9 +103,33 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
} else {
isPlaying = false;
// playNextFromQueue(); // 播放下一项
// 播放完成后立即清理当前资源
clearCurrentResource();
mainHandler.postDelayed(this::playNextFromQueue, 50);
}
}
private void clearCurrentResource() {
// 清理当前播放的文件引用
// mFile = null;
// 清理SVGA资源
if (svgaSurface != null) {
svgaSurface.stopAnimation();
svgaSurface.clearAnimation();
svgaSurface.setImageDrawable(null);
}
// 清理MP4资源
if (exoPlayer != null) {
exoPlayer.stop();
exoPlayer.clearVideoSurface();
}
if (mBinding != null && mBinding.playView != null) {
mBinding.playView.stopPlay();
}
}
@Override
public void onVideoDestroy() {

View File

@@ -374,6 +374,8 @@ public class Constants {
public static final String DELAY = "/api/Friend/delay";//点击延时 交友房
public static final String END_FRIEND = "/api/Friend/end_friend";//点击结束 交友房
public static final String CREATE_RELATION = "/api/Friend/create_relation";//卡关系 (创建关系) 交友房
public static final String GET_BOX_GIFT_LIST = "/api/BlindBoxTurntable/get_gift_list";//获取活动礼物列表
public static final String POST_DRAW_GIFT_LIST = "/api/BlindBoxTurntable/draw_gift";//盲盒转盘抽奖

View File

@@ -0,0 +1,291 @@
package com.xscm.moduleutil.widget;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import com.google.android.material.card.MaterialCardView;
import com.xscm.moduleutil.R;
import com.xscm.moduleutil.bean.GiftBean;
import com.xscm.moduleutil.utils.ImageUtils;
/**
* 礼物卡片控件 - 支持选中效果和自定义样式
*/
public class GiftCardView extends FrameLayout {
private ImageView mIconImageView;
private TextView mNameTextView;
private TextView mCountTextView;
private TextView mResultTextView;
private boolean isSelected = false;
private Drawable selectedBackground;
private Drawable normalBackground;
// 添加GiftBean数据引用
private GiftBean giftBean;
private ObjectAnimator pulseAnimator;
public GiftCardView(Context context) {
this(context, null);
}
public GiftCardView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public GiftCardView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initViews();
initAttributes(attrs);
}
private void initViews() {
LayoutInflater.from(getContext()).inflate(R.layout.view_gift_card, this, true);
mIconImageView = findViewById(R.id.img_gift_icon);
mNameTextView = findViewById(R.id.tv_gift_name);
mCountTextView = findViewById(R.id.tv_gift_count);
mResultTextView= findViewById(R.id.result);
// 设置默认点击事件
setOnClickListener(v -> {
if (getOnGiftClickListener() != null) {
getOnGiftClickListener().onGiftClick(this);
}
});
}
private void initAttributes(AttributeSet attrs) {
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.GiftCardView);
try {
// 获取自定义属性
String name = typedArray.getString(R.styleable.GiftCardView_giftName);
String count = typedArray.getString(R.styleable.GiftCardView_giftCount);
int iconResId = typedArray.getResourceId(R.styleable.GiftCardView_giftIcon, 0);
// 设置默认值
if (name != null) {
setName(name);
}
if (count != null) {
setCount(count);
}
if (iconResId != 0) {
setIcon("");
}
// 获取选中状态相关属性
selectedBackground = typedArray.getDrawable(R.styleable.GiftCardView_selectedBackground);
normalBackground = typedArray.getDrawable(R.styleable.GiftCardView_normalBackground);
// 如果没有设置选中背景,则使用默认的选中效果
if (selectedBackground == null) {
selectedBackground = ContextCompat.getDrawable(getContext(), R.mipmap.tkzj_x);
}
if (normalBackground == null) {
normalBackground = ContextCompat.getDrawable(getContext(), R.mipmap.tkzj_w);
}
// 设置默认背景
if (normalBackground != null) {
setBackground(normalBackground);
}
} finally {
typedArray.recycle();
}
}
/**
* 绑定GiftBean数据
*/
public void bindGiftData(GiftBean giftBean) {
this.giftBean = giftBean;
if (giftBean != null) {
// 设置礼物图标
if (giftBean.getBase_image() != null && !giftBean.getBase_image().isEmpty()) {
setIcon(giftBean.getBase_image());
// 如果是资源ID
} else {
setIcon("");
}
// 设置礼物名称
setName(giftBean.getGift_name() != null ? giftBean.getGift_name() : "未知礼物");
// 设置礼物数量
setCount(giftBean.getGift_price() != null ? giftBean.getGift_price() : "0");
setmResultTextView(giftBean.getNumber());
}
}
/**
* 获取绑定的GiftBean数据
*/
public GiftBean getGiftBean() {
return giftBean;
}
/**
* 设置礼物图标URL
*/
public void setIcon(String url) {
if (mIconImageView != null) {
if (url != null && !url.isEmpty()) {
ImageUtils.loadHeadCC(url, mIconImageView);
} else {
mIconImageView.setImageResource(R.mipmap.ic_launcher);
}
}
}
public void startPulseAnimationWithLayer() {
if (pulseAnimator != null && pulseAnimator.isRunning()) {
pulseAnimator.cancel();
}
pulseAnimator = ObjectAnimator.ofFloat(this, "scaleX", 0.9f, 1.1f);
pulseAnimator.setDuration(500);
pulseAnimator.setRepeatCount(ObjectAnimator.INFINITE);
pulseAnimator.setRepeatMode(ObjectAnimator.REVERSE);
ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(this, "scaleY", 0.9f, 1.1f);
scaleYAnimator.setDuration(500);
scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);
scaleYAnimator.setRepeatMode(ObjectAnimator.REVERSE);
// 组合动画
android.animation.AnimatorSet animatorSet = new android.animation.AnimatorSet();
animatorSet.playTogether(pulseAnimator, scaleYAnimator);
animatorSet.start();
}
public void stopPulseAnimationWithLayer() {
if (pulseAnimator != null) {
pulseAnimator.cancel();
}
this.setScaleX(1f);
this.setScaleY(1f);
}
/**
* 设置礼物名称
*/
public void setName(String name) {
if (mNameTextView != null) {
mNameTextView.setText(name);
}
}
/**
* 设置礼物数量
*/
public void setCount(String count) {
if (mCountTextView != null) {
mCountTextView.setText(count);
}
}
/**
* 设置选中状态
*/
public void setSelected(boolean selected) {
isSelected = selected;
if (selected) {
setBackground(selectedBackground);
// 可以添加额外的选中效果
setElevation(8f); // 提高阴影
// 添加发光效果
addGlowEffect();
} else {
setBackground(normalBackground);
setElevation(4f); // 恢复默认阴影
removeGlowEffect();
}
}
public void setmResultTextView(int num){
if (mResultTextView!=null) {
mResultTextView.setText("X" + num);
}
}
public void setVisibilitymResultTextView(boolean isVisible){
if (mResultTextView!=null) {
mResultTextView.setVisibility(isVisible?View.VISIBLE:View.GONE);
}
}
/**
* 添加发光效果
*/
private void addGlowEffect() {
// 使用LayerDrawable创建发光效果
GradientDrawable glow = new GradientDrawable();
glow.setColor(Color.TRANSPARENT);
glow.setStroke(8, Color.argb(150, 255, 255, 255));
glow.setCornerRadius(16f);
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{glow, getBackground()});
setBackground(layerDrawable);
}
/**
* 移除发光效果
*/
private void removeGlowEffect() {
setBackground(normalBackground);
}
/**
* 获取当前是否选中
*/
public boolean isSelected() {
return isSelected;
}
/**
* 切换选中状态
*/
public void toggleSelected() {
setSelected(!isSelected);
}
/**
* 设置点击监听器
*/
public void setOnGiftClickListener(OnGiftClickListener listener) {
this.onGiftClickListener = listener;
}
/**
* 获取点击监听器
*/
public OnGiftClickListener getOnGiftClickListener() {
return onGiftClickListener;
}
/**
* 点击监听器接口
*/
public interface OnGiftClickListener {
void onGiftClick(GiftCardView giftCardView);
}
private OnGiftClickListener onGiftClickListener;
}