1.修改BUG
2.礼物添加一键全送功能 3.转盘修改底部按钮展示、音效和特效功能
This commit is contained in:
@@ -16,6 +16,7 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@@ -38,6 +39,7 @@ import androidx.databinding.ViewDataBinding;
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.blankj.utilcode.util.ActivityUtils;
|
||||
import com.blankj.utilcode.util.BarUtils;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo;
|
||||
import com.xscm.moduleutil.R;
|
||||
@@ -47,6 +49,7 @@ import com.xscm.moduleutil.event.MqttBean;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
import com.xscm.moduleutil.utils.BackgroundManager;
|
||||
import com.xscm.moduleutil.utils.ColorManager;
|
||||
import com.xscm.moduleutil.utils.DialogUtils;
|
||||
import com.xscm.moduleutil.utils.DisplayUtil;
|
||||
import com.xscm.moduleutil.utils.ImageUtils;
|
||||
import com.xscm.moduleutil.utils.LanguageUtil;
|
||||
@@ -279,6 +282,36 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
|
||||
// 清理MQTT相关资源
|
||||
synchronized (mqttQueueLock) {
|
||||
mqttMessageQueue.clear();
|
||||
isMqttPlaying = false;
|
||||
}
|
||||
|
||||
// 清理XLH相关资源
|
||||
synchronized (xlhQueueLock) {
|
||||
xlhMessageQueue.clear();
|
||||
isXlhPlaying = false;
|
||||
}
|
||||
|
||||
// 移除当前显示的视图
|
||||
try {
|
||||
if (currentMqttView != null && currentMqttView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentMqttView.getParent();
|
||||
parent.removeView(currentMqttView);
|
||||
}
|
||||
currentMqttView = null;
|
||||
|
||||
if (currentXlhView != null && currentXlhView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentXlhView.getParent();
|
||||
parent.removeView(currentXlhView);
|
||||
}
|
||||
currentXlhView = null;
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("清理飘屏视图失败", e);
|
||||
}
|
||||
|
||||
// 移除背景更新监听器
|
||||
BackgroundManager.getInstance().removeListener(this);
|
||||
// 移除颜色变化监听器
|
||||
@@ -289,6 +322,12 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
if (EventBus.getDefault().isRegistered(this)) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
try {
|
||||
unregisterReceiver(mLogoutReceiver);
|
||||
} catch (Exception e) {
|
||||
// 忽略异常
|
||||
}
|
||||
|
||||
try {
|
||||
unregisterReceiver(mLogoutReceiver);
|
||||
} catch (Exception e) {
|
||||
@@ -363,164 +402,255 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
// 在类中添加以下成员变量
|
||||
private final List<MqttBean> messageQueue = new ArrayList<>(); // 消息队列
|
||||
private boolean isPlaying = false; // 播放状态标志
|
||||
private boolean isPlaying2 = false; // 播放状态标志
|
||||
private final Object queueLock = new Object(); // 队列同步锁
|
||||
|
||||
/// 礼物特效
|
||||
// 在类中添加以下成员变量
|
||||
private final List<MqttBean> mqttMessageQueue = new ArrayList<>(); // MQTT消息队列
|
||||
private final List<XLHBean> xlhMessageQueue = new ArrayList<>(); // XLH消息队列
|
||||
private boolean isMqttPlaying = false; // MQTT播放状态标志
|
||||
private boolean isXlhPlaying = false; // XLH播放状态标志
|
||||
private final Object mqttQueueLock = new Object(); // MQTT队列同步锁
|
||||
private final Object xlhQueueLock = new Object(); // XLH队列同步锁
|
||||
private View currentMqttView = null; // 当前正在播放的MQTT视图
|
||||
private View currentXlhView = null; // 当前正在播放的XLH视图
|
||||
|
||||
/// 礼物特效 - MQTT消息处理
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageReceived(MqttBean mqttBean) {
|
||||
if (mqttBean == null) {
|
||||
return;
|
||||
}
|
||||
LogUtils.e("收到MQTT", mqttBean);
|
||||
if (mqttBean == null) return;
|
||||
|
||||
// 将消息添加到队列
|
||||
synchronized (queueLock) {
|
||||
messageQueue.add(mqttBean);
|
||||
synchronized (mqttQueueLock) {
|
||||
mqttMessageQueue.add(mqttBean);
|
||||
if (!isMqttPlaying) {
|
||||
isMqttPlaying = true;
|
||||
processNextMqttMessage();
|
||||
}
|
||||
}
|
||||
// 尝试播放下一个消息
|
||||
processNextMessage();
|
||||
|
||||
}
|
||||
|
||||
/// XLH消息处理
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEvent(XLHBean event) {
|
||||
LogUtils.e("收到XLH", event);
|
||||
if (event == null) return;
|
||||
|
||||
private void processNextMessage() {
|
||||
synchronized (queueLock) {
|
||||
// 如果正在播放或队列为空,则不处理
|
||||
if (isPlaying || messageQueue.isEmpty()) {
|
||||
synchronized (xlhQueueLock) {
|
||||
xlhMessageQueue.add(event);
|
||||
if (!isXlhPlaying) {
|
||||
isXlhPlaying = true;
|
||||
processNextXlhMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理下一个MQTT消息
|
||||
private void processNextMqttMessage() {
|
||||
MqttBean mqttBean;
|
||||
synchronized (mqttQueueLock) {
|
||||
if (mqttMessageQueue.isEmpty()) {
|
||||
isMqttPlaying = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// 标记为正在播放
|
||||
isPlaying = true;
|
||||
mqttBean = mqttMessageQueue.remove(0);
|
||||
}
|
||||
|
||||
MqttBean mqttBean;
|
||||
synchronized (queueLock) {
|
||||
mqttBean = messageQueue.remove(0); // 取出队列中的第一个消息
|
||||
}
|
||||
|
||||
// 显示飘屏消息
|
||||
showFloatingMessage(mqttBean);
|
||||
}
|
||||
|
||||
|
||||
private void showFloatingMessage(MqttBean mqttBean) {
|
||||
ViewGroup decorView = (ViewGroup) this.getWindow().getDecorView();
|
||||
// 如果浮动视图未创建,则创建一次
|
||||
View floatingView = LayoutInflater.from(this).inflate(R.layout.item_piaoping, null);
|
||||
|
||||
// 设置布局参数
|
||||
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
layoutParams.topMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 70);
|
||||
layoutParams.gravity = android.view.Gravity.TOP | android.view.Gravity.CENTER_HORIZONTAL;
|
||||
floatingView.setLayoutParams(layoutParams);
|
||||
|
||||
// 初始化动画监听器
|
||||
setupAnimationListener(floatingView, decorView);
|
||||
|
||||
// 更新视图数据
|
||||
updateFloatingViewData(floatingView, mqttBean);
|
||||
|
||||
// 如果浮动视图未添加到 decorView,则添加
|
||||
decorView.addView(floatingView);
|
||||
|
||||
// 重置视图位置并开始动画
|
||||
resetAndStartAnimation(floatingView);
|
||||
// 处理下一个XLH消息
|
||||
private void processNextXlhMessage() {
|
||||
XLHBean xlhBean;
|
||||
synchronized (xlhQueueLock) {
|
||||
if (xlhMessageQueue.isEmpty()) {
|
||||
isXlhPlaying = false;
|
||||
return;
|
||||
}
|
||||
xlhBean = xlhMessageQueue.remove(0);
|
||||
}
|
||||
showPiaoPingMessageXlh(xlhBean);
|
||||
}
|
||||
|
||||
private void setupAnimationListener(View floatingView, ViewGroup decorView) {
|
||||
// 为视图添加一个全局布局监听器,确保在视图完全加载后再设置动画
|
||||
floatingView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
// 移除监听器,避免重复调用
|
||||
floatingView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
ViewGroup decorView;
|
||||
ViewGroup decorView1;
|
||||
|
||||
// 确保初始位置在屏幕右侧外部
|
||||
floatingView.setTranslationX(floatingView.getWidth());
|
||||
private void showFloatingMessage(MqttBean mqttBean) {
|
||||
try {
|
||||
// 清理之前的视图(如果存在)
|
||||
if (currentMqttView != null && currentMqttView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentMqttView.getParent();
|
||||
parent.removeView(currentMqttView);
|
||||
}
|
||||
|
||||
// 第一阶段:从右到屏幕右侧边缘(缓慢进入)
|
||||
ObjectAnimator animator1 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
floatingView.getWidth(), 0f);
|
||||
animator1.setDuration(1500); // 延长动画时间到1.5秒
|
||||
animator1.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
|
||||
animator1.start();
|
||||
if (decorView == null) {
|
||||
decorView = (ViewGroup) getWindow().getDecorView();
|
||||
}
|
||||
|
||||
// 第二阶段:延迟1秒后从当前位置向左滑出
|
||||
floatingView.postDelayed(() -> {
|
||||
ObjectAnimator animator2 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
0f, -floatingView.getWidth());
|
||||
animator2.setDuration(1500); // 延长动画时间到1.5秒
|
||||
animator2.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
|
||||
currentMqttView = LayoutInflater.from(this).inflate(R.layout.item_piaoping, null);
|
||||
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
layoutParams.topMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 70);
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
||||
currentMqttView.setLayoutParams(layoutParams);
|
||||
decorView.addView(currentMqttView);
|
||||
|
||||
updateFloatingViewData(currentMqttView, mqttBean);
|
||||
resetAndStartMqttAnimation(currentMqttView, () -> {
|
||||
// 清理当前视图
|
||||
if (currentMqttView != null && currentMqttView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentMqttView.getParent();
|
||||
parent.removeView(currentMqttView);
|
||||
}
|
||||
currentMqttView = null;
|
||||
|
||||
// 处理队列中的下一条消息
|
||||
synchronized (mqttQueueLock) {
|
||||
isMqttPlaying = false;
|
||||
processNextMqttMessage();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("显示MQTT飘屏失败", e);
|
||||
// 出现异常时继续处理队列
|
||||
synchronized (mqttQueueLock) {
|
||||
isMqttPlaying = false;
|
||||
processNextMqttMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showPiaoPingMessageXlh(XLHBean event) {
|
||||
try {
|
||||
// 清理之前的视图(如果存在)
|
||||
if (currentXlhView != null && currentXlhView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentXlhView.getParent();
|
||||
parent.removeView(currentXlhView);
|
||||
}
|
||||
|
||||
if (decorView1 == null) {
|
||||
decorView1 = (ViewGroup) getWindow().getDecorView();
|
||||
}
|
||||
|
||||
currentXlhView = LayoutInflater.from(this).inflate(R.layout.item_piaoping_xlh, null);
|
||||
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
layoutParams.topMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 100);
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
||||
currentXlhView.setLayoutParams(layoutParams);
|
||||
decorView1.addView(currentXlhView);
|
||||
|
||||
updateXlhFloatingViewData(currentXlhView, event);
|
||||
resetAndStartXlhAnimation(currentXlhView, () -> {
|
||||
// 清理当前视图
|
||||
if (currentXlhView != null && currentXlhView.getParent() != null) {
|
||||
ViewGroup parent = (ViewGroup) currentXlhView.getParent();
|
||||
parent.removeView(currentXlhView);
|
||||
}
|
||||
currentXlhView = null;
|
||||
|
||||
// 处理队列中的下一条消息
|
||||
synchronized (xlhQueueLock) {
|
||||
isXlhPlaying = false;
|
||||
processNextXlhMessage();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("显示XLH飘屏失败", e);
|
||||
// 出现异常时继续处理队列
|
||||
synchronized (xlhQueueLock) {
|
||||
isXlhPlaying = false;
|
||||
processNextXlhMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resetAndStartMqttAnimation(View view, Runnable onAnimationEnd) {
|
||||
try {
|
||||
view.setTranslationX(view.getWidth());
|
||||
ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "translationX", view.getWidth(), 0f);
|
||||
animator1.setDuration(1500);
|
||||
animator1.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
animator1.start();
|
||||
|
||||
view.postDelayed(() -> {
|
||||
try {
|
||||
ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "translationX", 0f, -view.getWidth());
|
||||
animator2.setDuration(1500);
|
||||
animator2.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
animator2.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
// 动画结束后移除悬浮窗
|
||||
decorView.removeView(floatingView);
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
|
||||
// 标记播放结束并处理下一个消息
|
||||
synchronized (queueLock) {
|
||||
isPlaying = false;
|
||||
}
|
||||
processNextMessage();
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
});
|
||||
animator2.start();
|
||||
}, 3000); // 停留1秒
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("MQTT动画执行失败", e);
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
}, 3000);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("MQTT动画启动失败", e);
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
}
|
||||
|
||||
private void resetAndStartAnimation(View floatingView) {
|
||||
// 重置视图位置并开始动画
|
||||
floatingView.setTranslationX(floatingView.getWidth());
|
||||
private void resetAndStartXlhAnimation(View view, Runnable onAnimationEnd) {
|
||||
try {
|
||||
view.setTranslationX(view.getWidth());
|
||||
ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "translationX", view.getWidth(), 0f);
|
||||
animator1.setDuration(1500);
|
||||
animator1.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
animator1.start();
|
||||
|
||||
// 第一阶段:从右到屏幕右侧边缘(缓慢进入)
|
||||
ObjectAnimator animator1 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
floatingView.getWidth(), 0f);
|
||||
animator1.setDuration(1500);
|
||||
animator1.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
animator1.start();
|
||||
view.postDelayed(() -> {
|
||||
try {
|
||||
ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "translationX", 0f, -view.getWidth());
|
||||
animator2.setDuration(1500);
|
||||
animator2.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
animator2.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
|
||||
// 第二阶段:延迟1秒后从当前位置向左滑出
|
||||
floatingView.postDelayed(() -> {
|
||||
ObjectAnimator animator2 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
0f, -floatingView.getWidth());
|
||||
animator2.setDuration(1500);
|
||||
animator2.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
animator2.start();
|
||||
}, 3000);
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
});
|
||||
animator2.start();
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("XLH动画执行失败", e);
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
}, 3000);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("XLH动画启动失败", e);
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateFloatingViewData(View floatingView, MqttBean mqttBean) {
|
||||
TextView textView = floatingView.findViewById(R.id.tv_name);
|
||||
TextView textView2 = floatingView.findViewById(R.id.tv_to_name);
|
||||
TextView tv_time = floatingView.findViewById(R.id.tv_num);
|
||||
private void updateFloatingViewData(View view, MqttBean mqttBean) {
|
||||
TextView textView = view.findViewById(R.id.tv_name);
|
||||
TextView textView2 = view.findViewById(R.id.tv_to_name);
|
||||
TextView tv_time = view.findViewById(R.id.tv_num);
|
||||
|
||||
if (mqttBean.getList() != null) {
|
||||
if (mqttBean.getList().getToUserName() != null) {
|
||||
textView2.setText("送给" + mqttBean.getList().getToUserName());
|
||||
} else {
|
||||
textView2.setText("送给");
|
||||
}
|
||||
|
||||
if (mqttBean.getList().getFromUserName() != null) {
|
||||
textView.setText(mqttBean.getList().getFromUserName());
|
||||
} else {
|
||||
textView.setText("");
|
||||
}
|
||||
|
||||
textView2.setText("送给" + (mqttBean.getList().getToUserName() != null ? mqttBean.getList().getToUserName() : ""));
|
||||
textView.setText(mqttBean.getList().getFromUserName() != null ? mqttBean.getList().getFromUserName() : "");
|
||||
if (mqttBean.getList().getGift_picture() != null) {
|
||||
ImageUtils.loadHeadCC(mqttBean.getList().getGift_picture(), floatingView.findViewById(R.id.iv_piaoping));
|
||||
}
|
||||
|
||||
if (mqttBean.getList().getNumber() != null) {
|
||||
tv_time.setText("x" + mqttBean.getList().getNumber());
|
||||
} else {
|
||||
tv_time.setText("x1");
|
||||
ImageUtils.loadHeadCC(mqttBean.getList().getGift_picture(), view.findViewById(R.id.iv_piaoping));
|
||||
}
|
||||
tv_time.setText("x" + (mqttBean.getList().getNumber() != null ? mqttBean.getList().getNumber() : "1"));
|
||||
} else {
|
||||
textView2.setText("送给");
|
||||
textView.setText("");
|
||||
@@ -528,207 +658,34 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
}
|
||||
}
|
||||
|
||||
// private void showFloatingMessage(MqttBean mqttBean) {
|
||||
// ViewGroup decorView = (ViewGroup) this.getWindow().getDecorView();
|
||||
// View floatingView = LayoutInflater.from(this).inflate(R.layout.item_piaoping, null);
|
||||
//
|
||||
// // 设置布局参数,使整个布局显示在屏幕顶部并距离顶部100dp
|
||||
// FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
|
||||
// FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
// FrameLayout.LayoutParams.WRAP_CONTENT
|
||||
// );
|
||||
// layoutParams.topMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 100); // 距离顶部100dp
|
||||
// layoutParams.gravity = android.view.Gravity.TOP | android.view.Gravity.CENTER_HORIZONTAL; // 顶部居中
|
||||
// floatingView.setLayoutParams(layoutParams);
|
||||
//
|
||||
// TextView textView = floatingView.findViewById(R.id.tv_name);
|
||||
// TextView textView2 = floatingView.findViewById(R.id.tv_to_name);
|
||||
// TextView tv_time = floatingView.findViewById(R.id.tv_num);
|
||||
//
|
||||
// // 添加对 getList() 返回值的空值检查
|
||||
// if (mqttBean.getList() != null) {
|
||||
// // 检查各个字段是否为 null
|
||||
// if (mqttBean.getList().getToUserName() != null) {
|
||||
// textView2.setText("送给" + mqttBean.getList().getToUserName());
|
||||
// } else {
|
||||
// textView2.setText("送给");
|
||||
// }
|
||||
//
|
||||
// if (mqttBean.getList().getFromUserName() != null) {
|
||||
// textView.setText(mqttBean.getList().getFromUserName());
|
||||
// } else {
|
||||
// textView.setText("");
|
||||
// }
|
||||
//
|
||||
// // 检查礼物图片
|
||||
// if (mqttBean.getList().getGift_picture() != null) {
|
||||
// ImageUtils.loadHeadCC(mqttBean.getList().getGift_picture(), floatingView.findViewById(R.id.iv_piaoping));
|
||||
// }
|
||||
//
|
||||
// // 检查数量
|
||||
// if (mqttBean.getList().getNumber() != null) {
|
||||
// tv_time.setText("x" + mqttBean.getList().getNumber());
|
||||
// } else {
|
||||
// tv_time.setText("x1");
|
||||
// }
|
||||
// } else {
|
||||
// // 如果 getList() 返回 null,设置默认值
|
||||
// textView2.setText("送给");
|
||||
// textView.setText("");
|
||||
// tv_time.setText("x1");
|
||||
// }
|
||||
//
|
||||
// floatingView.setTranslationX(10000); // 先放到屏幕外
|
||||
//
|
||||
// floatingView.post(() -> {
|
||||
// // 确保初始位置在屏幕右侧外部
|
||||
// floatingView.setTranslationX(floatingView.getWidth());
|
||||
//
|
||||
// // 第一阶段:从右到屏幕右侧边缘(缓慢进入)
|
||||
// ObjectAnimator animator1 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
// floatingView.getWidth(), 0f);
|
||||
// animator1.setDuration(1500); // 延长动画时间到1.5秒
|
||||
// animator1.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
|
||||
// animator1.start();
|
||||
//
|
||||
// // 第二阶段:延迟1秒后从当前位置向左滑出
|
||||
// floatingView.postDelayed(() -> {
|
||||
// ObjectAnimator animator2 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
// 0f, -floatingView.getWidth());
|
||||
// animator2.setDuration(1500); // 延长动画时间到1.5秒
|
||||
// animator2.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
|
||||
// animator2.addListener(new AnimatorListenerAdapter() {
|
||||
// @Override
|
||||
// public void onAnimationEnd(Animator animation) {
|
||||
// // 动画结束后移除悬浮窗
|
||||
// decorView.removeView(floatingView);
|
||||
//
|
||||
// // 标记播放结束并处理下一个消息
|
||||
// synchronized (queueLock) {
|
||||
// isPlaying = false;
|
||||
// }
|
||||
// processNextMessage();
|
||||
// }
|
||||
// });
|
||||
// animator2.start();
|
||||
// }, 3000); // 停留1秒
|
||||
// });
|
||||
// decorView.addView(floatingView);
|
||||
// }
|
||||
|
||||
|
||||
// 在类中添加新的成员变量
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEvent(XLHBean event) {
|
||||
showPiaoPingMessageXlh(event);
|
||||
}
|
||||
|
||||
private void showPiaoPingMessageXlh(XLHBean event) {
|
||||
// 创建 FloatingX 配置
|
||||
ViewGroup decorView = (ViewGroup) this.getWindow().getDecorView();
|
||||
|
||||
// 如果XLH浮动视图未创建,则创建一次
|
||||
View xlhFloatingView = LayoutInflater.from(this).inflate(R.layout.item_piaoping_xlh, null);
|
||||
|
||||
// 设置布局参数
|
||||
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
layoutParams.topMargin = com.sunfusheng.marqueeview.DisplayUtil.dip2px(this, 100);
|
||||
layoutParams.gravity = android.view.Gravity.TOP | android.view.Gravity.CENTER_HORIZONTAL;
|
||||
xlhFloatingView.setLayoutParams(layoutParams);
|
||||
|
||||
// 初始化动画监听器
|
||||
setupXlhAnimationListener(xlhFloatingView, decorView);
|
||||
updateXlhFloatingViewData(xlhFloatingView, event);
|
||||
|
||||
// 如果浮动视图未添加到 decorView,则添加
|
||||
decorView.addView(xlhFloatingView);
|
||||
|
||||
// 重置视图位置并开始动画
|
||||
resetAndStartXlhAnimation(xlhFloatingView);
|
||||
}
|
||||
|
||||
private void setupXlhAnimationListener(View floatingView, ViewGroup decorView) {
|
||||
// 为视图添加一个全局布局监听器,确保在视图完全加载后再设置动画
|
||||
floatingView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
// 移除监听器,避免重复调用
|
||||
floatingView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
|
||||
// 确保初始位置在屏幕右侧外部
|
||||
floatingView.setTranslationX(floatingView.getWidth());
|
||||
|
||||
// 第一阶段:从右到屏幕右侧边缘(缓慢进入)
|
||||
ObjectAnimator animator1 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
floatingView.getWidth(), 0f);
|
||||
animator1.setDuration(1500); // 延长动画时间到1.5秒
|
||||
animator1.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
|
||||
animator1.start();
|
||||
|
||||
// 第二阶段:延迟1秒后从当前位置向左滑出
|
||||
floatingView.postDelayed(() -> {
|
||||
ObjectAnimator animator2 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
0f, -floatingView.getWidth());
|
||||
animator2.setDuration(1500); // 延长动画时间到1.5秒
|
||||
animator2.setInterpolator(new DecelerateInterpolator(2.0f)); // 更平缓的减速效果
|
||||
animator2.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
// 动画结束后移除悬浮窗
|
||||
decorView.removeView(floatingView);
|
||||
|
||||
// 标记播放结束并处理下一个消息
|
||||
synchronized (queueLock) {
|
||||
isPlaying = false;
|
||||
}
|
||||
processNextMessage();
|
||||
}
|
||||
});
|
||||
animator2.start();
|
||||
}, 3000); // 停留1秒
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void resetAndStartXlhAnimation(View floatingView) {
|
||||
// 重置视图位置并开始动画
|
||||
floatingView.setTranslationX(floatingView.getWidth());
|
||||
|
||||
// 第一阶段:从右到屏幕右侧边缘(缓慢进入)
|
||||
ObjectAnimator animator1 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
floatingView.getWidth(), 0f);
|
||||
animator1.setDuration(1500);
|
||||
animator1.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
animator1.start();
|
||||
|
||||
// 第二阶段:延迟1秒后从当前位置向左滑出
|
||||
floatingView.postDelayed(() -> {
|
||||
ObjectAnimator animator2 = ObjectAnimator.ofFloat(floatingView, "translationX",
|
||||
0f, -floatingView.getWidth());
|
||||
animator2.setDuration(1500);
|
||||
animator2.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
animator2.start();
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
private void updateXlhFloatingViewData(View xlhFloatingView, XLHBean xlhBean) {
|
||||
TextView textView = xlhFloatingView.findViewById(R.id.tv_name);
|
||||
ImageView xlh_image = xlhFloatingView.findViewById(R.id.im_xlh);
|
||||
private void updateXlhFloatingViewData(View view, XLHBean xlhBean) {
|
||||
TextView textView = view.findViewById(R.id.tv_name);
|
||||
ImageView xlh_image = view.findViewById(R.id.im_xlh);
|
||||
|
||||
if (xlhBean != null) {
|
||||
xlh_image.setImageDrawable(xlhBean.getFrom_type() == 1 ? getResources().getDrawable(R.mipmap.xlh_jjks) : getResources().getDrawable(R.mipmap.xlh_zsks));
|
||||
|
||||
xlh_image.setImageDrawable(xlhBean.getFrom_type() == 1 ?
|
||||
getResources().getDrawable(R.mipmap.xlh_jjks) :
|
||||
getResources().getDrawable(R.mipmap.xlh_zsks));
|
||||
textView.setText(xlhBean.getText());
|
||||
|
||||
} else {
|
||||
textView.setText("");
|
||||
}
|
||||
|
||||
view.setOnClickListener(v -> {
|
||||
// 点击时执行跳转操作
|
||||
handleItemClick(xlhBean);
|
||||
});
|
||||
}
|
||||
|
||||
private void handleItemClick(XLHBean xlhBean) {
|
||||
// 这里可以根据实际需求实现跳转逻辑
|
||||
// 例如:跳转到礼物详情页面、用户主页等
|
||||
|
||||
ARouter.getInstance().build(ARouteConstants.ROOM_DETAILS).withString("from", "我的界面").withString("roomId", xlhBean.getRoom_id()).navigation();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEvent(ChatInfo event) {
|
||||
String id = event.getId().replace("g", "");
|
||||
|
||||
Reference in New Issue
Block a user