Show centered node join/leave overlay for 5s (v1.0.4)
- Replaces bottom toast: dark rounded card centered on screen, auto-hides after 5 seconds - Optional test trigger via node_toast_test intent extra
This commit is contained in:
@@ -9,6 +9,7 @@ import android.content.Intent
|
|||||||
import android.content.ServiceConnection
|
import android.content.ServiceConnection
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.graphics.PixelFormat
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
@@ -16,6 +17,7 @@ import android.os.IBinder
|
|||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.view.Gravity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
@@ -101,6 +103,11 @@ class MainActivity : Activity(), SvxService.Listener {
|
|||||||
btnSettings = findViewById(R.id.btn_settings)
|
btnSettings = findViewById(R.id.btn_settings)
|
||||||
pttButton.enabled2 = false
|
pttButton.enabled2 = false
|
||||||
|
|
||||||
|
val testText = intent?.getStringExtra("node_toast_test")
|
||||||
|
if (testText != null) {
|
||||||
|
mainHandler.postDelayed({ showNodeOverlay(testText) }, 1500)
|
||||||
|
}
|
||||||
|
|
||||||
btnSettings.setOnClickListener {
|
btnSettings.setOnClickListener {
|
||||||
startActivity(Intent(this, SettingsActivity::class.java))
|
startActivity(Intent(this, SettingsActivity::class.java))
|
||||||
}
|
}
|
||||||
@@ -170,6 +177,8 @@ class MainActivity : Activity(), SvxService.Listener {
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
hideNodeOverlay()
|
||||||
|
mainHandler.removeCallbacksAndMessages(null)
|
||||||
SplashActivity.mainAlive = false
|
SplashActivity.mainAlive = false
|
||||||
svc?.listener = null
|
svc?.listener = null
|
||||||
unbindService(svcConn)
|
unbindService(svcConn)
|
||||||
@@ -273,6 +282,53 @@ class MainActivity : Activity(), SvxService.Listener {
|
|||||||
// последний говоривший остаётся на экране
|
// последний говоривший остаётся на экране
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onNodeJoined(callsign: String, tg: Long?) {
|
||||||
|
showNodeToast(R.string.toast_node_joined, callsign, tg)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNodeLeft(callsign: String, tg: Long?) {
|
||||||
|
showNodeToast(R.string.toast_node_left, callsign, tg)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showNodeToast(tpl: Int, callsign: String, tg: Long?) {
|
||||||
|
if (!Prefs.nodeToastsEnabled(this)) return
|
||||||
|
if (callsign.equals(settings.callsign, ignoreCase = true)) return
|
||||||
|
val suffix = if (tg != null) getString(R.string.node_tg_suffix, tg) else ""
|
||||||
|
mainHandler.post { showNodeOverlay(getString(tpl, callsign, suffix)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private var nodeOverlay: View? = null
|
||||||
|
|
||||||
|
private fun showNodeOverlay(text: String) {
|
||||||
|
hideNodeOverlay()
|
||||||
|
val view = layoutInflater.inflate(R.layout.view_node_toast, null, false)
|
||||||
|
view.findViewById<TextView>(R.id.lbl_node_toast).text = text
|
||||||
|
try {
|
||||||
|
windowManager.addView(
|
||||||
|
view,
|
||||||
|
WindowManager.LayoutParams(
|
||||||
|
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||||
|
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||||
|
WindowManager.LayoutParams.TYPE_APPLICATION,
|
||||||
|
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
|
||||||
|
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
|
||||||
|
PixelFormat.TRANSLUCENT
|
||||||
|
).apply { gravity = Gravity.CENTER }
|
||||||
|
)
|
||||||
|
nodeOverlay = view
|
||||||
|
mainHandler.postDelayed({ hideNodeOverlay() }, 5000)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
toast(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hideNodeOverlay() {
|
||||||
|
nodeOverlay?.let { v ->
|
||||||
|
try { windowManager.removeView(v) } catch (_: Exception) { }
|
||||||
|
nodeOverlay = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onAudioPacket(packet: ByteArray, seq: Int) {
|
override fun onAudioPacket(packet: ByteArray, seq: Int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package ru.ua1zbe.svxremote
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
|
import android.widget.CheckBox
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import ru.ua1zbe.svxremote.prefs.ConnectionSettings
|
import ru.ua1zbe.svxremote.prefs.ConnectionSettings
|
||||||
@@ -27,6 +28,8 @@ class SettingsActivity : Activity() {
|
|||||||
inputAuthKey = findViewById(R.id.input_auth_key)
|
inputAuthKey = findViewById(R.id.input_auth_key)
|
||||||
inputTg = findViewById(R.id.input_tg)
|
inputTg = findViewById(R.id.input_tg)
|
||||||
inputGroups = findViewById(R.id.input_groups)
|
inputGroups = findViewById(R.id.input_groups)
|
||||||
|
val chkNodeToasts = findViewById<CheckBox>(R.id.chk_node_toasts)
|
||||||
|
chkNodeToasts.isChecked = Prefs.nodeToastsEnabled(this)
|
||||||
|
|
||||||
val s = Prefs.load(this)
|
val s = Prefs.load(this)
|
||||||
inputHost.setText(s.host)
|
inputHost.setText(s.host)
|
||||||
@@ -63,6 +66,7 @@ class SettingsActivity : Activity() {
|
|||||||
groups = groups
|
groups = groups
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Prefs.setNodeToastsEnabled(this, chkNodeToasts.isChecked)
|
||||||
toast(getString(R.string.saved))
|
toast(getString(R.string.saved))
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ class SplashActivity : Activity() {
|
|||||||
Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
||||||
Intent.FLAG_ACTIVITY_SINGLE_TOP
|
Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||||
)
|
)
|
||||||
|
val testText = this.intent?.getStringExtra("node_toast_test")
|
||||||
|
if (testText != null) intent.putExtra("node_toast_test", testText)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
|
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
|
||||||
finish()
|
finish()
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ class SvxService : Service(), ReflectorClient.Callbacks {
|
|||||||
fun onServerInfo(info: MsgParser.ServerInfo)
|
fun onServerInfo(info: MsgParser.ServerInfo)
|
||||||
fun onTalkerStart(tg: Long, callsign: String)
|
fun onTalkerStart(tg: Long, callsign: String)
|
||||||
fun onTalkerStop(tg: Long, callsign: String)
|
fun onTalkerStop(tg: Long, callsign: String)
|
||||||
|
fun onNodeJoined(callsign: String, tg: Long?)
|
||||||
|
fun onNodeLeft(callsign: String, tg: Long?)
|
||||||
fun onAudioPacket(packet: ByteArray, seq: Int)
|
fun onAudioPacket(packet: ByteArray, seq: Int)
|
||||||
fun onAudioFlush()
|
fun onAudioFlush()
|
||||||
fun onError(detail: String)
|
fun onError(detail: String)
|
||||||
@@ -123,12 +125,14 @@ class SvxService : Service(), ReflectorClient.Callbacks {
|
|||||||
/** Текущий список подключенных узлов (копия для UI). */
|
/** Текущий список подключенных узлов (копия для UI). */
|
||||||
fun nodeList(): List<String> = synchronized(nodeSet) { nodeSet.toList() }
|
fun nodeList(): List<String> = synchronized(nodeSet) { nodeSet.toList() }
|
||||||
|
|
||||||
override fun onNodeJoined(callsign: String) {
|
override fun onNodeJoined(callsign: String, tg: Long?) {
|
||||||
synchronized(nodeSet) { nodeSet.add(callsign) }
|
synchronized(nodeSet) { nodeSet.add(callsign) }
|
||||||
|
listener?.onNodeJoined(callsign, tg)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNodeLeft(callsign: String) {
|
override fun onNodeLeft(callsign: String, tg: Long?) {
|
||||||
synchronized(nodeSet) { nodeSet.remove(callsign) }
|
synchronized(nodeSet) { nodeSet.remove(callsign) }
|
||||||
|
listener?.onNodeLeft(callsign, tg)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTalkerStart(tg: Long, callsign: String) {
|
override fun onTalkerStart(tg: Long, callsign: String) {
|
||||||
|
|||||||
@@ -42,4 +42,14 @@ object Prefs {
|
|||||||
.putString("groups", s.groups.distinct().joinToString(","))
|
.putString("groups", s.groups.distinct().joinToString(","))
|
||||||
.apply()
|
.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun nodeToastsEnabled(context: Context): Boolean {
|
||||||
|
return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||||
|
.getBoolean("node_toasts", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setNodeToastsEnabled(context: Context, enabled: Boolean) {
|
||||||
|
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||||
|
.edit().putBoolean("node_toasts", enabled).apply()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -23,8 +23,8 @@ class ReflectorClient(
|
|||||||
fun onServerInfo(info: MsgParser.ServerInfo)
|
fun onServerInfo(info: MsgParser.ServerInfo)
|
||||||
fun onTalkerStart(tg: Long, callsign: String)
|
fun onTalkerStart(tg: Long, callsign: String)
|
||||||
fun onTalkerStop(tg: Long, callsign: String)
|
fun onTalkerStop(tg: Long, callsign: String)
|
||||||
fun onNodeJoined(callsign: String)
|
fun onNodeJoined(callsign: String, tg: Long?)
|
||||||
fun onNodeLeft(callsign: String)
|
fun onNodeLeft(callsign: String, tg: Long?)
|
||||||
/** Входящий аудиопакет Opus. */
|
/** Входящий аудиопакет Opus. */
|
||||||
fun onAudioPacket(packet: ByteArray, seq: Int)
|
fun onAudioPacket(packet: ByteArray, seq: Int)
|
||||||
fun onAudioFlush()
|
fun onAudioFlush()
|
||||||
@@ -367,13 +367,13 @@ class ReflectorClient(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReflectorProtocol.MSG_NODE_JOINED -> {
|
ReflectorProtocol.MSG_NODE_JOINED -> {
|
||||||
val cs = parseSimpleString(msg.fields)
|
val (cs, tg) = parseNodeEvent(msg.fields)
|
||||||
callbacks.onNodeJoined(cs)
|
callbacks.onNodeJoined(cs, tg)
|
||||||
}
|
}
|
||||||
|
|
||||||
ReflectorProtocol.MSG_NODE_LEFT -> {
|
ReflectorProtocol.MSG_NODE_LEFT -> {
|
||||||
val cs = parseSimpleString(msg.fields)
|
val (cs, tg) = parseNodeEvent(msg.fields)
|
||||||
callbacks.onNodeLeft(cs)
|
callbacks.onNodeLeft(cs, tg)
|
||||||
}
|
}
|
||||||
|
|
||||||
ReflectorProtocol.MSG_TALKER_START -> {
|
ReflectorProtocol.MSG_TALKER_START -> {
|
||||||
@@ -404,6 +404,17 @@ class ReflectorClient(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun parseNodeEvent(fields: ByteArray): Pair<String, Long?> {
|
||||||
|
return try {
|
||||||
|
val r = BinReader(fields)
|
||||||
|
val cs = r.str().ifEmpty { "?" }
|
||||||
|
val tg = try { r.str().toLongOrNull() } catch (_: Exception) { null }
|
||||||
|
cs to tg
|
||||||
|
} catch (_: Exception) {
|
||||||
|
"?" to null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun parseSimpleString(fields: ByteArray): String {
|
private fun parseSimpleString(fields: ByteArray): String {
|
||||||
return try {
|
return try {
|
||||||
BinReader(fields).str().ifEmpty { "?" }
|
BinReader(fields).str().ifEmpty { "?" }
|
||||||
|
|||||||
7
app/src/main/res/drawable/bg_node_toast.xml
Normal file
7
app/src/main/res/drawable/bg_node_toast.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<solid android:color="#E61B222A" />
|
||||||
|
<corners android:radius="24dp" />
|
||||||
|
<stroke android:width="1dp" android:color="#40FFFFFF" />
|
||||||
|
</shape>
|
||||||
@@ -139,6 +139,15 @@
|
|||||||
android:padding="12dp"
|
android:padding="12dp"
|
||||||
android:hint="9, 11, 12, 13" />
|
android:hint="9, 11, 12, 13" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/chk_node_toasts"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="24dp"
|
||||||
|
android:text="@string/pref_node_toasts"
|
||||||
|
android:textColor="@color/text_primary"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btn_save"
|
android:id="@+id/btn_save"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
20
app/src/main/res/layout/view_node_toast.xml
Normal file
20
app/src/main/res/layout/view_node_toast.xml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/node_toast_root"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/bg_node_toast"
|
||||||
|
android:paddingLeft="24dp"
|
||||||
|
android:paddingRight="24dp"
|
||||||
|
android:paddingTop="14dp"
|
||||||
|
android:paddingBottom="14dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/lbl_node_toast"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textColor="#F0F0F0"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</FrameLayout>
|
||||||
@@ -14,6 +14,10 @@
|
|||||||
<string name="toast_groups_empty">Добавьте группы в настройках</string>
|
<string name="toast_groups_empty">Добавьте группы в настройках</string>
|
||||||
<string name="nodes_title">Узлы в сети (%1$d)</string>
|
<string name="nodes_title">Узлы в сети (%1$d)</string>
|
||||||
<string name="toast_nodes_empty">Нет подключенных узлов</string>
|
<string name="toast_nodes_empty">Нет подключенных узлов</string>
|
||||||
|
<string name="pref_node_toasts">Всплывающее уведомление о подключении/отключении узлов</string>
|
||||||
|
<string name="toast_node_joined">Подключился: %1$s%2$s</string>
|
||||||
|
<string name="toast_node_left">Отключился: %1$s%2$s</string>
|
||||||
|
<string name="node_tg_suffix"> (группа %1$d)</string>
|
||||||
<string name="btn_save">Сохранить</string>
|
<string name="btn_save">Сохранить</string>
|
||||||
<string name="app_version">SVXhomyak — v1.0.4</string>
|
<string name="app_version">SVXhomyak — v1.0.4</string>
|
||||||
<string name="saved">Сохранено</string>
|
<string name="saved">Сохранено</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user