暫時加上flag
This commit is contained in:
parent
7ac9063248
commit
fbe86451ba
@ -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()
|
||||||
@ -16,6 +16,8 @@ import androidx.lifecycle.Lifecycle
|
|||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.LifecycleRegistry
|
import androidx.lifecycle.LifecycleRegistry
|
||||||
import com.ray650128.floatwindowdemo.R
|
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.ItemViewTouchListener
|
||||||
import com.ray650128.floatwindowdemo.utils.Utils.isNull
|
import com.ray650128.floatwindowdemo.utils.Utils.isNull
|
||||||
import com.ray650128.floatwindowdemo.utils.ViewModelMain
|
import com.ray650128.floatwindowdemo.utils.ViewModelMain
|
||||||
@ -81,16 +83,19 @@ class WorkAccessibilityService : AccessibilityService(), LifecycleOwner {
|
|||||||
val layoutParam = WindowManager.LayoutParams()
|
val layoutParam = WindowManager.LayoutParams()
|
||||||
layoutParam.apply {
|
layoutParam.apply {
|
||||||
//顯示的位置
|
//顯示的位置
|
||||||
type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY
|
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
|
||||||
//劉海屏延伸到劉海里面
|
//劉海屏延伸到劉海里面
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
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
|
//flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|
||||||
width = 260
|
width = 145.px
|
||||||
height = 60
|
height = 38.px
|
||||||
format = PixelFormat.TRANSPARENT
|
format = PixelFormat.RGBA_8888
|
||||||
}
|
}
|
||||||
floatRootView = LayoutInflater.from(this).inflate(R.layout.activity_float_item, null)
|
floatRootView = LayoutInflater.from(this).inflate(R.layout.activity_float_item, null)
|
||||||
floatRootView?.findViewById<ImageView>(R.id.iv_close)?.setOnClickListener {
|
floatRootView?.findViewById<ImageView>(R.id.iv_close)?.setOnClickListener {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.ray650128.floatwindowdemo.utils
|
package com.ray650128.floatwindowdemo.utils
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
@ -15,8 +16,13 @@ class ItemViewTouchListener(val wl: WindowManager.LayoutParams, val windowManage
|
|||||||
private var x = 0
|
private var x = 0
|
||||||
private var y = 0
|
private var y = 0
|
||||||
override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
|
override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
|
||||||
|
Log.d("com.kldp.floating.floatingtools", "MotionEvent: $motionEvent")
|
||||||
when (motionEvent.action) {
|
when (motionEvent.action) {
|
||||||
MotionEvent.ACTION_DOWN -> {
|
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()
|
x = motionEvent.rawX.toInt()
|
||||||
y = motionEvent.rawY.toInt()
|
y = motionEvent.rawY.toInt()
|
||||||
}
|
}
|
||||||
@ -34,6 +40,12 @@ class ItemViewTouchListener(val wl: WindowManager.LayoutParams, val windowManage
|
|||||||
//更新懸浮球控制元件位置
|
//更新懸浮球控制元件位置
|
||||||
windowManager.updateViewLayout(view, wl)
|
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 -> {
|
else -> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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">
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
<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"/>
|
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>
|
</vector>
|
||||||
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
<solid android:color="#77000000"/>
|
android:shape="rectangle">
|
||||||
<corners android:radius="18dp"/>
|
<solid android:color="#77000000" />
|
||||||
|
<corners android:radius="18dp" />
|
||||||
</shape>
|
</shape>
|
||||||
@ -7,22 +7,22 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_time"
|
android:id="@+id/tv_time"
|
||||||
android:layout_width="140dp"
|
android:layout_width="110dp"
|
||||||
android:layout_height="38dp"
|
android:layout_height="38dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:letterSpacing="0.1"
|
android:letterSpacing="0.1"
|
||||||
android:paddingStart="15dp"
|
android:paddingStart="15dp"
|
||||||
android:text="22:22:22"
|
android:text="22:22:22"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="16dp"
|
android:textSize="16sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/iv_close"
|
android:id="@+id/iv_close"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="24dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="24dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
android:src="@drawable/ic_baseline_cancel_24"
|
android:src="@drawable/ic_baseline_cancel_24"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user