25 |
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ColorfulPicture
2 |
3 | 一款简单易用的照片相框生成工具,能够为您的照片添加美观的彩色相框,并展示相机和拍摄信息。
4 |
5 | ## 功能特点
6 |
7 | - **智能取色**: 自动从照片中提取主色调和相关配色方案
8 | - **实时预览**: 即时查看效果,所见即所得
9 | - **照片圆角**: 支持为照片和相框添加可调节大小的圆角效果
10 | - **EXIF信息读取**: 自动识别照片中的相机型号、镜头、光圈、快门速度等EXIF信息
11 | - **适应文本大小**: 智能计算最佳文字大小,确保信息清晰可读
12 | - **一键保存**: 生成的照片可直接保存到相册中
13 |
14 | ## 截图
15 |
16 | 
17 | 
18 |
19 |
20 | ## 技术特点
21 |
22 | - 使用 Palette 库智能提取照片主色调
23 | - 支持多种颜色变体生成算法
24 | - 优化的 EXIF 数据读取逻辑
25 | - 高质量图像处理,保证输出效果
26 |
27 | ## 权限需求
28 |
29 | 应用需要以下权限以提供完整功能:
30 | - 读取外部存储/媒体图像权限:用于选择照片
31 | - 写入外部存储权限:用于保存生成的照片
32 |
33 | ## 开发者
34 |
35 | Directed by X[@SeimoDev](https://x.com/SeimoDev)
36 | Dev: Cursor & Claude 3.7
37 | 图标: Gemini 2.0 exp
38 |
39 |
40 | ## 源代码
41 |
42 | 项目源码托管于 [GitHub 仓库](https://github.com/SeimoDev/ColorfulPicture)
43 |
44 | ## 特别鸣谢
45 |
46 | 特别感谢 X[@Yayoi_no_yume](https://x.com/Yayoi_no_yume)
47 |
48 | ## 许可证
49 |
50 | [GPL v3.0](https://github.com/SeimoDev/ColorfulPicture/blob/main/LICENSE)
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. For more details, visit
12 | # https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
24 | # 设置Java 17作为Gradle Java运行环境
25 | org.gradle.java.home=C:\\Program Files\\Java\\jdk-17
--------------------------------------------------------------------------------
/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | agp = "8.8.0"
3 | kotlin = "1.9.24"
4 | coreKtx = "1.15.0"
5 | junit = "4.13.2"
6 | junitVersion = "1.2.1"
7 | espressoCore = "3.6.1"
8 | appcompat = "1.7.0"
9 | material = "1.12.0"
10 | constraintlayout = "2.2.0"
11 | navigationFragmentKtx = "2.8.7"
12 | navigationUiKtx = "2.8.7"
13 |
14 | [libraries]
15 | androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
16 | junit = { group = "junit", name = "junit", version.ref = "junit" }
17 | androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
18 | androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
19 | androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
20 | material = { group = "com.google.android.material", name = "material", version.ref = "material" }
21 | androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
22 | androidx-navigation-fragment-ktx = { group = "androidx.navigation", name = "navigation-fragment-ktx", version.ref = "navigationFragmentKtx" }
23 | androidx-navigation-ui-ktx = { group = "androidx.navigation", name = "navigation-ui-ktx", version.ref = "navigationUiKtx" }
24 |
25 | [plugins]
26 | android-application = { id = "com.android.application", version.ref = "agp" }
27 | kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
28 |
29 |
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | alias(libs.plugins.android.application)
3 | alias(libs.plugins.kotlin.android)
4 | }
5 |
6 | android {
7 | namespace = "cn.seimo.colorfulpicture"
8 | compileSdk = 35
9 |
10 | defaultConfig {
11 | applicationId = "cn.seimo.colorfulpicture"
12 | minSdk = 24
13 | targetSdk = 35
14 | versionCode = 4
15 | versionName = "1.1.0"
16 |
17 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18 | }
19 |
20 | buildTypes {
21 | release {
22 | isMinifyEnabled = false
23 | proguardFiles(
24 | getDefaultProguardFile("proguard-android-optimize.txt"),
25 | "proguard-rules.pro"
26 | )
27 | }
28 | }
29 | compileOptions {
30 | sourceCompatibility = JavaVersion.VERSION_17
31 | targetCompatibility = JavaVersion.VERSION_17
32 | }
33 | kotlinOptions {
34 | jvmTarget = "17"
35 | }
36 | buildFeatures {
37 | viewBinding = true
38 | }
39 | }
40 |
41 | dependencies {
42 |
43 | implementation(libs.androidx.core.ktx)
44 | implementation(libs.androidx.appcompat)
45 | implementation(libs.material)
46 | implementation(libs.androidx.constraintlayout)
47 | implementation(libs.androidx.navigation.fragment.ktx)
48 | implementation(libs.androidx.navigation.ui.ktx)
49 | implementation("androidx.palette:palette-ktx:1.0.0")
50 | testImplementation(libs.junit)
51 | androidTestImplementation(libs.androidx.junit)
52 | androidTestImplementation(libs.androidx.espresso.core)
53 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
7 |
9 |
10 |
11 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
52 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 缤纷照片
3 | Settings
4 |
5 | First Fragment
6 | Second Fragment
7 | Next
8 | Previous
9 |
10 |
11 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam in scelerisque sem. Mauris
12 | volutpat, dolor id interdum ullamcorper, risus dolor egestas lectus, sit amet mattis purus
13 | dui nec risus. Maecenas non sodales nisi, vel dictum dolor. Class aptent taciti sociosqu ad
14 | litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse blandit eleifend
15 | diam, vel rutrum tellus vulputate quis. Aliquam eget libero aliquet, imperdiet nisl a,
16 | ornare ex. Sed rhoncus est ut libero porta lobortis. Fusce in dictum tellus.\n\n
17 | Suspendisse interdum ornare ante. Aliquam nec cursus lorem. Morbi id magna felis. Vivamus
18 | egestas, est a condimentum egestas, turpis nisl iaculis ipsum, in dictum tellus dolor sed
19 | neque. Morbi tellus erat, dapibus ut sem a, iaculis tincidunt dui. Interdum et malesuada
20 | fames ac ante ipsum primis in faucibus. Curabitur et eros porttitor, ultricies urna vitae,
21 | molestie nibh. Phasellus at commodo eros, non aliquet metus. Sed maximus nisl nec dolor
22 | bibendum, vel congue leo egestas.\n\n
23 | Sed interdum tortor nibh, in sagittis risus mollis quis. Curabitur mi odio, condimentum sit
24 | amet auctor at, mollis non turpis. Nullam pretium libero vestibulum, finibus orci vel,
25 | molestie quam. Fusce blandit tincidunt nulla, quis sollicitudin libero facilisis et. Integer
26 | interdum nunc ligula, et fermentum metus hendrerit id. Vestibulum lectus felis, dictum at
27 | lacinia sit amet, tristique id quam. Cras eu consequat dui. Suspendisse sodales nunc ligula,
28 | in lobortis sem porta sed. Integer id ultrices magna, in luctus elit. Sed a pellentesque
29 | est.\n\n
30 | Aenean nunc velit, lacinia sed dolor sed, ultrices viverra nulla. Etiam a venenatis nibh.
31 | Morbi laoreet, tortor sed facilisis varius, nibh orci rhoncus nulla, id elementum leo dui
32 | non lorem. Nam mollis ipsum quis auctor varius. Quisque elementum eu libero sed commodo. In
33 | eros nisl, imperdiet vel imperdiet et, scelerisque a mauris. Pellentesque varius ex nunc,
34 | quis imperdiet eros placerat ac. Duis finibus orci et est auctor tincidunt. Sed non viverra
35 | ipsum. Nunc quis augue egestas, cursus lorem at, molestie sem. Morbi a consectetur ipsum, a
36 | placerat diam. Etiam vulputate dignissim convallis. Integer faucibus mauris sit amet finibus
37 | convallis.\n\n
38 | Phasellus in aliquet mi. Pellentesque habitant morbi tristique senectus et netus et
39 | malesuada fames ac turpis egestas. In volutpat arcu ut felis sagittis, in finibus massa
40 | gravida. Pellentesque id tellus orci. Integer dictum, lorem sed efficitur ullamcorper,
41 | libero justo consectetur ipsum, in mollis nisl ex sed nisl. Donec maximus ullamcorper
42 | sodales. Praesent bibendum rhoncus tellus nec feugiat. In a ornare nulla. Donec rhoncus
43 | libero vel nunc consequat, quis tincidunt nisl eleifend. Cras bibendum enim a justo luctus
44 | vestibulum. Fusce dictum libero quis erat maximus, vitae volutpat diam dignissim.
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
19 |
20 |
21 |
22 |
27 |
28 |
32 |
33 |
41 |
42 |
53 |
54 |
64 |
65 |
69 |
70 |
82 |
83 |
84 |
85 |
86 |
94 |
95 |
104 |
105 |
110 |
111 |
112 |
119 |
120 |
129 |
130 |
142 |
143 |
151 |
152 |
160 |
161 |
167 |
168 |
169 |
177 |
178 |
184 |
185 |
186 |
195 |
196 |
215 |
216 |
217 |
218 |
219 |
220 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/seimo/colorfulpicture/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package cn.seimo.colorfulpicture
2 |
3 | import android.Manifest
4 | import android.content.Intent
5 | import android.content.pm.PackageManager
6 | import android.graphics.*
7 | import android.graphics.drawable.GradientDrawable
8 | import android.net.Uri
9 | import android.os.Build
10 | import android.os.Bundle
11 | import android.provider.MediaStore
12 | import android.view.View
13 | import android.widget.LinearLayout
14 | import android.widget.SeekBar
15 | import android.widget.Toast
16 | import androidx.activity.result.contract.ActivityResultContracts
17 | import androidx.appcompat.app.AppCompatActivity
18 | import androidx.core.app.ActivityCompat
19 | import androidx.core.content.ContextCompat
20 | import androidx.core.graphics.ColorUtils
21 | import androidx.palette.graphics.Palette
22 | import cn.seimo.colorfulpicture.databinding.ActivityMainBinding
23 | import java.io.FileNotFoundException
24 | import android.media.ExifInterface
25 | import android.util.Log
26 | import android.util.TypedValue
27 | import android.view.Menu
28 | import android.view.MenuItem
29 | import androidx.appcompat.app.AlertDialog
30 | import android.text.Html
31 | import android.text.method.LinkMovementMethod
32 | import android.widget.TextView
33 | import java.io.File
34 | import java.io.FileOutputStream
35 | import android.content.ContentValues
36 | import androidx.core.content.FileProvider
37 |
38 | class MainActivity : AppCompatActivity() {
39 |
40 | private lateinit var binding: ActivityMainBinding
41 | private var selectedImageUri: Uri? = null
42 | private var selectedFrameColor: Int = Color.WHITE
43 | private var dominantColor: Int = Color.WHITE
44 | private var originalBitmap: Bitmap? = null // 保存原始图片
45 | private var isPreviewMode = true // 控制预览模式
46 | private var selectedColorView: View? = null // 跟踪当前选中的颜色视图
47 | private var themeColor: Int = Color.BLUE // 默认主题色
48 | private var isCornerEnabled = false // 是否启用圆角
49 | private var cornerRadiusPercent = 20 // 圆角大小百分比
50 | private var lastGeneratedImagePath: String? = null // 保存最后生成的图片路径
51 |
52 | // 用于请求单个权限
53 | private val requestPermissionLauncher = registerForActivityResult(
54 | ActivityResultContracts.RequestPermission()
55 | ) { isGranted: Boolean ->
56 | if (isGranted) {
57 | // 如果是从选择图片按钮触发的,则打开图片选择器
58 | if (permissionRequestReason == REASON_PICK_IMAGE) {
59 | // 检查是否有分享的图片等待处理
60 | val shareUri = selectedImageUri
61 | if (shareUri != null && intent.action?.startsWith("android.intent.action.SEND") == true) {
62 | // 有分享的图片等待处理
63 | loadImage(shareUri)
64 | } else {
65 | // 没有分享的图片,打开图片选择器
66 | openImagePicker()
67 | }
68 | } else if (permissionRequestReason == REASON_SAVE_IMAGE) {
69 | saveImageToGallery()
70 | }
71 | } else {
72 | Toast.makeText(this, "需要相应权限才能完成操作", Toast.LENGTH_SHORT).show()
73 | }
74 | }
75 |
76 | // 用于请求多个权限
77 | private val requestMultiplePermissionsLauncher = registerForActivityResult(
78 | ActivityResultContracts.RequestMultiplePermissions()
79 | ) { permissions ->
80 | var allGranted = true
81 | permissions.entries.forEach {
82 | if (!it.value) {
83 | allGranted = false
84 | }
85 | }
86 |
87 | if (allGranted) {
88 | Toast.makeText(this, "所有权限已授予", Toast.LENGTH_SHORT).show()
89 | } else {
90 | Toast.makeText(this, "某些权限被拒绝,应用功能可能受限", Toast.LENGTH_SHORT).show()
91 | }
92 | }
93 |
94 | // 图片选择请求
95 | private val getContent = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? ->
96 | uri?.let {
97 | selectedImageUri = it
98 | loadImage(it)
99 | }
100 | }
101 |
102 | // 权限请求原因
103 | private var permissionRequestReason = REASON_NONE
104 |
105 | companion object {
106 | private const val REASON_NONE = 0
107 | private const val REASON_PICK_IMAGE = 1
108 | private const val REASON_SAVE_IMAGE = 2
109 | }
110 |
111 | override fun onCreate(savedInstanceState: Bundle?) {
112 | super.onCreate(savedInstanceState)
113 |
114 | binding = ActivityMainBinding.inflate(layoutInflater)
115 | setContentView(binding.root)
116 |
117 | setSupportActionBar(binding.toolbar)
118 |
119 | // 获取应用主题色
120 | val typedValue = TypedValue()
121 | if (theme.resolveAttribute(android.R.attr.colorAccent, typedValue, true)) {
122 | themeColor = typedValue.data
123 | } else if (theme.resolveAttribute(android.R.attr.colorPrimary, typedValue, true)) {
124 | themeColor = typedValue.data
125 | }
126 |
127 | // 在启动时检查所有权限
128 | checkAndRequestAllPermissions()
129 |
130 | setupListeners()
131 |
132 | // 处理接收到的分享图片
133 | handleReceivedImageIntent(intent)
134 |
135 | // 从保存的状态恢复数据
136 | if (savedInstanceState != null) {
137 | restoreState(savedInstanceState)
138 | }
139 | }
140 |
141 | override fun onNewIntent(intent: Intent) {
142 | super.onNewIntent(intent)
143 | setIntent(intent)
144 | // 处理新接收到的分享图片
145 | handleReceivedImageIntent(intent)
146 | }
147 |
148 | /**
149 | * 处理接收到的图片分享Intent
150 | */
151 | private fun handleReceivedImageIntent(intent: Intent) {
152 | val action = intent.action
153 | val type = intent.type
154 |
155 | if ((Intent.ACTION_SEND == action || Intent.ACTION_SEND_MULTIPLE == action) && type?.startsWith("image/") == true) {
156 | try {
157 | if (Intent.ACTION_SEND == action) {
158 | // 处理单张图片
159 | val imageUri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
160 | intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri::class.java)
161 | } else {
162 | @Suppress("DEPRECATION")
163 | intent.getParcelableExtra(Intent.EXTRA_STREAM) as? Uri
164 | }
165 |
166 | imageUri?.let {
167 | // 需要权限,检查并请求
168 | if (checkAndRequestImagePermission()) {
169 | // 已有权限,直接加载图片
170 | selectedImageUri = it
171 | loadImage(it)
172 | Toast.makeText(this, "已接收分享的图片", Toast.LENGTH_SHORT).show()
173 | } else {
174 | // 在权限授予后会从onCreate/onResume调用,不需额外处理
175 | permissionRequestReason = REASON_PICK_IMAGE
176 | }
177 | }
178 | } else if (Intent.ACTION_SEND_MULTIPLE == action) {
179 | // 处理多张图片(只取第一张)
180 | val imageUris = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
181 | intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM, Uri::class.java)
182 | } else {
183 | @Suppress("DEPRECATION")
184 | intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM)
185 | }
186 |
187 | if (!imageUris.isNullOrEmpty()) {
188 | val firstImageUri = imageUris[0]
189 | // 需要权限,检查并请求
190 | if (checkAndRequestImagePermission()) {
191 | // 已有权限,直接加载图片
192 | selectedImageUri = firstImageUri
193 | loadImage(firstImageUri)
194 | Toast.makeText(this, "已接收分享的图片(仅使用第一张)", Toast.LENGTH_SHORT).show()
195 | } else {
196 | // 在权限授予后会从onCreate/onResume调用,不需额外处理
197 | permissionRequestReason = REASON_PICK_IMAGE
198 | }
199 | }
200 | }
201 | } catch (e: Exception) {
202 | Log.e("ImageShare", "处理分享图片失败: ${e.message}")
203 | Toast.makeText(this, "处理分享图片时出错", Toast.LENGTH_SHORT).show()
204 | }
205 | }
206 | }
207 |
208 | // 保存状态
209 | override fun onSaveInstanceState(outState: Bundle) {
210 | super.onSaveInstanceState(outState)
211 |
212 | // 保存所选图片URI
213 | if (selectedImageUri != null) {
214 | outState.putString("selectedImageUri", selectedImageUri.toString())
215 | }
216 |
217 | // 保存颜色和模式设置
218 | outState.putInt("selectedFrameColor", selectedFrameColor)
219 | outState.putInt("dominantColor", dominantColor)
220 | outState.putBoolean("isPreviewMode", isPreviewMode)
221 |
222 | // 保存圆角设置
223 | outState.putBoolean("isCornerEnabled", isCornerEnabled)
224 | outState.putInt("cornerRadiusPercent", cornerRadiusPercent)
225 |
226 | // 保存文本信息
227 | outState.putString("cameraModel", binding.etCameraModel.text.toString())
228 | outState.putString("photoInfo", binding.etPhotoInfo.text.toString())
229 | }
230 |
231 | // 恢复状态
232 | private fun restoreState(savedInstanceState: Bundle) {
233 | // 恢复所选图片URI
234 | val uriString = savedInstanceState.getString("selectedImageUri")
235 | if (uriString != null) {
236 | selectedImageUri = Uri.parse(uriString)
237 | // 重新加载图片,但不提取颜色(避免重复工作)
238 | selectedImageUri?.let { loadImageFromSavedState(it) }
239 | }
240 |
241 | // 恢复颜色和模式设置
242 | selectedFrameColor = savedInstanceState.getInt("selectedFrameColor", Color.WHITE)
243 | dominantColor = savedInstanceState.getInt("dominantColor", Color.WHITE)
244 | isPreviewMode = savedInstanceState.getBoolean("isPreviewMode", true)
245 |
246 | // 恢复圆角设置
247 | isCornerEnabled = savedInstanceState.getBoolean("isCornerEnabled", false)
248 | cornerRadiusPercent = savedInstanceState.getInt("cornerRadiusPercent", 20)
249 |
250 | // 更新圆角UI状态
251 | binding.switchCorner.isChecked = isCornerEnabled
252 | binding.seekBarCornerRadius.progress = cornerRadiusPercent
253 | binding.seekBarCornerRadius.isEnabled = isCornerEnabled
254 | binding.tvCornerRadius.alpha = if (isCornerEnabled) 1.0f else 0.5f
255 | binding.tvCornerRadiusValue.alpha = if (isCornerEnabled) 1.0f else 0.5f
256 | binding.tvCornerRadiusValue.text = "$cornerRadiusPercent%"
257 |
258 | // 恢复文本信息
259 | binding.etCameraModel.setText(savedInstanceState.getString("cameraModel", ""))
260 | binding.etPhotoInfo.setText(savedInstanceState.getString("photoInfo", ""))
261 |
262 | // 更新预览模式标签
263 | binding.tvPreviewLabel.text = if (isPreviewMode) "实时预览 (点击切换)" else "已暂停预览 (点击切换)"
264 | }
265 |
266 | // 从已保存的状态加载图片,避免重复提取颜色
267 | private fun loadImageFromSavedState(uri: Uri) {
268 | try {
269 | val bitmap = MediaStore.Images.Media.getBitmap(contentResolver, uri)
270 | originalBitmap = bitmap
271 |
272 | if (isPreviewMode) {
273 | updatePreview()
274 | } else {
275 | binding.imagePreview.setImageBitmap(bitmap)
276 | }
277 | } catch (e: Exception) {
278 | Toast.makeText(this, "加载图片失败: ${e.message}", Toast.LENGTH_SHORT).show()
279 | }
280 | }
281 |
282 | private fun setupListeners() {
283 | binding.btnSelectImage.setOnClickListener {
284 | // 检查并请求图片访问权限
285 | permissionRequestReason = REASON_PICK_IMAGE
286 | if (checkAndRequestImagePermission()) {
287 | openImagePicker()
288 | }
289 | }
290 |
291 | binding.btnGenerate.setOnClickListener {
292 | if (selectedImageUri != null) {
293 | permissionRequestReason = REASON_SAVE_IMAGE
294 | if (checkAndRequestStoragePermission()) {
295 | saveImageToGallery()
296 | }
297 | } else {
298 | Toast.makeText(this, "请先选择一张图片", Toast.LENGTH_SHORT).show()
299 | }
300 | }
301 |
302 | // 添加分享按钮点击事件
303 | binding.btnShare.setOnClickListener {
304 | if (selectedImageUri != null) {
305 | if (lastGeneratedImagePath != null) {
306 | // 已有生成的图片,直接分享
307 | shareImage(File(lastGeneratedImagePath!!))
308 | } else {
309 | // 生成图片并分享
310 | generateAndShareImage()
311 | }
312 | } else {
313 | Toast.makeText(this, "请先选择一张图片", Toast.LENGTH_SHORT).show()
314 | }
315 | }
316 |
317 | // 文本框获取焦点时全选内容
318 | binding.etCameraModel.setOnFocusChangeListener { _, hasFocus ->
319 | if (hasFocus && binding.etCameraModel.text?.isNotEmpty() == true) {
320 | binding.etCameraModel.selectAll()
321 | }
322 | }
323 |
324 | binding.etPhotoInfo.setOnFocusChangeListener { _, hasFocus ->
325 | if (hasFocus && binding.etPhotoInfo.text?.isNotEmpty() == true) {
326 | binding.etPhotoInfo.selectAll()
327 | }
328 | }
329 |
330 | // 添加文本变化监听器,实时更新预览
331 | binding.etCameraModel.addTextChangedListener(object : android.text.TextWatcher {
332 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
333 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
334 | override fun afterTextChanged(s: android.text.Editable?) {
335 | updatePreviewTexts()
336 | if (isPreviewMode) {
337 | updatePreview()
338 | }
339 | }
340 | })
341 |
342 | binding.etPhotoInfo.addTextChangedListener(object : android.text.TextWatcher {
343 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
344 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
345 | override fun afterTextChanged(s: android.text.Editable?) {
346 | updatePreviewTexts()
347 | if (isPreviewMode) {
348 | updatePreview()
349 | }
350 | }
351 | })
352 |
353 | // 点击预览图片切换预览模式
354 | binding.imagePreview.setOnClickListener {
355 | togglePreviewMode()
356 | }
357 |
358 | // 点击预览标签也可以切换预览模式
359 | binding.tvPreviewLabel.setOnClickListener {
360 | togglePreviewMode()
361 | }
362 |
363 | // 圆角开关监听器
364 | binding.switchCorner.setOnCheckedChangeListener { _, isChecked ->
365 | isCornerEnabled = isChecked
366 |
367 | // 更新圆角相关控件的可用状态
368 | binding.seekBarCornerRadius.isEnabled = isChecked
369 | binding.tvCornerRadius.alpha = if (isChecked) 1.0f else 0.5f
370 | binding.tvCornerRadiusValue.alpha = if (isChecked) 1.0f else 0.5f
371 |
372 | // 如果在预览模式下,立即更新预览
373 | if (isPreviewMode) {
374 | updatePreview()
375 | }
376 | }
377 |
378 | // 圆角大小拖动条监听器
379 | binding.seekBarCornerRadius.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
380 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
381 | cornerRadiusPercent = progress
382 | binding.tvCornerRadiusValue.text = "$progress%"
383 |
384 | // 如果在预览模式下,立即更新预览
385 | if (isPreviewMode && fromUser) {
386 | updatePreview()
387 | }
388 | }
389 |
390 | override fun onStartTrackingTouch(seekBar: SeekBar?) {}
391 |
392 | override fun onStopTrackingTouch(seekBar: SeekBar?) {}
393 | })
394 |
395 | // 初始化圆角控件状态
396 | binding.seekBarCornerRadius.progress = cornerRadiusPercent
397 | binding.tvCornerRadiusValue.text = "$cornerRadiusPercent%"
398 | binding.switchCorner.isChecked = isCornerEnabled
399 | binding.seekBarCornerRadius.isEnabled = isCornerEnabled
400 | binding.tvCornerRadius.alpha = if (isCornerEnabled) 1.0f else 0.5f
401 | binding.tvCornerRadiusValue.alpha = if (isCornerEnabled) 1.0f else 0.5f
402 | }
403 |
404 | // 打开图片选择器
405 | private fun openImagePicker() {
406 | getContent.launch("image/*")
407 | }
408 |
409 | // 检查并请求所有需要的权限
410 | private fun checkAndRequestAllPermissions() {
411 | val permissionsToRequest = mutableListOf()
412 |
413 | // 根据Android版本请求不同的权限
414 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
415 | // Android 13及以上需要READ_MEDIA_IMAGES权限
416 | if (ContextCompat.checkSelfPermission(
417 | this,
418 | Manifest.permission.READ_MEDIA_IMAGES
419 | ) != PackageManager.PERMISSION_GRANTED
420 | ) {
421 | permissionsToRequest.add(Manifest.permission.READ_MEDIA_IMAGES)
422 | }
423 | } else {
424 | // 低版本Android需要读写外部存储权限
425 | if (ContextCompat.checkSelfPermission(
426 | this,
427 | Manifest.permission.READ_EXTERNAL_STORAGE
428 | ) != PackageManager.PERMISSION_GRANTED
429 | ) {
430 | permissionsToRequest.add(Manifest.permission.READ_EXTERNAL_STORAGE)
431 | }
432 |
433 | if (ContextCompat.checkSelfPermission(
434 | this,
435 | Manifest.permission.WRITE_EXTERNAL_STORAGE
436 | ) != PackageManager.PERMISSION_GRANTED
437 | ) {
438 | permissionsToRequest.add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
439 | }
440 | }
441 |
442 | // 如果有需要请求的权限,则请求
443 | if (permissionsToRequest.isNotEmpty()) {
444 | requestMultiplePermissionsLauncher.launch(permissionsToRequest.toTypedArray())
445 | }
446 | }
447 |
448 | // 检查并请求图片访问权限
449 | private fun checkAndRequestImagePermission(): Boolean {
450 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
451 | // Android 13及以上
452 | if (ContextCompat.checkSelfPermission(
453 | this,
454 | Manifest.permission.READ_MEDIA_IMAGES
455 | ) != PackageManager.PERMISSION_GRANTED
456 | ) {
457 | requestPermissionLauncher.launch(Manifest.permission.READ_MEDIA_IMAGES)
458 | false
459 | } else {
460 | true
461 | }
462 | } else {
463 | // Android 12及以下
464 | if (ContextCompat.checkSelfPermission(
465 | this,
466 | Manifest.permission.READ_EXTERNAL_STORAGE
467 | ) != PackageManager.PERMISSION_GRANTED
468 | ) {
469 | requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE)
470 | false
471 | } else {
472 | true
473 | }
474 | }
475 | }
476 |
477 | // 检查并请求存储权限
478 | private fun checkAndRequestStoragePermission(): Boolean {
479 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
480 | // Android 13及以上使用照片媒体库不需要特殊权限
481 | true
482 | } else {
483 | // Android 12及以下需要写入外部存储权限
484 | if (ContextCompat.checkSelfPermission(
485 | this,
486 | Manifest.permission.WRITE_EXTERNAL_STORAGE
487 | ) != PackageManager.PERMISSION_GRANTED
488 | ) {
489 | requestPermissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE)
490 | false
491 | } else {
492 | true
493 | }
494 | }
495 | }
496 |
497 | private fun loadImage(uri: Uri) {
498 | try {
499 | val bitmap = MediaStore.Images.Media.getBitmap(contentResolver, uri)
500 | originalBitmap = bitmap // 保存原始图片
501 |
502 | // 先显示原始图片
503 | binding.imagePreview.setImageBitmap(bitmap)
504 |
505 | // 尝试从图片EXIF信息中读取相机和照片信息
506 | readExifData(uri)
507 |
508 | // 更新预览中的文本信息(此方法现在为空操作)
509 | updatePreviewTexts()
510 |
511 | // 设置预览模式标签
512 | isPreviewMode = true
513 | binding.tvPreviewLabel.text = "正在加载预览..."
514 |
515 | // 使用Palette库分析图片颜色,并在完成后更新预览
516 | Palette.from(bitmap).generate { palette ->
517 | palette?.let {
518 | // 清除旧的颜色选项
519 | binding.colorContainer.removeAllViews()
520 |
521 | // 提取所有可能的颜色
522 | val colors = mutableListOf()
523 |
524 | // 首先尝试添加明亮的颜色
525 | it.lightVibrantSwatch?.rgb?.let { color -> colors.add(color) }
526 | it.lightMutedSwatch?.rgb?.let { color -> colors.add(color) }
527 |
528 | // 其次添加中等亮度的颜色
529 | it.vibrantSwatch?.rgb?.let { color -> colors.add(color) }
530 | it.mutedSwatch?.rgb?.let { color -> colors.add(color) }
531 |
532 | // 最后添加暗色
533 | it.darkVibrantSwatch?.rgb?.let { color -> colors.add(color) }
534 | it.darkMutedSwatch?.rgb?.let { color -> colors.add(color) }
535 |
536 | // 获取主色调(默认值)
537 | dominantColor = it.getDominantColor(Color.WHITE)
538 | colors.add(dominantColor)
539 |
540 | // 按亮度排序,优先选择浅色
541 | colors.sortByDescending { color ->
542 | val hsl = FloatArray(3)
543 | ColorUtils.colorToHSL(color, hsl)
544 | hsl[2] // 按亮度排序
545 | }
546 |
547 | // 选择排序后的第一个颜色(最浅的)作为默认选中色
548 | if (colors.isNotEmpty()) {
549 | selectedFrameColor = colors[0]
550 | }
551 |
552 | // 添加所有提取的颜色
553 | colors.forEach { color ->
554 | addColorToContainer(color)
555 | }
556 |
557 | // 添加主色调的变体颜色
558 | if (colors.isNotEmpty()) {
559 | addColorVariations(colors[0])
560 | }
561 |
562 | // 在UI线程上更新预览标签和预览图像
563 | runOnUiThread {
564 | binding.tvPreviewLabel.text = "实时预览 (点击切换)"
565 | // 颜色分析完成后更新预览
566 | updatePreview()
567 | }
568 | }
569 | }
570 | } catch (e: FileNotFoundException) {
571 | Toast.makeText(this, "无法加载图片", Toast.LENGTH_SHORT).show()
572 | } catch (e: Exception) {
573 | Toast.makeText(this, "发生错误: ${e.message}", Toast.LENGTH_SHORT).show()
574 | }
575 | }
576 |
577 | /**
578 | * 尝试从图片的EXIF数据中读取相机和照片信息
579 | */
580 | private fun readExifData(uri: Uri) {
581 | try {
582 | contentResolver.openInputStream(uri)?.use { inputStream ->
583 | val exifInterface = ExifInterface(inputStream)
584 |
585 | // 读取相机制造商和型号
586 | val make = exifInterface.getAttribute(ExifInterface.TAG_MAKE) ?: ""
587 | val model = exifInterface.getAttribute(ExifInterface.TAG_MODEL) ?: ""
588 |
589 | // 读取焦距
590 | val focalLength = exifInterface.getAttribute(ExifInterface.TAG_FOCAL_LENGTH)
591 | val focalLengthValue = if (focalLength != null) {
592 | val parts = focalLength.split("/")
593 | if (parts.size == 2) {
594 | try {
595 | val num = parts[0].toFloat()
596 | val den = parts[1].toFloat()
597 | if (den != 0f) "${(num / den).toInt()}mm" else ""
598 | } catch (e: NumberFormatException) {
599 | ""
600 | }
601 | } else {
602 | focalLength
603 | }
604 | } else ""
605 |
606 | // 读取光圈值
607 | val aperture = exifInterface.getAttribute(ExifInterface.TAG_F_NUMBER)
608 | val apertureValue = if (aperture != null) {
609 | val parts = aperture.split("/")
610 | if (parts.size == 2) {
611 | try {
612 | val num = parts[0].toFloat()
613 | val den = parts[1].toFloat()
614 | if (den != 0f) "f/${(num / den)}" else ""
615 | } catch (e: NumberFormatException) {
616 | ""
617 | }
618 | } else {
619 | "f/$aperture"
620 | }
621 | } else ""
622 |
623 | // 读取快门速度
624 | val shutterSpeed = exifInterface.getAttribute(ExifInterface.TAG_EXPOSURE_TIME)
625 | val shutterSpeedValue = if (shutterSpeed != null) {
626 | val floatValue = shutterSpeed.toFloatOrNull()
627 | if (floatValue != null && floatValue > 0) {
628 | if (floatValue >= 1) {
629 | "${floatValue}s"
630 | } else {
631 | "1/${(1 / floatValue).toInt()}s"
632 | }
633 | } else {
634 | ""
635 | }
636 | } else ""
637 |
638 | // 读取ISO值 - 兼容不同Android版本
639 | val iso = when {
640 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> {
641 | // Android 7.0及以上版本
642 | exifInterface.getAttribute(ExifInterface.TAG_ISO_SPEED_RATINGS) ?: ""
643 | }
644 | else -> {
645 | // 低版本Android
646 | exifInterface.getAttribute("ISOSpeedRatings") ?: ""
647 | }
648 | }
649 | val isoValue = if (iso.isNotEmpty()) "ISO$iso" else ""
650 |
651 | // 组合相机信息
652 | val cameraInfo = if (make.isNotEmpty() && model.isNotEmpty()) {
653 | "$make | $model"
654 | } else if (model.isNotEmpty()) {
655 | model
656 | } else if (make.isNotEmpty()) {
657 | make
658 | } else {
659 | "" // 保持为空
660 | }
661 |
662 | // 组合照片信息
663 | val photoInfoParts = listOf(focalLengthValue, apertureValue, shutterSpeedValue, isoValue)
664 | .filter { it.isNotEmpty() }
665 | val photoInfo = photoInfoParts.joinToString(" ")
666 |
667 | // 更新UI
668 | runOnUiThread {
669 | binding.etCameraModel.setText(cameraInfo)
670 | binding.etPhotoInfo.setText(photoInfo)
671 | }
672 | }
673 | } catch (e: Exception) {
674 | Log.e("ExifReader", "读取EXIF信息失败: ${e.message}")
675 | // 读取失败时,设置为空字符串
676 | binding.etCameraModel.setText("")
677 | binding.etPhotoInfo.setText("")
678 | }
679 | }
680 |
681 | private fun updatePreviewTexts() {
682 | // 不再更新预览中的文本,因为视图已移除
683 | // 保留此方法以兼容现有代码,后续可考虑移除
684 | }
685 |
686 | private fun generateColorPalette(bitmap: Bitmap) {
687 | // 此方法不再使用,逻辑已移至loadImage方法中
688 | }
689 |
690 | private fun addColorVariations(color: Int) {
691 | // 生成色相变化的颜色
692 | val hsl = FloatArray(3)
693 | ColorUtils.colorToHSL(color, hsl)
694 |
695 | // 生成不同亮度的变体(偏向浅色)
696 | for (i in 1..3) {
697 | val newHsl = hsl.clone()
698 | newHsl[2] = minOf(0.5f + (i * 0.15f), 0.95f) // 调整亮度,确保偏向浅色
699 | addColorToContainer(ColorUtils.HSLToColor(newHsl))
700 | }
701 |
702 | // 生成不同色相的变体
703 | for (i in 1..5) {
704 | val newHsl = hsl.clone()
705 | newHsl[0] = (newHsl[0] + i * 30) % 360 // 调整色相
706 | // 确保亮度适中偏浅
707 | newHsl[2] = minOf(maxOf(newHsl[2], 0.6f), 0.85f)
708 | addColorToContainer(ColorUtils.HSLToColor(newHsl))
709 | }
710 | }
711 |
712 | private fun addColorToContainer(color: Int) {
713 | val colorView = View(this)
714 | val params = LinearLayout.LayoutParams(100, 100)
715 | params.marginEnd = 16
716 | colorView.layoutParams = params
717 |
718 | // 创建圆角矩形背景
719 | val shape = GradientDrawable()
720 | shape.shape = GradientDrawable.RECTANGLE
721 | shape.cornerRadius = 8f // 设置圆角半径
722 | shape.setColor(color) // 设置颜色
723 |
724 | // 默认边框样式
725 | shape.setStroke(2, Color.LTGRAY) // 浅灰色细边框
726 |
727 | colorView.background = shape
728 |
729 | // 给颜色视图添加点击事件
730 | colorView.setOnClickListener {
731 | // 更新选中颜色
732 | selectedFrameColor = color
733 | // 更新所有颜色视图的边框
734 | updateColorSelection(colorView)
735 | }
736 |
737 | // 如果该颜色与当前选中颜色相同,设置为选中状态
738 | if (color == selectedFrameColor) {
739 | updateColorSelection(colorView)
740 | }
741 |
742 | binding.colorContainer.addView(colorView)
743 | }
744 |
745 | private fun updateColorSelection(newSelectedView: View) {
746 | // 移除旧选中视图的高亮边框
747 | selectedColorView?.let { oldView ->
748 | val oldBackground = oldView.background as? GradientDrawable
749 | oldBackground?.setStroke(2, Color.LTGRAY) // 恢复为浅灰色细边框
750 | }
751 |
752 | // 设置新选中视图的高亮边框
753 | val newBackground = newSelectedView.background as? GradientDrawable
754 | newBackground?.setStroke(4, themeColor) // 使用主题色粗边框
755 |
756 | // 添加阴影效果 (API 21及以上)
757 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
758 | newSelectedView.elevation = 6f // 添加阴影
759 | selectedColorView?.elevation = 0f // 移除旧视图阴影
760 | }
761 |
762 | // 更新当前选中视图引用
763 | selectedColorView = newSelectedView
764 |
765 | // 更新实时预览
766 | if (isPreviewMode) {
767 | updatePreview()
768 | }
769 | }
770 |
771 | private fun saveImageToGallery() {
772 | try {
773 | selectedImageUri?.let { uri ->
774 | // 获取原始图片的位图
775 | val originalBitmap = MediaStore.Images.Media.getBitmap(contentResolver, uri)
776 |
777 | // 创建相框图片
778 | val framedBitmap = createFramedImage(originalBitmap)
779 |
780 | // 获取原始图片的EXIF数据
781 | var exifInterface: ExifInterface? = null
782 | try {
783 | contentResolver.openInputStream(uri)?.use { inputStream ->
784 | exifInterface = ExifInterface(inputStream)
785 | }
786 | } catch (e: Exception) {
787 | Log.e("ExifSaver", "读取原始EXIF数据失败: ${e.message}")
788 | }
789 |
790 | // 保存图片到临时文件并应用EXIF数据
791 | val fileName = "ColorfulPicture_${System.currentTimeMillis()}.jpg"
792 | val outputDir = cacheDir // 使用应用缓存目录
793 | val outputFile = File(outputDir, fileName)
794 |
795 | // 将位图保存到临时文件
796 | val outputStream = FileOutputStream(outputFile)
797 | framedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, outputStream)
798 | outputStream.flush()
799 | outputStream.close()
800 |
801 | // 将EXIF数据写入新图片
802 | if (exifInterface != null) {
803 | try {
804 | val newExif = ExifInterface(outputFile.absolutePath)
805 |
806 | // 复制原始EXIF标签到新图片
807 | copyExifTags(exifInterface!!, newExif)
808 |
809 | // 保存EXIF更改
810 | newExif.saveAttributes()
811 | } catch (e: Exception) {
812 | Log.e("ExifSaver", "写入EXIF数据失败: ${e.message}")
813 | }
814 | }
815 |
816 | // 将图片添加到媒体库
817 | val values = ContentValues().apply {
818 | put(MediaStore.Images.Media.DISPLAY_NAME, fileName)
819 | put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg")
820 | put(MediaStore.Images.Media.TITLE, fileName)
821 | put(MediaStore.Images.Media.DESCRIPTION, "使用ColorfulPicture创建的相框图片")
822 |
823 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
824 | put(MediaStore.Images.Media.RELATIVE_PATH, "Pictures")
825 | put(MediaStore.Images.Media.IS_PENDING, 1)
826 | }
827 | }
828 |
829 | // 插入到媒体库并获取URI
830 | val imageUri = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)
831 |
832 | if (imageUri != null) {
833 | // 将位图数据写入媒体库
834 | contentResolver.openOutputStream(imageUri)?.use { os ->
835 | outputFile.inputStream().use { it.copyTo(os) }
836 | }
837 |
838 | // 对于Android 10及以上版本,标记完成
839 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
840 | values.clear()
841 | values.put(MediaStore.Images.Media.IS_PENDING, 0)
842 | contentResolver.update(imageUri, values, null, null)
843 | }
844 |
845 | // 保存最后生成的图片路径(用于分享)
846 | lastGeneratedImagePath = outputFile.absolutePath
847 |
848 | // 删除临时文件
849 | outputFile.delete()
850 |
851 | Toast.makeText(this, "图片已保存到相册", Toast.LENGTH_SHORT).show()
852 | } else {
853 | Toast.makeText(this, "保存失败: 无法创建媒体条目", Toast.LENGTH_SHORT).show()
854 | }
855 | }
856 | } catch (e: Exception) {
857 | Toast.makeText(this, "保存失败: ${e.message}", Toast.LENGTH_SHORT).show()
858 | Log.e("SaveImage", "保存失败", e)
859 | }
860 | }
861 |
862 | /**
863 | * 生成图片并分享
864 | */
865 | private fun generateAndShareImage() {
866 | try {
867 | selectedImageUri?.let { uri ->
868 | // 获取原始图片的位图
869 | val originalBitmap = MediaStore.Images.Media.getBitmap(contentResolver, uri)
870 |
871 | // 创建相框图片
872 | val framedBitmap = createFramedImage(originalBitmap)
873 |
874 | // 获取原始图片的EXIF数据
875 | var exifInterface: ExifInterface? = null
876 | try {
877 | contentResolver.openInputStream(uri)?.use { inputStream ->
878 | exifInterface = ExifInterface(inputStream)
879 | }
880 | } catch (e: Exception) {
881 | Log.e("ExifSaver", "读取原始EXIF数据失败: ${e.message}")
882 | }
883 |
884 | // 保存图片到临时文件
885 | val fileName = "ColorfulPicture_share_${System.currentTimeMillis()}.jpg"
886 | val outputDir = File(cacheDir, "images")
887 | if (!outputDir.exists()) {
888 | outputDir.mkdirs()
889 | }
890 | val outputFile = File(outputDir, fileName)
891 |
892 | // 将位图保存到临时文件
893 | val outputStream = FileOutputStream(outputFile)
894 | framedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, outputStream)
895 | outputStream.flush()
896 | outputStream.close()
897 |
898 | // 将EXIF数据写入分享图片
899 | if (exifInterface != null) {
900 | try {
901 | val newExif = ExifInterface(outputFile.absolutePath)
902 |
903 | // 复制原始EXIF标签到新图片
904 | copyExifTags(exifInterface!!, newExif)
905 |
906 | // 保存EXIF更改
907 | newExif.saveAttributes()
908 | } catch (e: Exception) {
909 | Log.e("ExifSaver", "写入EXIF数据到分享图片失败: ${e.message}")
910 | }
911 | }
912 |
913 | // 保存最后生成的图片路径
914 | lastGeneratedImagePath = outputFile.absolutePath
915 |
916 | // 分享图片
917 | shareImage(outputFile)
918 | }
919 | } catch (e: Exception) {
920 | Toast.makeText(this, "生成图片失败: ${e.message}", Toast.LENGTH_SHORT).show()
921 | Log.e("ShareImage", "生成失败", e)
922 | }
923 | }
924 |
925 | /**
926 | * 分享图片
927 | */
928 | private fun shareImage(imageFile: File) {
929 | try {
930 | val contentUri = FileProvider.getUriForFile(
931 | this,
932 | "cn.seimo.colorfulpicture.fileprovider",
933 | imageFile
934 | )
935 |
936 | val shareIntent = Intent().apply {
937 | action = Intent.ACTION_SEND
938 | putExtra(Intent.EXTRA_STREAM, contentUri)
939 | type = "image/jpeg"
940 | addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
941 | }
942 |
943 | startActivity(Intent.createChooser(shareIntent, "分享图片"))
944 | } catch (e: Exception) {
945 | Toast.makeText(this, "分享失败: ${e.message}", Toast.LENGTH_SHORT).show()
946 | Log.e("ShareImage", "分享失败", e)
947 | }
948 | }
949 |
950 | /**
951 | * 复制EXIF标签从源到目标
952 | */
953 | private fun copyExifTags(source: ExifInterface, target: ExifInterface) {
954 | // Android支持的基础EXIF标签列表(在所有支持的Android版本中都可用)
955 | val basicTags = arrayOf(
956 | // 设备信息
957 | ExifInterface.TAG_MAKE,
958 | ExifInterface.TAG_MODEL,
959 |
960 | // 拍摄时间信息
961 | ExifInterface.TAG_DATETIME,
962 | ExifInterface.TAG_DATETIME_ORIGINAL,
963 | ExifInterface.TAG_DATETIME_DIGITIZED,
964 |
965 | // 拍摄参数
966 | ExifInterface.TAG_EXPOSURE_TIME,
967 | ExifInterface.TAG_F_NUMBER,
968 | ExifInterface.TAG_ISO_SPEED_RATINGS,
969 | ExifInterface.TAG_SHUTTER_SPEED_VALUE,
970 | ExifInterface.TAG_APERTURE_VALUE,
971 | ExifInterface.TAG_BRIGHTNESS_VALUE,
972 | ExifInterface.TAG_EXPOSURE_BIAS_VALUE,
973 | ExifInterface.TAG_MAX_APERTURE_VALUE,
974 | ExifInterface.TAG_SUBJECT_DISTANCE,
975 | ExifInterface.TAG_METERING_MODE,
976 | ExifInterface.TAG_LIGHT_SOURCE,
977 | ExifInterface.TAG_FLASH,
978 | ExifInterface.TAG_FOCAL_LENGTH,
979 | ExifInterface.TAG_WHITE_BALANCE,
980 |
981 | // 图像信息
982 | ExifInterface.TAG_IMAGE_LENGTH,
983 | ExifInterface.TAG_IMAGE_WIDTH,
984 | ExifInterface.TAG_ORIENTATION,
985 | ExifInterface.TAG_JPEG_INTERCHANGE_FORMAT,
986 | ExifInterface.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH,
987 |
988 | // GPS信息
989 | ExifInterface.TAG_GPS_LATITUDE,
990 | ExifInterface.TAG_GPS_LATITUDE_REF,
991 | ExifInterface.TAG_GPS_LONGITUDE,
992 | ExifInterface.TAG_GPS_LONGITUDE_REF,
993 | ExifInterface.TAG_GPS_ALTITUDE,
994 | ExifInterface.TAG_GPS_ALTITUDE_REF,
995 | ExifInterface.TAG_GPS_TIMESTAMP,
996 | ExifInterface.TAG_GPS_DATESTAMP,
997 |
998 | // 版权和作者信息
999 | ExifInterface.TAG_COPYRIGHT,
1000 | ExifInterface.TAG_ARTIST
1001 | )
1002 |
1003 | // 复制基础标签
1004 | for (tag in basicTags) {
1005 | try {
1006 | val value = source.getAttribute(tag)
1007 | if (value != null) {
1008 | target.setAttribute(tag, value)
1009 | }
1010 | } catch (e: Exception) {
1011 | Log.d("ExifCopy", "复制基础标签[$tag]失败: ${e.message}")
1012 | }
1013 | }
1014 |
1015 | // Android 7.0 (N, API 24)及以上版本支持的额外标签
1016 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
1017 | try {
1018 | val nAndAboveTags = arrayOf(
1019 | ExifInterface.TAG_IMAGE_DESCRIPTION,
1020 | ExifInterface.TAG_EXPOSURE_PROGRAM,
1021 | ExifInterface.TAG_SPECTRAL_SENSITIVITY,
1022 | // Android N开始支持,但有些设备可能不支持
1023 | "PhotoographicSensitivity", // 替代TAG_PHOTOGRAPHIC_SENSITIVITY
1024 | ExifInterface.TAG_OECF,
1025 | ExifInterface.TAG_FOCAL_LENGTH_IN_35MM_FILM,
1026 | ExifInterface.TAG_SCENE_CAPTURE_TYPE,
1027 | ExifInterface.TAG_GAIN_CONTROL,
1028 | ExifInterface.TAG_CONTRAST,
1029 | ExifInterface.TAG_SATURATION,
1030 | ExifInterface.TAG_SHARPNESS,
1031 | ExifInterface.TAG_DEVICE_SETTING_DESCRIPTION,
1032 | ExifInterface.TAG_SUBJECT_DISTANCE_RANGE,
1033 | ExifInterface.TAG_IMAGE_UNIQUE_ID,
1034 | ExifInterface.TAG_EXIF_VERSION,
1035 | ExifInterface.TAG_FLASHPIX_VERSION,
1036 | ExifInterface.TAG_COLOR_SPACE,
1037 | ExifInterface.TAG_PIXEL_X_DIMENSION,
1038 | ExifInterface.TAG_PIXEL_Y_DIMENSION,
1039 | ExifInterface.TAG_COMPONENTS_CONFIGURATION,
1040 | ExifInterface.TAG_COMPRESSED_BITS_PER_PIXEL,
1041 | ExifInterface.TAG_USER_COMMENT,
1042 | ExifInterface.TAG_RELATED_SOUND_FILE,
1043 | ExifInterface.TAG_OFFSET_TIME,
1044 | ExifInterface.TAG_OFFSET_TIME_ORIGINAL,
1045 | ExifInterface.TAG_OFFSET_TIME_DIGITIZED,
1046 | ExifInterface.TAG_SUBSEC_TIME,
1047 | ExifInterface.TAG_SUBSEC_TIME_ORIGINAL,
1048 | ExifInterface.TAG_SUBSEC_TIME_DIGITIZED
1049 | )
1050 |
1051 | for (tag in nAndAboveTags) {
1052 | val value = source.getAttribute(tag)
1053 | if (value != null) {
1054 | target.setAttribute(tag, value)
1055 | }
1056 | }
1057 | } catch (e: Exception) {
1058 | Log.d("ExifCopy", "复制Android N及以上标签失败: ${e.message}")
1059 | }
1060 | }
1061 |
1062 | // Android 10 (Q, API 29)及以上版本支持的标签
1063 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
1064 | try {
1065 | val qAndAboveTags = arrayOf(
1066 | ExifInterface.TAG_GPS_IMG_DIRECTION,
1067 | ExifInterface.TAG_GPS_IMG_DIRECTION_REF,
1068 | ExifInterface.TAG_GPS_TRACK,
1069 | ExifInterface.TAG_GPS_TRACK_REF,
1070 | ExifInterface.TAG_GPS_SPEED,
1071 | ExifInterface.TAG_GPS_SPEED_REF,
1072 | ExifInterface.TAG_GPS_DEST_BEARING,
1073 | ExifInterface.TAG_GPS_DEST_BEARING_REF,
1074 | ExifInterface.TAG_GPS_DEST_DISTANCE,
1075 | ExifInterface.TAG_GPS_DEST_DISTANCE_REF,
1076 | ExifInterface.TAG_GPS_PROCESSING_METHOD,
1077 | ExifInterface.TAG_GPS_AREA_INFORMATION,
1078 | ExifInterface.TAG_GPS_DIFFERENTIAL,
1079 | "GPSHPositioningError", // 替代TAG_GPS_H_POSITIONING_ERROR
1080 | ExifInterface.TAG_INTEROPERABILITY_INDEX,
1081 | ExifInterface.TAG_DNG_VERSION,
1082 | ExifInterface.TAG_DEFAULT_CROP_SIZE
1083 | )
1084 |
1085 | for (tag in qAndAboveTags) {
1086 | val value = source.getAttribute(tag)
1087 | if (value != null) {
1088 | target.setAttribute(tag, value)
1089 | }
1090 | }
1091 | } catch (e: Exception) {
1092 | Log.d("ExifCopy", "复制Android Q及以上标签失败: ${e.message}")
1093 | }
1094 | }
1095 |
1096 | // Android 11 (R, API 30)及以上版本支持的标签
1097 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
1098 | try {
1099 | // 使用字符串常量替代 ExifInterface 中的常量
1100 | val rAndAboveTags = arrayOf(
1101 | "CameraOwnerName", // 替代TAG_CAMERA_OWNER_NAME
1102 | "BodySerialNumber", // 替代TAG_BODY_SERIAL_NUMBER
1103 | "LensSpecification", // 替代TAG_LENS_SPECIFICATION
1104 | "LensMake", // 替代TAG_LENS_MAKE
1105 | "LensModel", // 替代TAG_LENS_MODEL
1106 | "LensSerialNumber" // 替代TAG_LENS_SERIAL_NUMBER
1107 | )
1108 |
1109 | for (tag in rAndAboveTags) {
1110 | val value = source.getAttribute(tag)
1111 | if (value != null) {
1112 | target.setAttribute(tag, value)
1113 | }
1114 | }
1115 | } catch (e: Exception) {
1116 | Log.d("ExifCopy", "复制Android R及以上标签失败: ${e.message}")
1117 | }
1118 | }
1119 |
1120 | // 针对不同Android版本的ISO标签特殊处理
1121 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
1122 | try {
1123 | val isoValue = source.getAttribute("ISOSpeedRatings")
1124 | if (isoValue != null) {
1125 | target.setAttribute("ISOSpeedRatings", isoValue)
1126 | }
1127 | } catch (e: Exception) {
1128 | Log.e("ExifCopy", "复制ISO标签失败: ${e.message}")
1129 | }
1130 | }
1131 |
1132 | // 尝试复制可能的未列出标签 - 尽最大努力捕获所有可能的标签
1133 | try {
1134 | val additionalTags = arrayOf(
1135 | // 一些相机特有标签
1136 | "SerialNumber",
1137 | "LensSerialNumber",
1138 | "ImageNumber",
1139 | "SonyModelID",
1140 | "CanonModelID",
1141 | "NikonModelID",
1142 | "FujiFilmModelID",
1143 | // 一些图像编辑软件可能添加的标签
1144 | "Rating",
1145 | "Software",
1146 | "HostComputer"
1147 | )
1148 |
1149 | for (tag in additionalTags) {
1150 | val value = source.getAttribute(tag)
1151 | if (value != null) {
1152 | target.setAttribute(tag, value)
1153 | }
1154 | }
1155 | } catch (e: Exception) {
1156 | Log.d("ExifCopy", "复制额外标签失败: ${e.message}")
1157 | }
1158 | }
1159 |
1160 | private fun createFramedImage(originalBitmap: Bitmap): Bitmap {
1161 | val cameraInfo = binding.etCameraModel.text.toString()
1162 | val photoInfo = binding.etPhotoInfo.text.toString()
1163 |
1164 | // 计算不同边框宽度
1165 | val sideWidth = originalBitmap.width * 0.01f // 左右边框较窄
1166 | val topWidth = originalBitmap.width * 0.01f // 顶部边框较窄
1167 | val bottomWidth = originalBitmap.width * 0.12f // 底部边框较宽
1168 |
1169 | // 计算输出图片的总尺寸
1170 | val totalWidth = originalBitmap.width + 2 * sideWidth.toInt()
1171 | val totalHeight = originalBitmap.height + topWidth.toInt() + bottomWidth.toInt()
1172 |
1173 | // 创建新的位图
1174 | val outputBitmap = Bitmap.createBitmap(totalWidth.toInt(), totalHeight.toInt(), Bitmap.Config.ARGB_8888)
1175 | val canvas = Canvas(outputBitmap)
1176 |
1177 | // 计算圆角半径
1178 | val cornerRadius = if (isCornerEnabled && cornerRadiusPercent > 0) {
1179 | originalBitmap.width * (cornerRadiusPercent / 100f) * 0.03f
1180 | } else {
1181 | 0f
1182 | }
1183 |
1184 | // 绘制带圆角的边框(相框背景)
1185 | val backgroundPaint = Paint().apply {
1186 | color = selectedFrameColor
1187 | style = Paint.Style.FILL
1188 | isAntiAlias = true
1189 | }
1190 |
1191 | // 创建一个矩形,用于绘制整个相框
1192 | val rectF = RectF(0f, 0f, totalWidth.toFloat(), totalHeight.toFloat())
1193 |
1194 | // 如果启用了圆角,绘制带圆角的矩形;否则绘制普通矩形
1195 | if (cornerRadius > 0) {
1196 | canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, backgroundPaint)
1197 | } else {
1198 | canvas.drawRect(rectF, backgroundPaint)
1199 | }
1200 |
1201 | // 处理照片圆角
1202 | if (isCornerEnabled && cornerRadiusPercent > 0) {
1203 | // 创建一个带圆角的位图
1204 | val roundedBitmap = getRoundedCornerBitmap(originalBitmap, cornerRadius)
1205 |
1206 | // 绘制圆角图片
1207 | canvas.drawBitmap(
1208 | roundedBitmap,
1209 | sideWidth,
1210 | topWidth,
1211 | null
1212 | )
1213 | } else {
1214 | // 绘制原始图片(无圆角)
1215 | canvas.drawBitmap(
1216 | originalBitmap,
1217 | sideWidth,
1218 | topWidth,
1219 | null
1220 | )
1221 | }
1222 |
1223 | // 生成文字颜色
1224 | val textColor = getComplementaryTextColor(selectedFrameColor)
1225 |
1226 | // 创建文本画笔
1227 | val textPaint = Paint().apply {
1228 | color = textColor
1229 | // 使用系统默认字体的粗体变体
1230 | typeface = Typeface.create(Typeface.DEFAULT_BOLD, Typeface.BOLD)
1231 | isAntiAlias = true // 启用抗锯齿,使文字更平滑
1232 | }
1233 |
1234 | // 计算智能文字大小
1235 | val textSettings = calculateOptimalTextSize(
1236 | cameraInfo,
1237 | photoInfo,
1238 | totalWidth.toFloat(),
1239 | bottomWidth,
1240 | sideWidth
1241 | )
1242 |
1243 | textPaint.textSize = textSettings.textSize
1244 |
1245 | // 计算字体指标,用于垂直居中
1246 | val fontMetrics = textPaint.fontMetrics
1247 | // 文字基线到字体顶部的距离
1248 | val textHeight = fontMetrics.bottom - fontMetrics.top
1249 |
1250 | // 计算文字垂直居中位置
1251 | // 图片底部 + 底部边框高度的一半 + 文字基线偏移(文字高度一半 - 基线到底部距离)
1252 | val textY = (originalBitmap.height + topWidth.toInt()) +
1253 | (bottomWidth / 2) +
1254 | ((textHeight / 2) - fontMetrics.bottom)
1255 |
1256 | // 左下角绘制相机信息 - 垂直居中
1257 | textPaint.textAlign = Paint.Align.LEFT
1258 | canvas.drawText(
1259 | textSettings.leftText,
1260 | sideWidth * 3.0f, // 增加左侧边距
1261 | textY,
1262 | textPaint
1263 | )
1264 |
1265 | // 右下角绘制照片信息 - 垂直居中
1266 | textPaint.textAlign = Paint.Align.RIGHT
1267 | canvas.drawText(
1268 | textSettings.rightText,
1269 | totalWidth - sideWidth * 3.0f, // 增加右侧边距
1270 | textY,
1271 | textPaint
1272 | )
1273 |
1274 | return outputBitmap
1275 | }
1276 |
1277 | /**
1278 | * 创建带圆角的位图
1279 | */
1280 | private fun getRoundedCornerBitmap(bitmap: Bitmap, radius: Float): Bitmap {
1281 | val output = Bitmap.createBitmap(
1282 | bitmap.width,
1283 | bitmap.height,
1284 | Bitmap.Config.ARGB_8888
1285 | )
1286 | val canvas = Canvas(output)
1287 |
1288 | val paint = Paint().apply {
1289 | isAntiAlias = true
1290 | color = Color.BLACK
1291 | }
1292 |
1293 | val rect = Rect(0, 0, bitmap.width, bitmap.height)
1294 | val rectF = RectF(rect)
1295 |
1296 | canvas.drawRoundRect(rectF, radius, radius, paint)
1297 |
1298 | paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN)
1299 | canvas.drawBitmap(bitmap, rect, rect, paint)
1300 |
1301 | return output
1302 | }
1303 |
1304 | /**
1305 | * 获取与背景色相协调的文字颜色
1306 | * 如果背景是深色,返回相近的浅色
1307 | * 如果背景是浅色,返回相近的深色
1308 | */
1309 | private fun getComplementaryTextColor(backgroundColor: Int): Int {
1310 | val hsl = FloatArray(3)
1311 | ColorUtils.colorToHSL(backgroundColor, hsl)
1312 |
1313 | // 判断背景是浅色还是深色
1314 | val isBackgroundDark = hsl[2] < 0.5f
1315 |
1316 | // 保持色相和饱和度,调整亮度
1317 | if (isBackgroundDark) {
1318 | // 如果背景是深色,生成一个相近的浅色
1319 | hsl[2] = 0.85f // 高亮度
1320 | } else {
1321 | // 如果背景是浅色,生成一个相近的深色
1322 | hsl[2] = 0.25f // 低亮度
1323 | }
1324 |
1325 | return ColorUtils.HSLToColor(hsl)
1326 | }
1327 |
1328 | /**
1329 | * 切换原始图片和预览模式
1330 | */
1331 | private fun togglePreviewMode() {
1332 | isPreviewMode = !isPreviewMode
1333 |
1334 | if (isPreviewMode) {
1335 | // 切换到预览模式
1336 | binding.tvPreviewLabel.text = "实时预览 (点击切换)"
1337 | updatePreview()
1338 | } else {
1339 | // 切换到原始图片
1340 | binding.tvPreviewLabel.text = "原始图片 (点击查看预览)"
1341 | originalBitmap?.let {
1342 | binding.imagePreview.setImageBitmap(it)
1343 | }
1344 | }
1345 | }
1346 |
1347 | /**
1348 | * 更新实时预览图像
1349 | */
1350 | private fun updatePreview() {
1351 | originalBitmap?.let { bitmap ->
1352 | try {
1353 | // 计算预览图片尺寸,保持比例
1354 | val displayMetrics = resources.displayMetrics
1355 | val screenWidth = displayMetrics.widthPixels - (32 * displayMetrics.density).toInt() // 减去边距
1356 |
1357 | // 根据屏幕宽度和原始比例计算高度
1358 | val ratio = bitmap.height.toFloat() / bitmap.width.toFloat()
1359 | val previewWidth = screenWidth
1360 | val previewHeight = (screenWidth * ratio).toInt()
1361 |
1362 | // 限制最大高度
1363 | val maxHeight = (400 * displayMetrics.density).toInt()
1364 | val finalHeight = minOf(previewHeight, maxHeight)
1365 | val finalWidth = if (previewHeight > maxHeight) {
1366 | (maxHeight / ratio).toInt()
1367 | } else {
1368 | previewWidth
1369 | }
1370 |
1371 | // 创建预览图片
1372 | val scaledBitmap = Bitmap.createScaledBitmap(bitmap, finalWidth, finalHeight, true)
1373 |
1374 | // 生成预览相框图像
1375 | val framedBitmap = createFramedImagePreview(scaledBitmap)
1376 |
1377 | // 更新预览
1378 | binding.imagePreview.setImageBitmap(framedBitmap)
1379 | } catch (e: Exception) {
1380 | // 如果预览生成失败,使用原始图像
1381 | Toast.makeText(this, "预览生成失败: ${e.message}", Toast.LENGTH_SHORT).show()
1382 | binding.imagePreview.setImageBitmap(bitmap)
1383 | }
1384 | }
1385 | }
1386 |
1387 | /**
1388 | * 为预览创建相框图像,与最终输出版本略有不同
1389 | */
1390 | private fun createFramedImagePreview(originalBitmap: Bitmap): Bitmap {
1391 | val cameraInfo = binding.etCameraModel.text.toString()
1392 | val photoInfo = binding.etPhotoInfo.text.toString()
1393 |
1394 | // 使用与最终生成图片相同的边框宽度
1395 | val sideWidth = originalBitmap.width * 0.01f // 左右边框较窄
1396 | val topWidth = originalBitmap.width * 0.01f // 顶部边框较窄
1397 | val bottomWidth = originalBitmap.width * 0.12f // 底部边框较宽
1398 |
1399 | // 计算输出图片的总尺寸
1400 | val totalWidth = originalBitmap.width + 2 * sideWidth.toInt()
1401 | val totalHeight = originalBitmap.height + topWidth.toInt() + bottomWidth.toInt()
1402 |
1403 | // 创建新的位图
1404 | val outputBitmap = Bitmap.createBitmap(totalWidth.toInt(), totalHeight.toInt(), Bitmap.Config.ARGB_8888)
1405 | val canvas = Canvas(outputBitmap)
1406 |
1407 | // 计算圆角半径
1408 | val cornerRadius = if (isCornerEnabled && cornerRadiusPercent > 0) {
1409 | originalBitmap.width * (cornerRadiusPercent / 100f) * 0.03f
1410 | } else {
1411 | 0f
1412 | }
1413 |
1414 | // 绘制带圆角的边框(相框背景)
1415 | val backgroundPaint = Paint().apply {
1416 | color = selectedFrameColor
1417 | style = Paint.Style.FILL
1418 | isAntiAlias = true
1419 | }
1420 |
1421 | // 创建一个矩形,用于绘制整个相框
1422 | val rectF = RectF(0f, 0f, totalWidth.toFloat(), totalHeight.toFloat())
1423 |
1424 | // 如果启用了圆角,绘制带圆角的矩形;否则绘制普通矩形
1425 | if (cornerRadius > 0) {
1426 | canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, backgroundPaint)
1427 | } else {
1428 | canvas.drawRect(rectF, backgroundPaint)
1429 | }
1430 |
1431 | // 处理照片圆角
1432 | if (isCornerEnabled && cornerRadiusPercent > 0) {
1433 | // 创建一个带圆角的位图
1434 | val roundedBitmap = getRoundedCornerBitmap(originalBitmap, cornerRadius)
1435 |
1436 | // 绘制圆角图片
1437 | canvas.drawBitmap(
1438 | roundedBitmap,
1439 | sideWidth,
1440 | topWidth,
1441 | null
1442 | )
1443 | } else {
1444 | // 绘制原始图片(无圆角)
1445 | canvas.drawBitmap(
1446 | originalBitmap,
1447 | sideWidth,
1448 | topWidth,
1449 | null
1450 | )
1451 | }
1452 |
1453 | // 生成文字颜色
1454 | val textColor = getComplementaryTextColor(selectedFrameColor)
1455 |
1456 | // 创建文本画笔
1457 | val textPaint = Paint().apply {
1458 | color = textColor
1459 | // 使用系统默认字体的粗体变体
1460 | typeface = Typeface.create(Typeface.DEFAULT_BOLD, Typeface.BOLD)
1461 | isAntiAlias = true // 启用抗锯齿,使文字更平滑
1462 | }
1463 |
1464 | // 使用与最终图像相同的文字大小计算方法
1465 | val textSettings = calculateOptimalTextSize(
1466 | cameraInfo,
1467 | photoInfo,
1468 | totalWidth.toFloat(),
1469 | bottomWidth,
1470 | sideWidth
1471 | )
1472 |
1473 | textPaint.textSize = textSettings.textSize
1474 |
1475 | // 计算字体指标,用于垂直居中
1476 | val fontMetrics = textPaint.fontMetrics
1477 | // 文字基线到字体顶部的距离
1478 | val textHeight = fontMetrics.bottom - fontMetrics.top
1479 |
1480 | // 计算文字垂直居中位置
1481 | // 图片底部 + 底部边框高度的一半 + 文字基线偏移(文字高度一半 - 基线到底部距离)
1482 | val textY = (originalBitmap.height + topWidth.toInt()) +
1483 | (bottomWidth / 2) +
1484 | ((textHeight / 2) - fontMetrics.bottom)
1485 |
1486 | // 左下角绘制相机信息 - 垂直居中
1487 | textPaint.textAlign = Paint.Align.LEFT
1488 | canvas.drawText(
1489 | textSettings.leftText,
1490 | sideWidth * 3.0f, // 增加左侧边距
1491 | textY,
1492 | textPaint
1493 | )
1494 |
1495 | // 右下角绘制照片信息 - 垂直居中
1496 | textPaint.textAlign = Paint.Align.RIGHT
1497 | canvas.drawText(
1498 | textSettings.rightText,
1499 | totalWidth - sideWidth * 3.0f, // 增加右侧边距
1500 | textY,
1501 | textPaint
1502 | )
1503 |
1504 | return outputBitmap
1505 | }
1506 |
1507 | /**
1508 | * 根据文本长度和图片宽度计算最佳文字大小和处理后的文本
1509 | */
1510 | private fun calculateOptimalTextSize(
1511 | leftText: String,
1512 | rightText: String,
1513 | totalWidth: Float,
1514 | bottomHeight: Float,
1515 | sideWidth: Float
1516 | ): TextSettings {
1517 | // 临时画笔用于文本测量
1518 | val tempPaint = Paint().apply {
1519 | typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
1520 | }
1521 |
1522 | // 计算基础字体大小因素
1523 | val totalChars = leftText.length + rightText.length
1524 | val availableWidth = totalWidth - (sideWidth * 6.0f) // 考虑更大的两侧边距
1525 |
1526 | // 字符密度因子 - 字符数与可用宽度的比率
1527 | val charDensity = totalChars / availableWidth
1528 |
1529 | // 基于图片宽度和字符密度动态计算初始字体大小
1530 | var baseTextSize = bottomHeight * 0.4f // 基础大小
1531 |
1532 | // 考虑字符密度调整大小
1533 | if (charDensity > 0.1f) {
1534 | // 字符密度较高,适当缩小字体
1535 | baseTextSize *= (1f - (charDensity * 2f)).coerceIn(0.35f, 0.9f)
1536 | }
1537 |
1538 | // 确保字体大小下限
1539 | val minTextSize = (bottomHeight * 0.2f).coerceAtLeast(12f)
1540 | baseTextSize = baseTextSize.coerceAtLeast(minTextSize)
1541 |
1542 | // 设置测量字体大小
1543 | tempPaint.textSize = baseTextSize
1544 |
1545 | // 计算两侧文本最大可用宽度(考虑中间间隙)
1546 | val sideMaxWidth = (availableWidth * 0.45f).coerceAtMost(totalWidth * 0.4f)
1547 |
1548 | // 测量文本宽度
1549 | val leftWidth = tempPaint.measureText(leftText)
1550 | val rightWidth = tempPaint.measureText(rightText)
1551 |
1552 | // 如果任一文本超出最大宽度,进一步调整字体大小或截断文本
1553 | var finalLeftText = leftText
1554 | var finalRightText = rightText
1555 | var finalTextSize = baseTextSize
1556 |
1557 | if (leftWidth > sideMaxWidth || rightWidth > sideMaxWidth) {
1558 | // 先尝试适度缩小字体
1559 | val leftScale = if (leftWidth > 0) sideMaxWidth / leftWidth else 1f
1560 | val rightScale = if (rightWidth > 0) sideMaxWidth / rightWidth else 1f
1561 | val scale = minOf(leftScale, rightScale)
1562 |
1563 | // 如果缩放不会导致字体过小,则缩放字体
1564 | if (baseTextSize * scale >= minTextSize) {
1565 | finalTextSize = baseTextSize * scale
1566 | } else {
1567 | // 字体已经达到最小,需要截断文本
1568 | finalTextSize = minTextSize
1569 | tempPaint.textSize = finalTextSize
1570 |
1571 | // 处理左侧文本
1572 | if (tempPaint.measureText(leftText) > sideMaxWidth && leftText.length > 5) {
1573 | val ellipsis = "..."
1574 | var shortened = leftText
1575 | while (tempPaint.measureText(shortened + ellipsis) > sideMaxWidth && shortened.length > 3) {
1576 | shortened = shortened.substring(0, shortened.length - 1)
1577 | }
1578 | finalLeftText = shortened + ellipsis
1579 | }
1580 |
1581 | // 处理右侧文本
1582 | if (tempPaint.measureText(rightText) > sideMaxWidth && rightText.length > 5) {
1583 | val ellipsis = "..."
1584 | var shortened = rightText
1585 | while (tempPaint.measureText(ellipsis + shortened) > sideMaxWidth && shortened.length > 3) {
1586 | shortened = shortened.substring(1)
1587 | }
1588 | finalRightText = ellipsis + shortened
1589 | }
1590 | }
1591 | }
1592 |
1593 | return TextSettings(finalTextSize, finalLeftText, finalRightText)
1594 | }
1595 |
1596 | /**
1597 | * 文字设置数据类
1598 | */
1599 | private data class TextSettings(
1600 | val textSize: Float,
1601 | val leftText: String,
1602 | val rightText: String
1603 | )
1604 |
1605 | private fun max(a: Float, b: Float): Float {
1606 | return if (a > b) a else b
1607 | }
1608 |
1609 | override fun onCreateOptionsMenu(menu: Menu): Boolean {
1610 | // 加载菜单资源
1611 | menuInflater.inflate(R.menu.menu_main, menu)
1612 | return true
1613 | }
1614 |
1615 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
1616 | return when (item.itemId) {
1617 | R.id.action_about -> {
1618 | showAboutDialog()
1619 | true
1620 | }
1621 | else -> super.onOptionsItemSelected(item)
1622 | }
1623 | }
1624 |
1625 | private fun showAboutDialog() {
1626 | val aboutContent = """
1627 |