1:新版定包版本
This commit is contained in:
@@ -704,6 +704,7 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
public void onEvent(XLHBean event) {
|
||||
LogUtils.e("收到XLH", event);
|
||||
if (event == null) return;
|
||||
if (event.getText()==null || event.getText().isEmpty()) return;
|
||||
if (SpUtil.getFloatingScreen() == 1) {
|
||||
synchronized (xlhQueueLock) {
|
||||
xlhMessageQueue.add(event);
|
||||
@@ -830,6 +831,7 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("播放红包音效失败", e);
|
||||
isRedPacketMediaPrepared=false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1017,6 +1019,7 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
Animation.ABSOLUTE, 0
|
||||
);
|
||||
enterAnim.setDuration(1500);
|
||||
enterAnim.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
enterAnim.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
@@ -1032,7 +1035,8 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
Animation.ABSOLUTE, 0,
|
||||
Animation.ABSOLUTE, 0
|
||||
);
|
||||
exitAnim.setDuration(2000);
|
||||
exitAnim.setDuration(3000);
|
||||
exitAnim.setInterpolator(new DecelerateInterpolator(2f));
|
||||
exitAnim.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
@@ -1041,19 +1045,6 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
// 移除视图并处理下一个
|
||||
// ViewGroup rootView = (ViewGroup) getParent();
|
||||
// if (rootView != null) {
|
||||
// rootView.removeView(QXGiftDriftView.this);
|
||||
// }
|
||||
//
|
||||
// if (!dataArray.isEmpty()) {
|
||||
// dataArray.remove(0);
|
||||
// }
|
||||
// isPlaying = false;
|
||||
//
|
||||
// if (!dataArray.isEmpty()) {
|
||||
// giftAction();
|
||||
// }
|
||||
onAnimationEnd.run();
|
||||
}
|
||||
|
||||
@@ -1062,7 +1053,7 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
}
|
||||
});
|
||||
view.startAnimation(exitAnim);
|
||||
}, 3000); // 停留1秒
|
||||
}, 5000); // 停留1秒
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1071,34 +1062,6 @@ public abstract class BaseAppCompatActivity<VDB extends ViewDataBinding> extends
|
||||
});
|
||||
view.startAnimation(enterAnim);
|
||||
|
||||
|
||||
// ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "translationX", view.getWidth(), 0f);
|
||||
// animator1.setDuration(1500);
|
||||
// animator1.setInterpolator(new DecelerateInterpolator(1f));
|
||||
// animator1.start();
|
||||
|
||||
// view.postDelayed(() -> {
|
||||
// try {
|
||||
// ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "translationX", 0f, -view.getWidth());
|
||||
// animator2.setDuration(3000);
|
||||
// animator2.setInterpolator(new DecelerateInterpolator(2.0f));
|
||||
// animator2.addListener(new AnimatorListenerAdapter() {
|
||||
// @Override
|
||||
// public void onAnimationEnd(Animator animation) {
|
||||
// onAnimationEnd.run();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onAnimationCancel(Animator animation) {
|
||||
// onAnimationEnd.run();
|
||||
// }
|
||||
// });
|
||||
// animator2.start();
|
||||
// } catch (Exception e) {
|
||||
// LogUtils.e("MQTT动画执行失败", e);
|
||||
// onAnimationEnd.run();
|
||||
// }
|
||||
// }, 3000);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e("MQTT动画启动失败", e);
|
||||
onAnimationEnd.run();
|
||||
|
||||
@@ -345,7 +345,7 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
|
||||
case TRIM_MEMORY_RUNNING_CRITICAL:
|
||||
// 应用仍在运行,但系统已开始杀死后台进程
|
||||
LogUtils.d("Memory trim: critical");
|
||||
releaseAllNonEssentialResources();
|
||||
// releaseAllNonEssentialResources();
|
||||
break;
|
||||
case TRIM_MEMORY_UI_HIDDEN:
|
||||
// 应用UI已隐藏,可以释放UI相关资源
|
||||
@@ -377,9 +377,9 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
|
||||
// Glide.get(this).clearMemory();
|
||||
|
||||
// 释放MQTT资源
|
||||
if (mqttConnect != null) {
|
||||
mqttConnect.close();
|
||||
}
|
||||
// if (mqttConnect != null) {
|
||||
// mqttConnect.close();
|
||||
// }
|
||||
|
||||
// 通知各个组件释放资源
|
||||
// EventBus.getDefault().post(new MemoryTrimEvent());
|
||||
@@ -450,8 +450,8 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
|
||||
// startService(mqttServiceIntent);
|
||||
// }
|
||||
|
||||
mqttConnect=MqttConnect.getInstance(this,"tcp://1.13.181.248","android-"+ MqttClient.generateClientId());
|
||||
// mqttConnect=MqttConnect.getInstance(this,"tcp://62.234.12.147","android-"+ MqttClient.generateClientId());
|
||||
// mqttConnect=MqttConnect.getInstance(this,"tcp://1.13.181.248","android-"+ MqttClient.generateClientId());
|
||||
mqttConnect=MqttConnect.getInstance(this,"tcp://62.234.12.147","android-"+ MqttClient.generateClientId());
|
||||
mqttConnect.mqttClient();
|
||||
|
||||
// 每次启动应用时重置状态
|
||||
@@ -526,6 +526,14 @@ public class CommonAppContext extends MultiDexApplication implements Applicatio
|
||||
return null;
|
||||
}
|
||||
|
||||
public void upMqtt(){
|
||||
if (mqttConnect==null){
|
||||
mqttConnect=MqttConnect.getInstance(this,"tcp://1.13.181.248","android-"+ MqttClient.generateClientId());
|
||||
// mqttConnect=MqttConnect.getInstance(this,"tcp://62.234.12.147","android-"+ MqttClient.generateClientId());
|
||||
mqttConnect.mqttClient();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
MultiDex.install(this);
|
||||
|
||||
@@ -2,7 +2,10 @@ package com.xscm.moduleutil.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class MqttXlhEnd {
|
||||
public class MqttXlhEnd implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String message;
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ public class RoomMessageEvent {
|
||||
private String gift_num;
|
||||
|
||||
private RedPacketInfo redpacketInfo;
|
||||
private String redpacket_id;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -65,6 +65,7 @@ public class UserInfo implements Serializable {
|
||||
private int heartId; // "heartId": 4,
|
||||
private int heartNum; //
|
||||
private String red_num;
|
||||
private String ta;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.xscm.moduleutil.bean;
|
||||
|
||||
import com.xscm.moduleutil.bean.blindboxwheel.BlindBoxBean;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -15,5 +16,11 @@ public class XLHBean implements Serializable {
|
||||
private String text;
|
||||
private String room_id;
|
||||
|
||||
private int from_type ;
|
||||
private int from_type ;//100:巡乐会进度更新 101:巡乐会即将开始 102:巡乐会已经开始 103:巡乐会有人锁定了礼物 104:巡乐会结束落包
|
||||
private BlindBoxBean.XlhData xlh_data;
|
||||
private UserInfo FromUserInfo;
|
||||
private String end_time;
|
||||
private BlindBoxBean.xlhUser room_user;
|
||||
private String gift_num;
|
||||
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ public class EMMessageInfo implements MultiItemEntity {
|
||||
public static final int QXRoomMessageTypeQingGRMl = 1059;
|
||||
//有红包列表
|
||||
public static final int QXRoomMessageTypeQXRoomMessageRed = 1060;
|
||||
public static final int QXRoomMessageTypeQXRoomMessageRedRemove = 1061;
|
||||
|
||||
///房间内换麦
|
||||
public static final int QXRoomMessageTypehm = 1039;
|
||||
|
||||
@@ -22,6 +22,7 @@ public class RoomHourBean {
|
||||
private int total_price;
|
||||
private String label_icon;
|
||||
private int xlh_status;
|
||||
private int redpacket_status;// >0 有红包,=0 没有红包
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public class GiftItemAdapter extends BaseQuickAdapter<XlhDrawBean, BaseViewHolde
|
||||
|
||||
helper.setText(R.id.tv_gift_name, item.getGift_name()+"x"+item.getCount());
|
||||
ImageUtils.loadHeadCC(item.getBase_image(),helper.getView(R.id.gift_img));
|
||||
helper.setText(R.id.tv_gift_num, item.getGift_price());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -583,10 +583,13 @@ public class GiftLotteryDialog extends BaseMvpDialogFragment<GiftLotteryPresente
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageReceived(MqttXlhEnd event) {
|
||||
XLHBean xlhBean = GsonUtils.fromJson(event.getMessage(), XLHBean.class);
|
||||
// if (xlhBean.getFrom_type()==3) {
|
||||
// dismiss();
|
||||
// }
|
||||
// BlindBoxBean.XlhData xlhData =new BlindBoxBean.XlhData();
|
||||
if (xlhBean.getFrom_type()==100 || xlhBean.getFrom_type()==101 || xlhBean.getFrom_type()==102){
|
||||
UpView(xlhBean.getXlh_data());
|
||||
}else if (xlhBean.getFrom_type()==104){
|
||||
xlhData.setCurrent_num(0);
|
||||
xlhData.setStatus(0);
|
||||
UpView(xlhData);
|
||||
}
|
||||
if (xlhBean.getFrom_type() == 3) {
|
||||
xlhData.setCurrent_num(0);
|
||||
xlhData.setStatus(0);
|
||||
|
||||
@@ -183,7 +183,7 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
}
|
||||
});
|
||||
mBinding.tvNumber.setText("x0");
|
||||
mBinding.tvNumber.setTypeface(android.graphics.Typeface.create("sans-serif-condensed", Typeface.BOLD));
|
||||
mBinding.tvNumber.setTypeface(android.graphics.Typeface.create("semibold", Typeface.NORMAL));
|
||||
}
|
||||
|
||||
// 添加自动滚动相关的方法
|
||||
@@ -433,7 +433,24 @@ public class TourClubDialogFragment extends BaseMvpDialogFragment<GiftLotteryPre
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onMessageReceived(MqttXlhEnd event) {
|
||||
dismiss();
|
||||
XLHBean xlhBean = GsonUtils.fromJson(event.getMessage(), XLHBean.class);
|
||||
if (xlhBean.getFrom_type()==103){
|
||||
endTime = Long.parseLong(xlhBean.getEnd_time() != null ? xlhBean.getEnd_time() : "0");
|
||||
BlindBoxBean.xlhUser xlhUser = new BlindBoxBean.xlhUser();
|
||||
xlhUser.setAvatar(xlhBean.getFromUserInfo().getAvatar());
|
||||
xlhUser.setNickname(xlhBean.getFromUserInfo().getNickname());
|
||||
mBinding.gvXyz.setModel(xlhUser);
|
||||
mBinding.qxDjs.setEndTime(endTime);
|
||||
mBinding.tvNumber.setText("x"+(xlhBean.getGift_num() != null ? xlhBean.getGift_num() : "0"));
|
||||
isDrawing=false;
|
||||
if (xlhBean.getRoom_user()!=null){
|
||||
mBinding.gvFz.setModel(xlhBean.getRoom_user());
|
||||
}
|
||||
mBinding.gvFz.setIsLuckUser(false);
|
||||
}else if (xlhBean.getFrom_type()==104){
|
||||
dismiss();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.util.Log;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.blankj.utilcode.util.GsonUtils;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import com.orhanobut.logger.Logger;
|
||||
import com.xscm.moduleutil.bean.MqttXlhEnd;
|
||||
@@ -30,17 +31,19 @@ public class MqttInitCallback implements MqttCallback {
|
||||
private String clientId = "";
|
||||
private MqttConnect mqttConnect = null;
|
||||
private Context context = null;
|
||||
MqttInitCallback(Context context, String host, String clientId){
|
||||
|
||||
MqttInitCallback(Context context, String host, String clientId) {
|
||||
this.context = context;
|
||||
this.HOST = host;
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接丢失
|
||||
*/
|
||||
@Override
|
||||
public void connectionLost(Throwable cause) {
|
||||
Log.d(Tag,"mqtt连接断开,执行重连");
|
||||
Log.d(Tag, "mqtt连接断开,执行重连");
|
||||
// ToastUtils.show("mqtt连接断开,执行重连");
|
||||
mqttConnect = MqttConnect.getInstance(context, HOST, clientId);
|
||||
mqttConnect.mqttClient();
|
||||
@@ -50,7 +53,7 @@ public class MqttInitCallback implements MqttCallback {
|
||||
* subscribe订阅后得到的消息会执行到这里
|
||||
*/
|
||||
@Override
|
||||
public void messageArrived(String topic, MqttMessage message){
|
||||
public void messageArrived(String topic, MqttMessage message) {
|
||||
// Log.d(Tag,"topic");
|
||||
// Log.d(Tag,topic);
|
||||
|
||||
@@ -62,9 +65,9 @@ public class MqttInitCallback implements MqttCallback {
|
||||
} else if (topic.equals("qx_xunlehui")) {
|
||||
// ToastUtils.show("收到轮盘飘屏");
|
||||
receiveXlhMessage(messageStr);
|
||||
}else if (topic.equals("qx_hour_ranking")){
|
||||
} else if (topic.equals("qx_hour_ranking")) {
|
||||
receiveQXHourRanking(topic, messageStr);
|
||||
}else if (topic.equals("qx_redpacket_arrive")){
|
||||
} else if (topic.equals("qx_redpacket_arrive")) {
|
||||
receiveRed(topic, messageStr);
|
||||
}
|
||||
}
|
||||
@@ -85,13 +88,13 @@ public class MqttInitCallback implements MqttCallback {
|
||||
private void processRedMessage(String topic, String message) {
|
||||
try {
|
||||
// 如果 data 是集合字符串
|
||||
// 解析为集合
|
||||
RedBean dataList = JSON.parseObject(message, RedBean.class);
|
||||
// 解析为集合
|
||||
RedBean dataList = JSON.parseObject(message, RedBean.class);
|
||||
|
||||
// 在主线程处理集合数据
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
processDataRed(dataList);
|
||||
});
|
||||
// 在主线程处理集合数据
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
processDataRed(dataList);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e("MQTT", "解析MQTT消息异常", e);
|
||||
}
|
||||
@@ -123,7 +126,7 @@ public class MqttInitCallback implements MqttCallback {
|
||||
}
|
||||
}
|
||||
|
||||
private void processMessage(String topic, String data){
|
||||
private void processMessage(String topic, String data) {
|
||||
try {
|
||||
// 如果 data 是集合字符串
|
||||
if (isJsonArray(data)) {
|
||||
@@ -139,6 +142,7 @@ public class MqttInitCallback implements MqttCallback {
|
||||
Log.e("MQTT", "解析MQTT消息异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理集合数据
|
||||
private void processDataList(List<HourlyBean> dataList) {
|
||||
// 遍历集合并发送每个元素
|
||||
@@ -147,8 +151,9 @@ public class MqttInitCallback implements MqttCallback {
|
||||
// }
|
||||
|
||||
// 或者发送整个集合
|
||||
EventBus.getDefault().post(dataList);
|
||||
EventBus.getDefault().post(dataList);
|
||||
}
|
||||
|
||||
// 判断是否为 JSON 数组
|
||||
private boolean isJsonArray(String jsonString) {
|
||||
try {
|
||||
@@ -157,6 +162,7 @@ public class MqttInitCallback implements MqttCallback {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void receiveMessage(String topic, String data) {
|
||||
try {
|
||||
JSONObject jsonObject = JSON.parseObject(data);
|
||||
@@ -179,16 +185,19 @@ public class MqttInitCallback implements MqttCallback {
|
||||
new RoomGiftRunable(message).run();
|
||||
break;
|
||||
case 8000:
|
||||
XLHBean xlhBean= GsonUtils.fromJson(message, XLHBean.class);
|
||||
if (xlhBean!=null && xlhBean.getRoom_id()!=null && SpUtil.getMyRoomId()!=null) {
|
||||
if (xlhBean.getRoom_id().equals(SpUtil.getMyRoomId())) {
|
||||
if (xlhBean.getFrom_type()==3) {
|
||||
MqttXlhEnd mqttXlhEnd = new MqttXlhEnd();
|
||||
mqttXlhEnd.setMessage(message);
|
||||
EventBus.getDefault().post(mqttXlhEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
// XLHBean xlhBean= GsonUtils.fromJson(message, XLHBean.class);
|
||||
// if (xlhBean!=null && xlhBean.getRoom_id()!=null && SpUtil.getMyRoomId()!=null) {
|
||||
// if (xlhBean.getRoom_id().equals(SpUtil.getMyRoomId())) {
|
||||
// if (xlhBean.getFrom_type()==3) {
|
||||
LogUtils.e("MQTT", "收到消息" + message);
|
||||
|
||||
MqttXlhEnd mqttXlhEnd = new MqttXlhEnd();
|
||||
mqttXlhEnd.setMessage(message);
|
||||
EventBus.getDefault().post(mqttXlhEnd);
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -200,7 +209,7 @@ public class MqttInitCallback implements MqttCallback {
|
||||
JSONObject jsonObject = JSON.parseObject(messageStr);
|
||||
int type = jsonObject.getIntValue("type");
|
||||
String message = jsonObject.getString("msg");
|
||||
XLHBean xlhBean=JSON.parseObject(message, XLHBean.class);
|
||||
XLHBean xlhBean = JSON.parseObject(message, XLHBean.class);
|
||||
// 将事件处理放到主线程执行
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
processMessageType(type, message);
|
||||
@@ -211,6 +220,7 @@ public class MqttInitCallback implements MqttCallback {
|
||||
// ToastUtils.show("收到轮盘飘屏,解析异常");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* publish发布成功后会执行到这里
|
||||
*/
|
||||
|
||||
@@ -7,10 +7,7 @@ import com.xscm.moduleutil.bean.RedPacketInfo;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
@@ -42,6 +39,11 @@ public class QXRedPacketManager {
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
public List<RedPacketInfo> getSortedUserListLambda(Map<String, RedPacketInfo> userMap) {
|
||||
List<RedPacketInfo> redPacketInfoList = new ArrayList<>(userMap.values());
|
||||
redPacketInfoList.sort((user1, user2) -> Long.compare(user1.getStart_time(), user2.getStart_time()));
|
||||
return redPacketInfoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加红包列表
|
||||
@@ -102,7 +104,7 @@ public class QXRedPacketManager {
|
||||
* @return 红包列表
|
||||
*/
|
||||
public List<RedPacketInfo> getAllRedPackets() {
|
||||
return new ArrayList<>(this.redPackets.values());
|
||||
return getSortedUserListLambda(redPackets);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,7 +146,7 @@ public class QXRedPacketManager {
|
||||
if (this.redPackets == null || this.redPackets.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<RedPacketInfo> packets = new ArrayList<>(this.redPackets.values());
|
||||
List<RedPacketInfo> packets = getAllRedPackets();
|
||||
|
||||
for (RedPacketInfo packet : packets) {
|
||||
long packetTime = packet.remainingTime();
|
||||
@@ -181,7 +183,11 @@ public class QXRedPacketManager {
|
||||
}
|
||||
|
||||
// 继续执行定时任务
|
||||
checkTimerHandler.postDelayed(checkTimerRunnable, 1000);
|
||||
// 修复:增加空值检查避免 NullPointerException
|
||||
if (checkTimerHandler != null && checkTimerRunnable != null) {
|
||||
// 继续执行定时任务
|
||||
checkTimerHandler.postDelayed(checkTimerRunnable, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
package com.xscm.moduleutil.utils
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.LinearGradient
|
||||
import android.graphics.Shader
|
||||
import android.text.TextUtils
|
||||
import android.util.Base64
|
||||
import android.widget.TextView
|
||||
import com.blankj.utilcode.util.LogUtils
|
||||
import com.tencent.qcloud.tuikit.timcommon.BuildConfig
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
import java.lang.reflect.ParameterizedType
|
||||
|
||||
|
||||
fun setGradient(textView: TextView) {
|
||||
val endX = textView.paint.textSize * textView.text.length
|
||||
val colors = intArrayOf(
|
||||
Color.parseColor("#4E67F1"),
|
||||
Color.parseColor("#AA88F8")
|
||||
) //颜色的数组
|
||||
val position = floatArrayOf(0f, 1.0f) //颜色渐变位置的数组
|
||||
val linearGradient =
|
||||
LinearGradient(0f, 0f, endX, 0f, colors, position, Shader.TileMode.CLAMP)
|
||||
textView.paint.shader = linearGradient
|
||||
textView.invalidate()
|
||||
}
|
||||
|
||||
/**
|
||||
* service是否正在运行
|
||||
* @param context
|
||||
* @param className
|
||||
* @return
|
||||
*/
|
||||
fun isServiceExisted(context: Context, className: String): Boolean {
|
||||
val activityManager = context
|
||||
.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
val serviceList = activityManager
|
||||
.getRunningServices(Int.MAX_VALUE)
|
||||
if (serviceList.size <= 0) {
|
||||
return false
|
||||
}
|
||||
for (i in serviceList.indices) {
|
||||
val serviceInfo = serviceList[i]
|
||||
val serviceName = serviceInfo.service
|
||||
val name = serviceName.className
|
||||
if (name == className) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun String.showToast() {
|
||||
if (!TextUtils.isEmpty(this)) {
|
||||
// ToastUtils.showShort(this)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun String.log() {
|
||||
if (!TextUtils.isEmpty(this)) {
|
||||
if (BuildConfig.DEBUG)
|
||||
LogUtils.dTag("midinLog", this)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun String.log2() {
|
||||
if (!TextUtils.isEmpty(this)) {
|
||||
if (BuildConfig.DEBUG)
|
||||
LogUtils.dTag("midi2", this)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据手机分辨率从DP转成PX
|
||||
*
|
||||
* @param context
|
||||
* @param dpValue
|
||||
* @return
|
||||
*/
|
||||
fun dip2px(context: Context, dpValue: Float): Int {
|
||||
val scale = context.resources.displayMetrics.density
|
||||
return (dpValue * scale + 0.5f).toInt()
|
||||
}
|
||||
|
||||
fun <T> getClass(t: Any): Class<T> {
|
||||
// 通过反射 获取父类泛型 (T) 对应 Class类
|
||||
return (t.javaClass.genericSuperclass as ParameterizedType)
|
||||
.actualTypeArguments[0]
|
||||
as Class<T>
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 文件转Base64.
|
||||
*
|
||||
* @param filePath
|
||||
* @return
|
||||
*/
|
||||
fun file2Base64(filePath: String): String {
|
||||
var objFileIS: FileInputStream? = null
|
||||
try {
|
||||
objFileIS = FileInputStream(filePath)
|
||||
} catch (e: FileNotFoundException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
val objByteArrayOS = ByteArrayOutputStream()
|
||||
val byteBufferString = ByteArray(1024)
|
||||
try {
|
||||
var readNum: Int
|
||||
while (objFileIS!!.read(byteBufferString).also { readNum = it } != -1) {
|
||||
objByteArrayOS.write(byteBufferString, 0, readNum)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return Base64.encodeToString(objByteArrayOS.toByteArray(), Base64.DEFAULT)
|
||||
}
|
||||
|
||||
|
||||
@@ -51,11 +51,11 @@ public class EnvironmentPrefs {
|
||||
// }
|
||||
|
||||
// 默认使用生产环境
|
||||
String envName = sharedPreferences.getString(KEY_ENV, EnvironmentEnum.TEST.name());
|
||||
String envName = sharedPreferences.getString(KEY_ENV, EnvironmentEnum.PRODUCTION.name());
|
||||
try {
|
||||
return EnvironmentEnum.valueOf(envName);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return EnvironmentEnum.TEST; // 出错时默认返回生产环境
|
||||
return EnvironmentEnum.PRODUCTION; // 出错时默认返回生产环境
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class QXMeetGiftView extends RelativeLayout {
|
||||
giftImageView = new ImageView(context);
|
||||
giftImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
LayoutParams giftImageParams = new LayoutParams(
|
||||
dpToPx(62), // 固定宽度
|
||||
dpToPx(48), // 固定宽度
|
||||
dpToPx(62) // 固定高度
|
||||
);
|
||||
giftImageParams.addRule(CENTER_IN_PARENT);
|
||||
@@ -146,8 +146,8 @@ public class QXMeetGiftView extends RelativeLayout {
|
||||
if (isLockGift) {
|
||||
// 重新设置礼物图片的约束
|
||||
LayoutParams params = (LayoutParams) giftImageView.getLayoutParams();
|
||||
params.width = dpToPx(62);
|
||||
params.height = dpToPx(62);
|
||||
params.width = dpToPx(36);
|
||||
params.height = dpToPx(36);
|
||||
params.addRule(CENTER_IN_PARENT);
|
||||
params.setMargins(0, 0, 0, 0);
|
||||
giftImageView.setLayoutParams(params);
|
||||
|
||||
@@ -100,6 +100,7 @@ public class QXTimeDownView extends FrameLayout {
|
||||
bigTimeLabel.setTextColor(0xFFFFECA7);
|
||||
bigTimeLabel.setGravity(Gravity.CENTER);
|
||||
bigTimeLabel.setVisibility(View.GONE);
|
||||
bigTimeLabel.setTypeface(Typeface.create("semibold", Typeface.NORMAL));
|
||||
LayoutParams bigTimeParams = new LayoutParams(
|
||||
LayoutParams.WRAP_CONTENT,
|
||||
LayoutParams.WRAP_CONTENT
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
package com.xscm.moduleutil.widget
|
||||
|
||||
|
||||
import android.graphics.SurfaceTexture
|
||||
import android.opengl.GLES20
|
||||
import android.opengl.Matrix
|
||||
|
||||
class ChannelSplitRenderer {
|
||||
|
||||
private val vertexShaderCode = """
|
||||
attribute vec4 aPosition;
|
||||
attribute vec2 aTexCoord;
|
||||
varying vec2 vTexCoord;
|
||||
void main() {
|
||||
gl_Position = aPosition;
|
||||
vTexCoord = aTexCoord;
|
||||
}
|
||||
"""
|
||||
|
||||
private val fragmentShaderCode = """
|
||||
precision mediump float;
|
||||
uniform sampler2D uTexture;
|
||||
varying vec2 vTexCoord;
|
||||
void main() {
|
||||
// 只使用左半部分作为最终颜色
|
||||
vec2 leftCoord = vec2(vTexCoord.x * 0.5, vTexCoord.y);
|
||||
vec4 color = texture2D(uTexture, leftCoord);
|
||||
|
||||
// 设置 alpha 为 1.0 表示完全不透明,或根据需求设为 0.0 表示全透明
|
||||
gl_FragColor = vec4(color.rgb, 0.0); // 左通道颜色 + 不透明
|
||||
}"""
|
||||
|
||||
private var program = 0
|
||||
private var positionHandle = 0
|
||||
private var texCoordHandle = 0
|
||||
private var textureHandle = 0
|
||||
private val projectionMatrix = FloatArray(16)
|
||||
private val modelMatrix = FloatArray(16)
|
||||
|
||||
fun onSurfaceCreated(surface: SurfaceTexture, width: Int, height: Int) {
|
||||
// 初始化着色器
|
||||
val vertexShader = ShaderUtils.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode)
|
||||
val fragmentShader = ShaderUtils.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode)
|
||||
|
||||
program = GLES20.glCreateProgram().also {
|
||||
GLES20.glAttachShader(it, vertexShader)
|
||||
GLES20.glAttachShader(it, fragmentShader)
|
||||
GLES20.glLinkProgram(it)
|
||||
}
|
||||
|
||||
positionHandle = GLES20.glGetAttribLocation(program, "aPosition")
|
||||
texCoordHandle = GLES20.glGetAttribLocation(program, "aTexCoord")
|
||||
textureHandle = GLES20.glGetUniformLocation(program, "uTexture")
|
||||
|
||||
// 初始化矩阵
|
||||
Matrix.setIdentityM(projectionMatrix, 0)
|
||||
Matrix.setIdentityM(modelMatrix, 0)
|
||||
|
||||
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f)
|
||||
GLES20.glEnable(GLES20.GL_BLEND)
|
||||
GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA)
|
||||
}
|
||||
|
||||
fun onSurfaceChanged(width: Int, height: Int) {
|
||||
GLES20.glViewport(0, 0, width, height)
|
||||
}
|
||||
|
||||
fun onDrawFrame(textureId: Int) {
|
||||
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT)
|
||||
GLES20.glUseProgram(program)
|
||||
|
||||
// 定义顶点坐标(全屏)
|
||||
val vertices = floatArrayOf(
|
||||
-1.0f, -1.0f, 0.0f,
|
||||
1.0f, -1.0f, 0.0f,
|
||||
-1.0f, 1.0f, 0.0f,
|
||||
1.0f, 1.0f, 0.0f
|
||||
)
|
||||
|
||||
// 修改纹理坐标,只映射左半部分视频内容到左侧屏幕
|
||||
val texCoords = floatArrayOf(
|
||||
0.0f, 1.0f, // 左下角
|
||||
0.5f, 1.0f, // 右下角(对应视频中间)
|
||||
0.0f, 0.0f, // 左上角
|
||||
0.5f, 0.0f // 右上角
|
||||
)
|
||||
|
||||
val vertexBuffer = ShaderUtils.createFloatBuffer(vertices)
|
||||
val texBuffer = ShaderUtils.createFloatBuffer(texCoords)
|
||||
|
||||
GLES20.glEnableVertexAttribArray(positionHandle)
|
||||
GLES20.glVertexAttribPointer(
|
||||
positionHandle, 3,
|
||||
GLES20.GL_FLOAT, false,
|
||||
0, vertexBuffer
|
||||
)
|
||||
|
||||
GLES20.glEnableVertexAttribArray(texCoordHandle)
|
||||
GLES20.glVertexAttribPointer(
|
||||
texCoordHandle, 2,
|
||||
GLES20.GL_FLOAT, false,
|
||||
0, texBuffer
|
||||
)
|
||||
|
||||
// 绑定纹理
|
||||
GLES20.glActiveTexture(GLES20.GL_TEXTURE0)
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId)
|
||||
GLES20.glUniform1i(textureHandle, 0)
|
||||
|
||||
// 绘制
|
||||
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4)
|
||||
|
||||
// 清理
|
||||
GLES20.glDisableVertexAttribArray(positionHandle)
|
||||
GLES20.glDisableVertexAttribArray(texCoordHandle)
|
||||
}
|
||||
|
||||
|
||||
fun release() {
|
||||
GLES20.glDeleteProgram(program)
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.xscm.moduleutil.widget.room
|
||||
|
||||
import androidx.lifecycle.LifecycleObserver
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.xscm.moduleutil.bean.room.RoomInfoResp
|
||||
import com.xscm.moduleutil.http.RetrofitClient
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
open class BaseViewModel : ViewModel(),LifecycleObserver {
|
||||
|
||||
val roomInfoData=MutableLiveData<RoomInfoResp>()
|
||||
private val passRoom by lazy { MutableLiveData<Exception>() }
|
||||
|
||||
private val error by lazy { MutableLiveData<Exception>() }
|
||||
|
||||
private val finally by lazy { MutableLiveData<Int>() }
|
||||
//加入房间
|
||||
fun jiaoRoom(roomId:String, password:String){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求失败,出现异常
|
||||
*/
|
||||
fun getError(): LiveData<Exception> {
|
||||
return error
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求完成,在此处做一些关闭操作
|
||||
*/
|
||||
fun getFinally(): LiveData<Int> {
|
||||
return finally
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user