diff --git a/CHANGELOG.md b/CHANGELOG.md index 4288b68..1a3668b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # CodePocket 更新日志 +## [0.1.1] — 2026-11-25 + +移动端布局收口版本。不改 Python 引擎和 Git 地基,只把手机、横屏、平板和字体放大下的摆放做明确,避免继续靠“看起来差不多”。 + +### 响应式布局 + +- 新增 `EditorLayoutPolicy`:600dp 以上或 520dp 以上的矮横屏切为左右两栏;普通手机竖屏仍上下排布,给代码留高度。 +- 顶栏在宽度小于 480dp 或字体缩放达到 1.3 倍时进入紧凑模式:只保留菜单、保存、运行/停止;预览、命令面板、调试收进“更多”下拉菜单,44dp 触控目标不再互相挤压。 +- 抽屉宽度按屏幕宽度计算(200–272dp),窄屏不再让侧栏吃掉主界面。 +- 快捷动作从固定四列改为窄屏/大字号三列,避免“项目/导入/设置”等两字标签被压成省略号。 +- 宽屏顶栏才显示语言名和“仅编辑”,小屏只留文件名;文件名仍单行省略。 + +### 测试 + +- `EditorLayoutPolicyTest` 覆盖两栏阈值、紧凑顶栏阈值、抽屉宽度和动作列数。 +- `EditorTopBarTest` 用 Compose/Robolectric 验证紧凑顶栏把预览收进“更多”、宽屏顶栏保留预览入口。 +- 全量 JVM/Robolectric:179 tests / 0 failures / 0 errors / 0 skipped。 + +### 边界 + +- 本版仍无 ARM64 真机验收;Robolectric 只能证明节点存在和交互路径,不等于 ROM 上的最终手感。 +- 不做 Gradle/Java/Kotlin 工程构建、完整 LSP、原生 wheel ABI,边界与 0.1.0 相同。 + ## [0.1.0] — 2026-11-25 跨小数位的“可信移动 IDE”版本。重点不是再加面板,而是把 Python 引擎、Git 审阅、包安装和质量门禁补成能长期使用的地基。 diff --git a/README.md b/README.md index b4acbe7..bd28248 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,12 @@ Three runtimes are bundled inside the APK: a natively cross-compiled CPython 3.1 - **Python pdb debugger**: real stdlib `pdb`; breakpoints, next/step/continue, `p locals()`, stack, quit; quick-action bar in output panel - **Offline by design**: no language server process, no model download, hard caps at 300 `.py` files / 512KB per file +### Mobile layout pass (0.1.1) +- **Compact toolbar**: below 480dp or at 1.3× font scale, the top bar keeps only menu, save and run/stop; preview, command palette and debug move into a **更多** menu so 44dp touch targets stop squeezing the filename +- **Width-based two-pane**: 600dp tablets and short landscape phones (≥520dp wide) place output beside the editor; normal portrait phones keep the vertical stack so code height is not sacrificed +- **Adaptive drawer**: sidebar width is clamped to 200–272dp by screen width; quick actions switch from four to three columns on narrow screens or large fonts +- **Tests**: `EditorLayoutPolicyTest` for breakpoints, `EditorTopBarTest` for compact/wide Compose behavior; 179 JVM/Robolectric tests all green + ### Trusted mobile IDE foundation (0.1.0) - **Python engine isolation**: Python runs in `android:process=":engine"`; the main process holds only a Messenger proxy. The output panel's **重启引擎** action kills and rebinds only the engine process, preserving unsaved editor buffers, Git and terminal state - **Git review loop**: per-file stage / unstage, stage-all, commit-staged-only, and a diff dialog (working tree vs index, untracked files as all-added); 200KB output cap with bounded streaming so a 100MB log does not OOM diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0d509bc..1ba24a5 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -24,8 +24,8 @@ android { applicationId = "com.devterminal" minSdk = libs.versions.minSdk.get().toInt() targetSdk = libs.versions.targetSdk.get().toInt() - versionCode = 40 - versionName = "0.1.0" + versionCode = 41 + versionName = "0.1.1" vectorDrawables { useSupportLibrary = true } // 原生 CPython 引擎:同时打 arm64 与 x86_64(后者用于模拟器/ChromeOS) ndk { abiFilters += listOf("arm64-v8a", "x86_64") } diff --git a/app/src/main/java/com/devterminal/ui/EditorLayoutPolicy.kt b/app/src/main/java/com/devterminal/ui/EditorLayoutPolicy.kt new file mode 100644 index 0000000..9d9a684 --- /dev/null +++ b/app/src/main/java/com/devterminal/ui/EditorLayoutPolicy.kt @@ -0,0 +1,41 @@ +package com.devterminal.ui + +/** + * 主界面的宽度/字号断点。 + * + * 这些数字只负责「布局决策」,不参与绘制,因此可以单测。 + * 取舍: + * - 600dp 是 Material 的 medium 起点;到了它,编辑器与输出面板并排才不会把代码压成一条。 + * - 480dp 是普通手机与小平板的分界;低于它,顶栏必须收掉次要动作。 + * - 1.3 倍字体是 200% 字体设置前的预警线;再放大时,图标和标题会先互相挤。 + */ +object EditorLayoutPolicy { + const val TWO_PANE_MIN_WIDTH_DP = 600 + const val COMPACT_TOOLBAR_MAX_WIDTH_DP = 480 + const val COMPACT_TOOLBAR_MIN_FONT_SCALE = 1.3f + const val DRAWER_MAX_WIDTH_DP = 272 + const val DRAWER_MIN_WIDTH_DP = 200 + private const val DRAWER_WIDTH_FRACTION = 0.86f + + /** + * 宽屏/平板用左右两栏;普通手机竖屏仍保持上下结构,给代码留高度。 + * 520dp 以上的横屏手机即使没到 600dp,也横向摆放:这时高度通常只有 320dp, + * 上下叠放会把编辑器压没。 + */ + fun useTwoPane(widthDp: Float, heightDp: Float): Boolean = + widthDp >= TWO_PANE_MIN_WIDTH_DP || (widthDp > heightDp && widthDp >= 520f) + + /** 小屏或大字号时,顶栏只保留主操作,其余进入「更多」。 */ + fun useCompactToolbar(widthDp: Int, fontScale: Float): Boolean = + widthDp < COMPACT_TOOLBAR_MAX_WIDTH_DP || fontScale >= COMPACT_TOOLBAR_MIN_FONT_SCALE + + /** 抽屉最宽 272dp,但窄屏上必须给主界面留出至少 14% 的可见区域。 */ + fun drawerWidthDp(widthDp: Int): Int { + val fraction = (widthDp * DRAWER_WIDTH_FRACTION).toInt() + return maxOf(DRAWER_MIN_WIDTH_DP, minOf(DRAWER_MAX_WIDTH_DP, fraction)) + } + + /** 快捷动作在窄屏/大字号下改成三列,避免四列文字被压成省略号。 */ + fun drawerColumns(widthDp: Int, fontScale: Float): Int = + if (widthDp < 480 || fontScale >= 1.5f) 3 else 4 +} diff --git a/app/src/main/java/com/devterminal/ui/EditorScreen.kt b/app/src/main/java/com/devterminal/ui/EditorScreen.kt index eced41a..d2f8d55 100644 --- a/app/src/main/java/com/devterminal/ui/EditorScreen.kt +++ b/app/src/main/java/com/devterminal/ui/EditorScreen.kt @@ -2,7 +2,6 @@ package com.devterminal.ui import android.Manifest import android.content.Intent -import android.content.res.Configuration import android.os.Build import androidx.activity.compose.BackHandler import androidx.activity.compose.rememberLauncherForActivityResult @@ -93,6 +92,7 @@ import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.draw.clip import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow @@ -186,6 +186,38 @@ private val scrollToLineSaver = run { ) } +private data class DrawerActionItem( + val icon: androidx.compose.ui.graphics.vector.ImageVector, + val label: String, + val enabled: Boolean = true, + val accent: androidx.compose.ui.graphics.Color? = null, + val onClick: () -> Unit, +) + +@Composable +private fun DrawerActionGrid(actions: List, columns: Int) { + val cs = MaterialTheme.colorScheme + Column(verticalArrangement = Arrangement.spacedBy(Dimens.sm)) { + actions.chunked(columns).forEach { row -> + Row(horizontalArrangement = Arrangement.spacedBy(Dimens.sm)) { + row.forEach { item -> + ActionTile( + icon = item.icon, + label = item.label, + onClick = item.onClick, + modifier = Modifier.weight(1f), + enabled = item.enabled, + accent = item.accent ?: cs.primary, + ) + } + repeat(columns - row.size) { + Spacer(Modifier.weight(1f)) + } + } + } + } +} + @OptIn(ExperimentalMaterial3Api::class) @Composable fun EditorScreen(vm: EditorViewModel) { @@ -357,11 +389,16 @@ fun EditorScreen(vm: EditorViewModel) { return } + val config = LocalConfiguration.current + val fontScale = LocalDensity.current.fontScale + val drawerWidth = EditorLayoutPolicy.drawerWidthDp(config.screenWidthDp).dp + val drawerColumns = EditorLayoutPolicy.drawerColumns(config.screenWidthDp, fontScale) + ModalNavigationDrawer( drawerState = drawerState, drawerContent = { ModalDrawerSheet( - modifier = Modifier.width(272.dp), + modifier = Modifier.width(drawerWidth), drawerContainerColor = cs.surface ) { Column(Modifier.fillMaxHeight()) { @@ -416,46 +453,42 @@ fun EditorScreen(vm: EditorViewModel) { ) { SectionLabel("快捷动作") Spacer(Modifier.height(Dimens.sm)) - Row(horizontalArrangement = Arrangement.spacedBy(Dimens.sm)) { - ActionTile(Icons.Outlined.Folder, "项目", - onClick = { overlay = Overlay.SwitchProject }, - modifier = Modifier.weight(1f)) - ActionTile(Icons.Filled.FileDownload, "导入", - onClick = { importLauncher.launch(arrayOf("*/*")) }, - modifier = Modifier.weight(1f)) - ActionTile(Icons.Filled.FileUpload, "导出", - onClick = { exportLauncher.launch(vm.suggestedExportName()) }, - enabled = ui.currentFile != null, - modifier = Modifier.weight(1f)) - } - Spacer(Modifier.height(Dimens.sm)) - Row(horizontalArrangement = Arrangement.spacedBy(Dimens.sm)) { - ActionTile(Icons.Filled.AccountTree, "Git", - onClick = { overlay = Overlay.Git; vm.refreshGitStatus() }, - modifier = Modifier.weight(1f)) - ActionTile(Icons.Filled.AutoAwesome, "AI", - onClick = { overlay = Overlay.Ai }, - accent = cs.secondary, - modifier = Modifier.weight(1f)) - ActionTile(Icons.Filled.Search, "搜索", - onClick = { overlay = Overlay.GlobalSearch }, - modifier = Modifier.weight(1f)) - } - Spacer(Modifier.height(Dimens.sm)) - Row(horizontalArrangement = Arrangement.spacedBy(Dimens.sm)) { - ActionTile(Icons.Outlined.HealthAndSafety, "自检", - onClick = { overlay = Overlay.Diagnostics }, - modifier = Modifier.weight(1f)) - ActionTile(Icons.Filled.Settings, "设置", - onClick = { overlay = Overlay.Settings }, - modifier = Modifier.weight(1f)) - ActionTile(Icons.Outlined.LibraryBooks, "指南", - onClick = { overlay = Overlay.Onboarding }, - modifier = Modifier.weight(1f)) - ActionTile(Icons.Outlined.Info, "关于", - onClick = { overlay = Overlay.About }, - modifier = Modifier.weight(1f)) - } + DrawerActionGrid( + actions = listOf( + DrawerActionItem(Icons.Outlined.Folder, "项目") { + overlay = Overlay.SwitchProject + }, + DrawerActionItem(Icons.Filled.FileDownload, "导入") { + importLauncher.launch(arrayOf("*/*")) + }, + DrawerActionItem(Icons.Filled.FileUpload, "导出", enabled = ui.currentFile != null) { + exportLauncher.launch(vm.suggestedExportName()) + }, + DrawerActionItem(Icons.Filled.AccountTree, "Git") { + overlay = Overlay.Git + vm.refreshGitStatus() + }, + DrawerActionItem(Icons.Filled.AutoAwesome, "AI", accent = cs.secondary) { + overlay = Overlay.Ai + }, + DrawerActionItem(Icons.Filled.Search, "搜索") { + overlay = Overlay.GlobalSearch + }, + DrawerActionItem(Icons.Outlined.HealthAndSafety, "自检") { + overlay = Overlay.Diagnostics + }, + DrawerActionItem(Icons.Filled.Settings, "设置") { + overlay = Overlay.Settings + }, + DrawerActionItem(Icons.Outlined.LibraryBooks, "指南") { + overlay = Overlay.Onboarding + }, + DrawerActionItem(Icons.Outlined.Info, "关于") { + overlay = Overlay.About + }, + ), + columns = drawerColumns, + ) } } } @@ -463,99 +496,26 @@ fun EditorScreen(vm: EditorViewModel) { ) { Scaffold( topBar = { - TopAppBar( - title = { - Row(verticalAlignment = Alignment.CenterVertically) { - MonoText( - ui.currentFile?.name ?: "未打开文件", - color = if (ui.currentFile != null) cs.onSurface else cs.faint, - fontSize = 13, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - modifier = Modifier.weight(1f, fill = false) - ) - if (ui.dirty) { - Spacer(Modifier.width(6.dp)) - Box( - Modifier - .size(6.dp) - .background(cs.secondary, androidx.compose.foundation.shape.CircleShape) - ) - } - if (ui.currentFile != null) { - Spacer(Modifier.width(8.dp)) - Text( - currentSpec.displayName, - style = MaterialTheme.typography.labelSmall, - color = cs.muted, - maxLines = 1, - overflow = TextOverflow.Ellipsis - ) - if (!currentSpec.isRunnable) { - Spacer(Modifier.width(4.dp)) - Text( - "仅编辑", - style = MaterialTheme.typography.labelSmall, - color = cs.faint, - maxLines = 1 - ) - } - } - } - }, - navigationIcon = { - IconButton(onClick = { scope.launch { drawerState.open() } }) { - Icon(Icons.Outlined.Menu, "打开文件树", tint = cs.muted) - } - }, - actions = { - // 预览开关:只有 Markdown / HTML 文件出现 - if (vm.isPreviewable(ui.currentFile)) { - QuietIconButton( - Icons.Outlined.Preview, "实时预览", - onClick = { vm.togglePreview() }, - tint = if (ui.previewVisible) cs.primary else cs.muted - ) - } - // 命令面板:其余动作的归处,保持顶栏清爽 - QuietIconButton( - Icons.Outlined.Terminal, "命令面板", - onClick = { overlay = Overlay.Palette } - ) - if (ui.dirty) { - QuietIconButton( - Icons.Filled.Save, "保存", - onClick = { vm.save() }, tint = cs.primary - ) - } - if (ui.running) { - QuietIconButton( - Icons.Filled.Stop, "停止", - onClick = { vm.stopRun() }, tint = cs.error - ) - } else { - val canRun = vm.canRun(ui.currentFile) - if (canRun && ui.currentFile?.extension.equals("py", ignoreCase = true)) { - QuietIconButton( - Icons.Outlined.BugReport, "调试当前文件", - onClick = { vm.debugCurrent() }, - tint = cs.muted, - size = 20.dp - ) - } - QuietIconButton( - Icons.Filled.PlayArrow, "运行", - onClick = { vm.runCurrent() }, - enabled = canRun, - tint = if (canRun) cs.primary else cs.faint, - size = 24.dp - ) - } - }, - colors = TopAppBarDefaults.topAppBarColors( - containerColor = cs.surface, - scrolledContainerColor = cs.surface - ) + val config = LocalConfiguration.current + val fontScale = LocalDensity.current.fontScale + EditorTopBar( + fileName = ui.currentFile?.name, + dirty = ui.dirty, + languageLabel = currentSpec.displayName, + isRunnable = currentSpec.isRunnable, + canRun = vm.canRun(ui.currentFile), + isPython = ui.currentFile?.extension.equals("py", ignoreCase = true), + previewable = vm.isPreviewable(ui.currentFile), + previewVisible = ui.previewVisible, + running = ui.running, + compact = EditorLayoutPolicy.useCompactToolbar(config.screenWidthDp, fontScale), + onOpenDrawer = { scope.launch { drawerState.open() } }, + onSave = vm::save, + onStop = vm::stopRun, + onRun = vm::runCurrent, + onDebug = vm::debugCurrent, + onPalette = { overlay = Overlay.Palette }, + onPreview = vm::togglePreview, ) }, bottomBar = { @@ -587,13 +547,12 @@ fun EditorScreen(vm: EditorViewModel) { } BoxWithConstraints(Modifier.padding(padding).fillMaxSize()) { val availableHeight = maxHeight.value - // ---- 横竖屏共用同一份内容、只是摆放不同 ---- + // ---- 宽屏用两栏,窄屏保持上下结构 ---- // 内容抽成局部 Composable(捕获 ui/vm 等闭包变量),避免两份拷贝日后走样。 - // 横屏下编辑器与输出面板左右分栏:横屏最缺的是纵向空间, - // 继续上下排布会把编辑器挤到看不见代码(设计稿 grid 方案已验证过两栏收益)。 - // 不能用内容区高度判断横竖屏:键盘弹起会让可用高度骤减, - // 竖屏手机可能被误判成横屏并突然变成左右分栏。这里以系统方向为准。 - val isLandscape = LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE + // 600dp 以上(横屏手机、平板竖屏)把输出面板放到右侧:横向有余量时, + // 上下叠放反而会把代码挤成一条。窄屏不按方向强分栏,给编辑器留高度。 + // 用内容区宽度而不是 orientation,避免键盘弹起/分屏把方向判断带偏。 + val useTwoPane = EditorLayoutPolicy.useTwoPane(maxWidth.value, maxHeight.value) // 只在渲染时夹取;键盘收起后自动恢复用户偏好高度。 val visibleOutputHeight = LayoutMetrics.visibleOutputHeight( @@ -745,7 +704,7 @@ fun EditorScreen(vm: EditorViewModel) { ) } - if (isLandscape) { + if (useTwoPane) { Column(Modifier.fillMaxSize()) { envBanner() Row(Modifier.fillMaxWidth().weight(1f)) { diff --git a/app/src/main/java/com/devterminal/ui/EditorTopBar.kt b/app/src/main/java/com/devterminal/ui/EditorTopBar.kt new file mode 100644 index 0000000..7191eda --- /dev/null +++ b/app/src/main/java/com/devterminal/ui/EditorTopBar.kt @@ -0,0 +1,206 @@ +package com.devterminal.ui + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.MoreVert +import androidx.compose.material.icons.filled.PlayArrow +import androidx.compose.material.icons.filled.Save +import androidx.compose.material.icons.filled.Stop +import androidx.compose.material.icons.outlined.BugReport +import androidx.compose.material.icons.outlined.Menu +import androidx.compose.material.icons.outlined.Preview +import androidx.compose.material.icons.outlined.Terminal +import androidx.compose.material3.DropdownMenu +import androidx.compose.material3.DropdownMenuItem +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import com.devterminal.ui.components.MonoText +import com.devterminal.ui.components.QuietIconButton +import com.devterminal.ui.theme.faint +import com.devterminal.ui.theme.muted + +/** + * 主界面顶栏。 + * + * 普通手机上它是「菜单 + 文件名 + 运行」的窄条;宽屏上才展开预览、命令面板、调试。 + * 小屏或大字号时把次要动作收进「更多」,避免 44dp 触控目标在 360dp 宽的手机上 + * 把标题挤成一条省略号。纯展示 + 回调,方便在 Robolectric 里单独验证两种形态。 + */ +@OptIn(ExperimentalMaterial3Api::class) +@Composable +internal fun EditorTopBar( + fileName: String?, + dirty: Boolean, + languageLabel: String, + isRunnable: Boolean, + canRun: Boolean, + isPython: Boolean, + previewable: Boolean, + previewVisible: Boolean, + running: Boolean, + compact: Boolean, + onOpenDrawer: () -> Unit, + onSave: () -> Unit, + onStop: () -> Unit, + onRun: () -> Unit, + onDebug: () -> Unit, + onPalette: () -> Unit, + onPreview: () -> Unit, +) { + val cs = MaterialTheme.colorScheme + var moreExpanded by remember { mutableStateOf(false) } + + TopAppBar( + title = { + Row(verticalAlignment = Alignment.CenterVertically) { + MonoText( + fileName ?: "未打开文件", + color = if (fileName != null) cs.onSurface else cs.faint, + fontSize = 13, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = Modifier.weight(1f, fill = false) + ) + if (dirty) { + Spacer(Modifier.width(6.dp)) + Box( + Modifier + .size(6.dp) + .background(cs.secondary, CircleShape) + ) + } + // 小屏只留文件名:语言名和「仅编辑」在 320dp 宽、200% 字体下最先被挤掉。 + if (!compact && fileName != null) { + Spacer(Modifier.width(8.dp)) + Text( + languageLabel, + style = MaterialTheme.typography.labelSmall, + color = cs.muted, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + if (!isRunnable) { + Spacer(Modifier.width(4.dp)) + Text( + "仅编辑", + style = MaterialTheme.typography.labelSmall, + color = cs.faint, + maxLines = 1 + ) + } + } + } + }, + navigationIcon = { + IconButton(onClick = onOpenDrawer) { + Icon(Icons.Outlined.Menu, "打开文件树", tint = cs.muted) + } + }, + actions = { + if (!compact && previewable) { + QuietIconButton( + Icons.Outlined.Preview, "实时预览", + onClick = onPreview, + tint = if (previewVisible) cs.primary else cs.muted + ) + } + if (!compact) { + QuietIconButton( + Icons.Outlined.Terminal, "命令面板", + onClick = onPalette + ) + } + if (dirty) { + QuietIconButton( + Icons.Filled.Save, "保存", + onClick = onSave, tint = cs.primary + ) + } + if (!compact && canRun && isPython) { + QuietIconButton( + Icons.Outlined.BugReport, "调试当前文件", + onClick = onDebug, + tint = cs.muted, + size = 20.dp + ) + } + if (running) { + QuietIconButton( + Icons.Filled.Stop, "停止", + onClick = onStop, tint = cs.error + ) + } else { + QuietIconButton( + Icons.Filled.PlayArrow, "运行", + onClick = onRun, + enabled = canRun, + tint = if (canRun) cs.primary else cs.faint, + size = 24.dp + ) + } + if (compact) { + Box { + QuietIconButton( + Icons.Filled.MoreVert, "更多操作", + onClick = { moreExpanded = true }, + tint = cs.muted + ) + DropdownMenu( + expanded = moreExpanded, + onDismissRequest = { moreExpanded = false } + ) { + if (previewable) { + DropdownMenuItem( + text = { Text(if (previewVisible) "关闭实时预览" else "实时预览") }, + onClick = { + moreExpanded = false + onPreview() + } + ) + } + DropdownMenuItem( + text = { Text("命令面板") }, + onClick = { + moreExpanded = false + onPalette() + } + ) + if (canRun && isPython) { + DropdownMenuItem( + text = { Text("调试当前文件") }, + onClick = { + moreExpanded = false + onDebug() + } + ) + } + } + } + } + }, + colors = TopAppBarDefaults.topAppBarColors( + containerColor = cs.surface, + scrolledContainerColor = cs.surface + ) + ) +} diff --git a/app/src/test/java/com/devterminal/ui/EditorLayoutPolicyTest.kt b/app/src/test/java/com/devterminal/ui/EditorLayoutPolicyTest.kt new file mode 100644 index 0000000..d8b0501 --- /dev/null +++ b/app/src/test/java/com/devterminal/ui/EditorLayoutPolicyTest.kt @@ -0,0 +1,51 @@ +package com.devterminal.ui + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class EditorLayoutPolicyTest { + + @Test + fun `窄屏手机保持上下布局`() { + assertFalse(EditorLayoutPolicy.useTwoPane(360f, 640f)) + assertFalse(EditorLayoutPolicy.useTwoPane(599f, 720f)) + } + + @Test + fun `六百 dp 起切换为两栏`() { + assertTrue(EditorLayoutPolicy.useTwoPane(600f, 800f)) + assertTrue(EditorLayoutPolicy.useTwoPane(840f, 600f)) + } + + @Test + fun `矮横屏也能两栏`() { + assertTrue(EditorLayoutPolicy.useTwoPane(568f, 320f)) + assertTrue(EditorLayoutPolicy.useTwoPane(640f, 360f)) + assertFalse(EditorLayoutPolicy.useTwoPane(540f, 720f)) + } + + @Test + fun `小屏或大字号才收顶栏`() { + assertTrue(EditorLayoutPolicy.useCompactToolbar(360, 1f)) + assertFalse(EditorLayoutPolicy.useCompactToolbar(480, 1f)) + assertTrue(EditorLayoutPolicy.useCompactToolbar(840, 1.5f)) + assertFalse(EditorLayoutPolicy.useCompactToolbar(840, 1f)) + } + + @Test + fun `抽屉不会吃掉主界面`() { + assertEquals(272, EditorLayoutPolicy.drawerWidthDp(360)) + assertEquals(272, EditorLayoutPolicy.drawerWidthDp(840)) + assertEquals(240, EditorLayoutPolicy.drawerWidthDp(280)) + assertEquals(200, EditorLayoutPolicy.drawerWidthDp(220)) + } + + @Test + fun `快捷动作在大字号下减列`() { + assertEquals(4, EditorLayoutPolicy.drawerColumns(600, 1f)) + assertEquals(3, EditorLayoutPolicy.drawerColumns(360, 1f)) + assertEquals(3, EditorLayoutPolicy.drawerColumns(600, 2f)) + } +} diff --git a/app/src/test/java/com/devterminal/ui/EditorTopBarTest.kt b/app/src/test/java/com/devterminal/ui/EditorTopBarTest.kt new file mode 100644 index 0000000..39ea5e4 --- /dev/null +++ b/app/src/test/java/com/devterminal/ui/EditorTopBarTest.kt @@ -0,0 +1,64 @@ +package com.devterminal.ui + +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithContentDescription +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import com.devterminal.ui.theme.CodePocketTheme +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [34], qualifiers = "w360dp-h640dp-xhdpi") +class EditorTopBarTest { + + @get:Rule + val compose = createComposeRule() + + private fun topBar(compact: Boolean) { + compose.setContent { + CodePocketTheme { + EditorTopBar( + fileName = "main.py", + dirty = false, + languageLabel = "Python", + isRunnable = true, + canRun = true, + isPython = true, + previewable = true, + previewVisible = false, + running = false, + compact = compact, + onOpenDrawer = {}, + onSave = {}, + onStop = {}, + onRun = {}, + onDebug = {}, + onPalette = {}, + onPreview = {}, + ) + } + } + } + + @Test + fun `紧凑顶栏把预览收进更多`() { + topBar(compact = true) + compose.onNodeWithContentDescription("更多操作").assertIsDisplayed() + compose.onNodeWithContentDescription("实时预览").assertDoesNotExist() + compose.onNodeWithContentDescription("更多操作").performClick() + compose.onNodeWithText("实时预览").assertIsDisplayed() + compose.onNodeWithText("命令面板").assertIsDisplayed() + } + + @Test + fun `宽屏顶栏保留预览入口`() { + topBar(compact = false) + compose.onNodeWithContentDescription("实时预览").assertIsDisplayed() + compose.onNodeWithContentDescription("更多操作").assertDoesNotExist() + } +} diff --git a/docs/RELEASE_NOTES_0.1.1.md b/docs/RELEASE_NOTES_0.1.1.md new file mode 100644 index 0000000..dfd200e --- /dev/null +++ b/docs/RELEASE_NOTES_0.1.1.md @@ -0,0 +1,27 @@ +# CodePocket 0.1.1 — 移动端布局收口 + +**版本号**:0.1.1(versionCode 41) +**发布日期**:2026-11-25 +**定位**:0.1.0 之后的第一次小步迭代。不改 Python 引擎、Git 和包安装地基,只把手机、横屏、平板、字体放大下的布局做明确。 + +## 这一版改了什么 + +- **紧凑顶栏**:宽度小于 480dp 或字体缩放 ≥1.3 倍时,顶栏只保留菜单、保存、运行/停止;预览、命令面板、调试收进「更多」下拉菜单。44dp 触控目标不再把文件名挤成一条省略号。 +- **按宽度分栏**:600dp 以上,或 520dp 以上的矮横屏,编辑器与输出面板左右分栏;普通手机竖屏仍上下排布,给代码留高度。 +- **抽屉收窄**:侧栏宽度按屏幕宽度夹在 200–272dp;窄屏上不会吃掉主界面。 +- **快捷动作换列**:窄屏/大字号从四列改成三列,避免两字标签被压成省略号。 +- **小屏标题减法**:宽屏才显示语言名和「仅编辑」;小屏只保留文件名,仍单行省略。 + +## 质量门禁 + +- JVM/Robolectric:179 tests / 0 failures / 0 errors / 0 skipped。 +- 新增 `EditorLayoutPolicyTest`、`EditorTopBarTest`。 +- `lintRelease`:0 Error;警告为非阻断项。 +- release APK:24,336,988 B,双 ABI、121 个 `.so` 全部 16KB 对齐、正式证书 SHA-256 `1b02135746d1426d7beda47e706fdb2c77a7145ea41e0f7e14addb191b87fac5`。 +- release SHA-256:`5339e11690787c4b7bc9edca5fcf285103166bc6eaf41569014785dc783a6d4e`;debug `43,445,946 B` / `80d64d7c205088658956e417e87de7842535eb1bf7aebe44b3893378b41baad8`。 + +## 明确边界 + +- **仍无 ARM64 真机验收**:Robolectric 只能证明节点存在与交互路径,不等于各 ROM 上的最终手感;本版不生成假截图。 +- 不做 Gradle/Java/Kotlin 工程构建、完整 LSP、原生 wheel ABI;边界与 0.1.0 相同。 +- 这不是“全部功能补齐”的版本;它只关闭移动布局这一层,避免把未验证的视觉改动说成已验收。 diff --git a/site/index.html b/site/index.html index ef3a7b7..c287654 100644 --- a/site/index.html +++ b/site/index.html @@ -139,7 +139,7 @@

