fix: adapt phone share QR to window size
This commit is contained in:
@@ -16,7 +16,7 @@ v0.4.16 提供两套互不依赖的传输方式:
|
|||||||
|
|
||||||
> v0.4.16 已完成协议、图像合成解码、ROI、双向并发传输、专用 Wi-Fi 快速发现、队列拖动稳定性和关键 Kotlin 源码测试。当前生成环境没有真实 Windows 显示器、Android 相机或 Wi‑Fi Direct 适配器,因此物理 30/45/60 FPS 和真实扫码配网仍需在你的设备上跑 `VERIFY_WINDOWS_HOST.ps1` 后做最终验收;详见 `TEST_REPORT.md`。
|
> v0.4.16 已完成协议、图像合成解码、ROI、双向并发传输、专用 Wi-Fi 快速发现、队列拖动稳定性和关键 Kotlin 源码测试。当前生成环境没有真实 Windows 显示器、Android 相机或 Wi‑Fi Direct 适配器,因此物理 30/45/60 FPS 和真实扫码配网仍需在你的设备上跑 `VERIFY_WINDOWS_HOST.ps1` 后做最终验收;详见 `TEST_REPORT.md`。
|
||||||
|
|
||||||
## v0.5.0-dev1:Android → Android 手机互传
|
## v0.5.0-dev2:Android → Android 手机互传
|
||||||
|
|
||||||
当前开发版新增 Android 手机之间的扫码直传闭环:
|
当前开发版新增 Android 手机之间的扫码直传闭环:
|
||||||
|
|
||||||
@@ -26,6 +26,7 @@ v0.4.16 提供两套互不依赖的传输方式:
|
|||||||
- 二维码只携带一次性会话和网络身份,文件队列通过会话认证后读取,避免多文件让二维码过密;
|
- 二维码只携带一次性会话和网络身份,文件队列通过会话认证后读取,避免多文件让二维码过密;
|
||||||
- 每个文件复用现有最高 8 路 HTTP Range、断点位图和 SHA-256 校验,按发送队列顺序保存到 `Downloads/QFT`;
|
- 每个文件复用现有最高 8 路 HTTP Range、断点位图和 SHA-256 校验,按发送队列顺序保存到 `Downloads/QFT`;
|
||||||
- 发送页面必须保持打开,返回首页会立即关闭发送服务和临时热点。
|
- 发送页面必须保持打开,返回首页会立即关闭发送服务和临时热点。
|
||||||
|
- 发送二维码按当前应用窗口的实际可用宽高动态生成并居中,手机、平板和分屏窗口都不会再被 `match_parent` 放大溢出。
|
||||||
|
|
||||||
此阶段只实现 Android → Android;Android ↔ iOS 尚未接入。
|
此阶段只实现 Android → Android;Android ↔ iOS 尚未接入。
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ android {
|
|||||||
applicationId = "com.qft.optical"
|
applicationId = "com.qft.optical"
|
||||||
minSdk = 24
|
minSdk = 24
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 24
|
versionCode = 25
|
||||||
versionName = "0.5.0-dev1"
|
versionName = "0.5.0-dev2"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -228,7 +228,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.5.0-dev1 · Android 7+ 到最新", 12f, MUTED))
|
root.addView(text("QFT v0.5.0-dev2 · Android 7+ 到最新", 12f, MUTED))
|
||||||
setContentView(ScrollView(this).apply { setBackgroundColor(BG); addView(root) })
|
setContentView(ScrollView(this).apply { setBackgroundColor(BG); addView(root) })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -993,17 +993,27 @@ class MainActivity : ComponentActivity() {
|
|||||||
phoneShareStatusText?.text = "无法生成配对二维码:${e.message}"
|
phoneShareStatusText?.text = "无法生成配对二维码:${e.message}"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val qr = PhoneQr.render(encoded, 720)
|
// Use the measured app content area. `resources.displayMetrics` is only
|
||||||
|
// a fallback for the short interval before the decor has completed a
|
||||||
|
// layout pass; using the physical display alone breaks tablets and
|
||||||
|
// split-screen windows because it ignores the actual app bounds.
|
||||||
|
val content = findViewById<View>(android.R.id.content)
|
||||||
|
val windowWidth = content?.width?.takeIf { it > 0 } ?: resources.displayMetrics.widthPixels
|
||||||
|
val windowHeight = content?.height?.takeIf { it > 0 } ?: resources.displayMetrics.heightPixels
|
||||||
|
val qrSide = phoneQrSidePx(windowWidth, windowHeight, resources.displayMetrics.density)
|
||||||
|
val qr = PhoneQr.render(encoded, qrSide)
|
||||||
val root = pageColumn()
|
val root = pageColumn()
|
||||||
root.addView(text("等待另一台 Android 扫码", 27f, Color.WHITE, true))
|
root.addView(text("等待另一台 Android 扫码", 27f, Color.WHITE, true))
|
||||||
root.addView(text("$receiverDeviceLabel · ${selectedFiles.size} 个文件", 15f, ACCENT))
|
root.addView(text("$receiverDeviceLabel · ${selectedFiles.size} 个文件", 15f, ACCENT))
|
||||||
root.addView(space(12))
|
root.addView(space(12))
|
||||||
root.addView(ImageView(this).apply {
|
root.addView(ImageView(this).apply {
|
||||||
setImageBitmap(qr)
|
setImageBitmap(qr)
|
||||||
adjustViewBounds = true
|
adjustViewBounds = false
|
||||||
|
scaleType = ImageView.ScaleType.CENTER
|
||||||
setBackgroundColor(Color.WHITE)
|
setBackgroundColor(Color.WHITE)
|
||||||
setPadding(dp(8), dp(8), dp(8), dp(8))
|
}, LinearLayout.LayoutParams(qrSide, qrSide).apply {
|
||||||
}, LinearLayout.LayoutParams(-1, -2))
|
gravity = Gravity.CENTER_HORIZONTAL
|
||||||
|
})
|
||||||
root.addView(space(12))
|
root.addView(space(12))
|
||||||
phoneShareStatusText = text(
|
phoneShareStatusText = text(
|
||||||
note ?: "QFT 临时网络已就绪;另一台手机扫码后会自动连接并开始接收。",
|
note ?: "QFT 临时网络已就绪;另一台手机扫码后会自动连接并开始接收。",
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.qft.optical
|
||||||
|
|
||||||
|
import kotlin.math.min
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Size a square pairing QR against the *current app window*, not a fixed phone
|
||||||
|
* resolution. The vertical reserve covers page padding, titles, connection
|
||||||
|
* details and the stop button, keeping the whole sender page visible on phones,
|
||||||
|
* tablets and split-window layouts.
|
||||||
|
*/
|
||||||
|
internal fun phoneQrSidePx(windowWidthPx: Int, windowHeightPx: Int, density: Float): Int {
|
||||||
|
val safeDensity = density.takeIf { it.isFinite() && it > 0f } ?: 1f
|
||||||
|
val horizontalPagePadding = (40f * safeDensity).roundToInt()
|
||||||
|
val nonQrVerticalUi = (300f * safeDensity).roundToInt()
|
||||||
|
val widthLimit = (windowWidthPx - horizontalPagePadding).coerceAtLeast(1)
|
||||||
|
val heightLimit = (windowHeightPx - nonQrVerticalUi).coerceAtLeast(1)
|
||||||
|
return min(widthLimit, heightLimit)
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.qft.optical
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class PhoneQrLayoutTest {
|
||||||
|
@Test
|
||||||
|
fun phoneUsesWidthWithoutOverflowingTheRemainingHeight() {
|
||||||
|
// 360 × 800 dp at 3× density: width is the limiting dimension.
|
||||||
|
assertEquals(960, phoneQrSidePx(1080, 2400, 3f))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun tabletQrDoesNotExpandToTheFullContentWidth() {
|
||||||
|
// 800 × 1280 dp portrait tablet at 2×: width limits the QR before overflow.
|
||||||
|
val side = phoneQrSidePx(1600, 2560, 2f)
|
||||||
|
assertEquals(1520, side)
|
||||||
|
assertTrue(side + 600 <= 2560)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shortOrSplitWindowPrioritizesNoOverflow() {
|
||||||
|
// 320 × 480 dp at 2×: height becomes the limiting dimension.
|
||||||
|
val side = phoneQrSidePx(640, 960, 2f)
|
||||||
|
assertEquals(360, side)
|
||||||
|
assertTrue(side <= 640)
|
||||||
|
assertTrue(side + 600 <= 960)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun invalidMetricsStillReturnASafePositiveSize() {
|
||||||
|
assertEquals(1, phoneQrSidePx(0, 0, Float.NaN))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# Android → Android 真机验收(v0.5.0-dev1)
|
# Android → Android 真机验收(v0.5.0-dev2)
|
||||||
|
|
||||||
## 构建约束
|
## 构建约束
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ cd android
|
|||||||
|
|
||||||
## 首轮验收
|
## 首轮验收
|
||||||
|
|
||||||
1. 两台 Android 安装同一个 `v0.5.0-dev1` APK。
|
1. 两台 Android 安装同一个 `v0.5.0-dev2` APK。
|
||||||
2. 发送手机进入“手机 → 手机”,选择至少两个文件并调整一次顺序。
|
2. 发送手机进入“手机 → 手机”,选择至少两个文件并调整一次顺序。
|
||||||
3. 点击“创建发送二维码”,允许附近 Wi-Fi/位置权限。
|
3. 点击“创建发送二维码”,允许附近 Wi-Fi/位置权限。
|
||||||
4. 接收手机进入“扫码直传”,扫描发送手机二维码并确认系统连接提示。
|
4. 接收手机进入“扫码直传”,扫描发送手机二维码并确认系统连接提示。
|
||||||
@@ -27,6 +27,12 @@ cd android
|
|||||||
- 手动停止发送端热点:接收端应报连接中断,而不是无限等待。
|
- 手动停止发送端热点:接收端应报连接中断,而不是无限等待。
|
||||||
- 传输中返回发送端首页:服务和临时热点应立即关闭。
|
- 传输中返回发送端首页:服务和临时热点应立即关闭。
|
||||||
|
|
||||||
|
## 二维码布局组合
|
||||||
|
|
||||||
|
- 普通手机:二维码、状态、网络信息和停止按钮应在首屏完整显示。
|
||||||
|
- 10–14 英寸平板:二维码按窗口宽高取较小限制,不应拉伸到全宽后挤出下方按钮。
|
||||||
|
- 分屏/小窗:重新进入发送二维码页后,应按当前应用窗口而非物理屏幕分辨率计算尺寸。
|
||||||
|
|
||||||
## 当前边界
|
## 当前边界
|
||||||
|
|
||||||
- 仅文件,不包含文件夹。
|
- 仅文件,不包含文件夹。
|
||||||
|
|||||||
+1
-1
@@ -99,7 +99,7 @@ The sender returns `206 Partial Content`, the matching `Content-Range`, and the
|
|||||||
|
|
||||||
For both direct-transfer directions, the Windows listener may accept connections non-blockingly for shutdown responsiveness, but each accepted file socket is switched to blocking I/O with explicit timeouts before reading or writing request bodies. This prevents `WSAEWOULDBLOCK (10035)` from turning an in-progress parallel transfer into an HTTP 500 failure.
|
For both direct-transfer directions, the Windows listener may accept connections non-blockingly for shutdown responsiveness, but each accepted file socket is switched to blocking I/O with explicit timeouts before reading or writing request bodies. This prevents `WSAEWOULDBLOCK (10035)` from turning an in-progress parallel transfer into an HTTP 500 failure.
|
||||||
|
|
||||||
## 6. Android → Android (`QFTPHONE2`, v0.5.0-dev1)
|
## 6. Android → Android (`QFTPHONE2`, v0.5.0-dev2)
|
||||||
|
|
||||||
The sender starts an authenticated local HTTP service and encodes only session,
|
The sender starts an authenticated local HTTP service and encodes only session,
|
||||||
port, sender identity and optional LocalOnlyHotspot credentials in the QR. The
|
port, sender identity and optional LocalOnlyHotspot credentials in the QR. The
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ assert 'QFTPHONE2:' in (ROOT/'android/app/src/main/java/com/qft/optical/PairingP
|
|||||||
assert 'startLocalOnlyHotspot' in phone_hotspot and 'PhoneShareServer.create' in main
|
assert 'startLocalOnlyHotspot' in phone_hotspot and 'PhoneShareServer.create' in main
|
||||||
assert '/qft/phone/manifest' in phone_server and '/qft/phone/download/' in phone_server
|
assert '/qft/phone/manifest' in phone_server and '/qft/phone/download/' in phone_server
|
||||||
assert 'startDownloadsFromPhone' in main and 'downloadPath = item.path' in main
|
assert 'startDownloadsFromPhone' in main and 'downloadPath = item.path' in main
|
||||||
|
assert 'phoneQrSidePx(windowWidth, windowHeight' in main
|
||||||
|
assert 'LinearLayout.LayoutParams(qrSide, qrSide)' in main
|
||||||
|
assert 'PhoneQr.render(encoded, 720)' 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 '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
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ ROOT = Path(__file__).resolve().parents[1]
|
|||||||
pairing = (ROOT / "android/app/src/main/java/com/qft/optical/PairingProtocol.kt").read_text()
|
pairing = (ROOT / "android/app/src/main/java/com/qft/optical/PairingProtocol.kt").read_text()
|
||||||
server = (ROOT / "android/app/src/main/java/com/qft/optical/PhoneShareServer.kt").read_text()
|
server = (ROOT / "android/app/src/main/java/com/qft/optical/PhoneShareServer.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()
|
||||||
|
layout = (ROOT / "android/app/src/main/java/com/qft/optical/PhoneQrLayout.kt").read_text()
|
||||||
|
|
||||||
session = base64.urlsafe_b64encode(bytes(range(24))).decode().rstrip("=")
|
session = base64.urlsafe_b64encode(bytes(range(24))).decode().rstrip("=")
|
||||||
payload = {
|
payload = {
|
||||||
@@ -47,4 +48,7 @@ assert 'headers["x-qft-token"] != session' in server
|
|||||||
assert 'Range: bytes=<start>-<end>' not in server # implementation, not documentation placeholder
|
assert 'Range: bytes=<start>-<end>' not in server # implementation, not documentation placeholder
|
||||||
assert 'baseUrl + pairing.downloadPath' in download
|
assert 'baseUrl + pairing.downloadPath' in download
|
||||||
assert 'digest(downloadPath.toByteArray' in download
|
assert 'digest(downloadPath.toByteArray' in download
|
||||||
|
assert 'windowWidthPx - horizontalPagePadding' in layout
|
||||||
|
assert 'windowHeightPx - nonQrVerticalUi' in layout
|
||||||
|
assert 'min(widthLimit, heightLimit)' in layout
|
||||||
print(f"PASS Android phone share: compact QR={len(qr)} chars, authenticated fixed manifest paths, per-file partial isolation, SHA-256={sha[:12]}…")
|
print(f"PASS Android phone share: compact QR={len(qr)} chars, authenticated fixed manifest paths, per-file partial isolation, SHA-256={sha[:12]}…")
|
||||||
|
|||||||
Reference in New Issue
Block a user