| |
---|
| | |
---|
| | import android.app.Service |
---|
| | import android.content.Context |
---|
| | import android.content.Intent |
---|
| | import android.databinding.DataBindingUtil |
---|
| | import android.graphics.PixelFormat |
---|
| | import android.graphics.Point |
---|
| | import android.os.Build |
---|
| | import android.os.IBinder |
---|
| |
---|
| | import jackall.moncalc.Const |
---|
| | import jackall.moncalc.R |
---|
| | import jackall.moncalc.common.PreferenceKeys |
---|
| | import jackall.moncalc.common.PreferenceNames |
---|
| | import jackall.moncalc.databinding.RegistOverlayBinding |
---|
| | import jackall.moncalc.utils.MySharedPref |
---|
| | import jackall.moncalc.viewmodel.OverlayRegistViewModel |
---|
| | |
---|
| | /** |
---|
| | * Created by matsumoto_k on 2017/11/01. |
---|
| | */ |
---|
| | class MainService : Service() { |
---|
| | |
---|
| | val mySharedPref by lazy { MySharedPref(this, PreferenceNames.CONFIG) } |
---|
| | val moveOverlayView: ViewGroup by lazy { LayoutInflater.from(this).inflate(R.layout.move_overlay, null) as ViewGroup } |
---|
| | val registOverlayView: ViewGroup by lazy { LayoutInflater.from(this).inflate(R.layout.regist_overlay, null) as ViewGroup } |
---|
| | val registBinding by lazy { |
---|
| | DataBindingUtil.inflate<RegistOverlayBinding>(LayoutInflater.from(this), R.layout.regist_overlay, null, false) |
---|
| | } |
---|
| | val windowManager: WindowManager by lazy { applicationContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager } |
---|
| | var moveViewParams: WindowManager.LayoutParams? = null |
---|
| | var registViewParams: WindowManager.LayoutParams? = null |
---|
| | val displaySize: Point by lazy { |
---|
| |
---|
| | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, |
---|
| | PixelFormat.TRANSLUCENT) |
---|
| | } |
---|
| | |
---|
| | registBinding.registViewModel = OverlayRegistViewModel() |
---|
| | |
---|
| | registViewParams?.gravity = Gravity.TOP |
---|
| | } |
---|
| | |
---|
| | private fun showMoveView() { |
---|
| | moveViewParams?.x = mySharedPref.getValue(PreferenceKeys.VIEWX, Int::class.java, 0) as Int |
---|
| | moveViewParams?.y = mySharedPref.getValue(PreferenceKeys.VIEWY, Int::class.java, 0) as Int |
---|
| | |
---|
| | if (registOverlayView.isShown) { |
---|
| | windowManager.removeView(registOverlayView) |
---|
| | if (registBinding.root.isShown) { |
---|
| | windowManager.removeView(registBinding.root) |
---|
| | } |
---|
| | |
---|
| | windowManager.addView(moveOverlayView, moveViewParams) |
---|
| | } |
---|
| |
---|
| | if (moveOverlayView.isShown) { |
---|
| | windowManager.removeView(moveOverlayView) |
---|
| | } |
---|
| | |
---|
| | windowManager.addView(registOverlayView, registViewParams) |
---|
| | windowManager.addView(registBinding.root, registViewParams) |
---|
| | } |
---|
| | |
---|
| | private fun setMoveViewClickListener(): View.() -> Unit { |
---|
| | return { |
---|
| |
---|
| | |