手机上真正离线的 编程终端

100% 离线运行 Python 3.13 · JS · Lua - v0.1.0 可信移动 IDE + v0.1.1 移动布局收口 0 广告 · 免费开源
@@ -169,7 +169,7 @@

开箱即用,装完即离线

现代 IDE 体验

多文件 Tab、全局搜索、正则计数跳转、报错行点击直达源码、自动闭合括号、行号开关、自动换行、跳行、图片预览、双指缩放字号,还有 Git 面板、命令面板与分屏预览。

-

0.1.0 新增:Python 引擎移入独立 :engine 进程,卡死时只重启引擎不丢编辑器内容;Git 补单文件暂存/取消/全部暂存、只提交暂存区与 Diff 审阅;文件树/预览截断有提示;设置加密字段后台合并写;纯 Python .whl/.zip 离线导入与失败回滚;170 个 JVM/Robolectric 测试把门。

+

0.1.1 新增:顶栏在 480dp 以下或 1.3 倍字体时只留菜单/保存/运行,其余动作进「更多」;600dp 平板与矮横屏切换左右两栏;抽屉宽度按屏幕夹在 200–272dp;快捷动作改三列。0.1.0 的引擎进程隔离、Git 暂存/Diff、纯 Python 包导入继续保留;179 个 JVM/Robolectric 测试把门。

