This commit is contained in:
2026-05-11 14:32:27 +08:00
parent c6fbcec2d6
commit 473e2c2d89
11 changed files with 165 additions and 137 deletions

View File

@@ -56,7 +56,14 @@ class DefaultFloatService : BaseFloatWindow(), View.OnClickListener {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
LogUtils.d(TAG, "onStartCommand: ${intent?.data}")
show()
when (intent?.getStringExtra(FloatWindowManager.EXTRA_ACTION)) {
FloatWindowManager.ACTION_HIDE -> {
hide()
stopForeground(true)
stopSelf()
}
else -> show()
}
return super.onStartCommand(intent, flags, startId)
}
@@ -197,4 +204,10 @@ class DefaultFloatService : BaseFloatWindow(), View.OnClickListener {
}
override fun onDestroyed() {}
override fun onDestroy() {
hide()
stopForeground(true)
super.onDestroy()
}
}

View File

@@ -11,9 +11,13 @@ object FloatWindowManager {
private val TAG = FloatWindowManager::class.java.simpleName
private var context = Utils.getApp()
const val EXTRA_ACTION = "float_action"
const val ACTION_SHOW = "show"
const val ACTION_HIDE = "hide"
fun show(service: Class<out BaseFloatWindow>, intent: Intent? = null) {
startServiceSafe(Intent(context, service).apply {
putExtra(EXTRA_ACTION, ACTION_SHOW)
if (intent != null) {
this.putExtras(intent)
}
@@ -22,6 +26,7 @@ object FloatWindowManager {
fun hide(service: Class<out BaseFloatWindow>, intent: Intent? = null) {
startServiceSafe(Intent(context, service).apply {
putExtra(EXTRA_ACTION, ACTION_HIDE)
if (intent != null) {
this.putExtras(intent)
}
@@ -36,4 +41,4 @@ object FloatWindowManager {
}
}
}
}