From b6db157d67556f565dd948c847d5a28bcb93c42d Mon Sep 17 00:00:00 2001 From: mingzhixian Date: Sun, 23 Jul 2023 23:09:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0V12.7.8=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=B0=8F=E7=AA=97=E5=8F=8A=E6=82=AC=E6=B5=AE=E7=90=83=E8=BE=B9?= =?UTF-8?q?=E7=BC=98=E6=BA=A2=E5=87=BA=E5=AF=BC=E8=87=B4=E4=B8=8D=E6=98=93?= =?UTF-8?q?=E8=A7=A6=E7=A2=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.idea/deploymentTargetDropDown.xml | 2 +- scrcpy_android/app/build.gradle | 4 +- .../scrcpy/android/entity/FloatVideo.kt | 55 ++++++++++++------- .../saymzx/scrcpy/android/helper/AppData.kt | 8 +-- .../scrcpy/android/helper/PublicTools.kt | 8 +++ .../app/src/main/res/layout/float_nav.xml | 6 +- .../app/src/main/res/values/size.xml | 2 +- 7 files changed, 52 insertions(+), 33 deletions(-) diff --git a/scrcpy_android/.idea/deploymentTargetDropDown.xml b/scrcpy_android/.idea/deploymentTargetDropDown.xml index 440cfc97..d0462394 100644 --- a/scrcpy_android/.idea/deploymentTargetDropDown.xml +++ b/scrcpy_android/.idea/deploymentTargetDropDown.xml @@ -23,6 +23,6 @@ - + \ No newline at end of file diff --git a/scrcpy_android/app/build.gradle b/scrcpy_android/app/build.gradle index 4a27ff2d..9923fff6 100644 --- a/scrcpy_android/app/build.gradle +++ b/scrcpy_android/app/build.gradle @@ -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 { diff --git a/scrcpy_android/app/src/main/java/top/saymzx/scrcpy/android/entity/FloatVideo.kt b/scrcpy_android/app/src/main/java/top/saymzx/scrcpy/android/entity/FloatVideo.kt index 87924eab..1ab5ec2b 100644 --- a/scrcpy_android/app/src/main/java/top/saymzx/scrcpy/android/entity/FloatVideo.kt +++ b/scrcpy_android/app/src/main/java/top/saymzx/scrcpy/android/entity/FloatVideo.kt @@ -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 @@ -171,7 +180,8 @@ class FloatVideo( // 设置全屏 private fun setFull() { // 取消焦点 - setFocus(false) + isFocus = false + floatVideoParams.flags = fullLayoutParamsFlag device.isFull = true // 旋转屏幕方向 val isLandScape = remoteVideoWidth > remoteVideoHeight @@ -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 @@ -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 { @@ -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 @@ -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 @@ -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 @@ -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() @@ -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 @@ -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 ) diff --git a/scrcpy_android/app/src/main/java/top/saymzx/scrcpy/android/helper/AppData.kt b/scrcpy_android/app/src/main/java/top/saymzx/scrcpy/android/helper/AppData.kt index 48a56269..ff888a02 100644 --- a/scrcpy_android/app/src/main/java/top/saymzx/scrcpy/android/helper/AppData.kt +++ b/scrcpy_android/app/src/main/java/top/saymzx/scrcpy/android/helper/AppData.kt @@ -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 @@ -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 } } diff --git a/scrcpy_android/app/src/main/java/top/saymzx/scrcpy/android/helper/PublicTools.kt b/scrcpy_android/app/src/main/java/top/saymzx/scrcpy/android/helper/PublicTools.kt index 7ea49487..e03f544b 100644 --- a/scrcpy_android/app/src/main/java/top/saymzx/scrcpy/android/helper/PublicTools.kt +++ b/scrcpy_android/app/src/main/java/top/saymzx/scrcpy/android/helper/PublicTools.kt @@ -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 @@ -87,4 +88,11 @@ class PublicTools { } } } + + // 获取当前界面宽高 + fun getScreenSize(context: Activity):Pair{ + val metric = DisplayMetrics() + context.windowManager.defaultDisplay.getRealMetrics(metric) + return Pair(metric.widthPixels,metric.heightPixels) + } } \ No newline at end of file diff --git a/scrcpy_android/app/src/main/res/layout/float_nav.xml b/scrcpy_android/app/src/main/res/layout/float_nav.xml index 7d0dc812..e21b541a 100644 --- a/scrcpy_android/app/src/main/res/layout/float_nav.xml +++ b/scrcpy_android/app/src/main/res/layout/float_nav.xml @@ -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"> @@ -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" /> diff --git a/scrcpy_android/app/src/main/res/values/size.xml b/scrcpy_android/app/src/main/res/values/size.xml index 9dff6310..d5fd8224 100644 --- a/scrcpy_android/app/src/main/res/values/size.xml +++ b/scrcpy_android/app/src/main/res/values/size.xml @@ -10,7 +10,7 @@ 10dp 9dp 8dp - 200dp + 140dp 300dp 80dp 16dp