Skip to content

Commit

Permalink
update 优化关闭服务;优化悬浮窗位置
Browse files Browse the repository at this point in the history
  • Loading branch information
gallonyin committed May 29, 2023
1 parent e7813b2 commit 5f8bc34
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.blankj.utilcode.constant.PermissionConstants
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.qmuiteam.qmui.widget.dialog.QMUIDialog
import org.yameida.worktool.service.PlayNotifyService
import org.yameida.worktool.service.WeworkController
import org.yameida.worktool.service.fastStartActivity
import org.yameida.worktool.utils.*
import org.yameida.worktool.utils.capture.MediaProjectionHolder
Expand Down Expand Up @@ -152,9 +153,7 @@ class ListenActivity : AppCompatActivity() {
}
} else {
if (PermissionHelper.isAccessibilitySettingOn()) {
sw_accessibility.isChecked = true
val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
startActivity(intent)
WeworkController.weworkService.disableSelf()
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import okhttp3.RequestBody
import org.json.JSONObject
import org.yameida.worktool.Constant
import org.yameida.worktool.R
import org.yameida.worktool.service.WeworkController
import org.yameida.worktool.utils.*


Expand Down Expand Up @@ -87,8 +88,7 @@ class SettingsActivity : AppCompatActivity() {
bt_open_main.setOnClickListener {
freshOpenMain()
if (PermissionHelper.isAccessibilitySettingOn()) {
val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
startActivity(intent)
WeworkController.weworkService.disableSelf()
} else {
if (Constant.robotId.isBlank()) {
ToastUtils.showLong("请先填写并保存链接号~")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class WeworkService : AccessibilityService() {
lateinit var webSocketManager: WebSocketManager
var currentPackage = ""
var currentClass = ""
var currentClassPackage = ""

companion object {
private var mFileObserver: FileObserver? = null
Expand Down Expand Up @@ -98,6 +99,7 @@ class WeworkService : AccessibilityService() {
if (className.contains(currentPackage)) {
LogUtils.d("更新当前页面: currentPackage: ${event.packageName} className: ${event.className}")
currentClass = className
currentClassPackage = currentPackage
}
}

Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/org/yameida/worktool/utils/AccessibilityUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1323,4 +1323,29 @@ object AccessibilityUtil {
return false
}

/**
* 等待页面消失
* @param clazz 页面Class
* @param timeout 检查超时时间
*/
fun waitForPageMissing(
clazz: String,
timeout: Long = 5000
): Boolean {
val service = WeworkController.weworkService
val startTime = System.currentTimeMillis()
var currentTime = startTime
while (currentTime - startTime <= timeout) {
if (service.currentClass == clazz || service.currentClass.split(".").last() == clazz) {
} else {
Log.v(tag, "pageMissing: $clazz")
return true
}
sleep(SHORT_INTERVAL)
currentTime = System.currentTimeMillis()
}
Log.e(tag, "pageMissing: not found: $clazz current: ${service.currentClass}")
return false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,23 @@ class DefaultFloatService : BaseFloatWindow(), View.OnClickListener {
public override fun leftViewOpened(leftView: View) {
val layoutParams = leftView.fl_window_measure_left.layoutParams as FrameLayout.LayoutParams
leftView.fl_window_measure_left.measure(0, 0)
layoutParams.topMargin = params.y - BarUtils.getStatusBarHeight() - (leftView.fl_window_measure_left.measuredHeight / 2 - leftView.iv_logo_left.measuredHeight / 2)
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
layoutParams.topMargin = params.y - (leftView.fl_window_measure_left.measuredHeight / 2 - leftView.iv_logo_left.measuredHeight / 2)
} else {
layoutParams.topMargin = params.y - BarUtils.getStatusBarHeight() - (leftView.fl_window_measure_left.measuredHeight / 2 - leftView.iv_logo_left.measuredHeight / 2)
}
leftView.fl_window_measure_left.layoutParams = layoutParams
// ToastUtils.showShort("左边的菜单被打开了")
}

public override fun rightViewOpened(rightView: View) {
val layoutParams = rightView.fl_window_measure_right.layoutParams as FrameLayout.LayoutParams
rightView.fl_window_measure_right.measure(0, 0)
layoutParams.topMargin = params.y - BarUtils.getStatusBarHeight() - (rightView.fl_window_measure_right.measuredHeight / 2 - rightView.iv_logo_right.measuredHeight / 2)
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
layoutParams.topMargin = params.y - (rightView.fl_window_measure_right.measuredHeight / 2 - rightView.iv_logo_right.measuredHeight / 2)
} else {
layoutParams.topMargin = params.y - BarUtils.getStatusBarHeight() - (rightView.fl_window_measure_right.measuredHeight / 2 - rightView.iv_logo_right.measuredHeight / 2)
}
layoutParams.leftMargin = ScreenUtils.getScreenWidth() - rightView.fl_window_measure_right.measuredWidth
rightView.fl_window_measure_right.layoutParams = layoutParams
// ToastUtils.showShort("右边的菜单被打开了")
Expand Down

0 comments on commit 5f8bc34

Please sign in to comment.