-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 添加submodule * 接入capturable * 调通 * 实现结果页截图(但还没实现长截图) * 实现长截图 * 实现长截图 * fix bug that capture before requests collection was not handled * modify build.gradle.kts * update workflows * Update about libraries * update workflows * 截图添加背景色 * update workflows * cleanup * update workflows * 修复安卓崩溃 * 支持保存后打开或分享 --------- Co-authored-by: ssttkkl <[email protected]>
- Loading branch information
Showing
38 changed files
with
829 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,12 +35,16 @@ jobs: | |
steps: | ||
- name: Checkout my repository | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: 'true' | ||
|
||
- name: Setup Java JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
java-version: | | ||
11 | ||
17 | ||
cache: 'gradle' | ||
|
||
- name: Package Distribution | ||
|
@@ -69,12 +73,16 @@ jobs: | |
steps: | ||
- name: Checkout my repository | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: 'true' | ||
|
||
- name: Setup Java JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
java-version: | | ||
11 | ||
17 | ||
cache: 'gradle' | ||
|
||
- name: Package Distribution | ||
|
@@ -103,12 +111,16 @@ jobs: | |
steps: | ||
- name: Checkout my repository | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: 'true' | ||
|
||
- name: Setup Java JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
java-version: | | ||
11 | ||
17 | ||
cache: 'gradle' | ||
|
||
- name: Install FUSE (linux) | ||
|
@@ -125,12 +137,12 @@ jobs: | |
with: | ||
name: distribution | ||
path: | | ||
composeApp/build/appimage/mahjong-utils-app.AppImage | ||
composeApp/build/appimage/main-release/mahjong-utils-app.AppImage | ||
composeApp/build/compose/jars/*.jar | ||
- name: Upload Release Assets | ||
if: ${{ github.event_name == 'release' }} | ||
uses: AButler/[email protected] | ||
with: | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
files: "composeApp/build/appimage/*.AppImage;composeApp/build/compose/jars/*.jar" | ||
files: "composeApp/build/appimage/main-release/*.AppImage;composeApp/build/compose/jars/*.jar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "external/mahjong-utils"] | ||
path = external/mahjong-utils | ||
url = https://github.com/ssttkkl/mahjong-utils | ||
[submodule "external/Capturable"] | ||
path = external/Capturable | ||
url = https://github.com/ssttkkl/Capturable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
composeApp/src/androidMain/kotlin/io/ssttkkl/mahjongutils/app/MyApp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
composeApp/src/androidMain/kotlin/io/ssttkkl/mahjongutils/app/utils/ActivityHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.ssttkkl.mahjongutils.app.utils | ||
|
||
import android.app.Activity | ||
import java.lang.ref.WeakReference | ||
|
||
object ActivityHelper { | ||
private var currentActivityRef: WeakReference<Activity>? = null | ||
|
||
var currentActivity: Activity? | ||
get() = currentActivityRef?.get() | ||
set(value) { | ||
currentActivityRef = WeakReference(value) | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
...eApp/src/androidMain/kotlin/io/ssttkkl/mahjongutils/app/utils/image/ImageUtils.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package io.ssttkkl.mahjongutils.app.utils.image | ||
|
||
import android.content.ContentValues | ||
import android.content.Intent | ||
import android.graphics.Bitmap | ||
import android.graphics.Canvas | ||
import android.graphics.Paint | ||
import android.net.Uri | ||
import android.os.Environment | ||
import android.provider.MediaStore | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.graphics.asAndroidBitmap | ||
import androidx.compose.ui.graphics.asImageBitmap | ||
import androidx.compose.ui.graphics.toArgb | ||
import androidx.core.content.ContextCompat.startActivity | ||
import io.ssttkkl.mahjongutils.app.MyApp | ||
import io.ssttkkl.mahjongutils.app.utils.ActivityHelper | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
|
||
actual suspend fun platformWithBackground( | ||
imageBitmap: ImageBitmap, | ||
background: Color | ||
): ImageBitmap { | ||
val newBitmap = | ||
Bitmap.createBitmap(imageBitmap.width, imageBitmap.height, Bitmap.Config.ARGB_8888) | ||
val canvas = Canvas(newBitmap) | ||
|
||
// 绘制背景 | ||
val paintBackground = Paint().apply { | ||
color = background.toArgb() | ||
style = Paint.Style.FILL | ||
} | ||
canvas.drawRect( | ||
0f, | ||
0f, | ||
imageBitmap.width.toFloat(), | ||
imageBitmap.height.toFloat(), | ||
paintBackground | ||
) | ||
|
||
// 将原始硬件位图转换为软件位图 | ||
val softwareBitmap = imageBitmap.asAndroidBitmap().copy(Bitmap.Config.ARGB_8888, false) | ||
// 绘制原始位图 | ||
canvas.drawBitmap(softwareBitmap, 0f, 0f, null) | ||
|
||
return newBitmap.asImageBitmap() | ||
} | ||
|
||
actual class SaveResult(val uri: Uri, val title: String) { | ||
actual val isSupportOpen: Boolean | ||
get() = true | ||
actual val isSupportShare: Boolean | ||
get() = true | ||
|
||
actual suspend fun open() { | ||
// 创建Intent以打开图片 | ||
val intent = Intent().apply { | ||
action = Intent.ACTION_VIEW | ||
setDataAndType(uri, "image/png") // 设置MIME类型 | ||
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION // 给予读权限 | ||
} | ||
|
||
// 启动Intent | ||
ActivityHelper.currentActivity?.startActivity(intent) | ||
} | ||
|
||
actual suspend fun share() { | ||
// 创建分享意图 | ||
val shareIntent = Intent().apply { | ||
action = Intent.ACTION_SEND | ||
putExtra(Intent.EXTRA_STREAM, uri) // 附加 URI | ||
type = "image/png" // 或 "image/jpeg" 根据实际情况 | ||
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION // 给予读权限 | ||
} | ||
|
||
// 启动分享意图 | ||
ActivityHelper.currentActivity?.startActivity(Intent.createChooser(shareIntent, title)) | ||
} | ||
} | ||
|
||
actual object ImageUtils : CommonImageUtils() { | ||
actual suspend fun save(imageBitmap: ImageBitmap, title: String): SaveResult? { | ||
return withContext(Dispatchers.IO) { | ||
val values = ContentValues().apply { | ||
put(MediaStore.Images.Media.DISPLAY_NAME, title) | ||
put(MediaStore.Images.Media.MIME_TYPE, "image/png") | ||
put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_PICTURES) | ||
put(MediaStore.Images.Media.IS_PENDING, 1) | ||
} | ||
|
||
val uri: Uri = MyApp.current.contentResolver.insert( | ||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, | ||
values | ||
) ?: return@withContext null | ||
|
||
try { | ||
MyApp.current.contentResolver.openOutputStream(uri)?.use { | ||
imageBitmap.asAndroidBitmap().compress(Bitmap.CompressFormat.PNG, 100, it) | ||
} ?: return@withContext null | ||
values.clear() | ||
values.put(MediaStore.Images.Media.IS_PENDING, 0) | ||
MyApp.current.contentResolver.update(uri, values, null, null) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
return@withContext null | ||
} | ||
return@withContext SaveResult(uri, title) | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
composeApp/src/commonMain/composeResources/files/aboutlibraries.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.