optimize direct transfer UI and Android queue
This commit is contained in:
@@ -12,8 +12,8 @@ android {
|
|||||||
applicationId = "com.qft.optical"
|
applicationId = "com.qft.optical"
|
||||||
minSdk = 24
|
minSdk = 24
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 21
|
versionCode = 22
|
||||||
versionName = "0.4.9"
|
versionName = "0.4.10"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import android.util.Size
|
|||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.ScaleGestureDetector
|
import android.view.ScaleGestureDetector
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
@@ -79,15 +80,17 @@ class MainActivity : ComponentActivity() {
|
|||||||
@Volatile private var connectedNetwork: Network? = null
|
@Volatile private var connectedNetwork: Network? = null
|
||||||
private var connectedBaseUrl: String? = null
|
private var connectedBaseUrl: String? = null
|
||||||
private val selectedFiles = mutableListOf<SelectedFile>()
|
private val selectedFiles = mutableListOf<SelectedFile>()
|
||||||
private var managingFilesForPair: PairingPayload? = null
|
|
||||||
private var managingFilesForBaseUrl: String? = null
|
|
||||||
private var sendStatusText: TextView? = null
|
private var sendStatusText: TextView? = null
|
||||||
private var sendFilesText: TextView? = null
|
private var sendFilesText: TextView? = null
|
||||||
|
private var sendFilesContainer: LinearLayout? = null
|
||||||
|
private var sendAddButton: Button? = null
|
||||||
|
private var sendClearButton: Button? = null
|
||||||
private var sendProgress: ProgressBar? = null
|
private var sendProgress: ProgressBar? = null
|
||||||
private var sendButton: Button? = null
|
private var sendButton: Button? = null
|
||||||
private var connectingStatusText: TextView? = null
|
private var connectingStatusText: TextView? = null
|
||||||
private var downloadStatusText: TextView? = null
|
private var downloadStatusText: TextView? = null
|
||||||
@Volatile private var downloadRunning = false
|
@Volatile private var downloadRunning = false
|
||||||
|
@Volatile private var uploadRunning = false
|
||||||
/** 非 null 表示当前传输应立刻中止(QFT 临时网络断开等)。
|
/** 非 null 表示当前传输应立刻中止(QFT 临时网络断开等)。
|
||||||
* 下载线程每读一个缓冲区就检查一次,避免在 readTimeout 上白等。 */
|
* 下载线程每读一个缓冲区就检查一次,避免在 readTimeout 上白等。 */
|
||||||
@Volatile private var transferAbortReason: String? = null
|
@Volatile private var transferAbortReason: String? = null
|
||||||
@@ -117,18 +120,16 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val pickFiles = registerForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { uris ->
|
private val pickFiles = registerForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { uris ->
|
||||||
|
if (uploadRunning) {
|
||||||
|
sendStatusText?.text = "传输已经开始,当前队列已锁定"
|
||||||
|
return@registerForActivityResult
|
||||||
|
}
|
||||||
var unknown = 0
|
var unknown = 0
|
||||||
for (uri in uris) {
|
for (uri in uris) {
|
||||||
val file = UploadClient.describeFile(contentResolver, uri)
|
val file = UploadClient.describeFile(contentResolver, uri)
|
||||||
if (file != null && selectedFiles.none { it.uri == file.uri }) selectedFiles += file else if (file == null) unknown++
|
if (file != null && selectedFiles.none { it.uri == file.uri }) selectedFiles += file else if (file == null) unknown++
|
||||||
}
|
}
|
||||||
renderSelectedFiles()
|
renderSelectedFiles()
|
||||||
val pair = managingFilesForPair
|
|
||||||
val baseUrl = managingFilesForBaseUrl
|
|
||||||
if (pair != null && baseUrl != null) {
|
|
||||||
showFileSelection(pair, baseUrl)
|
|
||||||
return@registerForActivityResult
|
|
||||||
}
|
|
||||||
if (unknown > 0) {
|
if (unknown > 0) {
|
||||||
sendStatusText?.text = "有 $unknown 个文件无法确定大小,已跳过"
|
sendStatusText?.text = "有 $unknown 个文件无法确定大小,已跳过"
|
||||||
} else if (selectedFiles.isNotEmpty()) {
|
} else if (selectedFiles.isNotEmpty()) {
|
||||||
@@ -159,8 +160,14 @@ class MainActivity : ComponentActivity() {
|
|||||||
downloadRunning = false
|
downloadRunning = false
|
||||||
downloadStatusText = null
|
downloadStatusText = null
|
||||||
selectedFiles.clear()
|
selectedFiles.clear()
|
||||||
managingFilesForPair = null
|
uploadRunning = false
|
||||||
managingFilesForBaseUrl = null
|
sendFilesContainer = null
|
||||||
|
sendAddButton = null
|
||||||
|
sendClearButton = null
|
||||||
|
sendFilesText = null
|
||||||
|
sendStatusText = null
|
||||||
|
sendProgress = null
|
||||||
|
sendButton = null
|
||||||
|
|
||||||
val root = pageColumn()
|
val root = pageColumn()
|
||||||
root.addView(text("QFT", 30f, Color.WHITE, true))
|
root.addView(text("QFT", 30f, Color.WHITE, true))
|
||||||
@@ -195,7 +202,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
) { showReceivedFiles() })
|
) { showReceivedFiles() })
|
||||||
root.addView(space(22))
|
root.addView(space(22))
|
||||||
root.addView(text("本机设备:$receiverDeviceLabel", 13f, MUTED))
|
root.addView(text("本机设备:$receiverDeviceLabel", 13f, MUTED))
|
||||||
root.addView(text("QFT v0.4.9 · Android 7+ 到最新", 12f, MUTED))
|
root.addView(text("QFT v0.4.10 · Android 7+ 到最新", 12f, MUTED))
|
||||||
setContentView(ScrollView(this).apply { setBackgroundColor(BG); addView(root) })
|
setContentView(ScrollView(this).apply { setBackgroundColor(BG); addView(root) })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -811,12 +818,34 @@ class MainActivity : ComponentActivity() {
|
|||||||
})
|
})
|
||||||
root.addView(space(14))
|
root.addView(space(14))
|
||||||
root.addView(card().apply {
|
root.addView(card().apply {
|
||||||
addView(text("选择文件", 17f, Color.WHITE, true))
|
addView(text("传输队列", 17f, Color.WHITE, true))
|
||||||
sendFilesText = text("请先选择需要传输的文件", 14f, WARNING)
|
sendFilesText = text("请先选择需要传输的文件", 14f, WARNING)
|
||||||
addView(sendFilesText, matchWrap(top = 8))
|
addView(sendFilesText, matchWrap(top = 8))
|
||||||
addView(button("选择文件(可多选)").apply {
|
sendFilesContainer = LinearLayout(this@MainActivity).apply {
|
||||||
setOnClickListener { showFileSelection(pair, baseUrl) }
|
orientation = LinearLayout.VERTICAL
|
||||||
}, matchWrap(top = 12))
|
}
|
||||||
|
addView(sendFilesContainer, matchWrap(top = 6))
|
||||||
|
val actions = LinearLayout(this@MainActivity).apply {
|
||||||
|
orientation = LinearLayout.HORIZONTAL
|
||||||
|
gravity = Gravity.CENTER_VERTICAL
|
||||||
|
}
|
||||||
|
sendAddButton = button("添加文件").apply {
|
||||||
|
setOnClickListener { pickFiles.launch(arrayOf("*/*")) }
|
||||||
|
}
|
||||||
|
sendClearButton = button("清空").apply {
|
||||||
|
setOnClickListener {
|
||||||
|
if (!uploadRunning) {
|
||||||
|
selectedFiles.clear()
|
||||||
|
renderSelectedFiles()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
actions.addView(sendAddButton, LinearLayout.LayoutParams(0, dp(48), 1f).apply {
|
||||||
|
marginEnd = dp(8)
|
||||||
|
})
|
||||||
|
actions.addView(sendClearButton, LinearLayout.LayoutParams(dp(96), dp(48)))
|
||||||
|
addView(actions, matchWrap(top = 12))
|
||||||
|
addView(text("按住“拖动”上下移动可调整发送优先级;传输开始后队列会锁定。", 12f, MUTED), matchWrap(top = 8))
|
||||||
})
|
})
|
||||||
root.addView(space(14))
|
root.addView(space(14))
|
||||||
root.addView(card().apply {
|
root.addView(card().apply {
|
||||||
@@ -826,10 +855,9 @@ class MainActivity : ComponentActivity() {
|
|||||||
sendProgress = ProgressBar(this@MainActivity, null, android.R.attr.progressBarStyleHorizontal).apply { max = 1000; progress = 0 }
|
sendProgress = ProgressBar(this@MainActivity, null, android.R.attr.progressBarStyleHorizontal).apply { max = 1000; progress = 0 }
|
||||||
addView(sendProgress, LinearLayout.LayoutParams(-1, dp(9)).apply { topMargin = dp(12) })
|
addView(sendProgress, LinearLayout.LayoutParams(-1, dp(9)).apply { topMargin = dp(12) })
|
||||||
sendButton = button("选择传输文件").apply {
|
sendButton = button("选择传输文件").apply {
|
||||||
isEnabled = connectedBaseUrl != null
|
isEnabled = false
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
if (selectedFiles.isEmpty()) showFileSelection(pair, baseUrl)
|
startUploads(pair, baseUrl)
|
||||||
else startUploads(pair, baseUrl)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addView(sendButton, matchWrap(top = 14))
|
addView(sendButton, matchWrap(top = 14))
|
||||||
@@ -1008,95 +1036,117 @@ class MainActivity : ComponentActivity() {
|
|||||||
setContentView(ScrollView(this).apply { setBackgroundColor(BG); addView(root) })
|
setContentView(ScrollView(this).apply { setBackgroundColor(BG); addView(root) })
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showFileSelection(pair: PairingPayload, baseUrl: String) {
|
|
||||||
managingFilesForPair = pair
|
|
||||||
managingFilesForBaseUrl = baseUrl
|
|
||||||
val root = pageColumn()
|
|
||||||
root.addView(text("选择发送文件", 28f, Color.WHITE, true))
|
|
||||||
root.addView(text("可多次添加文件,并在列表中单独移除。", 14f, MUTED))
|
|
||||||
root.addView(space(14))
|
|
||||||
val total = selectedFiles.sumOf { it.size }
|
|
||||||
root.addView(card().apply {
|
|
||||||
addView(text("已选 ${selectedFiles.size} 个 · ${humanBytes(total)}", 16f, ACCENT, true))
|
|
||||||
if (selectedFiles.isEmpty()) {
|
|
||||||
addView(text("请先选择需要传输的文件", 14f, WARNING), matchWrap(top = 8))
|
|
||||||
} else {
|
|
||||||
selectedFiles.toList().forEach { file ->
|
|
||||||
val row = LinearLayout(this@MainActivity).apply {
|
|
||||||
orientation = LinearLayout.HORIZONTAL
|
|
||||||
gravity = Gravity.CENTER_VERTICAL
|
|
||||||
}
|
|
||||||
row.addView(
|
|
||||||
text("${file.name}\n${humanBytes(file.size)}", 14f, Color.WHITE),
|
|
||||||
LinearLayout.LayoutParams(0, -2, 1f).apply { marginEnd = dp(8) },
|
|
||||||
)
|
|
||||||
row.addView(button("移除").apply {
|
|
||||||
setOnClickListener {
|
|
||||||
selectedFiles.removeAll { it.uri == file.uri }
|
|
||||||
showFileSelection(pair, baseUrl)
|
|
||||||
}
|
|
||||||
}, LinearLayout.LayoutParams(dp(82), dp(44)))
|
|
||||||
addView(row, matchWrap(top = 10))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
root.addView(space(14))
|
|
||||||
root.addView(button("添加文件(可多选)").apply {
|
|
||||||
setOnClickListener { pickFiles.launch(arrayOf("*/*")) }
|
|
||||||
})
|
|
||||||
if (selectedFiles.isNotEmpty()) {
|
|
||||||
root.addView(space(10))
|
|
||||||
root.addView(button("清空选择").apply {
|
|
||||||
setOnClickListener {
|
|
||||||
selectedFiles.clear()
|
|
||||||
showFileSelection(pair, baseUrl)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
root.addView(space(10))
|
|
||||||
root.addView(button("完成并返回传输").apply {
|
|
||||||
isEnabled = selectedFiles.isNotEmpty()
|
|
||||||
setOnClickListener {
|
|
||||||
managingFilesForPair = null
|
|
||||||
managingFilesForBaseUrl = null
|
|
||||||
showSendReady(pair, baseUrl)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
root.addView(space(10))
|
|
||||||
root.addView(button("取消并返回传输").apply {
|
|
||||||
setOnClickListener {
|
|
||||||
managingFilesForPair = null
|
|
||||||
managingFilesForBaseUrl = null
|
|
||||||
showSendReady(pair, baseUrl)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
setContentView(ScrollView(this).apply { setBackgroundColor(BG); addView(root) })
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun renderSelectedFiles() {
|
private fun renderSelectedFiles() {
|
||||||
val total = selectedFiles.sumOf { it.size }
|
val total = selectedFiles.sumOf { it.size }
|
||||||
sendFilesText?.text = if (selectedFiles.isEmpty()) {
|
sendFilesText?.text = if (selectedFiles.isEmpty()) {
|
||||||
"请先选择需要传输的文件"
|
"请先选择需要传输的文件"
|
||||||
} else {
|
} else {
|
||||||
buildString {
|
"已选 ${selectedFiles.size} 个 · ${humanBytes(total)} · 按列表顺序发送"
|
||||||
selectedFiles.take(8).forEach { append("• ${it.name} ${humanBytes(it.size)}\n") }
|
}
|
||||||
if (selectedFiles.size > 8) append("…另外 ${selectedFiles.size - 8} 个文件\n")
|
sendFilesText?.setTextColor(if (selectedFiles.isEmpty()) WARNING else ACCENT)
|
||||||
append("共 ${selectedFiles.size} 个 · ${humanBytes(total)}")
|
|
||||||
}.trim()
|
val container = sendFilesContainer
|
||||||
|
container?.removeAllViews()
|
||||||
|
selectedFiles.toList().forEachIndexed { index, file ->
|
||||||
|
val row = LinearLayout(this).apply {
|
||||||
|
orientation = LinearLayout.HORIZONTAL
|
||||||
|
gravity = Gravity.CENTER_VERTICAL
|
||||||
|
setPadding(0, dp(4), 0, dp(4))
|
||||||
|
}
|
||||||
|
val drag = button("拖动").apply {
|
||||||
|
isEnabled = !uploadRunning
|
||||||
|
textSize = 12f
|
||||||
|
}
|
||||||
|
row.addView(drag, LinearLayout.LayoutParams(dp(76), dp(44)).apply {
|
||||||
|
marginEnd = dp(8)
|
||||||
|
})
|
||||||
|
row.addView(
|
||||||
|
text("${index + 1}. ${file.name}\n${humanBytes(file.size)}", 14f, Color.WHITE),
|
||||||
|
LinearLayout.LayoutParams(0, -2, 1f).apply { marginEnd = dp(8) },
|
||||||
|
)
|
||||||
|
row.addView(button("删除").apply {
|
||||||
|
isEnabled = !uploadRunning
|
||||||
|
textSize = 12f
|
||||||
|
setOnClickListener {
|
||||||
|
if (!uploadRunning) {
|
||||||
|
selectedFiles.removeAll { it.uri == file.uri }
|
||||||
|
renderSelectedFiles()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, LinearLayout.LayoutParams(dp(76), dp(44)))
|
||||||
|
container?.addView(row, matchWrap(top = if (index == 0) 2 else 4))
|
||||||
|
if (container != null && !uploadRunning) {
|
||||||
|
installFileQueueDrag(drag, row, file, container)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sendAddButton?.isEnabled = !uploadRunning
|
||||||
|
sendClearButton?.isEnabled = !uploadRunning && selectedFiles.isNotEmpty()
|
||||||
|
sendButton?.text = when {
|
||||||
|
uploadRunning -> "传输中 · 队列已锁定"
|
||||||
|
selectedFiles.isEmpty() -> "请先添加文件"
|
||||||
|
else -> "开始传输 ${selectedFiles.size} 个文件"
|
||||||
|
}
|
||||||
|
sendButton?.isEnabled = connectedBaseUrl != null && selectedFiles.isNotEmpty() && !uploadRunning
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun installFileQueueDrag(
|
||||||
|
handle: View,
|
||||||
|
row: View,
|
||||||
|
file: SelectedFile,
|
||||||
|
container: LinearLayout,
|
||||||
|
) {
|
||||||
|
handle.setOnTouchListener { view, event ->
|
||||||
|
if (uploadRunning) return@setOnTouchListener false
|
||||||
|
when (event.actionMasked) {
|
||||||
|
MotionEvent.ACTION_DOWN -> {
|
||||||
|
view.parent?.requestDisallowInterceptTouchEvent(true)
|
||||||
|
row.alpha = 0.72f
|
||||||
|
true
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_MOVE -> {
|
||||||
|
val location = IntArray(2)
|
||||||
|
container.getLocationOnScreen(location)
|
||||||
|
val y = event.rawY - location[1]
|
||||||
|
var target = container.childCount - 1
|
||||||
|
for (index in 0 until container.childCount) {
|
||||||
|
val child = container.getChildAt(index)
|
||||||
|
if (y < child.top + child.height / 2f) {
|
||||||
|
target = index
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val current = selectedFiles.indexOfFirst { it.uri == file.uri }
|
||||||
|
if (moveQueueItem(selectedFiles, current, target)) {
|
||||||
|
container.removeView(row)
|
||||||
|
container.addView(row, target)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
||||||
|
view.parent?.requestDisallowInterceptTouchEvent(false)
|
||||||
|
row.alpha = 1f
|
||||||
|
view.performClick()
|
||||||
|
renderSelectedFiles()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sendButton?.text = if (selectedFiles.isEmpty()) "选择传输文件" else "开始传输"
|
|
||||||
sendButton?.isEnabled = connectedBaseUrl != null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startUploads(pair: PairingPayload, baseUrl: String) {
|
private fun startUploads(pair: PairingPayload, baseUrl: String) {
|
||||||
|
if (uploadRunning) return
|
||||||
if (selectedFiles.isEmpty()) {
|
if (selectedFiles.isEmpty()) {
|
||||||
sendStatusText?.setTextColor(WARNING)
|
sendStatusText?.setTextColor(WARNING)
|
||||||
sendStatusText?.text = "请先选择需要传输的文件"
|
sendStatusText?.text = "请先选择需要传输的文件"
|
||||||
showFileSelection(pair, baseUrl)
|
pickFiles.launch(arrayOf("*/*"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val files = selectedFiles.toList()
|
val files = selectedFiles.toList()
|
||||||
sendButton?.isEnabled = false
|
uploadRunning = true
|
||||||
|
transferAbortReason = null
|
||||||
|
renderSelectedFiles()
|
||||||
wifiConnector.acquireHighPerfLock()
|
wifiConnector.acquireHighPerfLock()
|
||||||
transferExecutor.execute {
|
transferExecutor.execute {
|
||||||
try {
|
try {
|
||||||
@@ -1132,15 +1182,17 @@ class MainActivity : ComponentActivity() {
|
|||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
sendProgress?.progress = 1000
|
sendProgress?.progress = 1000
|
||||||
sendStatusText?.text = "全部完成 · 已发送 ${files.size} 个文件"
|
sendStatusText?.text = "全部完成 · 已发送 ${files.size} 个文件"
|
||||||
sendButton?.isEnabled = true
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
sendStatusText?.text = "传输失败:${e.message}"
|
sendStatusText?.text = "传输失败:${e.message}"
|
||||||
sendButton?.isEnabled = true
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
wifiConnector.releaseHighPerfLock()
|
wifiConnector.releaseHighPerfLock()
|
||||||
|
runOnUiThread {
|
||||||
|
uploadRunning = false
|
||||||
|
renderSelectedFiles()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.qft.optical
|
||||||
|
|
||||||
|
/** Move one item while preserving every other item's relative order. */
|
||||||
|
internal fun <T> moveQueueItem(items: MutableList<T>, from: Int, to: Int): Boolean {
|
||||||
|
if (from !in items.indices || to !in items.indices || from == to) return false
|
||||||
|
items.add(to, items.removeAt(from))
|
||||||
|
return true
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.qft.optical
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class TransferQueueTest {
|
||||||
|
@Test
|
||||||
|
fun movesFilesInBothDirectionsWithoutLosingItems() {
|
||||||
|
val queue = mutableListOf("A", "B", "C", "D")
|
||||||
|
assertTrue(moveQueueItem(queue, 0, 2))
|
||||||
|
assertEquals(listOf("B", "C", "A", "D"), queue)
|
||||||
|
assertTrue(moveQueueItem(queue, 3, 1))
|
||||||
|
assertEquals(listOf("B", "D", "C", "A"), queue)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun rejectsInvalidOrNoOpMoves() {
|
||||||
|
val queue = mutableListOf("A", "B")
|
||||||
|
assertFalse(moveQueueItem(queue, -1, 0))
|
||||||
|
assertFalse(moveQueueItem(queue, 0, 2))
|
||||||
|
assertFalse(moveQueueItem(queue, 1, 1))
|
||||||
|
assertEquals(listOf("A", "B"), queue)
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+1
-1
@@ -2587,7 +2587,7 @@ checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "qft-desktop"
|
name = "qft-desktop"
|
||||||
version = "0.4.14"
|
version = "0.4.15"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64",
|
"base64",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "qft-desktop"
|
name = "qft-desktop"
|
||||||
version = "0.4.14"
|
version = "0.4.15"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.95"
|
rust-version = "1.95"
|
||||||
|
|
||||||
|
|||||||
+56
-67
@@ -111,7 +111,6 @@ struct SendState {
|
|||||||
status: String,
|
status: String,
|
||||||
connected_device: String,
|
connected_device: String,
|
||||||
qr_focus: bool,
|
qr_focus: bool,
|
||||||
qr_controls_height: f32,
|
|
||||||
qr_zoom: f32,
|
qr_zoom: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,7 +240,6 @@ impl QftApp {
|
|||||||
status: "选择文件后生成二维码;手机扫码会自动配网并开始下载。".into(),
|
status: "选择文件后生成二维码;手机扫码会自动配网并开始下载。".into(),
|
||||||
connected_device: "等待 Android 扫码".into(),
|
connected_device: "等待 Android 扫码".into(),
|
||||||
qr_focus: false,
|
qr_focus: false,
|
||||||
qr_controls_height: 220.0,
|
|
||||||
qr_zoom: 1.0,
|
qr_zoom: 1.0,
|
||||||
},
|
},
|
||||||
pc: PcPeerState {
|
pc: PcPeerState {
|
||||||
@@ -574,6 +572,7 @@ impl QftApp {
|
|||||||
}
|
}
|
||||||
let running = self.receive.server.is_some();
|
let running = self.receive.server.is_some();
|
||||||
|
|
||||||
|
if !running {
|
||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
ui.heading("1 · 保存位置");
|
ui.heading("1 · 保存位置");
|
||||||
ui.horizontal_wrapped(|ui| {
|
ui.horizontal_wrapped(|ui| {
|
||||||
@@ -629,17 +628,16 @@ impl QftApp {
|
|||||||
});
|
});
|
||||||
ui.label(&self.receive.status);
|
ui.label(&self.receive.status);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if self.receive.server.is_some() {
|
if self.receive.server.is_some() {
|
||||||
ui.add_space(10.0);
|
ui.add_space(10.0);
|
||||||
|
let listen_port = self.receive.server.as_ref()
|
||||||
|
.map(|server| server.port)
|
||||||
|
.unwrap_or(receiver::PREFERRED_PORT);
|
||||||
ui.columns(2, |cols| {
|
ui.columns(2, |cols| {
|
||||||
cols[0].group(|ui| {
|
cols[0].group(|ui| {
|
||||||
ui.heading("手机扫码 · QFTPAIR2");
|
ui.heading("手机扫码 · QFTPAIR2");
|
||||||
// Direct AP 的虚拟网卡最容易被防火墙拦住,把检测结果放在
|
|
||||||
// 二维码旁边——用户在这里停留最久,也正是在这一步失败的。
|
|
||||||
let listen_port = self.receive.server.as_ref().map(|s| s.port).unwrap_or(receiver::PREFERRED_PORT);
|
|
||||||
self.firewall_panel(ui, listen_port);
|
|
||||||
ui.add_space(8.0);
|
|
||||||
if let Some(texture) = &self.receive.pair_texture {
|
if let Some(texture) = &self.receive.pair_texture {
|
||||||
let qr_zoom = self.receive.qr_zoom;
|
let qr_zoom = self.receive.qr_zoom;
|
||||||
ui.vertical_centered(|ui| {
|
ui.vertical_centered(|ui| {
|
||||||
@@ -670,7 +668,12 @@ impl QftApp {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
cols[1].group(|ui| {
|
cols[1].group(|ui| {
|
||||||
|
ui.horizontal_wrapped(|ui| {
|
||||||
ui.heading("接收状态 · Parallel v2");
|
ui.heading("接收状态 · Parallel v2");
|
||||||
|
if ui.button("停止接收").clicked() {
|
||||||
|
self.stop_receiver();
|
||||||
|
}
|
||||||
|
});
|
||||||
ui.label(format!("电脑:{}", self.local_device));
|
ui.label(format!("电脑:{}", self.local_device));
|
||||||
ui.label(format!("手机:{}", self.receive.connected_device));
|
ui.label(format!("手机:{}", self.receive.connected_device));
|
||||||
ui.separator();
|
ui.separator();
|
||||||
@@ -688,6 +691,8 @@ impl QftApp {
|
|||||||
ui.label(format!("最近保存:{}", self.receive.last_saved));
|
ui.label(format!("最近保存:{}", self.receive.last_saved));
|
||||||
if !self.receive.last_sha256.is_empty() { ui.small(format!("SHA-256:{}", self.receive.last_sha256)); }
|
if !self.receive.last_sha256.is_empty() { ui.small(format!("SHA-256:{}", self.receive.last_sha256)); }
|
||||||
});
|
});
|
||||||
|
cols[1].add_space(8.0);
|
||||||
|
self.firewall_panel(&mut cols[1], listen_port);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -783,51 +788,19 @@ impl QftApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn pc_to_phone_resizable_qr_ui(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) {
|
fn pc_to_phone_resizable_qr_ui(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) {
|
||||||
const DIVIDER_HEIGHT: f32 = 10.0;
|
let _ = ctx;
|
||||||
let available_height = ui.available_height();
|
if ui.available_width() >= 820.0 {
|
||||||
let min_controls_height = 150.0;
|
ui.columns(2, |cols| {
|
||||||
let min_qr_height = 260.0_f32.min((available_height * 0.55).max(180.0));
|
self.pc_to_phone_qr_panel(&mut cols[0], false);
|
||||||
let max_controls_height = (available_height - min_qr_height - DIVIDER_HEIGHT)
|
egui::ScrollArea::vertical()
|
||||||
.max(min_controls_height);
|
.auto_shrink([false, false])
|
||||||
self.send.qr_controls_height = self
|
.show(&mut cols[1], |ui| self.pc_to_phone_running_controls(ui));
|
||||||
.send
|
|
||||||
.qr_controls_height
|
|
||||||
.clamp(min_controls_height, max_controls_height);
|
|
||||||
|
|
||||||
ui.allocate_ui_with_layout(
|
|
||||||
egui::vec2(ui.available_width(), self.send.qr_controls_height),
|
|
||||||
egui::Layout::top_down(egui::Align::Min),
|
|
||||||
|ui| {
|
|
||||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
|
||||||
self.pc_to_phone_running_controls(ui);
|
|
||||||
});
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let (divider_rect, divider_response) = ui.allocate_exact_size(
|
|
||||||
egui::vec2(ui.available_width(), DIVIDER_HEIGHT),
|
|
||||||
egui::Sense::drag(),
|
|
||||||
);
|
|
||||||
let divider_response = divider_response.on_hover_cursor(egui::CursorIcon::ResizeVertical);
|
|
||||||
let divider_color = if divider_response.dragged() || divider_response.hovered() {
|
|
||||||
ui.visuals().widgets.active.bg_fill
|
|
||||||
} else {
|
} else {
|
||||||
ui.visuals().widgets.inactive.bg_fill
|
|
||||||
};
|
|
||||||
ui.painter().rect_filled(
|
|
||||||
divider_rect.shrink2(egui::vec2(0.0, 3.0)),
|
|
||||||
3.0,
|
|
||||||
divider_color,
|
|
||||||
);
|
|
||||||
if divider_response.dragged() {
|
|
||||||
let delta_y = ui.input(|input| input.pointer.delta().y);
|
|
||||||
self.send.qr_controls_height = (self.send.qr_controls_height + delta_y)
|
|
||||||
.clamp(min_controls_height, max_controls_height);
|
|
||||||
ctx.request_repaint();
|
|
||||||
}
|
|
||||||
divider_response.on_hover_text("上下拖动,调整控制区和二维码区域的高度");
|
|
||||||
|
|
||||||
self.pc_to_phone_qr_panel(ui, false);
|
self.pc_to_phone_qr_panel(ui, false);
|
||||||
|
ui.add_space(8.0);
|
||||||
|
self.pc_to_phone_running_controls(ui);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pc_to_phone_running_controls(&mut self, ui: &mut egui::Ui) {
|
fn pc_to_phone_running_controls(&mut self, ui: &mut egui::Ui) {
|
||||||
@@ -869,7 +842,7 @@ impl QftApp {
|
|||||||
ui.label(format!("文件:{} · {}", file.display(), human_bytes(self.send.file_size)));
|
ui.label(format!("文件:{} · {}", file.display(), human_bytes(self.send.file_size)));
|
||||||
}
|
}
|
||||||
ui.label(&self.send.status);
|
ui.label(&self.send.status);
|
||||||
ui.small("拖动下方分隔条可为二维码腾出更多高度;也可切换到“专注二维码”。");
|
ui.small("二维码与控制区已并排显示;需要更大画面时可手动切换“专注二维码”。");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -949,8 +922,7 @@ impl QftApp {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.columns(2, |cols| {
|
ui.group(|ui| {
|
||||||
cols[0].group(|ui| {
|
|
||||||
ui.heading("手机扫码 · QFTSEND2");
|
ui.heading("手机扫码 · QFTSEND2");
|
||||||
if let Some(texture) = &self.send.pair_texture {
|
if let Some(texture) = &self.send.pair_texture {
|
||||||
let available = ui.available_size();
|
let available = ui.available_size();
|
||||||
@@ -961,16 +933,7 @@ impl QftApp {
|
|||||||
ui.image((texture.id(), egui::vec2(side, side)));
|
ui.image((texture.id(), egui::vec2(side, side)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ui.set_min_height(panel_height);
|
|
||||||
});
|
|
||||||
cols[1].group(|ui| {
|
|
||||||
ui.heading("发送状态");
|
|
||||||
ui.label(format!("电脑:{}", self.local_device));
|
|
||||||
ui.label(format!("手机:{}", self.send.connected_device));
|
|
||||||
ui.label(self.send.file.as_ref().map(|file| format!("文件:{}", file.display())).unwrap_or_default());
|
|
||||||
ui.small("二维码只在本次直传会话有效;停止直传后立即失效。");
|
ui.small("二维码只在本次直传会话有效;停止直传后立即失效。");
|
||||||
ui.set_min_height(panel_height);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1143,9 +1106,9 @@ impl QftApp {
|
|||||||
self.receive.direct_ap = direct_ap;
|
self.receive.direct_ap = direct_ap;
|
||||||
self.receive.events = Some(rx);
|
self.receive.events = Some(rx);
|
||||||
self.receive.pair_texture = Some(ctx.load_texture("qft-pair-code", image, TextureOptions::NEAREST));
|
self.receive.pair_texture = Some(ctx.load_texture("qft-pair-code", image, TextureOptions::NEAREST));
|
||||||
// 扫码是启动后的唯一下一步,默认把窗口让给大二维码;用户仍可退出
|
// 保持普通布局,让用户同时看到二维码、连接状态和防火墙诊断;只有
|
||||||
// 专注模式查看防火墙、地址和接收状态。
|
// 用户主动点击“专注二维码”时才隐藏其余信息。
|
||||||
self.receive.focus_qr = true;
|
self.receive.focus_qr = false;
|
||||||
self.receive.session_token = token;
|
self.receive.session_token = token;
|
||||||
self.receive.connected_device = "等待 Android 扫码".into();
|
self.receive.connected_device = "等待 Android 扫码".into();
|
||||||
self.receive.current_file = "—".into();
|
self.receive.current_file = "—".into();
|
||||||
@@ -1236,9 +1199,8 @@ impl QftApp {
|
|||||||
self.send.direct_ap = direct_ap;
|
self.send.direct_ap = direct_ap;
|
||||||
self.send.events = Some(rx);
|
self.send.events = Some(rx);
|
||||||
self.send.pair_texture = Some(ctx.load_texture("qft-send-code", image, TextureOptions::NEAREST));
|
self.send.pair_texture = Some(ctx.load_texture("qft-send-code", image, TextureOptions::NEAREST));
|
||||||
// QFTSEND2 往往还带文件名、大小和 SHA-256,比接收码更密;生成后
|
// 启动后保持二维码与状态并排;专注模式由用户手动进入。
|
||||||
// 直接放大显示,避免控制区把模块压到手机相机的识别下限附近。
|
self.send.qr_focus = false;
|
||||||
self.send.qr_focus = true;
|
|
||||||
self.send.session_token = token;
|
self.send.session_token = token;
|
||||||
self.send.connected_device = "等待 Android 扫码".into();
|
self.send.connected_device = "等待 Android 扫码".into();
|
||||||
self.send.status = if self.send.use_direct_ap {
|
self.send.status = if self.send.use_direct_ap {
|
||||||
@@ -2201,6 +2163,33 @@ mod font_tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn running_send_qr_starts_beside_controls_without_forced_focus() {
|
||||||
|
let app = QftApp::bare(String::new());
|
||||||
|
assert!(!app.send.qr_focus, "扫码直传不应默认进入专注二维码");
|
||||||
|
assert!(!app.receive.focus_qr, "扫码接收不应默认进入专注二维码");
|
||||||
|
|
||||||
|
let positions = rendered_text_positions(|ui| {
|
||||||
|
let context = ui.ctx().clone();
|
||||||
|
let mut app = QftApp::bare(String::new());
|
||||||
|
app.pc_to_phone_resizable_qr_ui(ui, &context);
|
||||||
|
});
|
||||||
|
let qr_y = positions
|
||||||
|
.iter()
|
||||||
|
.find(|(text, _)| text.contains("手机扫码 · QFTSEND2"))
|
||||||
|
.map(|(_, y)| *y)
|
||||||
|
.expect("应绘制二维码面板");
|
||||||
|
let controls_y = positions
|
||||||
|
.iter()
|
||||||
|
.find(|(text, _)| text.contains("直传控制"))
|
||||||
|
.map(|(_, y)| *y)
|
||||||
|
.expect("应绘制控制面板");
|
||||||
|
assert!(
|
||||||
|
(qr_y - controls_y).abs() <= 8.0,
|
||||||
|
"二维码和控制区应从同一行开始,实际 qr={qr_y}, controls={controls_y}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// 接收页运行态(非专注模式)同样必须有防火墙入口。
|
/// 接收页运行态(非专注模式)同样必须有防火墙入口。
|
||||||
#[test]
|
#[test]
|
||||||
fn receive_running_page_renders_the_firewall_panel() {
|
fn receive_running_page_renders_the_firewall_panel() {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ gradle=(ROOT/'android/app/build.gradle.kts').read_text(); manifest=(ROOT/'androi
|
|||||||
wifi=(ROOT/'android/app/src/main/java/com/qft/optical/WifiConnector.kt').read_text(); upload=(ROOT/'android/app/src/main/java/com/qft/optical/UploadClient.kt').read_text()
|
wifi=(ROOT/'android/app/src/main/java/com/qft/optical/WifiConnector.kt').read_text(); upload=(ROOT/'android/app/src/main/java/com/qft/optical/UploadClient.kt').read_text()
|
||||||
download=(ROOT/'android/app/src/main/java/com/qft/optical/DownloadClient.kt').read_text()
|
download=(ROOT/'android/app/src/main/java/com/qft/optical/DownloadClient.kt').read_text()
|
||||||
main=(ROOT/'android/app/src/main/java/com/qft/optical/MainActivity.kt').read_text(); analyzer=(ROOT/'android/app/src/main/java/com/qft/optical/QrAnalyzer.kt').read_text()
|
main=(ROOT/'android/app/src/main/java/com/qft/optical/MainActivity.kt').read_text(); analyzer=(ROOT/'android/app/src/main/java/com/qft/optical/QrAnalyzer.kt').read_text()
|
||||||
|
queue=(ROOT/'android/app/src/main/java/com/qft/optical/TransferQueue.kt').read_text()
|
||||||
gray=(ROOT/'android/app/src/main/java/com/qft/optical/GrayFrame.kt').read_text(); protocol=(ROOT/'android/app/src/main/java/com/qft/optical/Protocol.kt').read_text(); base45=(ROOT/'android/app/src/main/java/com/qft/optical/Base45.kt').read_text(); overlay=(ROOT/'android/app/src/main/java/com/qft/optical/QrLockOverlay.kt').read_text(); security=(ROOT/'android/app/src/main/res/xml/network_security_config.xml').read_text()
|
gray=(ROOT/'android/app/src/main/java/com/qft/optical/GrayFrame.kt').read_text(); protocol=(ROOT/'android/app/src/main/java/com/qft/optical/Protocol.kt').read_text(); base45=(ROOT/'android/app/src/main/java/com/qft/optical/Base45.kt').read_text(); overlay=(ROOT/'android/app/src/main/java/com/qft/optical/QrLockOverlay.kt').read_text(); security=(ROOT/'android/app/src/main/res/xml/network_security_config.xml').read_text()
|
||||||
assert re.search(r'minSdk\s*=\s*24',gradle)
|
assert re.search(r'minSdk\s*=\s*24',gradle)
|
||||||
assert 'WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"' in manifest
|
assert 'WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"' in manifest
|
||||||
@@ -15,7 +16,7 @@ assert 'Build.VERSION.SDK_INT >= 29' in wifi and 'connectLegacy' in wifi and 'su
|
|||||||
assert 'MAX_WORKERS = 8' in upload and 'QFTDISC2:' in upload
|
assert 'MAX_WORKERS = 8' in upload and 'QFTDISC2:' in upload
|
||||||
assert 'MAX_WORKERS = 8' in download and 'bytes=$start-$end' in download and 'completionMapFile' in download
|
assert 'MAX_WORKERS = 8' in download and 'bytes=$start-$end' in download and 'completionMapFile' in download
|
||||||
assert 'requestNetwork(request, cb)' in wifi and 'delivered.set(false)' in wifi
|
assert 'requestNetwork(request, cb)' in wifi and 'delivered.set(false)' in wifi
|
||||||
assert 'val targetSize = Size(640, 480)' in main and 'Size(960, 540)' not in main
|
assert 'if (mode == ScannerMode.PAIR) Size(960, 720) else Size(640, 480)' in main and 'Size(960, 540)' not in main
|
||||||
assert 'Camera2Interop.Extender' in main and 'CONTROL_AE_TARGET_FPS_RANGE' in main and 'STRATEGY_KEEP_ONLY_LATEST' in main
|
assert 'Camera2Interop.Extender' in main and 'CONTROL_AE_TARGET_FPS_RANGE' in main and 'STRATEGY_KEEP_ONLY_LATEST' in main
|
||||||
assert '设备拒绝显式高帧率请求' in main and 'fallbackAnalysis' in main
|
assert '设备拒绝显式高帧率请求' in main and 'fallbackAnalysis' in main
|
||||||
assert 'OPTICAL_LOCKED' in analyzer and 'OPTICAL_MULTI' not in analyzer and 'QRCodeReader' in analyzer and 'MultiFormatReader' not in analyzer
|
assert 'OPTICAL_LOCKED' in analyzer and 'OPTICAL_MULTI' not in analyzer and 'QRCodeReader' in analyzer and 'MultiFormatReader' not in analyzer
|
||||||
@@ -24,7 +25,9 @@ assert 'GrayFrameBuffer' in gray and 'scratch = ByteArray(0)' in gray
|
|||||||
assert 'Base45.decode' in protocol and 'QFT2' in protocol and 'looksLikeBinaryFrame' not in protocol
|
assert 'Base45.decode' in protocol and 'QFT2' in protocol and 'looksLikeBinaryFrame' not in protocol
|
||||||
assert 'lockedCenterInView' in overlay and 'postInvalidateDelayed' in overlay and 'maybeRefocusLockedQr' in main
|
assert 'lockedCenterInView' in overlay and 'postInvalidateDelayed' in overlay and 'maybeRefocusLockedQr' in main
|
||||||
assert 'assembler.acceptText(code.text)' in main and 'acceptBinary' not in main
|
assert 'assembler.acceptText(code.text)' in main and 'acceptBinary' not in main
|
||||||
|
assert 'showFileSelection' not in main and 'pickFiles.launch(arrayOf("*/*"))' in main
|
||||||
|
assert 'installFileQueueDrag' in main and 'uploadRunning' in main and 'moveQueueItem' in queue
|
||||||
assert 'BB8' in base45 or 'ALPHABET' in base45
|
assert 'BB8' in base45 or 'ALPHABET' in base45
|
||||||
all_kotlin='\n'.join(path.read_text() for path in (ROOT/'android/app/src/main/java/com/qft/optical').glob('*.kt'))
|
all_kotlin='\n'.join(path.read_text() for path in (ROOT/'android/app/src/main/java/com/qft/optical').glob('*.kt'))
|
||||||
assert 'java.util.Base64' not in all_kotlin
|
assert 'java.util.Base64' not in all_kotlin
|
||||||
print('PASS Android static guards: API24+, 640x480 single-QR ROI, reusable luma buffer, QFT2/Base45 text parse, dynamic lock/refocus, Camera2 FPS request, legacy/new Wi-Fi compatibility')
|
print('PASS Android static guards: API24+, fast-pair/640x480 optical ROI, inline sortable upload queue, QFT2/Base45, dynamic lock/refocus, legacy/new Wi-Fi compatibility')
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ with tempfile.TemporaryDirectory() as td:
|
|||||||
import java.util.zip.CRC32
|
import java.util.zip.CRC32
|
||||||
fun b45e(data: ByteArray): String { val a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"; val o=StringBuilder(); var i=0; while(i+1<data.size){val v=(data[i].toInt() and 255)*256+(data[i+1].toInt() and 255);o.append(a[v%45]).append(a[(v/45)%45]).append(a[v/2025]);i+=2};if(i<data.size){val v=data[i].toInt() and 255;o.append(a[v%45]).append(a[v/45])};return o.toString() }
|
fun b45e(data: ByteArray): String { val a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"; val o=StringBuilder(); var i=0; while(i+1<data.size){val v=(data[i].toInt() and 255)*256+(data[i+1].toInt() and 255);o.append(a[v%45]).append(a[(v/45)%45]).append(a[v/2025]);i+=2};if(i<data.size){val v=data[i].toInt() and 255;o.append(a[v%45]).append(a[v/45])};return o.toString() }
|
||||||
fun fr(p:ByteArray):String { val b=ByteBuffer.allocate(24+p.size+4).order(ByteOrder.BIG_ENDIAN);b.put("QFT2".toByteArray()).put(2).put(2).putLong(7L).putInt(9).putInt(11).putShort(p.size.toShort()).put(p);val n=b.position();val c=CRC32().apply{update(b.array(),0,n)}.value;b.putInt(c.toInt());return "QFT2:"+b45e(b.array()) }
|
fun fr(p:ByteArray):String { val b=ByteBuffer.allocate(24+p.size+4).order(ByteOrder.BIG_ENDIAN);b.put("QFT2".toByteArray()).put(2).put(2).putLong(7L).putInt(9).putInt(11).putShort(p.size.toShort()).put(p);val n=b.position();val c=CRC32().apply{update(b.array(),0,n)}.value;b.putInt(c.toInt());return "QFT2:"+b45e(b.array()) }
|
||||||
fun main(){check(Base45.decode("BB8")!!.contentEquals("AB".toByteArray()));check(Base45.decode("%69 VD92EX0")!!.contentEquals("Hello!!".toByteArray()));val p="hello-qft2".toByteArray();val f=QftProtocol.parseText(fr(p))!!;check(f.kind==FrameKind.DATA&&f.sessionId==7L&&f.seq==9L&&f.payload.contentEquals(p));val c=LockRect(100,100,300,300).smoothToward(LockRect(140,130,340,340),.25f);check(c.left in 101..139);println("PASS Kotlin QFT2/Base45 protocol + ROI lock smoothing")}
|
fun main(){check(Base45.decode("BB8")!!.contentEquals("AB".toByteArray()));check(Base45.decode("%69 VD92EX0")!!.contentEquals("Hello!!".toByteArray()));val p="hello-qft2".toByteArray();val f=QftProtocol.parseText(fr(p))!!;check(f.kind==FrameKind.DATA&&f.sessionId==7L&&f.seq==9L&&f.payload.contentEquals(p));val c=LockRect(100,100,300,300).smoothToward(LockRect(140,130,340,340),.25f);check(c.left in 101..139);val q=mutableListOf("A","B","C");check(moveQueueItem(q,0,2));check(q==listOf("B","C","A"));println("PASS Kotlin QFT2/Base45 protocol + ROI lock + transfer queue")}
|
||||||
'''))
|
'''))
|
||||||
jar=td/'smoke.jar'
|
jar=td/'smoke.jar'
|
||||||
run([kotlinc, str(K/'Base45.kt'), str(K/'Base64Url.kt'), str(K/'Protocol.kt'), str(K/'LockRect.kt'), str(smoke), '-include-runtime', '-d', str(jar)])
|
run([kotlinc, str(K/'Base45.kt'), str(K/'Base64Url.kt'), str(K/'Protocol.kt'), str(K/'LockRect.kt'), str(K/'TransferQueue.kt'), str(smoke), '-include-runtime', '-d', str(jar)])
|
||||||
p=subprocess.run(['java','-jar',str(jar)],text=True,capture_output=True,env={**os.environ,'TERM':'xterm'},check=True)
|
p=subprocess.run(['java','-jar',str(jar)],text=True,capture_output=True,env={**os.environ,'TERM':'xterm'},check=True)
|
||||||
print(p.stdout.strip())
|
print(p.stdout.strip())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user