feat(android): 平板版适配(1280×800dp,免授权,应用商店分发)
- flutter create 增加 android 平台:包名 cc.sincos.sequence_diagram,应用名「时序图设计器」,minSdk 24 / targetSdk 36 - 多分辨率动态兼容:触屏侧栏默认贴边把手(点把手直接停靠),面板宽度随屏宽压缩,窄屏双侧栏停靠不溢出 - 免授权:LicenseService 非 Windows 平台直接判定已授权 - 移动端存储/文件浏览器适配(无 APPDATA/盘符/桌面);edge-to-edge + SafeArea + 文本缩放固定 1.0 - launcher 图标沿用「环序」标志(tools/gen-android-icons.py);Gradle 腾讯镜像 + Maven 阿里镜像 - 自测:7 种分辨率无溢出回归(test/tablet_layout_test.dart)+ 平板截图(demo/tablet-*.png) - 产物:release/sequence_diagram_tablet_v1.0.1_release.apk(universal,50.3MB)
@@ -18,6 +18,9 @@ migration:
|
||||
- platform: windows
|
||||
create_revision: 9584c6713b324636289d067944a46fd6b49df14b
|
||||
base_revision: 9584c6713b324636289d067944a46fd6b49df14b
|
||||
- platform: android
|
||||
create_revision: 9584c6713b324636289d067944a46fd6b49df14b
|
||||
base_revision: 9584c6713b324636289d067944a46fd6b49df14b
|
||||
|
||||
# User provided section
|
||||
|
||||
|
||||
@@ -97,3 +97,54 @@ flutter build windows --release
|
||||
(不使用 `path_provider` / `file_selector`)。应用数据目录通过
|
||||
`%APPDATA%` 环境变量获取,文件打开/保存使用自研的应用内文件浏览器。
|
||||
- 国内网络请使用上述 Flutter/Pub 镜像。
|
||||
|
||||
---
|
||||
|
||||
## Android 平板版构建(`dev/android-tablet` 分支)
|
||||
|
||||
面向 1280×800dp(2560×1600)平板、无 license 授权的应用商店分发版。
|
||||
|
||||
### 环境
|
||||
|
||||
| 项 | 版本 / 说明 |
|
||||
| --- | --- |
|
||||
| JDK | 17(如 Temurin 17,`JAVA_HOME` 指向安装目录) |
|
||||
| Android SDK | cmdline-tools + `platform-tools` + `platforms;android-36` + `build-tools;36.0.0`,`ANDROID_HOME`/`ANDROID_SDK_ROOT` 指向 SDK 根目录 |
|
||||
| Gradle | 9.3.1(wrapper 分发已改腾讯镜像 `mirrors.cloud.tencent.com/gradle`) |
|
||||
| Maven | 已配置阿里镜像(google / central / gradle-plugin / public),官方源作回退 |
|
||||
|
||||
> SDK 组件也可用镜像安装,例如:
|
||||
> `https://mirrors.cloud.tencent.com/AndroidSDK/commandlinetools-win-11076708_latest.zip`
|
||||
|
||||
### 构建命令
|
||||
|
||||
```powershell
|
||||
$env:JAVA_HOME = "D:\jdk-17.0.20.1+1"
|
||||
$env:ANDROID_HOME = "D:\android-sdk"
|
||||
$env:FLUTTER_STORAGE_BASE_URL = "https://storage.flutter-io.cn"
|
||||
$env:PUB_HOSTED_URL = "https://pub.flutter-io.cn"
|
||||
flutter pub get
|
||||
flutter build apk --release # 产物:build\app\outputs\flutter-apk\app-release.apk
|
||||
```
|
||||
|
||||
- 发布包归档:`release\sequence_diagram_tablet_v1.0.1_release.apk`(universal:arm64-v8a / armeabi-v7a / x86_64)。
|
||||
- 上架应用商店时建议在 `android\app\build.gradle.kts` 配置正式签名后再构建 AAB:
|
||||
`flutter build appbundle --release`。
|
||||
- 应用名「时序图设计器」、包名 `cc.sincos.sequence_diagram`、launcher 图标由
|
||||
`tools\gen-android-icons.py` 生成(与桌面版「环序」标志同源)。
|
||||
|
||||
### 平台差异说明
|
||||
|
||||
- **license**:`LicenseService.init()` 在非 Windows 平台直接判定已授权,Android 版无授权限制。
|
||||
- **存储**:无 `%APPDATA%`,自动保存与快照落在系统临时目录(应用私有目录);文件浏览器
|
||||
隐藏「桌面 / 盘符」入口。
|
||||
- **侧栏**:触屏默认收起为贴边把手(点把手直接停靠展开);面板宽度随屏幕动态压缩,
|
||||
窄屏双侧栏停靠也不溢出。
|
||||
- **系统栏**:edge-to-edge + SafeArea,文本缩放固定 1.0,保证平板各分辨率像素级一致。
|
||||
|
||||
### 自测
|
||||
|
||||
```bash
|
||||
flutter test test\tablet_layout_test.dart # 7 种分辨率无溢出回归
|
||||
flutter test --update-goldens test\tablet_screenshots_test.dart # 重新生成 demo/tablet-*.png
|
||||
```
|
||||
|
||||
@@ -87,6 +87,17 @@ node tools/demo-gen.mjs
|
||||
|
||||
Flutter 3.29+(Desktop) · CustomPainter 自绘 · Riverpod · 不可变模型 + Command 撤销栈 · 纯 Dart 几何算法 · 自研 SVG 序列化器 · JSON(`.seq.json`)持久化 · 主题 Token 化(深浅双主题)
|
||||
|
||||
## Android 平板版(`dev/android-tablet` 分支)
|
||||
|
||||
- **目标分辨率**:1280×800dp(2560×1600 物理),并动态兼容其它横竖屏分辨率;
|
||||
- **无 license 授权**(面向应用商店分发);包名 `cc.sincos.sequence_diagram`,应用名「时序图设计器」;
|
||||
- **构建**:JDK 17 + Android SDK 36(详见 `BUILD-NOTES.md`),Gradle 与 Maven 已配置国内镜像:
|
||||
```bash
|
||||
flutter build apk --release # 产物 → release/sequence_diagram_tablet_v1.0.1_release.apk
|
||||
```
|
||||
- **自测**:`test/tablet_layout_test.dart` 覆盖 1280×800、2560×1600、960×600、800×480、竖屏 800×1280、600×960 等 7 种分辨率的无溢出回归;
|
||||
- **demo 图**:`demo/tablet-*.png`(由 `test/tablet_screenshots_test.dart` 生成)。
|
||||
|
||||
## 路线图
|
||||
|
||||
- [ ] M1 数据模型 + 单位体系 + JSON 存取 + 条形视图(渲染 / 缩放 / 平移)
|
||||
|
||||
@@ -13,6 +13,7 @@ analyzer:
|
||||
exclude:
|
||||
- build/**
|
||||
- windows/**
|
||||
- android/**
|
||||
|
||||
linter:
|
||||
# The lint rules applied to this project can be customized in the
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
gradle-wrapper.jar
|
||||
/.gradle
|
||||
/captures/
|
||||
/gradlew
|
||||
/gradlew.bat
|
||||
/local.properties
|
||||
GeneratedPluginRegistrant.java
|
||||
.cxx/
|
||||
|
||||
# Remember to never publicly share your keystore.
|
||||
# See https://flutter.dev/to/reference-keystore
|
||||
key.properties
|
||||
**/*.keystore
|
||||
**/*.jks
|
||||
@@ -0,0 +1,49 @@
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
|
||||
id("dev.flutter.flutter-gradle-plugin")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "cc.sincos.sequence_diagram"
|
||||
compileSdk = flutter.compileSdkVersion
|
||||
ndkVersion = flutter.ndkVersion
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId = "cc.sincos.sequence_diagram"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
||||
minSdk = flutter.minSdkVersion
|
||||
targetSdk = flutter.targetSdkVersion
|
||||
// Uses the version code from pubspec.yaml. When using split APKs, 1000 * ABI_VERSION
|
||||
// is added automatically by Flutter. (https://developer.android.com/studio/build/configure-apk-splits#configure-APK-versions)
|
||||
// You can force using the value of versionCode by specifying the `-P force-version-code-ignoring-abi=true`
|
||||
// flag during build.
|
||||
versionCode = flutter.versionCode
|
||||
versionName = flutter.versionName
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig = signingConfigs.getByName("debug")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
|
||||
}
|
||||
}
|
||||
|
||||
flutter {
|
||||
source = "../.."
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- The INTERNET permission is required for development. Specifically,
|
||||
the Flutter tool needs it to communicate with the running application
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
</manifest>
|
||||
@@ -0,0 +1,45 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application
|
||||
android:label="时序图设计器"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:taskAffinity=""
|
||||
android:theme="@style/LaunchTheme"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||
the Android process has started. This theme is visible to the user
|
||||
while the Flutter UI initializes. After that, this theme continues
|
||||
to determine the Window background behind the Flutter UI. -->
|
||||
<meta-data
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/NormalTheme"
|
||||
/>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Don't delete the meta-data below.
|
||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
</application>
|
||||
<!-- Required to query activities that can process text, see:
|
||||
https://developer.android.com/training/package-visibility and
|
||||
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
|
||||
|
||||
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
||||
<data android:mimeType="text/plain"/>
|
||||
</intent>
|
||||
</queries>
|
||||
</manifest>
|
||||
@@ -0,0 +1,5 @@
|
||||
package cc.sincos.sequence_diagram
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity : FlutterActivity()
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Modify this file to customize your launch splash screen -->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="?android:colorBackground" />
|
||||
|
||||
<!-- You can insert your own image assets here -->
|
||||
<!-- <item>
|
||||
<bitmap
|
||||
android:gravity="center"
|
||||
android:src="@mipmap/launch_image" />
|
||||
</item> -->
|
||||
</layer-list>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Modify this file to customize your launch splash screen -->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@android:color/white" />
|
||||
|
||||
<!-- You can insert your own image assets here -->
|
||||
<!-- <item>
|
||||
<bitmap
|
||||
android:gravity="center"
|
||||
android:src="@mipmap/launch_image" />
|
||||
</item> -->
|
||||
</layer-list>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 923 B |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
|
||||
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||
<!-- Show a splash screen on the activity. Automatically removed when
|
||||
the Flutter engine draws its first frame -->
|
||||
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||
</style>
|
||||
<!-- Theme applied to the Android Window as soon as the process has started.
|
||||
This theme determines the color of the Android Window while your
|
||||
Flutter UI initializes, as well as behind your Flutter UI while its
|
||||
running.
|
||||
|
||||
This Theme is only used starting with V2 of Flutter's Android embedding. -->
|
||||
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||
<item name="android:windowBackground">?android:colorBackground</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
|
||||
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
||||
<!-- Show a splash screen on the activity. Automatically removed when
|
||||
the Flutter engine draws its first frame -->
|
||||
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||
</style>
|
||||
<!-- Theme applied to the Android Window as soon as the process has started.
|
||||
This theme determines the color of the Android Window while your
|
||||
Flutter UI initializes, as well as behind your Flutter UI while its
|
||||
running.
|
||||
|
||||
This Theme is only used starting with V2 of Flutter's Android embedding. -->
|
||||
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
||||
<item name="android:windowBackground">?android:colorBackground</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -0,0 +1,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- The INTERNET permission is required for development. Specifically,
|
||||
the Flutter tool needs it to communicate with the running application
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
</manifest>
|
||||
@@ -0,0 +1,28 @@
|
||||
allprojects {
|
||||
repositories {
|
||||
// 国内镜像优先,加快依赖下载;保持官方源作为回退。
|
||||
maven { url = uri("https://maven.aliyun.com/repository/google") }
|
||||
maven { url = uri("https://maven.aliyun.com/repository/central") }
|
||||
maven { url = uri("https://maven.aliyun.com/repository/public") }
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
val newBuildDir: Directory =
|
||||
rootProject.layout.buildDirectory
|
||||
.dir("../../build")
|
||||
.get()
|
||||
rootProject.layout.buildDirectory.value(newBuildDir)
|
||||
|
||||
subprojects {
|
||||
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
|
||||
project.layout.buildDirectory.value(newSubprojectBuildDir)
|
||||
}
|
||||
subprojects {
|
||||
project.evaluationDependsOn(":app")
|
||||
}
|
||||
|
||||
tasks.register<Delete>("clean") {
|
||||
delete(rootProject.layout.buildDirectory)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
|
||||
android.useAndroidX=true
|
||||
# This newDsl flag was added by the Flutter template
|
||||
android.newDsl=false
|
||||
# This builtInKotlin flag was added by the Flutter template
|
||||
android.builtInKotlin=false
|
||||
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-9.3.1-all.zip
|
||||
@@ -0,0 +1,31 @@
|
||||
pluginManagement {
|
||||
val flutterSdkPath =
|
||||
run {
|
||||
val properties = java.util.Properties()
|
||||
file("local.properties").inputStream().use { properties.load(it) }
|
||||
val flutterSdkPath = properties.getProperty("flutter.sdk")
|
||||
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
|
||||
flutterSdkPath
|
||||
}
|
||||
|
||||
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
|
||||
|
||||
repositories {
|
||||
// 国内镜像优先,加快依赖下载;保持官方源作为回退。
|
||||
maven { url = uri("https://maven.aliyun.com/repository/google") }
|
||||
maven { url = uri("https://maven.aliyun.com/repository/central") }
|
||||
maven { url = uri("https://maven.aliyun.com/repository/gradle-plugin") }
|
||||
maven { url = uri("https://maven.aliyun.com/repository/public") }
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
|
||||
id("com.android.application") version "9.1.0" apply false
|
||||
id("org.jetbrains.kotlin.android") version "2.4.0" apply false
|
||||
}
|
||||
|
||||
include(":app")
|
||||
|
After Width: | Height: | Size: 114 KiB |
|
After Width: | Height: | Size: 183 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 183 KiB |
|
After Width: | Height: | Size: 183 KiB |
@@ -58,7 +58,14 @@ class LicenseService {
|
||||
Directory get licenseDir => Directory('${Directory.current.path}${Platform.pathSeparator}license');
|
||||
|
||||
/// 初始化:读取 MAC 并校验 `license/*.lic`。
|
||||
///
|
||||
/// Android 平板版(应用商店分发)不需要授权:非 Windows 平台直接判定为
|
||||
/// 已授权,跳过 MAC 读取与 .lic 校验。
|
||||
Future<LicenseInfo> init() async {
|
||||
if (!Platform.isWindows) {
|
||||
_info = const LicenseInfo(mac: null, valid: true);
|
||||
return _info;
|
||||
}
|
||||
final String? mac = await _readMac();
|
||||
bool valid = false;
|
||||
String? hitPath;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
// Storage(本地持久化),并通过 AppController 向整个 UI 层提供状态与
|
||||
// 业务动作。启动后还会检查是否存在异常退出遗留的自动快照,并引导用户
|
||||
// 选择恢复方式。
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
import 'dart:ui' show AppExitResponse;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -23,6 +25,16 @@ import 'ui/app_shell.dart';
|
||||
/// 然后启动根组件 [SequenceDiagramApp]。
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
// 移动端:沉浸式(edge-to-edge)显示,配合 SafeArea 自动避让系统栏。
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
systemNavigationBarColor: Colors.transparent,
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
statusBarBrightness: Brightness.light,
|
||||
));
|
||||
}
|
||||
await Storage.instance.init();
|
||||
runApp(const SequenceDiagramApp());
|
||||
}
|
||||
@@ -158,6 +170,16 @@ class _SequenceDiagramAppState extends State<SequenceDiagramApp> {
|
||||
title: '时序图设计器 · Sequence Diagram Studio',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: buildTheme(tokens),
|
||||
// 固定文本缩放并包裹 SafeArea:保证平板等分辨率下布局像素级精准,
|
||||
// 不受系统字体缩放影响,并自动避让状态栏 / 导航栏。
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
textScaler: const TextScaler.linear(1.0),
|
||||
),
|
||||
child: SafeArea(child: child ?? const SizedBox.shrink()),
|
||||
);
|
||||
},
|
||||
home: AppShell(controller: _controller),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -64,6 +64,18 @@ class _AppShellState extends State<AppShell> {
|
||||
AppController get c => widget.controller;
|
||||
|
||||
// ---- 由上述三态派生的侧栏呈现方式 ----
|
||||
/// 左侧栏宽度:随屏幕宽度动态压缩(300 → 200),窄屏双侧栏停靠也不溢出。
|
||||
double get _leftPanelWidth {
|
||||
final double w = MediaQuery.sizeOf(context).width;
|
||||
return math.min(300.0, math.max(200.0, w * 0.24));
|
||||
}
|
||||
|
||||
/// 右侧栏宽度:随屏幕宽度动态压缩(340 → 240),窄屏双侧栏停靠也不溢出。
|
||||
double get _rightPanelWidth {
|
||||
final double w = MediaQuery.sizeOf(context).width;
|
||||
return math.min(340.0, math.max(240.0, w * 0.26));
|
||||
}
|
||||
|
||||
/// 左侧栏是否处于停靠(固定)状态。
|
||||
bool get _leftDocked => _leftVisible && _leftPinned;
|
||||
/// 右侧栏是否处于停靠(固定)状态。
|
||||
@@ -84,6 +96,27 @@ class _AppShellState extends State<AppShell> {
|
||||
c.addListener(_onChange);
|
||||
}
|
||||
|
||||
/// 是否已完成一次按平台 / 屏幕宽度的默认布局初始化。
|
||||
bool _layoutInited = false;
|
||||
|
||||
/// 首次构建时按平台与屏幕宽度设定侧栏默认状态(动态兼容不同分辨率):
|
||||
/// - 触屏平台(Android / iOS):默认收起为贴边轨道,给画布让出完整宽度;
|
||||
/// - 桌面窄窗口(< 1500 逻辑宽):同样默认收起,避免两侧栏挤占画布。
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (_layoutInited) return;
|
||||
_layoutInited = true;
|
||||
final bool touch = Platform.isAndroid || Platform.isIOS;
|
||||
final double w = MediaQuery.of(context).size.width;
|
||||
if (touch || w < 1500) {
|
||||
_leftVisible = false;
|
||||
_rightVisible = false;
|
||||
_leftPinned = false;
|
||||
_rightPinned = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 取消订阅并释放资源。
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -733,10 +766,19 @@ class _AppShellState extends State<AppShell> {
|
||||
onTap: () => setState(() {
|
||||
if (left) {
|
||||
_leftVisible = true;
|
||||
if (!_leftPinned) _leftHover = true;
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
// 触屏平台:点把手直接停靠展开(无悬停概念)。
|
||||
_leftPinned = true;
|
||||
} else if (!_leftPinned) {
|
||||
_leftHover = true;
|
||||
}
|
||||
} else {
|
||||
_rightVisible = true;
|
||||
if (!_rightPinned) _rightHover = true;
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
_rightPinned = true;
|
||||
} else if (!_rightPinned) {
|
||||
_rightHover = true;
|
||||
}
|
||||
}
|
||||
}),
|
||||
child: Container(
|
||||
@@ -784,7 +826,7 @@ class _AppShellState extends State<AppShell> {
|
||||
Widget _leftPanel(Tokens t, {bool floating = false}) {
|
||||
final bool bar = c.project.viewState.mode == ViewMode.bar;
|
||||
return Container(
|
||||
width: 300,
|
||||
width: _leftPanelWidth,
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel,
|
||||
border: floating ? Border.all(color: t.line2) : Border(right: BorderSide(color: t.line)),
|
||||
@@ -1073,15 +1115,22 @@ class _AppShellState extends State<AppShell> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
bar ? '${a0.toStringAsFixed(0)}° – ${math.min(a1, 360).toStringAsFixed(0)}°' : 'L${li + 1}',
|
||||
style: TextStyle(color: t.sub, fontSize: 11),
|
||||
),
|
||||
Text('${acts.length} 个动作', style: TextStyle(color: t.dim, fontSize: 10)),
|
||||
],
|
||||
Flexible(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
bar ? '${a0.toStringAsFixed(0)}° – ${math.min(a1, 360).toStringAsFixed(0)}°' : 'L${li + 1}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: t.sub, fontSize: 11),
|
||||
),
|
||||
Text('${acts.length} 个动作',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: t.dim, fontSize: 10)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
InkWell(
|
||||
@@ -1156,18 +1205,24 @@ class _AppShellState extends State<AppShell> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
bar
|
||||
? '${a.startAngle.toStringAsFixed(0)}° – ${math.min(a.endAngle, 360).toStringAsFixed(0)}°'
|
||||
: 'L${a.layer + 1}',
|
||||
style: TextStyle(color: t.sub, fontSize: 10),
|
||||
),
|
||||
Text(tfmt(a.durationAngle / 360 * c.project.cycle.durationMs, c.project.units),
|
||||
style: TextStyle(color: t.dim, fontSize: 10)),
|
||||
],
|
||||
Flexible(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
bar
|
||||
? '${a.startAngle.toStringAsFixed(0)}° – ${math.min(a.endAngle, 360).toStringAsFixed(0)}°'
|
||||
: 'L${a.layer + 1}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: t.sub, fontSize: 10),
|
||||
),
|
||||
Text(tfmt(a.durationAngle / 360 * c.project.cycle.durationMs, c.project.units),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: t.dim, fontSize: 10)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
InkWell(
|
||||
@@ -1331,7 +1386,7 @@ class _AppShellState extends State<AppShell> {
|
||||
final Action? a = c.selected;
|
||||
final bool bar = c.project.viewState.mode == ViewMode.bar;
|
||||
return Container(
|
||||
width: 340,
|
||||
width: _rightPanelWidth,
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel,
|
||||
border: floating ? Border.all(color: t.line2) : Border(left: BorderSide(color: t.line)),
|
||||
|
||||
@@ -98,7 +98,11 @@ class _FileBrowserDialogState extends State<FileBrowserDialog> {
|
||||
super.initState();
|
||||
String start = widget.initialPath ?? '';
|
||||
if (start.isEmpty) {
|
||||
start = Platform.environment['USERPROFILE'] ?? Directory.current.path;
|
||||
// 桌面版从用户目录开始;Android/iOS 从应用可写目录(系统临时目录)开始。
|
||||
start = Platform.environment['USERPROFILE'] ??
|
||||
(Platform.isAndroid || Platform.isIOS
|
||||
? Directory.systemTemp.path
|
||||
: Directory.current.path);
|
||||
}
|
||||
if (File(start).existsSync()) {
|
||||
start = File(start).parent.path;
|
||||
@@ -218,21 +222,22 @@ class _FileBrowserDialogState extends State<FileBrowserDialog> {
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
// 桌面快捷入口:导出 / 打开 / 保存时一键跳到桌面。
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
child: ActionChip(
|
||||
avatar: Icon(Icons.desktop_windows_outlined, size: 15, color: t.accent),
|
||||
label: const Text('桌面'),
|
||||
onPressed: () {
|
||||
final Directory? d = _desktop();
|
||||
if (d != null) {
|
||||
_dir = d;
|
||||
_refresh();
|
||||
}
|
||||
},
|
||||
// 桌面快捷入口:仅在桌面平台显示(移动平台无“桌面”概念)。
|
||||
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
child: ActionChip(
|
||||
avatar: Icon(Icons.desktop_windows_outlined, size: 15, color: t.accent),
|
||||
label: const Text('桌面'),
|
||||
onPressed: () {
|
||||
final Directory? d = _desktop();
|
||||
if (d != null) {
|
||||
_dir = d;
|
||||
_refresh();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
...drives.map((String d) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 6),
|
||||
|
||||
@@ -260,10 +260,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_math
|
||||
sha256: f36f9f3be64c6198714492bb455c11056e33e2f85d9a0b676a48301e44fdcf47
|
||||
sha256: "92b9910f66ed1057fd4da7b040ae7c74cafacf885bdc81be496928d5049b032d"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.4.2"
|
||||
version: "2.4.3"
|
||||
vm_service:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// 测试辅助:构造演示工程与加载中文字体(用于平板布局测试与截图生成)。
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
|
||||
/// 构造一个动作较多、含依赖与相位分区的演示工程。
|
||||
Project demoTiming() {
|
||||
return Project(
|
||||
name: '装配线节拍',
|
||||
cycle: const Cycle(durationMs: 2400),
|
||||
stations: const <Station>[
|
||||
Station(id: 'ST1', name: '上料工位', order: 0, color: 0xFF4CC9F0),
|
||||
Station(id: 'ST2', name: '加工工位', order: 1, color: 0xFFFFD166),
|
||||
Station(id: 'ST3', name: '检测工位', order: 2, color: 0xFF34D399),
|
||||
],
|
||||
actions: <Action>[
|
||||
const Action(id: 'A1', name: '上料', stationId: 'ST1', driver: '气缸 Y1', startAngle: 0, durationAngle: 45, layer: 0, color: 0xFF4CC9F0),
|
||||
const Action(id: 'A2', name: '定位夹紧', stationId: 'ST1', driver: '气缸 Y2', startAngle: 50, durationAngle: 55, layer: 0, color: 0xFF7BD88F,
|
||||
deps: <Dependency>[Dependency(fromId: 'A1', toId: 'A2', type: DepType.fs)]),
|
||||
const Action(id: 'A3', name: '伺服下压', stationId: 'ST2', driver: '伺服 M1', startAngle: 90, durationAngle: 70, layer: 1, color: 0xFFFFD166,
|
||||
deps: <Dependency>[Dependency(fromId: 'A2', toId: 'A3', type: DepType.fs)]),
|
||||
const Action(id: 'A4', name: '超声焊接', stationId: 'ST2', driver: '超声 U1', startAngle: 100, durationAngle: 50, layer: 2, color: 0xFFF472B6,
|
||||
deps: <Dependency>[Dependency(fromId: 'A3', toId: 'A4', type: DepType.ss, offsetAngle: 10)]),
|
||||
const Action(id: 'A5', name: '视觉检测', stationId: 'ST3', driver: '相机 C1', startAngle: 160, durationAngle: 70, layer: 1, color: 0xFF7C5CFF,
|
||||
deps: <Dependency>[Dependency(fromId: 'A4', toId: 'A5', type: DepType.fs)]),
|
||||
const Action(id: 'A6', name: '分选下料', stationId: 'ST3', driver: '气缸 Y3', startAngle: 200, durationAngle: 70, layer: 2, color: 0xFFFF9F7C,
|
||||
deps: <Dependency>[Dependency(fromId: 'A5', toId: 'A6', type: DepType.fs)]),
|
||||
const Action(id: 'A7', name: '清洁吹气', stationId: 'ST1', driver: '电磁阀 V1', startAngle: 240, durationAngle: 80, layer: 3, color: 0xFF34D399,
|
||||
deps: <Dependency>[Dependency(fromId: 'A6', toId: 'A7', type: DepType.fs)]),
|
||||
],
|
||||
units: const UnitSettings(timeUnit: TimeUnit.s),
|
||||
viewState: const ViewState(mode: ViewMode.bar),
|
||||
phaseZones: const <PhaseZone>[
|
||||
PhaseZone(name: '上料相位', startAngle: 0, endAngle: 70),
|
||||
PhaseZone(name: '加工相位', startAngle: 70, endAngle: 200),
|
||||
PhaseZone(name: '检测相位', startAngle: 200, endAngle: 300),
|
||||
PhaseZone(name: '下料相位', startAngle: 300, endAngle: 360),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 从系统字体加载中文字体,使测试截图中的中文正常渲染。
|
||||
Future<void> loadZhFonts() async {
|
||||
const List<String> candidates = <String>[
|
||||
r'C:\Windows\Fonts\simhei.ttf',
|
||||
r'C:\Windows\Fonts\msyh.ttf',
|
||||
r'C:\Windows\Fonts\msyh.ttc',
|
||||
r'C:\Windows\Fonts\simsun.ttc',
|
||||
];
|
||||
for (final String path in candidates) {
|
||||
final File f = File(path);
|
||||
if (!f.existsSync()) continue;
|
||||
final ByteData bytes = ByteData.sublistView(await f.readAsBytes());
|
||||
final FontLoader loader = FontLoader('Microsoft YaHei UI')..addFont(Future<ByteData>.value(bytes));
|
||||
await loader.load();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// 平板/多分辨率布局回归测试:在多种分辨率、主题、视图模式下泵出整个外壳,
|
||||
// 并展开/停靠侧栏,确保无溢出异常(RenderFlex overflow 会导致测试失败)。
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/ui/app_shell.dart';
|
||||
|
||||
import 'helpers.dart';
|
||||
|
||||
void main() {
|
||||
const List<(String, Size, double)> cases = <(String, Size, double)>[
|
||||
('tablet-landscape', Size(1280, 800), 1.0),
|
||||
('tablet-landscape-2x', Size(1280, 800), 2.0), // 物理 2560×1600
|
||||
('wide-1920', Size(1920, 1080), 1.0),
|
||||
('small-960', Size(960, 600), 1.0),
|
||||
('phone-landscape-800', Size(800, 480), 1.0),
|
||||
('portrait-800x1280', Size(800, 1280), 1.0),
|
||||
('portrait-600x960', Size(600, 960), 1.0),
|
||||
];
|
||||
|
||||
for (final (String name, Size size, double dpr) in cases) {
|
||||
testWidgets('layout @ $name ${size.width}x${size.height} dpr=$dpr 无溢出', (WidgetTester tester) async {
|
||||
tester.view.physicalSize = size * dpr;
|
||||
tester.view.devicePixelRatio = dpr;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final AppController c = AppController(project: demoTiming());
|
||||
addTearDown(c.dispose);
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
theme: buildTheme(Tokens.light),
|
||||
home: AppShell(controller: c),
|
||||
));
|
||||
await tester.pump();
|
||||
|
||||
// 条形视图:深浅主题各渲染一次。
|
||||
c.toggleTheme();
|
||||
await tester.pump();
|
||||
c.toggleTheme();
|
||||
await tester.pump();
|
||||
|
||||
// 展开左侧栏(浮层)并钉住(停靠,压缩画布宽度)。
|
||||
if (tester.any(find.byIcon(Icons.chevron_right))) {
|
||||
await tester.tap(find.byIcon(Icons.chevron_right).first);
|
||||
await tester.pump();
|
||||
}
|
||||
if (tester.any(find.byIcon(Icons.push_pin_outlined))) {
|
||||
await tester.tap(find.byIcon(Icons.push_pin_outlined).first);
|
||||
await tester.pump();
|
||||
}
|
||||
// 展开右侧栏(浮层)并钉住。
|
||||
if (tester.any(find.byIcon(Icons.chevron_left))) {
|
||||
await tester.tap(find.byIcon(Icons.chevron_left).first);
|
||||
await tester.pump();
|
||||
}
|
||||
if (tester.any(find.byIcon(Icons.push_pin_outlined))) {
|
||||
await tester.tap(find.byIcon(Icons.push_pin_outlined).first);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
// 圆周视图 + 深色主题 + 缩放。
|
||||
c.setViewMode(ViewMode.circular);
|
||||
await tester.pump();
|
||||
c.toggleTheme();
|
||||
await tester.pump();
|
||||
c.setZoom(1.4);
|
||||
await tester.pump();
|
||||
|
||||
// 回到条形视图,选中一个动作(右侧栏渲染属性面板)。
|
||||
c.setViewMode(ViewMode.bar);
|
||||
c.select('A3');
|
||||
await tester.pump();
|
||||
c.toggleTheme();
|
||||
await tester.pump();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// 平板版演示截图生成:把整个应用外壳在 1280×800(平板横屏基准)下渲染为 PNG。
|
||||
// 运行方式:flutter test --update-goldens test\tablet_screenshots_test.dart
|
||||
// 输出:demo/tablet-*.png
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/ui/app_shell.dart';
|
||||
|
||||
import 'helpers.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('generate tablet demo screenshots', (WidgetTester tester) async {
|
||||
await tester.runAsync(() => loadZhFonts());
|
||||
|
||||
tester.view.physicalSize = const Size(1280, 800);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final AppController c = AppController(project: demoTiming());
|
||||
addTearDown(c.dispose);
|
||||
|
||||
Widget shell(Tokens t) => RepaintBoundary(
|
||||
key: const ValueKey<String>('shot'),
|
||||
child: MaterialApp(
|
||||
theme: buildTheme(t),
|
||||
home: AppShell(controller: c),
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> shot(String path) async {
|
||||
await tester.pump();
|
||||
await expectLater(find.byKey(const ValueKey<String>('shot')), matchesGoldenFile(path));
|
||||
}
|
||||
|
||||
await tester.pumpWidget(shell(Tokens.light));
|
||||
await shot('../demo/tablet-bar-light.png');
|
||||
|
||||
// 展开左右侧栏(浮层)并钉住,展示停靠布局。
|
||||
await tester.tap(find.byIcon(Icons.chevron_right).first);
|
||||
await tester.pump();
|
||||
if (tester.any(find.byIcon(Icons.push_pin_outlined))) {
|
||||
await tester.tap(find.byIcon(Icons.push_pin_outlined).first);
|
||||
await tester.pump();
|
||||
}
|
||||
await tester.tap(find.byIcon(Icons.chevron_left).first);
|
||||
await tester.pump();
|
||||
if (tester.any(find.byIcon(Icons.push_pin_outlined))) {
|
||||
await tester.tap(find.byIcon(Icons.push_pin_outlined).first);
|
||||
await tester.pump();
|
||||
}
|
||||
await shot('../demo/tablet-bar-light-panels.png');
|
||||
|
||||
// 圆周视图(浅色,含停靠侧栏)。
|
||||
c.setViewMode(ViewMode.circular);
|
||||
await shot('../demo/tablet-circular-light.png');
|
||||
|
||||
// 深色主题:条形与圆周。
|
||||
c.toggleTheme();
|
||||
await tester.pumpWidget(shell(Tokens.dark));
|
||||
c.setViewMode(ViewMode.bar);
|
||||
await shot('../demo/tablet-bar-dark.png');
|
||||
c.setViewMode(ViewMode.circular);
|
||||
await shot('../demo/tablet-circular-dark.png');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate Android launcher icons from the original "Cycle-Step" mark.
|
||||
|
||||
Renders the same geometry as tools/gen-icon.py (gapped ring + step polyline
|
||||
+ origin/terminal dots), full-bleed (no transparent inset) so the tile fills
|
||||
the icon, at every Android launcher density.
|
||||
|
||||
Outputs:
|
||||
android/app/src/main/res/mipmap-*/ic_launcher.png
|
||||
"""
|
||||
import math
|
||||
import os
|
||||
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
RES = os.path.join(ROOT, "android", "app", "src", "main", "res")
|
||||
|
||||
TILE_TOP = (24, 33, 61, 255) # #18213D
|
||||
TILE_BOT = (12, 18, 38, 255) # #0C1226
|
||||
EDGE = (255, 255, 255, 38)
|
||||
RING = (76, 201, 240, 255) # #4CC9F0
|
||||
STEP = (255, 209, 102, 255) # #FFD166
|
||||
ORIGIN = (255, 255, 255, 255)
|
||||
END = (52, 211, 153, 255) # #34D399
|
||||
|
||||
DENSITIES = {
|
||||
"mdpi": 48,
|
||||
"hdpi": 72,
|
||||
"xhdpi": 96,
|
||||
"xxhdpi": 144,
|
||||
"xxxhdpi": 192,
|
||||
}
|
||||
|
||||
|
||||
def lerp(a, b, t):
|
||||
return tuple(round(a[i] + (b[i] - a[i]) * t) for i in range(4))
|
||||
|
||||
|
||||
def polar(cx, cy, r, deg):
|
||||
t = math.radians(deg - 90)
|
||||
return (cx + r * math.cos(t), cy + r * math.sin(t))
|
||||
|
||||
|
||||
def draw_ring(img, cx, cy, r_ring, ring_w, gap_deg, color, s):
|
||||
outer = r_ring + ring_w / 2
|
||||
inner = r_ring - ring_w / 2
|
||||
mask = Image.new("L", (s, s), 0)
|
||||
md = ImageDraw.Draw(mask)
|
||||
md.ellipse([cx - outer, cy - outer, cx + outer, cy + outer], fill=255)
|
||||
md.ellipse([cx - inner, cy - inner, cx + inner, cy + inner], fill=0)
|
||||
a0 = polar(cx, cy, outer + 8, -90 - gap_deg / 2)
|
||||
a1 = polar(cx, cy, outer + 8, -90 + gap_deg / 2)
|
||||
md.polygon([(cx, cy), a0, a1], fill=0)
|
||||
for deg in (-90 + gap_deg / 2, -90 - gap_deg / 2):
|
||||
p = polar(cx, cy, r_ring, deg)
|
||||
md.ellipse([p[0] - ring_w / 2, p[1] - ring_w / 2,
|
||||
p[0] + ring_w / 2, p[1] + ring_w / 2], fill=255)
|
||||
img.paste(color, (0, 0), mask)
|
||||
|
||||
|
||||
def draw_steps(img, pts, width, color):
|
||||
d = ImageDraw.Draw(img)
|
||||
d.line(pts, fill=color, width=width, joint="curve")
|
||||
for p in pts:
|
||||
d.ellipse([p[0] - width / 2, p[1] - width / 2,
|
||||
p[0] + width / 2, p[1] + width / 2], fill=color)
|
||||
|
||||
|
||||
def build(s):
|
||||
img = Image.new("RGBA", (s, s), (0, 0, 0, 0))
|
||||
body = Image.new("RGBA", (s, s), (0, 0, 0, 0))
|
||||
bd = ImageDraw.Draw(body)
|
||||
for y in range(s):
|
||||
bd.line([(0, y), (s, y)], fill=lerp(TILE_TOP, TILE_BOT, y / (s - 1)))
|
||||
mask = Image.new("L", (s, s), 0)
|
||||
ImageDraw.Draw(mask).rounded_rectangle([0, 0, s - 1, s - 1], radius=int(0.27 * s), fill=255)
|
||||
img.paste(body, (0, 0), mask)
|
||||
ImageDraw.Draw(img).rounded_rectangle([0, 0, s - 1, s - 1], radius=int(0.27 * s), outline=EDGE, width=max(1, s // 200))
|
||||
|
||||
cx = cy = s / 2.0
|
||||
r_ring = 0.293 * s
|
||||
ring_w = (0.075 if s <= 48 else 0.062) * s
|
||||
draw_ring(img, cx, cy, r_ring, ring_w, 68, RING, s)
|
||||
|
||||
d = ImageDraw.Draw(img)
|
||||
od = 0.045 * s
|
||||
op = (cx, cy - r_ring)
|
||||
d.ellipse([op[0] - od, op[1] - od, op[0] + od, op[1] + od], fill=ORIGIN)
|
||||
|
||||
sw = (0.075 if s <= 48 else 0.057) * s
|
||||
p1 = (cx - 0.146 * s, cy + 0.088 * s)
|
||||
p2 = (cx - 0.010 * s, cy + 0.088 * s)
|
||||
p3 = (cx - 0.010 * s, cy - 0.059 * s)
|
||||
p4 = (cx + 0.166 * s, cy - 0.059 * s)
|
||||
draw_steps(img, [p1, p2, p3, p4], int(sw), STEP)
|
||||
|
||||
ed = (0.050 if s <= 48 else 0.037) * s
|
||||
d.ellipse([p4[0] - ed, p4[1] - ed, p4[0] + ed, p4[1] + ed], fill=END)
|
||||
return img
|
||||
|
||||
|
||||
def main():
|
||||
for density, size in DENSITIES.items():
|
||||
out_dir = os.path.join(RES, "mipmap-%s" % density)
|
||||
os.makedirs(out_dir, exist_ok=True)
|
||||
out = os.path.join(out_dir, "ic_launcher.png")
|
||||
build(size).save(out)
|
||||
print("wrote", out)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||