Skip to content

Commit

Permalink
更新V12.7.8
Browse files Browse the repository at this point in the history
修复小窗及悬浮球边缘溢出导致不易触碰的问题
  • Loading branch information
mingzhixian committed Jul 23, 2023
1 parent db444d6 commit b6db157
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 33 deletions.
2 changes: 1 addition & 1 deletion scrcpy_android/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions scrcpy_android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "top.saymzx.scrcpy.android"
minSdk 23
targetSdk 33
versionCode 1277
versionName "12.7.7"
versionCode 1278
versionName "12.7.8"
resConfigs "zh"
resConfigs "xhdpi"
ndk {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@ class FloatVideo(
type =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
else WindowManager.LayoutParams.TYPE_PHONE
flags =
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
flags = smallLayoutParamsFlagNoFocus
gravity = Gravity.START or Gravity.TOP
format = PixelFormat.TRANSLUCENT
}

// 悬浮设置
private val baseLayoutParamsFlag =
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
private val smallLayoutParamsFlagNoFocus =
baseLayoutParamsFlag or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
private val smallLayoutParamsFlagFocus =
baseLayoutParamsFlag or WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
private val fullLayoutParamsFlag =
smallLayoutParamsFlagNoFocus or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN

// 导航悬浮球
@SuppressLint("InflateParams")
lateinit var floatNav: FloatNavBinding
Expand Down Expand Up @@ -171,7 +180,8 @@ class FloatVideo(
// 设置全屏
private fun setFull() {
// 取消焦点
setFocus(false)
isFocus = false
floatVideoParams.flags = fullLayoutParamsFlag
device.isFull = true
// 旋转屏幕方向
val isLandScape = remoteVideoWidth > remoteVideoHeight
Expand Down Expand Up @@ -366,6 +376,7 @@ class FloatVideo(
}

// 检测旋转
private val add2DpPx = appData.publicTools.dp2px(2f).toInt()
fun checkRotation(newWidth: Int, newHeight: Int) {
if ((newWidth > newHeight) xor (localVideoWidth > localVideoHeight)) {
val isLandScape = newWidth > newHeight
Expand All @@ -383,13 +394,13 @@ class FloatVideo(
x = 40
y = (if (isLandScape) appData.deviceWidth else appData.deviceHeight) / 2
}
localVideoWidth = if (isLandScape) appData.deviceHeight else appData.deviceWidth
localVideoHeight = if (isLandScape) appData.deviceWidth else appData.deviceHeight
// 更新悬浮窗
floatVideoParams.apply {
width = if (isLandScape) appData.deviceHeight else appData.deviceWidth
height = if (isLandScape) appData.deviceWidth else appData.deviceHeight
width = localVideoWidth + add2DpPx
height = localVideoHeight + add2DpPx
}
localVideoWidth = floatVideoParams.width
localVideoHeight = floatVideoParams.height
} else {
// 更新悬浮窗
floatVideoParams.apply {
Expand Down Expand Up @@ -534,13 +545,6 @@ class FloatVideo(

// 设置上横条监听控制
private fun setFloatBar() {
// 横条按钮监听
var statusBarHeight = 0
// 获取状态栏高度
val resourceId = appData.main.resources.getIdentifier("status_bar_height", "dimen", "android")
if (resourceId > 0) {
statusBarHeight = appData.main.resources.getDimensionPixelSize(resourceId)
}
var deviceWidth = 0
val criticality = appData.publicTools.dp2px(60f).toInt()
var x = 0
Expand Down Expand Up @@ -573,8 +577,6 @@ class FloatVideo(
// 新位置
val newX = event.rawX.toInt() - x - floatVideoParams.width / 4
val newY = event.rawY.toInt() - y
// 避免移动至状态栏等不可触控区域
if (newY < statusBarHeight + 10) return@setOnTouchListener true
// 移动悬浮窗
floatVideoParams.x = newX
floatVideoParams.y = newY
Expand Down Expand Up @@ -628,8 +630,7 @@ class FloatVideo(
type =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
else WindowManager.LayoutParams.TYPE_PHONE
flags =
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
flags = smallLayoutParamsFlagNoFocus
gravity = Gravity.START or Gravity.TOP
width = floatNavSize
height = floatNavSize
Expand Down Expand Up @@ -683,13 +684,22 @@ class FloatVideo(
}

// 设置导航球菜单监听
private var floatNavSite = Pair(false, 0)
private fun setFloatNavMenuListener() {
// 展示MENU
floatNavParams.width = appData.main.resources.getDimension(R.dimen.floatNavMenuW).toInt()
val menuWidth = appData.main.resources.getDimension(R.dimen.floatNavMenuW).toInt()
floatNavParams.width = menuWidth
floatNavParams.height = appData.main.resources.getDimension(R.dimen.floatNavMenuH).toInt()
appData.main.windowManager.updateViewLayout(floatNav.root, floatNavParams)
floatNav.floatNavMenu.visibility = View.VISIBLE
floatNav.floatNavImage.visibility = View.GONE
// 获取系统宽高
val size = appData.publicTools.getScreenSize(appData.main)
if (floatNavParams.x + menuWidth > size.first) {
floatNavSite = Pair(true, floatNavParams.x)
floatNavParams.x = size.first - menuWidth
appData.main.windowManager.updateViewLayout(floatNav.root, floatNavParams)
}
// 返回导航球
floatNav.floatNavBack.setOnClickListener {
backFloatNav()
Expand All @@ -716,6 +726,10 @@ class FloatVideo(
appData.publicTools.dp2px(appData.setValue.floatNavSize.toFloat()).toInt()
floatNavParams.width = floatNavSize
floatNavParams.height = floatNavSize
if (floatNavSite.first) {
floatNavParams.x = floatNavSite.second
floatNavSite = Pair(false, 0)
}
appData.main.windowManager.updateViewLayout(floatNav.root, floatNavParams)
floatNav.floatNavImage.visibility = View.VISIBLE
floatNav.floatNavMenu.visibility = View.GONE
Expand All @@ -732,8 +746,7 @@ class FloatVideo(
private fun setFocus(newFocus: Boolean) {
if (!device.isFull && newFocus != isFocus) {
floatVideoParams.flags =
if (newFocus) WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
else WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
if (newFocus) smallLayoutParamsFlagFocus else smallLayoutParamsFlagNoFocus
appData.main.windowManager.updateViewLayout(
floatVideo.root, floatVideoParams
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.ClipboardManager
import android.content.Context
import android.content.SharedPreferences
import android.content.pm.ActivityInfo
import android.util.DisplayMetrics
import androidx.lifecycle.ViewModel
import kotlinx.coroutines.MainScope
import top.saymzx.scrcpy.adb.AdbKeyPair
Expand Down Expand Up @@ -86,10 +85,9 @@ class AppData : ViewModel() {

// 读取设备分辨率
private fun readDeviceResolution() {
val metric = DisplayMetrics()
main.windowManager.defaultDisplay.getRealMetrics(metric)
deviceWidth = metric.widthPixels
deviceHeight = metric.heightPixels
val size = publicTools.getScreenSize(main)
deviceWidth = size.first
deviceHeight = size.second
if (deviceWidth > deviceHeight) deviceWidth =
deviceWidth xor deviceHeight xor deviceWidth.also { deviceHeight = it }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.os.Build
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
Expand Down Expand Up @@ -87,4 +88,11 @@ class PublicTools {
}
}
}

// 获取当前界面宽高
fun getScreenSize(context: Activity):Pair<Int,Int>{
val metric = DisplayMetrics()
context.windowManager.defaultDisplay.getRealMetrics(metric)
return Pair(metric.widthPixels,metric.heightPixels)
}
}
6 changes: 3 additions & 3 deletions scrcpy_android/app/src/main/res/layout/float_nav.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
android:background="@drawable/background"
android:backgroundTint="@color/cardContainerBackground"
android:orientation="vertical"
android:paddingStart="20dp"
android:paddingStart="18dp"
android:paddingTop="14dp"
android:paddingEnd="20dp"
android:paddingEnd="14dp"
android:paddingBottom="14dp"
android:visibility="gone">

Expand Down Expand Up @@ -52,7 +52,7 @@
android:layout_height="wrap_content"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:text="发送最近任务键"
android:text="发送任务键"
android:textColor="@color/onCardContainerBackground"
android:textSize="@dimen/middleFont" />

Expand Down
2 changes: 1 addition & 1 deletion scrcpy_android/app/src/main/res/values/size.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<dimen name="floatVideoBarPadding">10dp</dimen>
<dimen name="floatVideoButtonPadding">9dp</dimen>
<dimen name="floatVideoNavButtonPadding">8dp</dimen>
<dimen name="floatNavMenuW">200dp</dimen>
<dimen name="floatNavMenuW">140dp</dimen>
<dimen name="floatNavMenuH">300dp</dimen>
<dimen name="floatVideoSmallSmall">80dp</dimen>
<dimen name="floatVideoSmallSmallPadding">16dp</dimen>
Expand Down

0 comments on commit b6db157

Please sign in to comment.