0.0.34:HTTPS Git clone、项目 zip 导入/导出、PTY 子进程 execve、命令进程组回收。

0.0.30:手机端遮挡治理:所有面板按键盘上方可用高度布局,标题/输入框/按钮固定,只有正文滚动;终端全屏自适应、按键条贴键盘;键盘不再误触发布局切换。

0.0.29:本地 xterm.js ANSI 终端模拟器:真 PTY + 颜色/光标/全屏重绘,vim/top/less 正常显示;移动端方向键与 Ctrl 键、亮暗双主题。

@@ -233,7 +233,7 @@

看一眼就知道

下载 APK

-

v0.1.0 可信移动 IDE:APK 内嵌 CPython 3.13 引擎、运行用标准库与 50+ 原生 C 扩展,安装即用;支持 arm64 手机与 x86_64 模拟器。本版把 Python 引擎移入独立进程,补齐 Git 暂存/Diff、纯 Python 包导入、文件树/预览截断提示与设置后台写;release 包约 24MB。真机交互仍需按机型人工验收,页面不冒充已跑通所有 ROM。

+

v0.1.1 移动布局收口:APK 内嵌 CPython 3.13 引擎、运行用标准库与 50+ 原生 C 扩展,安装即用;支持 arm64 手机与 x86_64 模拟器。0.1.1 把紧凑顶栏、宽屏两栏、抽屉宽度和快捷动作列数做成明确规则;0.1.0 的引擎进程隔离、Git 暂存/Diff、纯 Python 包导入继续保留。release 包约 24MB。真机交互仍需按机型人工验收,页面不冒充已跑通所有 ROM。

GitCode Release