Skip to content

Commit

Permalink
更新V8.5
Browse files Browse the repository at this point in the history
精简无用权限
增加导航球设置
增加修改设备
修复退出投屏bug
优化音频延迟
修复导航球崩溃bug
增加软件介绍页
增加小小悬浮窗
  • Loading branch information
mingzhixian committed Jun 1, 2023
1 parent d3253bd commit 57af7dd
Show file tree
Hide file tree
Showing 18 changed files with 570 additions and 190 deletions.
15 changes: 15 additions & 0 deletions pic/说明/show_app_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 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 84
versionName "8.4"
versionCode 85
versionName "8.5"
resConfigs "zh"
resConfigs "xhdpi"
ndk {
Expand Down Expand Up @@ -46,8 +46,6 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1'

implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'

implementation("dev.mobile:dadb:1.2.6")
}
2 changes: 0 additions & 2 deletions scrcpy_android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />

<application
android:icon="@drawable/icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package top.saymzx.scrcpy_android

import android.annotation.SuppressLint
import android.app.AlertDialog
import android.content.Context
import android.content.SharedPreferences
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
Expand All @@ -15,7 +17,7 @@ import java.io.File
class AppData : ViewModel() {

// 是否初始化
var isInit=false
var isInit = false

// 数据库管理
lateinit var dbHelper: DbHelper
Expand All @@ -32,15 +34,20 @@ class AppData : ViewModel() {
var deviceWidth = 0
var deviceHeight = 0

// 设置值
lateinit var settings: SharedPreferences

// 加载框(全局通用)
@SuppressLint("StaticFieldLeak")
lateinit var loadingDialog: AlertDialog

@SuppressLint("StaticFieldLeak")
lateinit var loading: View

// 初始化数据
fun init(main: MainActivity) {
isInit=true
isInit = true
settings = main.getSharedPreferences("setting", Context.MODE_PRIVATE)
// 获取系统分辨率
val metric = DisplayMetrics()
main.windowManager.defaultDisplay.getRealMetrics(metric)
Expand All @@ -49,7 +56,7 @@ class AppData : ViewModel() {
if (deviceWidth > deviceHeight) deviceWidth =
deviceWidth xor deviceHeight xor deviceWidth.also { deviceHeight = it }
// 数据库管理
dbHelper = DbHelper(main, "scrcpy_android.db", 4)
dbHelper = DbHelper(main, "scrcpy_android.db", 5)
deviceAdapter = DeviceAdapter(main)
// 从数据库获取设备列表
val cursor = dbHelper.readableDatabase.query("DevicesDb", null, null, null, null, null, null)
Expand All @@ -65,7 +72,8 @@ class AppData : ViewModel() {
cursor.getInt(cursor.getColumnIndex("fps")),
cursor.getInt(cursor.getColumnIndex("videoBit")),
cursor.getInt(cursor.getColumnIndex("setResolution")) == 1,
cursor.getInt(cursor.getColumnIndex("defaultFull")) == 1
cursor.getInt(cursor.getColumnIndex("defaultFull")) == 1,
cursor.getInt(cursor.getColumnIndex("floatNav")) == 1
)
)
} while (cursor.moveToNext())
Expand All @@ -92,7 +100,8 @@ class AppData : ViewModel() {
loading.findViewById<TextView>(R.id.loading_text).text = text
if (isCanCancel) {
loading.findViewById<Button>(R.id.loading_cancel).visibility = View.VISIBLE
loading.findViewById<Button>(R.id.loading_cancel).setOnClickListener { cancelFun?.let { it1 -> it1() } }
loading.findViewById<Button>(R.id.loading_cancel)
.setOnClickListener { cancelFun?.let { it1 -> it1() } }
} else loading.findViewById<Button>(R.id.loading_cancel).visibility = View.GONE
loadingDialog.show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class DbHelper(
"\t fps integer,\n" +
"\t videoBit integer," +
"\t setResolution integer,"+
"\t defaultFull integer"+
"\t defaultFull integer,"+
"\t floatNav integer"+
")"
)
}
Expand Down Expand Up @@ -124,5 +125,50 @@ class DbHelper(
// 删除旧表
db.execSQL("drop table DevicesDbOld")
}
// 修改列名,增加是否显示导航球列
if (oldVersion < 5) {
// 修改表名
db!!.execSQL("alter table DevicesDb rename to DevicesDbOld")
// 新建新表
db.execSQL(
"CREATE TABLE DevicesDb (\n" +
"\t name text PRIMARY KEY,\n" +
"\t address text,\n" +
"\t port integer,\n" +
"\t videoCodec text,\n" +
"\t maxSize integer,\n" +
"\t fps integer,\n" +
"\t videoBit integer," +
"\t setResolution integer,"+
"\t defaultFull integer,"+
"\t floatNav integer"+
")"
)
// 将数据搬移至新表
val cursor =
db.query("DevicesDbOld", null, null, null, null, null, null)
if (cursor.moveToFirst()) {
do {
val values = ContentValues().apply {
put("name", cursor.getString(cursor.getColumnIndex("name")))
put("address", cursor.getString(cursor.getColumnIndex("address")))
put("port", cursor.getInt(cursor.getColumnIndex("port")))
put("videoCodec", cursor.getString(cursor.getColumnIndex("videoCodec")))
// 修改为默认值
put("maxSize", "1600")
put("fps", cursor.getString(cursor.getColumnIndex("fps")))
// 修改为默认值
put("videoBit", "8000000")
put("setResolution", 1)
put("defaultFull", 1)
put("floatNav", 1)
}
db.insert("DevicesDb", null, values)
} while (cursor.moveToNext())
}
cursor.close()
// 删除旧表
db.execSQL("drop table DevicesDbOld")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ class Device(
val fps: Int,
val videoBit: Int,
val setResolution:Boolean,
val defaultFull:Boolean
val defaultFull:Boolean,
val floatNav:Boolean
){
var isFull=defaultFull
// -10为停止状态,-1~-9为停止中,0为准备中,1为已连接ADB,2为已连接音视频,3为投屏中
var status=-10
// -1为停止状态,0为准备中,1为投屏中
var status=-1
lateinit var scrcpy: Scrcpy
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ class DeviceAdapter(private val main: MainActivity) :
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val device = main.appData.devices[position]
holder.textViewName.text = device.name
val address = "${device.address}:${device.port}"
holder.textViewAddress.text = address
val addressID = "${device.address}:${device.port}"
holder.textViewAddress.text = addressID
// 单击打开投屏
holder.linearLayout.setOnClickListener {
if (device.status != -10) Toast.makeText(main, "此设备正在投屏或未完全关闭", Toast.LENGTH_SHORT).show()
if (device.status != -1) Toast.makeText(main, "此设备正在投屏", Toast.LENGTH_SHORT).show()
else {
device.scrcpy=Scrcpy(device, main)
device.scrcpy = Scrcpy(device, main)
device.scrcpy.start()
}
}
// 长按删除
// 长按选项
holder.linearLayout.setOnLongClickListener {
val deleteDeviceView = LayoutInflater.from(main).inflate(R.layout.delete_device, null, false)
val builder: AlertDialog.Builder = AlertDialog.Builder(main)
Expand All @@ -49,7 +49,121 @@ class DeviceAdapter(private val main: MainActivity) :
deleteDeviceView.findViewById<Button>(R.id.delete_device_cancel).setOnClickListener {
dialog.cancel()
}
deleteDeviceView.findViewById<Button>(R.id.delete_device_ok).setOnClickListener {
// 修改
deleteDeviceView.findViewById<Button>(R.id.delete_device_change).setOnClickListener {
dialog.cancel()
// 显示更新框
val addDeviceView = LayoutInflater.from(main).inflate(R.layout.add_device, null, false)
val updateBuilder: AlertDialog.Builder = AlertDialog.Builder(main)
updateBuilder.setView(addDeviceView)
updateBuilder.setCancelable(false)
val updateDialog = updateBuilder.create()
updateDialog.setCanceledOnTouchOutside(true)
updateDialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
// 控件
val name = addDeviceView.findViewById<EditText>(R.id.add_device_name)
val address = addDeviceView.findViewById<EditText>(R.id.add_device_address)
val port = addDeviceView.findViewById<EditText>(R.id.add_device_port)
val videoCodec = addDeviceView.findViewById<Spinner>(R.id.add_device_videoCodec)
val maxSize = addDeviceView.findViewById<Spinner>(R.id.add_device_max_size)
val fps = addDeviceView.findViewById<Spinner>(R.id.add_device_fps)
val videoBit = addDeviceView.findViewById<Spinner>(R.id.add_device_video_bit)
val setResolution = addDeviceView.findViewById<Switch>(R.id.add_device_set_resolution)
val defaultFull = addDeviceView.findViewById<Switch>(R.id.add_device_default_full)
val floatNav = addDeviceView.findViewById<Switch>(R.id.add_device_float_nav)
// 是否显示高级选项
addDeviceView.findViewById<CheckBox>(R.id.add_device_is_options).setOnClickListener {
addDeviceView.findViewById<LinearLayout>(R.id.add_device_options).visibility =
if (addDeviceView.findViewById<CheckBox>(R.id.add_device_is_options).isChecked)
View.VISIBLE
else View.GONE
}
// 确认按钮
addDeviceView.findViewById<Button>(R.id.add_device_ok).setOnClickListener {
updateDialog.cancel()
val newAddress = address.text.toString()
val newPort = port.text.toString().toInt()
val newVideoCodec = videoCodec.selectedItem.toString()
val newMaxSize = maxSize.selectedItem.toString().toInt()
val newFps = fps.selectedItem.toString().toInt()
val newVideoBit = videoBit.selectedItem.toString().toInt()
val newSetResolution = if (setResolution.isChecked) 1 else 0
val newDefaultFull = if (defaultFull.isChecked) 1 else 0
val newFloatNav = if (floatNav.isChecked) 1 else 0
val values = ContentValues().apply {
put("address", newAddress)
put("port", newPort)
put("videoCodec", newVideoCodec)
put("maxSize", newMaxSize)
put("fps", newFps)
put("videoBit", newVideoBit)
put("setResolution", newSetResolution)
put("defaultFull", newDefaultFull)
put("floatNav", newFloatNav)
}
if (main.appData.dbHelper.writableDatabase.update(
"DevicesDb",
values,
"name=?",
arrayOf(device.name)
) != -1
) {
main.appData.devices.remove(device)
main.appData.devices.add(
Device(
device.name,
newAddress,
newPort,
newVideoCodec,
newMaxSize,
newFps,
newVideoBit,
newSetResolution == 1,
newDefaultFull == 1,
newFloatNav == 1
)
)
notifyDataSetChanged()
}
}
updateDialog.show()
// 填充参数
name.setText(device.name)
address.setText(device.address)
port.setText(device.port.toString())
videoCodec.setSelection(
getStringIndex(
device.videoCodec,
main.resources.getStringArray(R.array.videoCodecItems)
)
)
maxSize.setSelection(
getStringIndex(
device.maxSize.toString(),
main.resources.getStringArray(R.array.maxSizeItems)
)
)
fps.setSelection(
getStringIndex(
device.fps.toString(),
main.resources.getStringArray(R.array.fpsItems)
)
)
videoBit.setSelection(
getStringIndex(
device.videoBit.toString(),
main.resources.getStringArray(R.array.videoBitItems)
)
)
setResolution.isChecked = device.setResolution
defaultFull.isChecked = device.defaultFull
floatNav.isChecked = device.floatNav
// 设置不可变参数
name.isFocusable = false
name.isFocusableInTouchMode = false
}
// 删除
deleteDeviceView.findViewById<Button>(R.id.delete_device_delete).setOnClickListener {
main.appData.dbHelper.writableDatabase.delete(
"DevicesDb", "name = ?", arrayOf(device.name)
)
Expand All @@ -75,7 +189,8 @@ class DeviceAdapter(private val main: MainActivity) :
fps: Int,
videoBit: Int,
setResolution: Boolean,
defaultFull: Boolean
defaultFull: Boolean,
floatNav: Boolean
) {
val values = ContentValues().apply {
put("name", name)
Expand All @@ -87,6 +202,7 @@ class DeviceAdapter(private val main: MainActivity) :
put("videoBit", videoBit)
put("setResolution", if (setResolution) 1 else 0)
put("defaultFull", if (defaultFull) 1 else 0)
put("floatNav", if (floatNav) 1 else 0)
}
// 名称重复
if (main.appData.dbHelper.writableDatabase.insert("DevicesDb", null, values).toInt() != -1) {
Expand All @@ -100,10 +216,22 @@ class DeviceAdapter(private val main: MainActivity) :
fps,
videoBit,
setResolution,
defaultFull
defaultFull,
floatNav
)
)
notifyDataSetChanged()
}
}

// 获取string 在string array中的位置
private fun getStringIndex(str: String, strArray: Array<String>): Int {
for ((index, i) in strArray.withIndex()) {
if (str == i) return index
else index
}
// 找不到返回0
return 0
}

}
Loading

0 comments on commit 57af7dd

Please sign in to comment.