change
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user