package com.jld.vod.service

import android.accessibilityservice.AccessibilityService
import android.view.KeyEvent
import android.view.accessibility.AccessibilityEvent
import com.jld.vod.utils.LogUtils
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe


/**
 * @author ZhaoFuXin
 * @Email：18276061387@163.com
 * @description:
 * @date :2020/9/7 20:06
 */
class MyAccessibilityService : AccessibilityService() {

    override fun onCreate() {
        super.onCreate()
        isRunning = true;
        //使用EventBus代替广播
        EventBus.getDefault().register(this)
    }

    override fun onAccessibilityEvent(event: AccessibilityEvent?) {
        LogUtils.logD("event"+event)
    }

    override fun onInterrupt() {}

    @Subscribe
    fun onReceive(action: Int?) {
        when (action) {
            BACK ->{
                val result = performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK)
                LogUtils.logD("result"+result)
            }
            HOME -> performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME)
        }
    }

    companion object {
        const val BACK = 1
        const val HOME = 2
        private const val TAG = "ICE"

        var isRunning = false
    }

    override fun onDestroy() {
        super.onDestroy()
        isRunning = false;
    }
}