This commit is contained in:
parent
5dc924baf3
commit
0c49fd0faa
|
|
@ -473,6 +473,14 @@
|
|||
|
||||
// 延迟检测
|
||||
setTimeout(checkApp, 300);
|
||||
// 同步 PTT 登录状态
|
||||
setTimeout(function() {
|
||||
if (window.android && window.android.pttGetLoginStatus) {
|
||||
var status = window.android.pttGetLoginStatus();
|
||||
var loginId = window.android.pttGetLoginId ? window.android.pttGetLoginId() : "";
|
||||
updatePttLoginStatus(status, loginId);
|
||||
}
|
||||
}, 500);
|
||||
|
||||
// 告知 Android 页面加载完成
|
||||
window.onload = function() {
|
||||
|
|
@ -670,22 +678,37 @@
|
|||
|
||||
// PTT 登录成功回调 (由 Android 调用)
|
||||
function onPttLoginSuccess() {
|
||||
pttStatusTag.innerText = "PTT 已登录";
|
||||
pttStatusTag.className = "ws-status ws-connected";
|
||||
|
||||
// 激活按钮
|
||||
pttBtn.disabled = false;
|
||||
pttBtn.style.background = "#ef4444";
|
||||
pttBtn.style.cursor = "pointer";
|
||||
|
||||
var actionBtns = document.querySelectorAll('.ptt-action-btn');
|
||||
for (var i = 0; i < actionBtns.length; i++) {
|
||||
actionBtns[i].disabled = false;
|
||||
}
|
||||
|
||||
updatePttLoginStatusUI("02");
|
||||
showPttResult("PTT 业务初始化成功,对讲功能已就绪");
|
||||
}
|
||||
|
||||
// 更新 PTT 登录状态 (由 Android 实时推送)
|
||||
window.updatePttLoginStatus = function(status, loginId) {
|
||||
updatePttLoginStatusUI(status);
|
||||
var statusMap = { "00": "未登录", "01": "登录中...", "02": "已登录" };
|
||||
showPttResult("登录状态变更: " + (statusMap[status] || status) + " (ID:" + loginId + ")");
|
||||
};
|
||||
|
||||
function updatePttLoginStatusUI(status) {
|
||||
if (status === "02") {
|
||||
pttStatusTag.innerText = "PTT 已登录";
|
||||
pttStatusTag.className = "ws-status ws-connected";
|
||||
pttBtn.disabled = false;
|
||||
pttBtn.style.background = "#ef4444";
|
||||
pttBtn.style.cursor = "pointer";
|
||||
var actionBtns = document.querySelectorAll('.ptt-action-btn');
|
||||
for (var i = 0; i < actionBtns.length; i++) {
|
||||
actionBtns[i].disabled = false;
|
||||
}
|
||||
} else if (status === "01") {
|
||||
pttStatusTag.innerText = "PTT 登录中...";
|
||||
pttStatusTag.className = "ws-status ws-disconnected";
|
||||
} else {
|
||||
pttStatusTag.innerText = "PTT 未登录";
|
||||
pttStatusTag.className = "ws-status ws-disconnected";
|
||||
}
|
||||
}
|
||||
|
||||
// 修复 PTT 按键逻辑:支持 TouchEvents 并处理异常中断
|
||||
if (pttBtn) {
|
||||
var isDown = false;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,21 @@ public class CallBackResolution {
|
|||
private static int logNum = 0;
|
||||
private static long offlineTime = 0;
|
||||
private static boolean loginState = false;
|
||||
private static String pttLoginStatus = "00"; // 00-未登录 01-登录中 02-已登录
|
||||
private static String pttLoginId = "";
|
||||
|
||||
public static String getPttLoginStatus() {
|
||||
return pttLoginStatus;
|
||||
}
|
||||
|
||||
public static String getPttLoginId() {
|
||||
return pttLoginId;
|
||||
}
|
||||
|
||||
public static void resetPttLoginStatus() {
|
||||
pttLoginStatus = "00";
|
||||
pttLoginId = "";
|
||||
}
|
||||
|
||||
public static void at_OEM_AT_cb(List<String> lisHex){
|
||||
if (lisHex.size() == 0) {
|
||||
|
|
@ -33,14 +48,23 @@ public class CallBackResolution {
|
|||
switch (firstHex){
|
||||
case "82"://登录状态通知指令
|
||||
String loginId = lisHex.get(2) + "" + lisHex.get(3) + "" + lisHex.get(4) + "" + lisHex.get(5);
|
||||
pttLoginStatus = errorNum;
|
||||
pttLoginId = loginId;
|
||||
Timber.tag(TAG).i("PTT login status: %s, id: %s", pttLoginStatus, pttLoginId);
|
||||
// 实时推送状态到前端
|
||||
com.stand.standapp.MainActivity.executeJs("updatePttLoginStatus('" + pttLoginStatus + "','" + pttLoginId + "')");
|
||||
CallBackUtil.callBackLoinState(errorNum, loginId);
|
||||
loginState = isLoginConflict(errorNum);
|
||||
CallBackUtil.callBackLoginConflict(loginState);
|
||||
if (loginState) {
|
||||
com.stand.standapp.MainActivity.showPttConflictDialog();
|
||||
}
|
||||
if ("02".equals(errorNum)) {
|
||||
com.stand.standapp.MainActivity.onPttLoginSuccess();
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case "a2"://账号有视频功能
|
||||
CallBackUtil.callBackHaveVideo();
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -46,4 +46,14 @@ public class MyApplication {
|
|||
Log.e("PTT_INIT", "Failed to init PTT: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void destroy() {
|
||||
if (pNative != null) {
|
||||
pNative.destory();
|
||||
pNative = null;
|
||||
}
|
||||
mContext = null;
|
||||
mAppInstance = new MyApplication();
|
||||
CallBackResolution.resetPttLoginStatus();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,9 +35,26 @@ class AndroidInterface(private val activity: MainActivity) {
|
|||
}
|
||||
|
||||
/**
|
||||
* PTT 停止说话
|
||||
* 获取 PTT 登录状态: "00"-未登录 "01"-登录中 "02"-已登录
|
||||
*/
|
||||
@JavascriptInterface
|
||||
fun pttGetLoginStatus(): String {
|
||||
return com.example.kingway.ptt.CallBackResolution.getPttLoginStatus()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 PTT 登录 ID
|
||||
*/
|
||||
@JavascriptInterface
|
||||
fun pttGetLoginId(): String {
|
||||
return com.example.kingway.ptt.CallBackResolution.getPttLoginId()
|
||||
}
|
||||
|
||||
/**
|
||||
* PTT 登录
|
||||
*/
|
||||
|
||||
@JavascriptInterface
|
||||
fun pttSpeakRelease() {
|
||||
if (isSpeaking) {
|
||||
val now = System.currentTimeMillis()
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ class LoginActivity : AppCompatActivity() {
|
|||
|
||||
// 4. 退出按钮
|
||||
btnExit.setOnClickListener {
|
||||
pttLogoutAndDestroy()
|
||||
finish()
|
||||
}
|
||||
|
||||
|
|
@ -231,8 +232,26 @@ class LoginActivity : AppCompatActivity() {
|
|||
AlertDialog.Builder(this)
|
||||
.setTitle("提示")
|
||||
.setMessage("确定要退出应用吗?")
|
||||
.setPositiveButton("确定") { _, _ -> finish() }
|
||||
.setPositiveButton("确定") { _, _ ->
|
||||
pttLogoutAndDestroy()
|
||||
finish()
|
||||
}
|
||||
.setNegativeButton("取消", null)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun pttLogoutAndDestroy() {
|
||||
try {
|
||||
com.example.kingway.ptt.SendAtUtil.toLogout()
|
||||
Timber.tag("LoginActivity").i("PTT logout sent")
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("LoginActivity").e(e, "PTT logout failed")
|
||||
}
|
||||
try {
|
||||
com.example.kingway.ptt.MyApplication.destroy()
|
||||
Timber.tag("LoginActivity").i("PTT native destroyed")
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("LoginActivity").e(e, "PTT destroy failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,11 @@ class MainActivity : AppCompatActivity() {
|
|||
.setMessage("您的 PTT 账号已在其他设备登录,当前设备已被迫下线。\n请点击确认退出并重新登录。")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("确认") { _, _ ->
|
||||
try {
|
||||
com.example.kingway.ptt.SendAtUtil.toLogout()
|
||||
com.example.kingway.ptt.MyApplication.destroy()
|
||||
com.stand.standapp.utils.GpioManager.stopListening()
|
||||
} catch (_: Exception) {}
|
||||
val pm = ctx.packageManager
|
||||
val intent = pm.getLaunchIntentForPackage(ctx.packageName)
|
||||
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
|
|
@ -171,11 +176,34 @@ class MainActivity : AppCompatActivity() {
|
|||
androidx.appcompat.app.AlertDialog.Builder(this)
|
||||
.setTitle("提示")
|
||||
.setMessage("确定要退出应用吗?")
|
||||
.setPositiveButton("确定") { _, _ -> finish() }
|
||||
.setPositiveButton("确定") { _, _ ->
|
||||
pttLogoutAndDestroy()
|
||||
finish()
|
||||
}
|
||||
.setNegativeButton("取消", null)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun pttLogoutAndDestroy() {
|
||||
try {
|
||||
com.example.kingway.ptt.SendAtUtil.toLogout()
|
||||
Timber.tag("MainActivity").i("PTT logout sent")
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("MainActivity").e(e, "PTT logout failed")
|
||||
}
|
||||
try {
|
||||
com.stand.standapp.utils.GpioManager.stopListening()
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("MainActivity").e(e, "GPIO stop failed")
|
||||
}
|
||||
try {
|
||||
com.example.kingway.ptt.MyApplication.destroy()
|
||||
Timber.tag("MainActivity").i("PTT native destroyed")
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("MainActivity").e(e, "PTT destroy failed")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
if (mAgentWeb?.handleKeyEvent(keyCode, event) == true) {
|
||||
return true
|
||||
|
|
|
|||
Loading…
Reference in New Issue