Skip to content

Commit

Permalink
更新12.7.6
Browse files Browse the repository at this point in the history
修复偶尔连续熄亮屏的bug
增加稳定性
  • Loading branch information
mingzhixian committed Jul 23, 2023
1 parent 00fcf9d commit 0b77e3f
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 39 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 1275
versionName "12.7.5"
versionCode 1276
versionName "12.7.6"
resConfigs "zh"
resConfigs "xhdpi"
ndk {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class MainActivity : Activity(), ViewModelStoreOwner {
asSlave()
}
// 检查更新
if (appData.setValue.checkUpdate) checkUpdate()
if (appData.setValue.checkUpdate) appData.publicTools.checkUpdate(this,false)
}

// 作为控制端
Expand Down Expand Up @@ -225,17 +225,6 @@ class MainActivity : Activity(), ViewModelStoreOwner {
}
}

// 检查更新
private fun checkUpdate() {
appData.netHelper.getJson("https://github.saymzx.top/api/repos/mingzhixian/scrcpy/releases/latest") {
val newVersionCode = it?.getInt("tag_name")
if (newVersionCode != null) {
if (newVersionCode > appData.versionCode)
Toast.makeText(this, "已发布新版本,可前往更新", Toast.LENGTH_LONG).show()
}
}
}

// 作为被控端
private fun asSlave() {
// 防止多次调用
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package top.saymzx.scrcpy.android

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.net.Uri
Expand Down Expand Up @@ -53,9 +54,12 @@ class SetActivity : Activity() {
// 关于
setIndexListener()
setPrivacyListener()
// 底栏
setVersionName()
}

// 设置默认值
@SuppressLint("SetTextI18n")
private fun setValue() {
setActivity.setDefaultVideoCodec.adapter =
ArrayAdapter(this, R.layout.spinner_item, resources.getStringArray(R.array.videoCodecItems))
Expand Down Expand Up @@ -105,6 +109,7 @@ class SetActivity : Activity() {
}
setActivity.setShowFps.isChecked = appData.setValue.showFps
setActivity.setCheckUpdate.isChecked = appData.setValue.checkUpdate
setActivity.setVersionName.text = "当前版本: ${BuildConfig.VERSION_NAME}"
}

// 设置返回按钮监听
Expand Down Expand Up @@ -319,6 +324,13 @@ class SetActivity : Activity() {
}
}

// 底栏
private fun setVersionName() {
setActivity.setVersionName.setOnClickListener {
appData.publicTools.checkUpdate(this,true)
}
}

// 检查存储权限
private fun openDirectory(mode: Int) {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@ class Scrcpy(private val device: Device) {
stop("投屏停止", e)
}
}.start()
// 显示刷新率
if (appData.setValue.showFps) {
launch {
try {
floatVideo.floatVideo.floatVideoFps.text = "0"
while (device.status == 1) {
delay(1000)
floatVideo.floatVideo.floatVideoFps.text = fps.toString()
fps = 0
}
} catch (_: Exception) {
launch {
// 显示刷新率
if (appData.setValue.showFps) floatVideo.floatVideo.floatVideoFps.text = "0"
while (device.status == 1) {
delay(1000)
// 显示刷新率
if (appData.setValue.showFps) {
floatVideo.floatVideo.floatVideoFps.text = fps.toString()
fps = 0
}
// 熄屏检测
checkScreenOff()
}
}
}
Expand Down Expand Up @@ -463,7 +463,6 @@ class Scrcpy(private val device: Device) {
private fun decodeInputThread(mode: String) {
val stream = if (mode == "video") videoStream else audioStream
val codec = if (mode == "video") videoDecodec else audioDecodec
var zeroFrameNum = 0
// 开始解码
while (device.status == 1) {
val buffer = readFrame(stream)
Expand All @@ -472,14 +471,6 @@ class Scrcpy(private val device: Device) {
codec.getInputBuffer(inIndex)!!.put(buffer.third)
// 提交解码器解码
codec.queueInputBuffer(inIndex, 0, buffer.second, buffer.first, 0)
// 连续8个空包检测是否熄屏了
if (buffer.second < 150) {
zeroFrameNum++
if (zeroFrameNum > 7) {
zeroFrameNum = 0
checkScreenOff()
}
}
}
}
}
Expand Down Expand Up @@ -607,7 +598,6 @@ class Scrcpy(private val device: Device) {
}
isScreenOning = false
} catch (_: Exception) {

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.os.Build
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.Toast
import top.saymzx.scrcpy.android.R
import top.saymzx.scrcpy.android.appData
import top.saymzx.scrcpy.android.databinding.LoadingBinding
Expand Down Expand Up @@ -73,4 +74,17 @@ class PublicTools {

// DP转PX
fun dp2px(dp: Float): Float = dp * appData.main.resources.displayMetrics.density

// 检查更新
fun checkUpdate(context: Context, isNeedShowWhenLatest: Boolean) {
appData.netHelper.getJson("https://github.saymzx.top/api/repos/mingzhixian/scrcpy/releases/latest") {
val newVersionCode = it?.getInt("tag_name")
if (newVersionCode != null) {
if (newVersionCode > appData.versionCode)
Toast.makeText(context, "已发布新版本,可前往更新", Toast.LENGTH_LONG).show()
else if (isNeedShowWhenLatest)
Toast.makeText(context, "当前已是最新版本", Toast.LENGTH_LONG).show()
}
}
}
}
14 changes: 13 additions & 1 deletion scrcpy_android/app/src/main/res/layout/activity_set.xml
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@
android:layout_marginStart="20dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="40dp"
android:background="@drawable/background"
android:backgroundTint="@color/cardBackground"
android:paddingStart="20dp"
Expand All @@ -589,6 +588,19 @@
android:textColor="@color/onCardBackground"
android:textSize="@dimen/middleFont" />

<TextView
android:id="@+id/set_version_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="当前版本:1.1.1"
android:textColor="@color/onCardBackground"
android:textSize="@dimen/smallFont" />

</LinearLayout>
</ScrollView>
</LinearLayout>
Binary file modified scrcpy_android/app/src/main/res/raw/scrcpy_server.jar
Binary file not shown.
1 change: 1 addition & 0 deletions scrcpy_android/app/src/main/res/values/size.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!--字体-->
<dimen name="largeFont">24sp</dimen>
<dimen name="middleFont">18sp</dimen>
<dimen name="smallFont">14sp</dimen>
<!--floatVideo界面-->
<dimen name="floatVideoBackground">20dp</dimen>
<dimen name="floatVideoTitle">34dp</dimen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,11 @@ public static boolean injectEvent(InputEvent inputEvent, int displayId, int inje
if (displayId != 0 && !InputManager.setDisplayId(inputEvent, displayId)) {
return false;
}

return ServiceManager.getInputManager().injectInputEvent(inputEvent, injectMode);
try {
return ServiceManager.getInputManager().injectInputEvent(inputEvent, injectMode);
} catch (Exception ignored) {
return false;
}
}

public boolean injectEvent(InputEvent event, int injectMode) {
Expand Down

0 comments on commit 0b77e3f

Please sign in to comment.