修改BUG
修改飘屏,飘屏不合适
This commit is contained in:
@@ -1,18 +1,26 @@
|
||||
package com.xscm.moduleutil.activity;
|
||||
|
||||
import static androidx.core.content.ContextCompat.getSystemService;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.databinding.DataBindingUtil;
|
||||
import androidx.databinding.ViewDataBinding;
|
||||
@@ -20,6 +28,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.hjq.toast.ToastUtils;
|
||||
import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.base.CommonAppContext;
|
||||
@@ -29,6 +38,7 @@ import com.xscm.moduleutil.utils.ColorManager;
|
||||
import com.xscm.moduleutil.utils.DisplayUtil;
|
||||
import com.xscm.moduleutil.utils.LanguageUtil;
|
||||
import com.xscm.moduleutil.utils.SpUtil;
|
||||
import com.xscm.moduleutil.widget.PiaoPingManager;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
@@ -72,7 +82,7 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
|
||||
ActivityUtils.finishAllActivities();
|
||||
}
|
||||
|
||||
private PiaoPingManager piaoPingManager;
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -126,6 +136,44 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
// | View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
// | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
|
||||
|
||||
// if (piaoPingManager==null){
|
||||
// piaoPingManager = PiaoPingManager.getInstance(this);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
// 在Activity中
|
||||
private static final int REQUEST_OVERLAY_PERMISSION = 1001;
|
||||
|
||||
private void checkAndRequestOverlayPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (!Settings.canDrawOverlays(this)) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("需要悬浮窗权限")
|
||||
.setMessage("应用需要悬浮窗权限才能显示飘屏效果")
|
||||
.setPositiveButton("去设置", (dialog, which) -> {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||
Uri.parse("package:" + getPackageName()));
|
||||
startActivityForResult(intent, REQUEST_OVERLAY_PERMISSION);
|
||||
})
|
||||
.setNegativeButton("取消", null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_OVERLAY_PERMISSION) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (Settings.canDrawOverlays(this)) {
|
||||
ToastUtils.show("已获得悬浮窗权限");
|
||||
} else {
|
||||
ToastUtils.show("未获得悬浮窗权限");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void finishAll() {
|
||||
|
||||
@@ -121,7 +121,7 @@ public class GiftPackAdapter extends BaseAdapter {
|
||||
viewHolder.item_layout = (ConstraintLayout) convertView.findViewById(R.id.cl_gift);
|
||||
viewHolder.ivDownOn = (ImageView) convertView.findViewById(R.id.iv_down_on);
|
||||
viewHolder.cl_iv_down_on = (ConstraintLayout) convertView.findViewById(R.id.cl_iv_down_on);
|
||||
|
||||
viewHolder.integral = (TextView) convertView.findViewById(R.id.integral);
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
viewHolder = (GiftPackAdapter.ViewHolder) convertView.getTag();
|
||||
@@ -129,10 +129,11 @@ public class GiftPackAdapter extends BaseAdapter {
|
||||
|
||||
viewHolder.item_layout.setOnClickListener(v -> {
|
||||
// RoonGiftModel clickedModel = (RoonGiftModel) v.getTag();
|
||||
EventBus.getDefault().post(new RoomGiftPackToEvent(this, giftModel, 1));
|
||||
EventBus.getDefault().post(new RoomGiftPackToEvent(this, giftModel, 2));
|
||||
|
||||
});
|
||||
|
||||
viewHolder.integral.setVisibility(View.VISIBLE);
|
||||
viewHolder.integral.setText("x"+giftModel.getNum());
|
||||
//设置礼物名字
|
||||
viewHolder.tv_gift_name.setText(giftModel.getGift_name());
|
||||
//设置礼物价格
|
||||
@@ -162,7 +163,7 @@ public class GiftPackAdapter extends BaseAdapter {
|
||||
|
||||
static class ViewHolder {
|
||||
public ConstraintLayout item_layout;
|
||||
public TextView tv_gift_name, tv_gift_price, tv_gift_num;
|
||||
public TextView tv_gift_name, tv_gift_price, integral;
|
||||
public ImageView iv_gift_pic;
|
||||
public TextView tv_gift_change_love_values;
|
||||
public ImageView ivDownOn;
|
||||
|
||||
@@ -158,7 +158,7 @@ public class GiftTwoAdapter extends BaseAdapter {
|
||||
viewHolder.ivDownOn.setVisibility(View.GONE);
|
||||
viewHolder.cl_iv_down_on.setBackgroundResource(0);
|
||||
}
|
||||
viewHolder.tv_gift_num.setText(String.format("x%s", giftModel.getNum()));
|
||||
viewHolder.tv_gift_num.setText(String.format("x%s", (giftModel.getNum()!=0?giftModel.getNum():"1")));
|
||||
|
||||
|
||||
//设置
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.xscm.moduleutil.base;
|
||||
|
||||
import static androidx.core.app.ActivityCompat.startActivityForResult;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Application;
|
||||
@@ -8,9 +10,11 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.Signature;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.util.Base64;
|
||||
import android.webkit.WebView;
|
||||
|
||||
@@ -95,7 +99,7 @@ public class CommonAppContext extends MultiDexApplication {
|
||||
EnvironmentPrefs prefs = new EnvironmentPrefs(this);
|
||||
currentEnvironment = prefs.getSelectedEnvironment();
|
||||
initialization();
|
||||
piaoPingManager = PiaoPingManager.getInstance(this);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -126,11 +130,20 @@ public class CommonAppContext extends MultiDexApplication {
|
||||
SpUtil.getInstance().setBooleanValue("youth_model_shown", false);
|
||||
}
|
||||
}
|
||||
piaoPingManager = PiaoPingManager.getInstance(this);
|
||||
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (!Settings.canDrawOverlays(this)) {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
|
||||
startActivityForResult(intent, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startActivityForResult(Intent intent, int i) {
|
||||
}
|
||||
|
||||
|
||||
private PiaoPingManager piaoPingManager;
|
||||
|
||||
private void initARouter() {
|
||||
|
||||
@@ -53,13 +53,16 @@ public class PlaceholderBean {
|
||||
@Data
|
||||
public static class ListsBean {
|
||||
private String user_id;
|
||||
private String user_code;
|
||||
private String nickname;
|
||||
private String nickname1;
|
||||
private String avatar;
|
||||
private String total;
|
||||
private String rank;
|
||||
private List<String> icon;
|
||||
private String room_name;
|
||||
private String room_id;
|
||||
private String room_number;
|
||||
private String room_cover;
|
||||
|
||||
private int id;//公会id
|
||||
|
||||
@@ -163,8 +163,8 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
int screenHeight = displayMetrics.heightPixels;
|
||||
// 设置高度为屏幕高度的100%(全屏)
|
||||
int heightInPx = (int) (screenHeight * 0.79);
|
||||
;
|
||||
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, heightInPx);
|
||||
|
||||
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
window.setBackgroundDrawableResource(android.R.color.transparent);
|
||||
|
||||
// 可选:设置动画样式(从底部弹出)
|
||||
|
||||
@@ -17,7 +17,7 @@ import lombok.Getter;
|
||||
public class GiftXlhChouAdapter extends BaseQuickAdapter<GiftBean, BaseViewHolder> {
|
||||
private List<GiftBean> giftLists = new ArrayList<>();
|
||||
private int selectedPosition = -1;
|
||||
private static final int LOOP_COUNT = 6; // 循环倍数
|
||||
private static final int LOOP_COUNT = 8; // 循环倍数
|
||||
|
||||
|
||||
public GiftXlhChouAdapter() {
|
||||
@@ -138,6 +138,10 @@ public class GiftXlhChouAdapter extends BaseQuickAdapter<GiftBean, BaseViewHolde
|
||||
* @return 原始数据大小
|
||||
*/
|
||||
public int getOriginalDataSize() {
|
||||
return giftLists.size();
|
||||
List<GiftBean> loopData = new ArrayList<>();
|
||||
for (int i = 0; i < LOOP_COUNT; i++) {
|
||||
loopData.addAll(giftLists);
|
||||
}
|
||||
return loopData.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
package com.xscm.moduleutil.dialog.giftLottery;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Handler;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.HorizontalScrollView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -39,6 +46,7 @@ import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPresenter, FragmentTourClubDialogBinding> implements GiftLotteryContacts.View {
|
||||
private String roomId;
|
||||
@@ -56,6 +64,14 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
private static final int ITEM_COUNT = 24;
|
||||
private static final int ROTATION_COUNT = 3;
|
||||
|
||||
|
||||
private Handler handler = new Handler();
|
||||
private boolean isLotteryRunning = false;
|
||||
private int scrollSpeed = 10; // 滚动速度
|
||||
private int totalScrollTime = 5000; // 总滚动时间,单位:毫秒
|
||||
private int targetPosition;
|
||||
|
||||
|
||||
@Override
|
||||
protected GiftLotteryPresenter bindPresenter() {
|
||||
return new GiftLotteryPresenter(this, getActivity());
|
||||
@@ -109,8 +125,7 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
int screenHeight = displayMetrics.heightPixels;
|
||||
// 设置高度为屏幕高度的100%(全屏)
|
||||
int heightInPx = (int) (screenHeight * 0.79);
|
||||
;
|
||||
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, heightInPx);
|
||||
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
window.setBackgroundDrawableResource(android.R.color.transparent);
|
||||
|
||||
// 可选:设置动画样式(从底部弹出)
|
||||
@@ -128,6 +143,8 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
mBinding.tvBd.setOnClickListener(this::onClick);
|
||||
mBinding.tvJl.setOnClickListener(this::onClick);
|
||||
|
||||
|
||||
|
||||
giftXlhChouAdapter=new GiftXlhChouAdapter();
|
||||
// 使用 LinearLayoutManager 横向滚动
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
|
||||
@@ -168,14 +185,17 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
com.hjq.toast.ToastUtils.show("奖池数据加载中,请稍后再试");
|
||||
}
|
||||
} else if (id == R.id.ll_one) {
|
||||
prepareForNewLottery();
|
||||
num="1";
|
||||
MvpPre.xlhChou(roomId,num);
|
||||
|
||||
} else if (id == R.id.ll_ten) {
|
||||
prepareForNewLottery();
|
||||
num="10";
|
||||
MvpPre.xlhChou(roomId,num);
|
||||
|
||||
} else if (id == R.id.ll_hundred) {
|
||||
prepareForNewLottery();
|
||||
num="100";
|
||||
MvpPre.xlhChou(roomId,num);
|
||||
|
||||
@@ -203,7 +223,6 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
xlhRecordDialog.show(getChildFragmentManager(), "XlhRecordDialog");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_tour_club_dialog;
|
||||
@@ -248,6 +267,7 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
}
|
||||
|
||||
giftXlhChouAdapter.setNewData(giftLists);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,6 +371,18 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
releaseCountDownTimer();
|
||||
// 清理所有待执行的任务
|
||||
clearPendingTasks();
|
||||
|
||||
// 清理滚动帮助类
|
||||
if (scrollHelper != null) {
|
||||
scrollHelper = null;
|
||||
}
|
||||
|
||||
// 清理适配器引用
|
||||
if (giftXlhChouAdapter != null) {
|
||||
giftXlhChouAdapter = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -380,66 +412,136 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
mBinding.tvIcon.setText(walletBean.getCoin());
|
||||
}
|
||||
}
|
||||
private Runnable pendingLotteryRunnable;
|
||||
private Runnable pendingCenteringRunnable;
|
||||
|
||||
@Override
|
||||
public void xlhChouSuccess(List<XlhDrawBean> data) {
|
||||
if (data != null){
|
||||
// 抽奖完成后执行动画滚动
|
||||
mBinding.recycleView.postDelayed(() -> {
|
||||
int winningPosition = findHighestValueWinningPosition(data);
|
||||
if (winningPosition != -1) {
|
||||
|
||||
startLotteryAnimation(winningPosition);
|
||||
// 取消之前可能存在的任务
|
||||
clearPendingTasks();
|
||||
// 抽奖完成后执行动画滚动
|
||||
pendingLotteryRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 清理之前的状态
|
||||
if (giftXlhChouAdapter != null) {
|
||||
giftXlhChouAdapter.clearSelection();
|
||||
}
|
||||
int winningPosition = findHighestValueWinningPosition(data);//这是获取到的中奖位置下标
|
||||
if (winningPosition != -1) {
|
||||
if (scrollHelper == null) {
|
||||
scrollHelper = new CenterScrollHelper(mBinding.recycleView);
|
||||
}
|
||||
|
||||
// 计算在循环列表中的目标位置(滚动几圈后停在目标位置)
|
||||
int loopCount = 4; // 滚动4圈
|
||||
int originalSize = giftLists.size();///这是列表的总大小
|
||||
// 计算目标在循环列表中的位置(确保在中间区域)
|
||||
///这是计算总圈数的大小
|
||||
int middleBaseIndex = (loopCount * originalSize);
|
||||
///这里是展示在中奖的位置,加上总圈数的大小,
|
||||
int targetLoopIndex = middleBaseIndex + (winningPosition % originalSize);
|
||||
|
||||
/**
|
||||
// 使用scrollWithCircles方法执行带动画的滚动(带完成回调)
|
||||
scrollHelper.scrollWithCircles(
|
||||
targetLoopIndex, // 在循环列表中的位置
|
||||
loopCount, // 滚动圈数
|
||||
200, // 每个item滚动时间200ms(控制速度)
|
||||
originalSize, // 原始数据大小
|
||||
() -> { // 滚动完成回调
|
||||
// 滚动完成后更新选中状态(使用原始位置)
|
||||
if (giftXlhChouAdapter != null) {
|
||||
giftXlhChouAdapter.setSelectedPosition(winningPosition);
|
||||
}
|
||||
// 滚动完成后延迟一小段时间再居中,确保UI更新完成
|
||||
pendingCenteringRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 手动将选中项居中
|
||||
centerSelectedItem(winningPosition, originalSize);
|
||||
|
||||
|
||||
// 计算在循环列表中的目标位置(滚动几圈后停在目标位置)
|
||||
int loopCount = 4; // 滚动3圈
|
||||
int originalSize = giftXlhChouAdapter.getOriginalDataSize();
|
||||
// 计算目标在循环列表中的位置(确保在中间区域)
|
||||
|
||||
int middleBaseIndex = (loopCount * originalSize) + (originalSize / 2);
|
||||
int targetLoopIndex = middleBaseIndex + (winningPosition % originalSize);
|
||||
|
||||
// 使用scrollWithCircles方法执行带动画的滚动(带完成回调)
|
||||
scrollHelper.scrollWithCircles(
|
||||
targetLoopIndex, // 在循环列表中的位置
|
||||
loopCount, // 滚动圈数
|
||||
500, // 每个item滚动时间200ms(控制速度)
|
||||
originalSize, // 原始数据大小
|
||||
() -> { // 滚动完成回调
|
||||
// 滚动完成后更新选中状态(使用原始位置)
|
||||
if (giftXlhChouAdapter != null) {
|
||||
giftXlhChouAdapter.setSelectedPosition(winningPosition);
|
||||
// 显示结果对话框
|
||||
getActivity().runOnUiThread(() -> {
|
||||
scrollHelper = null;
|
||||
showResultDialog(data);
|
||||
});
|
||||
}
|
||||
};
|
||||
mBinding.recycleView.postDelayed(pendingCenteringRunnable, 100);
|
||||
}
|
||||
// 滚动完成后延迟一小段时间再居中,确保UI更新完成
|
||||
mBinding.recycleView.postDelayed(() -> {
|
||||
// 手动将选中项居中
|
||||
centerSelectedItem(winningPosition, originalSize);
|
||||
);
|
||||
|
||||
// 显示结果对话框
|
||||
getActivity().runOnUiThread(() -> {
|
||||
showResultDialog(data);
|
||||
});
|
||||
}, 100);
|
||||
// 在滚动完成后再显示对话框
|
||||
// getActivity().runOnUiThread(() -> {
|
||||
// showResultDialog(data);
|
||||
// });
|
||||
}
|
||||
);
|
||||
*/
|
||||
} else {
|
||||
// 如果没有找到中奖位置,直接显示对话框
|
||||
showResultDialog(data);
|
||||
} else {
|
||||
// 如果没有找到中奖位置,直接显示对话框
|
||||
showResultDialog(data);
|
||||
}
|
||||
}
|
||||
}, 300);
|
||||
};
|
||||
mBinding.recycleView.postDelayed(pendingLotteryRunnable, 300);
|
||||
|
||||
|
||||
}
|
||||
MvpPre.wallet();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 为新的抽奖做准备,清理之前的状态
|
||||
*/
|
||||
private void prepareForNewLottery() {
|
||||
// 取消之前可能存在的任务
|
||||
clearPendingTasks();
|
||||
|
||||
// 清除之前的选择状态
|
||||
if (giftXlhChouAdapter != null) {
|
||||
giftXlhChouAdapter.clearSelection();
|
||||
}
|
||||
|
||||
// 重置滚动帮助类
|
||||
if (scrollHelper != null) {
|
||||
scrollHelper.reset();
|
||||
}
|
||||
|
||||
// 停止可能正在进行的滚动
|
||||
mBinding.recycleView.stopScroll();
|
||||
|
||||
// 清理可能存在的回调
|
||||
if (mBinding.recycleView.getHandler() != null) {
|
||||
mBinding.recycleView.getHandler().removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
// 重新初始化滚动帮助类
|
||||
scrollHelper = new CenterScrollHelper(mBinding.recycleView);
|
||||
}
|
||||
/**
|
||||
* 清除所有待执行的任务
|
||||
*/
|
||||
private void clearPendingTasks() {
|
||||
// 取消抽奖动画任务
|
||||
if (pendingLotteryRunnable != null) {
|
||||
mBinding.recycleView.removeCallbacks(pendingLotteryRunnable);
|
||||
pendingLotteryRunnable = null;
|
||||
}
|
||||
|
||||
// 取消居中任务
|
||||
if (pendingCenteringRunnable != null) {
|
||||
mBinding.recycleView.removeCallbacks(pendingCenteringRunnable);
|
||||
pendingCenteringRunnable = null;
|
||||
}
|
||||
|
||||
// 停止可能正在进行的滚动
|
||||
mBinding.recycleView.stopScroll();
|
||||
|
||||
// 清理handler中的所有消息
|
||||
if (mBinding.recycleView.getHandler() != null) {
|
||||
mBinding.recycleView.getHandler().removeCallbacksAndMessages(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void startLotteryAnimation(int targetIndex) {
|
||||
// 确保适配器有数据
|
||||
if (giftXlhChouAdapter == null || giftXlhChouAdapter.getOriginalDataSize() <= 0) {
|
||||
@@ -558,32 +660,53 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
* @param originalPosition 原始数据中的位置
|
||||
* @param originalSize 原始数据大小
|
||||
*/
|
||||
// 新增优化的居中方法
|
||||
private void centerSelectedItem(int originalPosition, int originalSize) {
|
||||
LinearLayoutManager layoutManager = (LinearLayoutManager) mBinding.recycleView.getLayoutManager();
|
||||
if (layoutManager == null) return;
|
||||
|
||||
// 计算出需要滚动到的目标位置
|
||||
// 计算出需要滚动到的目标位置(确保在中间可见区域)
|
||||
int targetPosition = originalPosition + 4 * originalSize;
|
||||
|
||||
// 使用smoothScrollToPosition滚动到目标位置
|
||||
mBinding.recycleView.smoothScrollToPosition(targetPosition);
|
||||
// 先滚动到目标位置附近
|
||||
mBinding.recycleView.scrollToPosition(targetPosition);
|
||||
|
||||
// 等待滚动完成
|
||||
mBinding.recycleView.postDelayed(() -> {
|
||||
// 计算出选中项的偏移量,确保它在中间
|
||||
View view = layoutManager.findViewByPosition(targetPosition);
|
||||
if (view == null) return;
|
||||
// 使用post确保布局完成后进行精确居中
|
||||
mBinding.recycleView.post(() -> {
|
||||
View targetView = layoutManager.findViewByPosition(targetPosition);
|
||||
if (targetView == null) {
|
||||
// 如果目标view不可见,使用smoothScrollToPosition
|
||||
mBinding.recycleView.smoothScrollToPosition(targetPosition);
|
||||
// 再次尝试居中
|
||||
mBinding.recycleView.postDelayed(() -> {
|
||||
View refreshedView = layoutManager.findViewByPosition(targetPosition);
|
||||
if (refreshedView != null) {
|
||||
performCentering(layoutManager, refreshedView);
|
||||
}
|
||||
}, 50);
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算出RecyclerView的宽度和View的宽度
|
||||
int recyclerViewWidth = mBinding.recycleView.getWidth();
|
||||
int viewWidth = view.getWidth();
|
||||
performCentering(layoutManager, targetView);
|
||||
});
|
||||
}
|
||||
|
||||
// 计算偏移量,确保view居中
|
||||
int offsetToCenter = (recyclerViewWidth / 2) - (viewWidth / 2) - view.getLeft();
|
||||
// 执行实际的居中操作
|
||||
private void performCentering(LinearLayoutManager layoutManager, View targetView) {
|
||||
// 计算RecyclerView的中心点
|
||||
int recyclerViewWidth = mBinding.recycleView.getWidth();
|
||||
int recyclerViewCenter = recyclerViewWidth / 2;
|
||||
|
||||
// 调整滚动的位置
|
||||
mBinding.recycleView.scrollBy(offsetToCenter, 0);
|
||||
}, 500); // 500毫秒的延迟,根据实际情况调整
|
||||
// 计算目标view的中心点
|
||||
int targetViewLeft = targetView.getLeft();
|
||||
int targetViewWidth = targetView.getWidth();
|
||||
int targetViewCenter = targetViewLeft + targetViewWidth / 2;
|
||||
|
||||
// 计算需要滚动的偏移量
|
||||
int offset = targetViewCenter - recyclerViewCenter;
|
||||
|
||||
// 精确滚动使目标view居中
|
||||
mBinding.recycleView.scrollBy(offset, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,8 +10,10 @@ import lombok.Data;
|
||||
@Data
|
||||
public class GiftRewardEvent {
|
||||
private int points;
|
||||
private String zone_id;
|
||||
|
||||
public GiftRewardEvent(int points) {
|
||||
public GiftRewardEvent(int points, String zone_id) {
|
||||
this.points = points;
|
||||
this.zone_id = zone_id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -616,7 +616,7 @@ public interface ApiServer {
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.POST_ROOM_INFO)
|
||||
Observable<BaseModel<RoomInfoResp>> postRoomInfo(@Field("room_id") String roomId);
|
||||
Call<BaseModel<RoomInfoResp>> postRoomInfo(@Field("room_id") String roomId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(Constants.CHANGE_SONG)
|
||||
|
||||
@@ -1621,7 +1621,24 @@ public class RetrofitClient {
|
||||
}
|
||||
|
||||
public void postRoomInfo(String roomId, BaseObserver<RoomInfoResp> observer) {
|
||||
sApiServer.postRoomInfo(roomId).compose(new DefaultTransformer<>()).subscribe(observer);
|
||||
sApiServer.postRoomInfo(roomId).enqueue(new Callback<BaseModel<RoomInfoResp>>() {
|
||||
@Override
|
||||
public void onResponse(Call<BaseModel<RoomInfoResp>> call, Response<BaseModel<RoomInfoResp>> response) {
|
||||
if (response.code() == 200){
|
||||
BaseModel<RoomInfoResp> baseModel = response.body();
|
||||
if (baseModel.getCode() != 1){
|
||||
observer.onNext(null);
|
||||
}else {
|
||||
observer.onNext(baseModel.getData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<BaseModel<RoomInfoResp>> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void getCharmRank(String roomId, BaseObserver<List<RoomCharmRankBean>> observer) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.widget.Toast;
|
||||
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.google.android.gms.common.api.Api;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import com.xscm.moduleutil.utils.logger.DataLogger;
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
@@ -69,20 +70,21 @@ public class MqttConnect {
|
||||
**/
|
||||
public void mqttClient()
|
||||
{
|
||||
close();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// close();
|
||||
// handler.postDelayed(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
try {
|
||||
// uiTip("MQTT开始连接");
|
||||
MqttConnectOptions options = mqttConnectOptions();
|
||||
mqttClient.setCallback(new MqttInitCallback(context, HOST, clientId));
|
||||
mqttClient.connect(options);
|
||||
// sub(topic,qos);
|
||||
sub(shutdown);
|
||||
sub(update_app);
|
||||
uiTip("MQTT连接成功");
|
||||
// uiTip("MQTT连接成功");
|
||||
}catch (MqttException e){
|
||||
uiTip("MQTT连接失败,准备重连。。。:"+e.getMessage());
|
||||
// uiTip("MQTT连接失败,准备重连。。。:"+e.getMessage());
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -91,8 +93,8 @@ public class MqttConnect {
|
||||
}
|
||||
},3000);
|
||||
}
|
||||
}
|
||||
},200);
|
||||
// }
|
||||
// },200);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,6 +108,7 @@ public class MqttConnect {
|
||||
public void run() {
|
||||
// Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
|
||||
LogUtils.e("mqtt","连接成功");
|
||||
ToastUtils.show(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -126,6 +129,7 @@ public class MqttConnect {
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关闭MQTT连接
|
||||
*/
|
||||
@@ -137,6 +141,7 @@ public class MqttConnect {
|
||||
mqttClient = null;
|
||||
} catch (MqttException e) {
|
||||
Log.e(Tag,"关闭MQTT连接报错:"+e.getMessage());
|
||||
// ToastUtils.show("关闭MQTT连接报错");
|
||||
}
|
||||
}else {
|
||||
Log.d(Tag,"Mqtt已关闭");
|
||||
@@ -180,6 +185,7 @@ public class MqttConnect {
|
||||
mqttClient.subscribe(topic);
|
||||
} catch (MqttException e) {
|
||||
Log.e(Tag,"MQTT主题订阅失败:" + e.getMessage());
|
||||
// uiTip("MQTT主题订阅失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.xscm.moduleutil.bean.XLHBean;
|
||||
import com.xscm.moduleutil.event.RoomGiftRunable;
|
||||
@@ -33,6 +34,7 @@ public class MqttInitCallback implements MqttCallback {
|
||||
@Override
|
||||
public void connectionLost(Throwable cause) {
|
||||
Log.d(Tag,"mqtt连接断开,执行重连");
|
||||
ToastUtils.show("mqtt连接断开,执行重连");
|
||||
mqttConnect = MqttConnect.getInstance(context, HOST, clientId);
|
||||
mqttConnect.mqttClient();
|
||||
}
|
||||
@@ -48,8 +50,10 @@ public class MqttInitCallback implements MqttCallback {
|
||||
String messageStr = message.toString();
|
||||
Logger.e("MQTT", "收到的消息", "主题:" + topic + " 收到的消息:" + messageStr);
|
||||
if (topic.equals("qx_room_topic")) {
|
||||
// ToastUtils.show("收到礼物飘屏");
|
||||
receiveMessage(topic, messageStr);
|
||||
} else if (topic.equals("qx_xunlehui")) {
|
||||
// ToastUtils.show("收到轮盘飘屏");
|
||||
receiveXlhMessage(messageStr);
|
||||
}
|
||||
}
|
||||
@@ -65,6 +69,7 @@ public class MqttInitCallback implements MqttCallback {
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e("MQTT", "解析MQTT消息异常", e);
|
||||
// ToastUtils.show("收到礼物飘屏,解析异常");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +94,7 @@ public class MqttInitCallback implements MqttCallback {
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e("MQTT", "解析MQTT消息异常", e);
|
||||
// ToastUtils.show("收到轮盘飘屏,解析异常");
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -126,7 +126,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
||||
currentProcessingCount = Math.max(0, currentProcessingCount - 1);
|
||||
|
||||
// 内存检查和清理
|
||||
if (playQueue.size() % 10 == 0) { // 每处理10个动画检查一次内存
|
||||
if (playQueue.size() % 1 == 0) { // 每处理10个动画检查一次内存
|
||||
performLightCleanup();
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
|
||||
public String pitNumber;
|
||||
public int pitImageVId;
|
||||
|
||||
public ImageView iv_on_line;
|
||||
// public ImageView iv_on_line;
|
||||
private boolean showGiftAnim = true;//显示麦位动画
|
||||
private ImageView iv_tag_type;
|
||||
|
||||
@@ -99,7 +99,7 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
|
||||
tvTime = findViewById(R.id.tv_time);
|
||||
tv_time_pk = findViewById(R.id.tv_time_pk);
|
||||
mTvNo = findViewById(R.id.tv_no);
|
||||
iv_on_line = findViewById(R.id.iv_online);
|
||||
// iv_on_line = findViewById(R.id.iv_online);
|
||||
iv_tag_type = findViewById(R.id.iv_tag_type);
|
||||
tv_zhul=findViewById(R.id.tv_zhul);
|
||||
setClipChildren(false);
|
||||
@@ -242,22 +242,11 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
|
||||
if (!mIvRipple.isAnimating()) {
|
||||
mIvRipple.startAnimation();
|
||||
}
|
||||
iv_on_line.setVisibility(GONE);
|
||||
// mIvRipple.setSource(getResources().getResourceName(R.raw.ripple3695), 2);
|
||||
// iv_on_line.setVisibility(GONE);
|
||||
|
||||
});
|
||||
}
|
||||
// if (pitBean.getUser_id().equals(SpUtil.getUserId()) && closePhone) {
|
||||
// mIvRipple.post(() -> {
|
||||
// mIvRipple.setVisibility(GONE);
|
||||
// });
|
||||
// }
|
||||
}
|
||||
// else {
|
||||
// mIvRipple.post(() -> {
|
||||
// mIvRipple.setVisibility(GONE);
|
||||
// });
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -273,8 +262,7 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
|
||||
if (!mIvRipple.isAnimating()) {
|
||||
mIvRipple.startAnimation();
|
||||
}
|
||||
iv_on_line.setVisibility(GONE);
|
||||
// mIvRipple.setSource(getResources().getResourceName(R.raw.ripple3695), 2);
|
||||
// iv_on_line.setVisibility(GONE);
|
||||
|
||||
});
|
||||
}
|
||||
@@ -284,7 +272,7 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
|
||||
public void userJoined(int userId, int elapsd) {
|
||||
if (pitBean != null && pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0")) {
|
||||
if (pitBean.getUser_id().equals(userId + "")) {
|
||||
iv_on_line.setVisibility(GONE);
|
||||
// iv_on_line.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -293,16 +281,16 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
|
||||
public void userOffline(int userId, int reason) {
|
||||
if (pitBean != null && pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0")) {
|
||||
if (pitBean.getUser_id().equals(userId + "")) {
|
||||
iv_on_line.setVisibility(VISIBLE);
|
||||
// iv_on_line.setVisibility(VISIBLE);
|
||||
}
|
||||
}else if (pitBean.getUser_id()==null || pitBean.getUser_id().equals("0") || pitBean.getUser_id().equals("")){
|
||||
iv_on_line.setVisibility(GONE);
|
||||
// iv_on_line.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
if (pitBean.getUser_id()==null || pitBean.getUser_id().equals("0") || pitBean.getUser_id().equals("") ){
|
||||
iv_on_line.setVisibility(GONE);
|
||||
// iv_on_line.setVisibility(GONE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -358,9 +346,9 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
|
||||
if (pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0") && !pitBean.getUser_id().isEmpty()) {
|
||||
if (pitBean.getUser_id().equals(isOnline.getUser_id())) {
|
||||
if (isOnline.getIs_online() == 1) {
|
||||
iv_on_line.setVisibility(GONE);
|
||||
// iv_on_line.setVisibility(GONE);
|
||||
} else {
|
||||
iv_on_line.setVisibility(VISIBLE);
|
||||
// iv_on_line.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,16 @@ public class CenterScrollHelper {
|
||||
smoothScroller.setTargetPosition(totalItems);
|
||||
recyclerView.getLayoutManager().startSmoothScroll(smoothScroller);
|
||||
}
|
||||
|
||||
// 在 CenterScrollHelper 类中添加
|
||||
public void reset() {
|
||||
// 清理可能存在的回调或状态
|
||||
if (recyclerView != null) {
|
||||
recyclerView.stopScroll();
|
||||
recyclerView.getHandler().removeCallbacksAndMessages(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用缓动函数计算滚动时间,实现加速减速效果
|
||||
* @param dx 滚动距离
|
||||
|
||||
@@ -1,12 +1,21 @@
|
||||
package com.xscm.moduleutil.widget;
|
||||
|
||||
import static com.liulishuo.okdownload.OkDownloadProvider.context;
|
||||
|
||||
import static android.app.PendingIntent.getActivity;
|
||||
import static android.content.Context.WINDOW_SERVICE;
|
||||
import static androidx.core.content.ContextCompat.getSystemService;
|
||||
|
||||
import static com.blankj.utilcode.util.ActivityUtils.startActivityForResult;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
@@ -17,10 +26,12 @@ import android.widget.TextView;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import com.petterp.floatingx.FloatingX;
|
||||
import com.petterp.floatingx.assist.FxGravity;
|
||||
import com.petterp.floatingx.assist.helper.FxAppHelper;
|
||||
import com.xscm.moduleutil.R;
|
||||
import com.xscm.moduleutil.activity.BaseAppCompatActivity;
|
||||
import com.xscm.moduleutil.bean.XLHBean;
|
||||
import com.xscm.moduleutil.event.MqttBean;
|
||||
import com.xscm.moduleutil.utils.ARouteConstants;
|
||||
@@ -47,13 +58,19 @@ public class PiaoPingManager {
|
||||
private Queue<XLHBean> XLHmessageQueue = new ConcurrentLinkedQueue<>(); // 消息队列
|
||||
private boolean isAnimating = false; // 动画状态标记
|
||||
private boolean XLHisAnimating = false; // 动画状态标记
|
||||
|
||||
private Context mContext; // 添加成员变量
|
||||
View floatingView;
|
||||
|
||||
private PiaoPingManager(Context context) {
|
||||
windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
this.mContext = context;
|
||||
windowManager = (WindowManager) context.getSystemService(WINDOW_SERVICE);
|
||||
if (windowManager == null) return;
|
||||
|
||||
// 创建飘屏消息的布局
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
piaoPingView = inflater.inflate(R.layout.item_piaoping, null);
|
||||
|
||||
}
|
||||
|
||||
public static synchronized PiaoPingManager getInstance(Context context) {
|
||||
@@ -68,11 +85,12 @@ public class PiaoPingManager {
|
||||
// 添加到队列
|
||||
messageQueue.offer(mqttBean);
|
||||
// 如果当前没有动画正在进行,则开始处理
|
||||
if (!isAnimating) {
|
||||
processNextMessage();
|
||||
}
|
||||
// if (!isAnimating) {
|
||||
processNextMessage();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private void processNextMessage() {
|
||||
if (messageQueue.isEmpty()) {
|
||||
isAnimating = false;
|
||||
@@ -81,65 +99,91 @@ public class PiaoPingManager {
|
||||
|
||||
isAnimating = true;
|
||||
MqttBean mqttBean = messageQueue.poll();
|
||||
|
||||
displayMessage(mqttBean);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void displayMessage(MqttBean mqttBean) {
|
||||
// 获取悬浮窗视图并设置内容
|
||||
View floatingView = LayoutInflater.from(context).inflate(R.layout.item_piaoping, new FrameLayout(context), false);
|
||||
TextView textView = floatingView.findViewById(R.id.tv_name);
|
||||
TextView textView2 = floatingView.findViewById(R.id.tv_to_name);
|
||||
textView2.setText("送给" + mqttBean.getList().getToUserName());
|
||||
textView.setText(mqttBean.getList().getFromUserName());
|
||||
ImageUtils.loadHeadCC(mqttBean.getList().getGift_picture(), floatingView.findViewById(R.id.iv_piaoping));
|
||||
TextView tv_time = floatingView.findViewById(R.id.tv_num);
|
||||
tv_time.setText("x" + mqttBean.getList().getNumber());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
|
||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
|
||||
PixelFormat.TRANSLUCENT
|
||||
);
|
||||
|
||||
|
||||
ToastUtils.show("飘屏开始");
|
||||
// 获取悬浮窗视图并设置内容
|
||||
floatingView = LayoutInflater.from(mContext).inflate(R.layout.item_piaoping, new FrameLayout(mContext), false);
|
||||
TextView textView = floatingView.findViewById(R.id.tv_name);
|
||||
TextView textView2 = floatingView.findViewById(R.id.tv_to_name);
|
||||
textView2.setText("送给" + mqttBean.getList().getToUserName());
|
||||
textView.setText(mqttBean.getList().getFromUserName());
|
||||
ImageUtils.loadHeadCC(mqttBean.getList().getGift_picture(), floatingView.findViewById(R.id.iv_piaoping));
|
||||
TextView tv_time = floatingView.findViewById(R.id.tv_num);
|
||||
tv_time.setText("x" + mqttBean.getList().getNumber());
|
||||
ToastUtils.show("飘屏创建");
|
||||
|
||||
WindowManager windowManager = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
|
||||
windowManager.addView(floatingView, params);
|
||||
}else {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 先将视图放置在屏幕右侧外部,避免闪现问题
|
||||
floatingView.setTranslationX(10000); // 先放到屏幕外
|
||||
|
||||
FxAppHelper fxAppHelper = FxAppHelper.builder()
|
||||
.setContext(context)
|
||||
.setLayoutView(floatingView)
|
||||
.setGravity(FxGravity.RIGHT_OR_TOP)
|
||||
.setX(0)
|
||||
.setY(100)
|
||||
.build();
|
||||
|
||||
FloatingX.install(fxAppHelper).show();
|
||||
|
||||
// floatingView.setTranslationX(10000); // 先放到屏幕外
|
||||
// 在 FloatingX 配置中或者通过其他方式设置
|
||||
// FxAppHelper fxAppHelper = FxAppHelper.builder()
|
||||
// .setContext(mContext)
|
||||
// .setLayoutView(floatingView)
|
||||
// .setGravity(FxGravity.RIGHT_OR_TOP)
|
||||
// .setX(0)
|
||||
// .setY(100)
|
||||
// .build();
|
||||
//
|
||||
// FloatingX.install(fxAppHelper).show();
|
||||
ToastUtils.show("飘屏创建2");
|
||||
// 首先从右侧滑入到屏幕中央
|
||||
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) {
|
||||
// 动画结束后移除悬浮窗
|
||||
FloatingX.uninstallAll();
|
||||
// 处理下一个消息
|
||||
processNextMessage();
|
||||
}
|
||||
});
|
||||
animator2.start();
|
||||
}, 1000); // 停留1秒
|
||||
});
|
||||
// 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();
|
||||
// ToastUtils.show("飘屏创建2第一阶段");
|
||||
// // 第二阶段:延迟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) {
|
||||
// // 动画结束后移除悬浮窗
|
||||
// FloatingX.uninstallAll();
|
||||
// windowManager.removeView(floatingView);
|
||||
// // 处理下一个消息
|
||||
// processNextMessage();
|
||||
// }
|
||||
// });
|
||||
// animator2.start();
|
||||
// }, 3000); // 停留1秒
|
||||
// ToastUtils.show("飘屏创建2第er阶段");
|
||||
// });
|
||||
ToastUtils.show("飘屏结束");
|
||||
}
|
||||
|
||||
|
||||
public void subscribe() {
|
||||
try {
|
||||
if (!EventBus.getDefault().isRegistered(this)) {
|
||||
@@ -169,7 +213,7 @@ public class PiaoPingManager {
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageReceived(MqttBean mqttBean) {
|
||||
showPiaoPingMessage(mqttBean);
|
||||
|
||||
ToastUtils.show("飘屏");
|
||||
// FxAppHelper fxAppHelper = FxAppHelper.builder().setContext( context).setLayout(R.layout.item_piaoping).build();
|
||||
// FloatingX.install(fxAppHelper).show();
|
||||
}
|
||||
@@ -199,10 +243,11 @@ public class PiaoPingManager {
|
||||
XLHBean xlhBean = XLHmessageQueue.poll();
|
||||
displayMessageXlh(xlhBean);
|
||||
}
|
||||
|
||||
@SuppressLint({"MissingInflatedId", "LocalSuppress"})
|
||||
private void displayMessageXlh(XLHBean xlhBean) {
|
||||
// 获取悬浮窗视图并设置内容
|
||||
View floatingView = LayoutInflater.from(context).inflate(R.layout.item_piaoping_xlh, new FrameLayout(context), false);
|
||||
View floatingView = LayoutInflater.from(mContext).inflate(R.layout.item_piaoping_xlh, new FrameLayout(mContext), false);
|
||||
TextView textView = floatingView.findViewById(R.id.tv_name);
|
||||
ImageView xlh_image = floatingView.findViewById(R.id.im_xlh);
|
||||
// if (xlhBean.getFrom_type() == 1){
|
||||
@@ -211,7 +256,7 @@ public class PiaoPingManager {
|
||||
// xlh_image.setImageResource(R.mipmap.xlh_zsks);
|
||||
// }
|
||||
|
||||
xlh_image.setImageDrawable(xlhBean.getFrom_type() == 1 ? context.getResources().getDrawable(R.mipmap.xlh_jjks) : context.getResources().getDrawable(R.mipmap.xlh_zsks));
|
||||
xlh_image.setImageDrawable(xlhBean.getFrom_type() == 1 ? mContext.getResources().getDrawable(R.mipmap.xlh_jjks) : mContext.getResources().getDrawable(R.mipmap.xlh_zsks));
|
||||
|
||||
textView.setText(xlhBean.getText());
|
||||
|
||||
@@ -219,7 +264,7 @@ public class PiaoPingManager {
|
||||
floatingView.setTranslationX(10000); // 先放到屏幕外
|
||||
|
||||
FxAppHelper fxAppHelper = FxAppHelper.builder()
|
||||
.setContext(context)
|
||||
.setContext(mContext)
|
||||
.setLayoutView(floatingView)
|
||||
.setGravity(FxGravity.RIGHT_OR_TOP)
|
||||
.setX(0)
|
||||
|
||||
@@ -22,7 +22,7 @@ public class RoomFriendshipWheatView extends BaseWheatView {
|
||||
|
||||
public ImageView mIvTagBoss;
|
||||
public TextView mTvTime;
|
||||
public ImageView iv_on_line;
|
||||
// public ImageView iv_on_line;
|
||||
private ImageView iv_tag_type;
|
||||
public WheatCharmView mCharmView;
|
||||
public TextView tv_zhul;
|
||||
@@ -51,7 +51,7 @@ public class RoomFriendshipWheatView extends BaseWheatView {
|
||||
typedArray.recycle();
|
||||
mIvTagBoss = findViewById(R.id.iv_tag_boos);
|
||||
mTvTime = findViewById(R.id.tv_time);
|
||||
iv_on_line = findViewById(R.id.iv_online);
|
||||
// iv_on_line = findViewById(R.id.iv_online);
|
||||
iv_tag_type = findViewById(R.id.iv_tag_type);
|
||||
mCharmView = findViewById(R.id.charm_view);
|
||||
mRiv.setImageResource(pitImageVId);
|
||||
@@ -281,9 +281,9 @@ public class RoomFriendshipWheatView extends BaseWheatView {
|
||||
if (pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0") && !pitBean.getUser_id().isEmpty()) {
|
||||
if (pitBean.getUser_id().equals(isOnline.getUser_id())) {
|
||||
if (isOnline.getIs_online() == 1) {
|
||||
iv_on_line.setVisibility(GONE);
|
||||
// iv_on_line.setVisibility(GONE);
|
||||
} else {
|
||||
iv_on_line.setVisibility(VISIBLE);
|
||||
// iv_on_line.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ public class RoomKtvWheatView extends BaseWheatView {
|
||||
public void userJoined(int userId, int elapsd) {
|
||||
if (pitBean != null && pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0")) {
|
||||
if (pitBean.getUser_id().equals(userId + "")) {
|
||||
iv_on_line.setVisibility(GONE);
|
||||
// iv_on_line.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,7 +246,7 @@ public class RoomKtvWheatView extends BaseWheatView {
|
||||
public void userOffline(int userId, int reason) {
|
||||
if (pitBean != null && pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0")) {
|
||||
if (pitBean.getUser_id().equals(userId + "")) {
|
||||
iv_on_line.setVisibility(VISIBLE);
|
||||
// iv_on_line.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class RoomMakeWheatView extends BaseWheatView {
|
||||
public ImageView mIvTagBoss;
|
||||
public TextView mTvTime;
|
||||
public ImageView iv_zhul;
|
||||
public ImageView iv_on_line;
|
||||
// public ImageView iv_on_line;
|
||||
private ImageView iv_tag_type;
|
||||
public WheatCharmView mCharmView;
|
||||
private boolean showBoss;//显示老板标识
|
||||
@@ -47,7 +47,7 @@ public class RoomMakeWheatView extends BaseWheatView {
|
||||
typedArray.recycle();
|
||||
mIvTagBoss = findViewById(R.id.iv_tag_boos);
|
||||
mTvTime = findViewById(R.id.tv_time);
|
||||
iv_on_line=findViewById(R.id.iv_online);
|
||||
// iv_on_line=findViewById(R.id.iv_online);
|
||||
iv_tag_type=findViewById(R.id.iv_tag_type);
|
||||
mCharmView = findViewById(R.id.charm_view);
|
||||
mRiv.setImageResource(pitImageVId);
|
||||
@@ -204,9 +204,9 @@ public class RoomMakeWheatView extends BaseWheatView {
|
||||
if (pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0") && !pitBean.getUser_id().isEmpty()) {
|
||||
if (pitBean.getUser_id().equals(isOnline.getUser_id())) {
|
||||
if (isOnline.getIs_online() == 1) {
|
||||
iv_on_line.setVisibility(GONE);
|
||||
// iv_on_line.setVisibility(GONE);
|
||||
} else {
|
||||
iv_on_line.setVisibility(VISIBLE);
|
||||
// iv_on_line.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class RoomSingWheatView extends LinearLayout {
|
||||
public String pitNumber;
|
||||
public int pitImageVId;
|
||||
|
||||
public ImageView iv_on_line;
|
||||
// public ImageView iv_on_line;
|
||||
private boolean showGiftAnim = true;//显示麦位动画
|
||||
private ImageView iv_tag_type;
|
||||
|
||||
@@ -82,7 +82,7 @@ public class RoomSingWheatView extends LinearLayout {
|
||||
tvTime = findViewById(R.id.tv_time);
|
||||
tv_time_pk = findViewById(R.id.tv_time_pk);
|
||||
mTvNo = findViewById(R.id.tv_no);
|
||||
iv_on_line = findViewById(R.id.iv_online);
|
||||
// iv_on_line = findViewById(R.id.iv_online);
|
||||
iv_tag_type = findViewById(R.id.iv_tag_type);
|
||||
tv_zhul = findViewById(R.id.tv_zhul);
|
||||
|
||||
|
||||
@@ -243,17 +243,17 @@ public class RewardGiftDialogFragment extends BaseMvpDialogFragment<RewardGiftPr
|
||||
}
|
||||
}
|
||||
|
||||
if (currentItem == 0) {
|
||||
// if (currentItem == 0) {
|
||||
//礼物打赏
|
||||
giftNumber = num;
|
||||
MvpPre.reward_zone(circle_id, roonGiftModel.getGift_id(), num, "1");
|
||||
} else {
|
||||
// } else {
|
||||
//背包礼物打赏
|
||||
// giftNumber = num;
|
||||
// roomGiftGiveEvent = new RoomGiftGiveEvent(userId, roomId, pit, num, 1, giftModel, null);
|
||||
//
|
||||
// MvpPre.giveBackGift(userId, giftModel.getGift_id(), roomId, pit, num, giftModel, 1);
|
||||
}
|
||||
// }
|
||||
}
|
||||
@Override
|
||||
public void setGiftList(List<RoonGiftModel> roonGiftModels,int type) {
|
||||
@@ -273,7 +273,7 @@ public class RewardGiftDialogFragment extends BaseMvpDialogFragment<RewardGiftPr
|
||||
@Override
|
||||
public void reward_zone() {
|
||||
com.blankj.utilcode.util.ToastUtils.showShort("打赏成功");
|
||||
EventBus.getDefault().post(new GiftRewardEvent(point));
|
||||
EventBus.getDefault().post(new GiftRewardEvent(point,circle_id));
|
||||
dismiss();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user