Skip to content

Commit

Permalink
WIP: workaround against invalid event
Browse files Browse the repository at this point in the history
  • Loading branch information
030 committed Nov 26, 2021
1 parent 51ceeda commit 01a9af1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package moe.dic1911.autodnd

import android.accessibilityservice.AccessibilityService
import android.accessibilityservice.AccessibilityServiceInfo
import android.app.Application
import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.media.AudioManager
import android.util.Log
import android.util.TimeUtils
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityEvent.*
import moe.dic1911.autodnd.data.Storage
Expand All @@ -22,6 +24,7 @@ class DNDAccessibilityService : AccessibilityService() {
private var state = 0
private var bakNotiState = NotificationManager.INTERRUPTION_FILTER_ALL
private var bakRingMode = AudioManager.RINGER_MODE_VIBRATE
private var launcherTimestamp: Long = 0

override fun onInterrupt() {}

Expand Down Expand Up @@ -75,6 +78,12 @@ class DNDAccessibilityService : AccessibilityService() {
notiMan.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALARMS)
state = 1
} else if (state == 1) {
// workaround against invalid(?) events triggered by gesture
if (false && curApp.contains("launcher")) {
val popup = Intent(this, PopupActivity()::class.java)
popup.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(popup)
}
state = 0
if (bakNotiState != notiMan.currentInterruptionFilter) {
notiMan.setInterruptionFilter(bakNotiState)
Expand All @@ -84,5 +93,4 @@ class DNDAccessibilityService : AccessibilityService() {
}
}
}

}
12 changes: 12 additions & 0 deletions app/src/main/java/moe/dic1911/autodnd/PopupActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package moe.dic1911.autodnd

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class PopupActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_popup)
finishAffinity()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MainFragment(val index: Int) : Fragment() {
pageViewModel.applist.observe(viewLifecycleOwner, {
Log.d("030-list", it.size.toString())
(recyclerView.adapter as AppListAdapter?)?.appList = it
(recyclerView.adapter as AppListAdapter?)?.notifyDataSetChanged()
(recyclerView.adapter as AppListAdapter?)?.notifyItemRangeChanged(0, it.size)
})
if (Storage.prefs_str.hasObservers()) {
Storage.prefs_str.removeObservers(this)
Expand Down

0 comments on commit 01a9af1

Please sign in to comment.