暫時加上flag

This commit is contained in:
Raymond Yang 2023-07-03 12:19:08 +08:00
parent 7ac9063248
commit fbe86451ba
6 changed files with 48 additions and 14 deletions

View File

@ -0,0 +1,9 @@
package com.ray650128.floatwindowdemo
import android.content.res.Resources
val Int.dp: Int
get() = (this / Resources.getSystem().displayMetrics.density).toInt()
val Int.px: Int
get() = (this * Resources.getSystem().displayMetrics.density).toInt()

View File

@ -16,6 +16,8 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import com.ray650128.floatwindowdemo.R
import com.ray650128.floatwindowdemo.dp
import com.ray650128.floatwindowdemo.px
import com.ray650128.floatwindowdemo.utils.ItemViewTouchListener
import com.ray650128.floatwindowdemo.utils.Utils.isNull
import com.ray650128.floatwindowdemo.utils.ViewModelMain
@ -81,16 +83,19 @@ class WorkAccessibilityService : AccessibilityService(), LifecycleOwner {
val layoutParam = WindowManager.LayoutParams()
layoutParam.apply {
//顯示的位置
type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
//劉海屏延伸到劉海里面
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
}
flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
//flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
//flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
width = 260
height = 60
format = PixelFormat.TRANSPARENT
width = 145.px
height = 38.px
format = PixelFormat.RGBA_8888
}
floatRootView = LayoutInflater.from(this).inflate(R.layout.activity_float_item, null)
floatRootView?.findViewById<ImageView>(R.id.iv_close)?.setOnClickListener {

View File

@ -1,5 +1,6 @@
package com.ray650128.floatwindowdemo.utils
import android.util.Log
import android.view.MotionEvent
import android.view.View
import android.view.WindowManager
@ -15,8 +16,13 @@ class ItemViewTouchListener(val wl: WindowManager.LayoutParams, val windowManage
private var x = 0
private var y = 0
override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
Log.d("com.kldp.floating.floatingtools", "MotionEvent: $motionEvent")
when (motionEvent.action) {
MotionEvent.ACTION_DOWN -> {
wl.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
windowManager.updateViewLayout(view, wl)
x = motionEvent.rawX.toInt()
y = motionEvent.rawY.toInt()
}
@ -34,6 +40,12 @@ class ItemViewTouchListener(val wl: WindowManager.LayoutParams, val windowManage
//更新懸浮球控制元件位置
windowManager.updateViewLayout(view, wl)
}
MotionEvent.ACTION_OUTSIDE -> {
wl.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
windowManager.updateViewLayout(view, wl)
}
else -> {
}

View File

@ -1,4 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:tint="#ffffff" android:height="24dp" android:width="24dp" android:viewportWidth="24" android:viewportHeight="24">
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM17,15.59L15.59,17 12,13.41 8.41,17 7,15.59 10.59,12 7,8.41 8.41,7 12,10.59 15.59,7 17,8.41 13.41,12 17,15.59z"/>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#ffffff"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM17,15.59L15.59,17 12,13.41 8.41,17 7,15.59 10.59,12 7,8.41 8.41,7 12,10.59 15.59,7 17,8.41 13.41,12 17,15.59z" />
</vector>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#77000000"/>
<corners android:radius="18dp"/>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#77000000" />
<corners android:radius="18dp" />
</shape>

View File

@ -7,22 +7,22 @@
<TextView
android:id="@+id/tv_time"
android:layout_width="140dp"
android:layout_width="110dp"
android:layout_height="38dp"
android:gravity="center"
android:letterSpacing="0.1"
android:paddingStart="15dp"
android:text="22:22:22"
android:textColor="@color/white"
android:textSize="16dp"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/iv_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="12dp"
android:src="@drawable/ic_baseline_cancel_24"
app:layout_constraintBottom_toBottomOf="parent"