From 2549d7a8c85e1d4dea2331b5b0d107250c768a39 Mon Sep 17 00:00:00 2001 From: zgf Date: Sat, 18 May 2024 18:15:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=9B=BE=E7=89=87=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zgf --- CHANGELOG.md | 3 + build-profile.json5 | 16 +++- entry/oh-package.json5 | 2 +- .../main/ets/common/CustomEngineKeyImpl.ets | 4 +- .../main/ets/entryability/EntryAbility.ets | 5 +- .../main/ets/pages/ImageTransformation.ets | 2 +- entry/src/main/ets/pages/Index.ets | 6 ++ entry/src/main/ets/pages/ListPage.ets | 2 +- entry/src/main/ets/pages/LoadStatePage.ets | 2 +- entry/src/main/ets/pages/LongImagePage.ets | 2 +- .../src/main/ets/pages/ManyPhotoShowPage.ets | 2 +- entry/src/main/ets/pages/ObjectFitPage.ets | 2 +- .../src/main/ets/pages/SignatureTestPage.ets | 2 +- entry/src/main/ets/pages/SingleImage.ets | 2 +- entry/src/main/ets/pages/TestHeader.ets | 2 +- .../main/ets/pages/TestHspPreLoadImage.ets | 25 +++++ entry/src/main/ets/pages/TestImageFlash.ets | 2 +- entry/src/main/ets/pages/TestIsUrlExist.ets | 2 +- .../ets/pages/TestPrefetchToFileCache.ets | 2 +- .../main/ets/pages/TestWriteCacheStage.ets | 2 +- entry/src/main/ets/pages/TransformPage.ets | 2 +- entry/src/main/ets/pages/User.ets | 2 +- .../src/main/resources/base/media/rabbit.gif | Bin 0 -> 10208 bytes .../resources/base/profile/main_pages.json | 3 +- library/index.ets | 4 +- library/src/main/ets/ImageKnife.ets | 4 + library/src/main/ets/ImageKnifeDispatcher.ets | 63 ++++++++---- library/src/main/ets/ImageKnifeOption.ets | 2 +- library/src/main/ets/model/ImageKnifeData.ets | 2 + library/src/main/ets/utils/MemoryLruCache.ets | 1 + sharedlibrary/.gitignore | 6 ++ sharedlibrary/Index.ets | 33 +++++++ sharedlibrary/build-profile.json5 | 28 ++++++ sharedlibrary/hvigorfile.ts | 6 ++ sharedlibrary/obfuscation-rules.txt | 18 ++++ sharedlibrary/oh-package.json5 | 12 +++ sharedlibrary/src/main/ets/pages/Index.ets | 39 ++++++++ .../src/main/ets/pages/InitImageKnife.ets | 21 ++++ sharedlibrary/src/main/ets/utils/Calc.ets | 3 + sharedlibrary/src/main/module.json5 | 14 +++ .../main/resources/base/element/color.json | 8 ++ .../main/resources/base/element/string.json | 8 ++ .../resources/base/profile/main_pages.json | 5 + sharedlibrary/src/mock/mock-config.json5 | 2 + .../src/ohosTest/ets/test/Ability.test.ets | 35 +++++++ .../src/ohosTest/ets/test/List.test.ets | 5 + .../ohosTest/ets/testability/TestAbility.ets | 47 +++++++++ .../ohosTest/ets/testability/pages/Index.ets | 17 ++++ .../ets/testrunner/OpenHarmonyTestRunner.ets | 90 ++++++++++++++++++ sharedlibrary/src/ohosTest/module.json5 | 38 ++++++++ .../resources/base/element/color.json | 8 ++ .../resources/base/element/string.json | 16 ++++ .../ohosTest/resources/base/media/icon.png | Bin 0 -> 2777 bytes .../resources/base/profile/test_pages.json | 5 + sharedlibrary/src/test/List.test.ets | 5 + sharedlibrary/src/test/LocalUnit.test.ets | 33 +++++++ 56 files changed, 630 insertions(+), 42 deletions(-) create mode 100644 entry/src/main/ets/pages/TestHspPreLoadImage.ets create mode 100644 entry/src/main/resources/base/media/rabbit.gif create mode 100644 sharedlibrary/.gitignore create mode 100644 sharedlibrary/Index.ets create mode 100644 sharedlibrary/build-profile.json5 create mode 100644 sharedlibrary/hvigorfile.ts create mode 100644 sharedlibrary/obfuscation-rules.txt create mode 100644 sharedlibrary/oh-package.json5 create mode 100644 sharedlibrary/src/main/ets/pages/Index.ets create mode 100644 sharedlibrary/src/main/ets/pages/InitImageKnife.ets create mode 100644 sharedlibrary/src/main/ets/utils/Calc.ets create mode 100644 sharedlibrary/src/main/module.json5 create mode 100644 sharedlibrary/src/main/resources/base/element/color.json create mode 100644 sharedlibrary/src/main/resources/base/element/string.json create mode 100644 sharedlibrary/src/main/resources/base/profile/main_pages.json create mode 100644 sharedlibrary/src/mock/mock-config.json5 create mode 100644 sharedlibrary/src/ohosTest/ets/test/Ability.test.ets create mode 100644 sharedlibrary/src/ohosTest/ets/test/List.test.ets create mode 100644 sharedlibrary/src/ohosTest/ets/testability/TestAbility.ets create mode 100644 sharedlibrary/src/ohosTest/ets/testability/pages/Index.ets create mode 100644 sharedlibrary/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets create mode 100644 sharedlibrary/src/ohosTest/module.json5 create mode 100644 sharedlibrary/src/ohosTest/resources/base/element/color.json create mode 100644 sharedlibrary/src/ohosTest/resources/base/element/string.json create mode 100644 sharedlibrary/src/ohosTest/resources/base/media/icon.png create mode 100644 sharedlibrary/src/ohosTest/resources/base/profile/test_pages.json create mode 100644 sharedlibrary/src/test/List.test.ets create mode 100644 sharedlibrary/src/test/LocalUnit.test.ets diff --git a/CHANGELOG.md b/CHANGELOG.md index 3715d2f..2a5ad77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ## 3.0.0-rc.5 - 图片加载事件增加请求开始的回调,以及修复有缓存时,没有回调的bug - 修复对已销毁组件不再下发请求的逻辑 +- 加载图片流程添加日志 +- 子线程写入文件缓存获取buffer优化 +- 成功回调增加返回图片分辨率宽高 ## 3.0.0-rc.4 - 支持hsp多包图片资源 diff --git a/build-profile.json5 b/build-profile.json5 index d2d4041..90f6b5d 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -7,8 +7,8 @@ { "name": "default", "signingConfig": "default", - "compileSdkVersion": "4.1.0(11)", - "compatibleSdkVersion": "4.1.0(11)", + "compileSdkVersion": "5.0.0(12)", + "compatibleSdkVersion": "5.0.0(12)", "runtimeOS": "HarmonyOS", } ], @@ -37,6 +37,18 @@ { "name": "library", "srcPath": "./library" + }, + { + "name": "sharedlibrary", + "srcPath": "./sharedlibrary", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] } ] } \ No newline at end of file diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 index 62b4158..c88bea1 100644 --- a/entry/oh-package.json5 +++ b/entry/oh-package.json5 @@ -6,7 +6,7 @@ "author": "", "license": "", "dependencies": { - "@ohos/imageknife": "file:../library" + "@ohos/libraryimageknife": "file:../sharedlibrary", } } diff --git a/entry/src/main/ets/common/CustomEngineKeyImpl.ets b/entry/src/main/ets/common/CustomEngineKeyImpl.ets index f780cd6..4354e1c 100644 --- a/entry/src/main/ets/common/CustomEngineKeyImpl.ets +++ b/entry/src/main/ets/common/CustomEngineKeyImpl.ets @@ -12,9 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { IEngineKey, ImageKnifeOption, PixelMapTransformation } from '@ohos/imageknife'; -import { SparkMD5 } from '@ohos/imageknife/src/main/ets/3rd_party/sparkmd5/spark-md5'; -import { ImageKnifeRequestSource } from '@ohos/imageknife/src/main/ets/model/ImageKnifeData'; +import { IEngineKey, ImageKnifeOption, PixelMapTransformation,SparkMD5 ,ImageKnifeRequestSource} from '@ohos/libraryimageknife'; //全局自定义key demo @Sendable diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index ee7fe45..9817874 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -17,7 +17,7 @@ import hilog from '@ohos.hilog'; import UIAbility from '@ohos.app.ability.UIAbility'; import Want from '@ohos.app.ability.Want'; import window from '@ohos.window'; -import { ImageKnife, LogUtil } from '@ohos/imageknife'; +import { ImageKnife, InitImageKnife, LogUtil } from '@ohos/libraryimageknife'; import { CustomEngineKeyImpl } from '../common/CustomEngineKeyImpl'; export default class EntryAbility extends UIAbility { @@ -35,11 +35,12 @@ export default class EntryAbility extends UIAbility { LogUtil.mLogLevel = LogUtil.ALL // 初始化ImageKnife的文件缓存 - await ImageKnife.getInstance().initFileCache(this.context, 256, 256 * 1024 * 1024) + await InitImageKnife.init(this.context) ImageKnife.getInstance().setEngineKeyImpl(new CustomEngineKeyImpl()) // 全局配置请求头 ImageKnife.getInstance().addHeader('refer', "http://1.94.37.200:7070/AntiTheftChain/downloadImage"); ImageKnife.getInstance().deleteHeader('refer'); + windowStage.loadContent('pages/Index', (err, data) => { if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); diff --git a/entry/src/main/ets/pages/ImageTransformation.ets b/entry/src/main/ets/pages/ImageTransformation.ets index 4cbbcba..ed863ca 100644 --- a/entry/src/main/ets/pages/ImageTransformation.ets +++ b/entry/src/main/ets/pages/ImageTransformation.ets @@ -1,6 +1,6 @@ import { BlurTransformation, BrightnessTransformation, ImageKnifeComponent, ImageKnifeOption, MultiTransTransformation, - PixelMapTransformation } from '@ohos/imageknife' + PixelMapTransformation } from '@ohos/libraryimageknife' import { collections } from '@kit.ArkTS' @Entry diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 4593079..34d9e90 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -26,6 +26,12 @@ struct Index { build() { Column() { + Button("测试HSP场景预加载").onClick(()=>{ + router.push({ + uri: 'pages/TestHspPreLoadImage', + + }); + }) Button("单个图片使用").onClick(()=>{ router.push({ uri: 'pages/SingleImage', diff --git a/entry/src/main/ets/pages/ListPage.ets b/entry/src/main/ets/pages/ListPage.ets index b56932c..c604d97 100644 --- a/entry/src/main/ets/pages/ListPage.ets +++ b/entry/src/main/ets/pages/ListPage.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife'; +import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife'; @Entry @Component diff --git a/entry/src/main/ets/pages/LoadStatePage.ets b/entry/src/main/ets/pages/LoadStatePage.ets index d12051d..0f7c2a1 100644 --- a/entry/src/main/ets/pages/LoadStatePage.ets +++ b/entry/src/main/ets/pages/LoadStatePage.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent, ImageKnifeOption } from "@ohos/imageknife" +import { ImageKnifeComponent, ImageKnifeOption } from "@ohos/libraryimageknife" import matrix4 from '@ohos.matrix4' @Entry diff --git a/entry/src/main/ets/pages/LongImagePage.ets b/entry/src/main/ets/pages/LongImagePage.ets index 930396b..c8f6e1f 100644 --- a/entry/src/main/ets/pages/LongImagePage.ets +++ b/entry/src/main/ets/pages/LongImagePage.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent } from '@ohos/imageknife' +import { ImageKnifeComponent } from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/ManyPhotoShowPage.ets b/entry/src/main/ets/pages/ManyPhotoShowPage.ets index 58ec187..0719141 100644 --- a/entry/src/main/ets/pages/ManyPhotoShowPage.ets +++ b/entry/src/main/ets/pages/ManyPhotoShowPage.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent } from '@ohos/imageknife'; +import { ImageKnifeComponent } from '@ohos/libraryimageknife'; diff --git a/entry/src/main/ets/pages/ObjectFitPage.ets b/entry/src/main/ets/pages/ObjectFitPage.ets index 22665b0..02f7f8c 100644 --- a/entry/src/main/ets/pages/ObjectFitPage.ets +++ b/entry/src/main/ets/pages/ObjectFitPage.ets @@ -1,4 +1,4 @@ -import { ImageKnife, ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife' +import { ImageKnife, ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/SignatureTestPage.ets b/entry/src/main/ets/pages/SignatureTestPage.ets index 445dc26..42f49e4 100644 --- a/entry/src/main/ets/pages/SignatureTestPage.ets +++ b/entry/src/main/ets/pages/SignatureTestPage.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife'; +import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife'; @Entry diff --git a/entry/src/main/ets/pages/SingleImage.ets b/entry/src/main/ets/pages/SingleImage.ets index 80ab7c1..c71f7bf 100644 --- a/entry/src/main/ets/pages/SingleImage.ets +++ b/entry/src/main/ets/pages/SingleImage.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent,BlurTransformation } from '@ohos/imageknife'; +import { ImageKnifeComponent,BlurTransformation } from '@ohos/libraryimageknife'; import fs from '@ohos.file.fs'; import image from '@ohos.multimedia.image'; diff --git a/entry/src/main/ets/pages/TestHeader.ets b/entry/src/main/ets/pages/TestHeader.ets index 93670a6..9be198e 100644 --- a/entry/src/main/ets/pages/TestHeader.ets +++ b/entry/src/main/ets/pages/TestHeader.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent,ImageKnife,ImageKnifeOption } from '@ohos/imageknife' +import { ImageKnifeComponent,ImageKnifeOption } from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/TestHspPreLoadImage.ets b/entry/src/main/ets/pages/TestHspPreLoadImage.ets new file mode 100644 index 0000000..16ff464 --- /dev/null +++ b/entry/src/main/ets/pages/TestHspPreLoadImage.ets @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { IndexComponent } from "@ohos/libraryimageknife" + +@Entry +@Component +struct TestHspPreLoadImage { + build() { + Column() { + IndexComponent() + }.width("100%").height('100%') + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/TestImageFlash.ets b/entry/src/main/ets/pages/TestImageFlash.ets index cd1ab28..c192a2b 100644 --- a/entry/src/main/ets/pages/TestImageFlash.ets +++ b/entry/src/main/ets/pages/TestImageFlash.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent } from '@ohos/imageknife/src/main/ets/components/ImageKnifeComponent' +import { ImageKnifeComponent } from '@ohos/libraryimageknife' @Observed export class MsgModel { diff --git a/entry/src/main/ets/pages/TestIsUrlExist.ets b/entry/src/main/ets/pages/TestIsUrlExist.ets index 4efc4b8..1225edc 100644 --- a/entry/src/main/ets/pages/TestIsUrlExist.ets +++ b/entry/src/main/ets/pages/TestIsUrlExist.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent, ImageKnife, ImageKnifeOption, CacheStrategy } from '@ohos/imageknife' +import { ImageKnifeComponent, ImageKnife, ImageKnifeOption, CacheStrategy } from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/TestPrefetchToFileCache.ets b/entry/src/main/ets/pages/TestPrefetchToFileCache.ets index 9dfef1f..d6b9e23 100644 --- a/entry/src/main/ets/pages/TestPrefetchToFileCache.ets +++ b/entry/src/main/ets/pages/TestPrefetchToFileCache.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent,ImageKnife,ImageKnifeOption } from '@ohos/imageknife' +import { ImageKnifeComponent,ImageKnife,ImageKnifeOption } from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/TestWriteCacheStage.ets b/entry/src/main/ets/pages/TestWriteCacheStage.ets index 43cd10a..6b0b203 100644 --- a/entry/src/main/ets/pages/TestWriteCacheStage.ets +++ b/entry/src/main/ets/pages/TestWriteCacheStage.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent,CacheStrategy,ImageKnifeOption } from '@ohos/imageknife' +import { ImageKnifeComponent,CacheStrategy,ImageKnifeOption } from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/TransformPage.ets b/entry/src/main/ets/pages/TransformPage.ets index b462c4c..7674156 100644 --- a/entry/src/main/ets/pages/TransformPage.ets +++ b/entry/src/main/ets/pages/TransformPage.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent, ImageKnifeOption } from "@ohos/imageknife" +import { ImageKnifeComponent, ImageKnifeOption } from "@ohos/libraryimageknife" import matrix4 from '@ohos.matrix4' diff --git a/entry/src/main/ets/pages/User.ets b/entry/src/main/ets/pages/User.ets index 9309648..02e5cc0 100644 --- a/entry/src/main/ets/pages/User.ets +++ b/entry/src/main/ets/pages/User.ets @@ -1,4 +1,4 @@ -import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife' +import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife' // const logger = new imUtils.logger.IMLogger('Avatar') diff --git a/entry/src/main/resources/base/media/rabbit.gif b/entry/src/main/resources/base/media/rabbit.gif new file mode 100644 index 0000000000000000000000000000000000000000..c2c1402e563c2d86c957b8d37ab28283b5b95986 GIT binary patch literal 10208 zcmZ{mcg{LrIBy1PSabR!rjp)^RR(k%`1 z`TqWZ=X!m=xz2s=b8cnT=aN!ppFn?s=MMo=Qc}vw%KG~HwzjrDK0ZOgAtLEV!s*9i z8HW#ZPGw7O6!H$97ahu%-@mEa*Q>cQZn(9o+jnZ%vuM8eZQb?ixe4gMkB*MX$jGRu zsBCX<$9C<8^`5@}bQC>soAq@!edIQG9A7!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@W%5vN}n<=?;^%wyoMsX$aGcW)Y)(vKgb&;;R{xB2yV#pBoI zM>qM0l*$cU@Dx@bawtdN4z@kzi`<4^96kTH!!X)G>0;`G^)k)Gu*HJ1zc`T3Xs- zoBj~?AWV8KMSQe@odk0j6wmQnXJPkjOW{P_1B5A~0(@)Kyq{nYMRRgdQ|#fLtLBqr z?kDIa({|?-fbD2@RLaAW#G5b;)He~10uKs89QV=0tDQ-SBI*a4jn`MAgf5~7oj9T@ z1h0!IaH4_L_>k==Cny; zE5QMEkM9v<26;!aPKmlG1ms}tY(N)a_JDeRoHh!*+jnNzb^a^>_Z;=tSmtxqrq|*& z{1x*!RA6JLy;&<Yo^L`DO?*!+%d__z4>gjhoQY+d zT~4m(q?~_KYy5fQ_ssIA=`AfM({)n6Q1Wf-Brm65vigq{#Wjvnwr~7dY1gmQEIKAN W3^IJOG6Lo@f*CTMgrER`^#23sTkf9# literal 0 HcmV?d00001 diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index bfefb27..e6d7674 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -15,6 +15,7 @@ "pages/ImageTransformation", "pages/ObjectFitPage", "pages/TestWriteCacheStage", - "pages/LoadStatePage" + "pages/LoadStatePage", + "pages/TestHspPreLoadImage" ] } \ No newline at end of file diff --git a/library/index.ets b/library/index.ets index d0f552e..bbeed44 100644 --- a/library/index.ets +++ b/library/index.ets @@ -12,7 +12,7 @@ export { LogUtil } from './src/main/ets/utils/LogUtil' export { IEngineKey } from './src/main/ets/key/IEngineKey' -export { ImageKnifeData , CacheStrategy} from "./src/main/ets/model/ImageKnifeData" +export { ImageKnifeData , CacheStrategy , ImageKnifeRequestSource} from "./src/main/ets/model/ImageKnifeData" export { PixelMapTransformation } from './src/main/ets/transform/PixelMapTransformation' @@ -22,4 +22,6 @@ export { BrightnessTransformation } from './src/main/ets/transform/BrightnessTra export { BlurTransformation } from './src/main/ets/transform/BlurTransformation' +export { SparkMD5 } from "./src/main/ets/3rd_party/sparkmd5/spark-md5" + diff --git a/library/src/main/ets/ImageKnife.ets b/library/src/main/ets/ImageKnife.ets index 6e01ae1..3a3a372 100644 --- a/library/src/main/ets/ImageKnife.ets +++ b/library/src/main/ets/ImageKnife.ets @@ -25,6 +25,7 @@ import { FileTypeUtil } from './utils/FileTypeUtil'; import { util } from '@kit.ArkTS'; import { image } from '@kit.ImageKit'; import { common } from '@kit.AbilityKit'; +import { LogUtil } from './utils/LogUtil'; export class ImageKnife { @@ -145,6 +146,7 @@ export class ImageKnife { } else { imageKnifeOption.loadSrc = loadSrc; } + LogUtil.log("ImageKnife_DataTime_preLoadCache-imageKnifeOption:"+loadSrc) let fileKey = this.getEngineKeyImpl().generateFileKey(imageKnifeOption.loadSrc, imageKnifeOption.signature) let cachePath = ImageKnife.getInstance().getFileCache().getFileToPath(fileKey) if (cachePath == null || cachePath == "" || cachePath == undefined) { @@ -299,10 +301,12 @@ export class ImageKnife { } async execute(request: ImageKnifeRequest): Promise { + LogUtil.log("ImageKnife_DataTime_execute.start:"+request.imageKnifeOption.loadSrc) if (this.headerMap.size > 0) { request.addHeaderMap(this.headerMap) } this.dispatcher.enqueue(request) + LogUtil.log("ImageKnife_DataTime_execute.end:"+request.imageKnifeOption.loadSrc) } setMaxRequests(concurrency: number): void { diff --git a/library/src/main/ets/ImageKnifeDispatcher.ets b/library/src/main/ets/ImageKnifeDispatcher.ets index 34d5810..0e099ea 100644 --- a/library/src/main/ets/ImageKnifeDispatcher.ets +++ b/library/src/main/ets/ImageKnifeDispatcher.ets @@ -51,6 +51,7 @@ export class ImageKnifeDispatcher { private engineKey: IEngineKey = new DefaultEngineKey(); showFromMemomry(request: ImageKnifeRequest, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource): boolean { + LogUtil.log("ImageKnife_DataTime_showFromMemomry.start:"+request.imageKnifeOption.loadSrc) let memoryCache: ImageKnifeData | undefined; if ((typeof (request.imageKnifeOption.loadSrc as image.PixelMap).isEditable) == 'boolean') { memoryCache = { @@ -70,22 +71,27 @@ export class ImageKnifeDispatcher { // 回调请求开始 if (requestSource === ImageKnifeRequestSource.SRC && request.imageKnifeOption.onLoadListener?.onLoadStart !== undefined) { request.imageKnifeOption.onLoadListener?.onLoadStart() + LogUtil.log("ImageKnife_DataTime_MemoryCache_onLoadStart:"+request.imageKnifeOption.loadSrc) } - + LogUtil.log("ImageKnife_DataTime_MemoryCache_showPixelMap.start:"+request.imageKnifeOption.loadSrc) request.ImageKnifeRequestCallback?.showPixelMap(request.componentVersion, memoryCache.source, requestSource) + LogUtil.log("ImageKnife_DataTime_MemoryCache_showPixelMap.end:"+request.imageKnifeOption.loadSrc) if (requestSource == ImageKnifeRequestSource.SRC) { request.requestState = ImageKnifeRequestState.COMPLETE // 回调请求开结束 if (request.imageKnifeOption.onLoadListener?.onLoadSuccess !== undefined) { - request.imageKnifeOption.onLoadListener?.onLoadSuccess(memoryCache.source) + request.imageKnifeOption.onLoadListener?.onLoadSuccess(memoryCache.source,memoryCache.imageWidth,memoryCache.imageHeight) + LogUtil.log("ImageKnife_DataTime_MemoryCache_onLoadSuccess:"+request.imageKnifeOption.loadSrc) } } else if (requestSource == ImageKnifeRequestSource.ERROR_HOLDER) { request.requestState = ImageKnifeRequestState.ERROR } } + LogUtil.log("ImageKnife_DataTime_showFromMemomry.end_true:"+request.imageKnifeOption.loadSrc) return true } + LogUtil.log("ImageKnife_DataTime_showFromMemomry.end_false:"+request.imageKnifeOption.loadSrc) return false } @@ -106,6 +112,7 @@ export class ImageKnifeDispatcher { } executeJob(request: ImageKnifeRequest): void { + LogUtil.log("ImageKnife_DataTime_executeJob.start:"+request.imageKnifeOption.loadSrc) // 加载占位符 if (request.imageKnifeOption.placeholderSrc !== undefined) { if (this.showFromMemomry(request, request.imageKnifeOption.placeholderSrc, ImageKnifeRequestSource.PLACE_HOLDER) === false) { @@ -115,12 +122,14 @@ export class ImageKnifeDispatcher { // 加载主图 this.getAndShowImage(request, request.imageKnifeOption.loadSrc, ImageKnifeRequestSource.SRC) + LogUtil.log("ImageKnife_DataTime_executeJob.end:"+request.imageKnifeOption.loadSrc) } /** * 获取和显示图片 */ getAndShowImage(currentRequest: ImageKnifeRequest, imageSrc: string | PixelMap | Resource, requestSource: ImageKnifeRequestSource): void { + LogUtil.log("ImageKnife_DataTime_getAndShowImage.start:"+currentRequest.imageKnifeOption.loadSrc) let memoryKey: string = this.engineKey.generateMemoryKey(imageSrc, requestSource, currentRequest.imageKnifeOption) let requestList: List | undefined = this.executingJobMap.get(memoryKey) if (requestList == undefined) { @@ -147,7 +156,9 @@ export class ImageKnifeDispatcher { requestSource } // 启动线程下载和解码主图 + LogUtil.log("ImageKnife_DataTime_getAndShowImage_Task.start:"+currentRequest.imageKnifeOption.loadSrc) let task = new taskpool.Task(requestJob, request) + LogUtil.log("ImageKnife_DataTime_getAndShowImage_Task.end:"+currentRequest.imageKnifeOption.loadSrc) // 监听网络回调事件 if (currentRequest.imageKnifeOption.progressListener !== undefined && requestSource === ImageKnifeRequestSource.SRC) { let progressCallBack = currentRequest.imageKnifeOption.progressListener @@ -160,11 +171,13 @@ export class ImageKnifeDispatcher { requestList.forEach((requestWithSource: ImageKnifeRequestWithSource) => { if (requestWithSource.source === ImageKnifeRequestSource.SRC && requestWithSource.request.imageKnifeOption.onLoadListener?.onLoadStart !== undefined) { requestWithSource.request.imageKnifeOption.onLoadListener?.onLoadStart() + LogUtil.log("ImageKnife_DataTime_getAndShowImage_onLoadStart:"+currentRequest.imageKnifeOption.loadSrc) } }); - + LogUtil.log("ImageKnife_DataTime_getAndShowImage_execute.start:"+currentRequest.imageKnifeOption.loadSrc) taskpool.execute(task).then((res: Object) => { + LogUtil.log("ImageKnife_DataTime_getAndShowImage_CallBack.start:"+currentRequest.imageKnifeOption.loadSrc) let requestJobResult = res as RequestJobResult let pixelmap = requestJobResult === undefined ? undefined : requestJobResult.pixelMap if (pixelmap === undefined) { @@ -173,6 +186,7 @@ export class ImageKnifeDispatcher { // 回调请求失败 if (requestWithSource.source === ImageKnifeRequestSource.SRC && requestWithSource.request.imageKnifeOption.onLoadListener?.onLoadFailed !== undefined && requestJobResult.loadFail){ requestWithSource.request.imageKnifeOption.onLoadListener.onLoadFailed(requestJobResult.loadFail); + LogUtil.log("ImageKnife_DataTime_getAndShowImage_onLoadFailed:"+currentRequest.imageKnifeOption.loadSrc) } if (requestWithSource.source === ImageKnifeRequestSource.SRC && requestWithSource.request.imageKnifeOption.errorholderSrc !== undefined) { @@ -190,22 +204,24 @@ export class ImageKnifeDispatcher { } // 保存文件缓存 if (requestJobResult.bufferSize > 0 && currentRequest.imageKnifeOption.writeCacheStrategy !== CacheStrategy.Memory) { - LogUtil.log("ImageKnifeComponent writeCacheStrategy File") + LogUtil.log("ImageKnife_DataTime_getAndShowImage_saveWithoutWriteFile.start:"+currentRequest.imageKnifeOption.loadSrc) ImageKnife.getInstance().saveWithoutWriteFile(requestJobResult.fileKey, requestJobResult.bufferSize) + LogUtil.log("ImageKnife_DataTime_getAndShowImage_saveWithoutWriteFile.end:"+currentRequest.imageKnifeOption.loadSrc) } let ImageKnifeData: ImageKnifeData = { source: pixelmap!, - imageWidth: 0, - imageHeight: 0 + imageWidth: requestJobResult.size == undefined ? 0 : requestJobResult.size.width, + imageHeight: requestJobResult.size == undefined ? 0 : requestJobResult.size.height } // 保存内存缓存 if (currentRequest.imageKnifeOption.writeCacheStrategy !== CacheStrategy.File) { - LogUtil.log("ImageKnifeComponent writeCacheStrategy Memory") + LogUtil.log("ImageKnife_DataTime_getAndShowImage_saveMemoryCache.start:"+currentRequest.imageKnifeOption.loadSrc) ImageKnife.getInstance() .saveMemoryCache(this.engineKey.generateMemoryKey(imageSrc, requestSource, currentRequest.imageKnifeOption), ImageKnifeData) + LogUtil.log("ImageKnife_DataTime_getAndShowImage_saveMemoryCache.end:"+currentRequest.imageKnifeOption.loadSrc) } if (requestList !== undefined) { @@ -218,15 +234,17 @@ export class ImageKnifeDispatcher { // 画主图 if (requestWithSource.source === ImageKnifeRequestSource.SRC || requestWithSource.source === ImageKnifeRequestSource.ERROR_HOLDER || (requestWithSource.source === ImageKnifeRequestSource.PLACE_HOLDER && requestWithSource.request.requestState === ImageKnifeRequestState.PROGRESS)) { - + LogUtil.log("ImageKnife_DataTime_getAndShowImage_showPixelMap.start:"+currentRequest.imageKnifeOption.loadSrc) requestWithSource.request.ImageKnifeRequestCallback.showPixelMap(requestWithSource.request.componentVersion, ImageKnifeData.source, requestWithSource.source) + LogUtil.log("ImageKnife_DataTime_getAndShowImage_showPixelMap.end:"+currentRequest.imageKnifeOption.loadSrc) } if (requestWithSource.source == ImageKnifeRequestSource.SRC) { requestWithSource.request.requestState = ImageKnifeRequestState.COMPLETE if (requestWithSource.request.imageKnifeOption.onLoadListener && requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess) { // 回调请求成功 - requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess(ImageKnifeData.source); + requestWithSource.request.imageKnifeOption.onLoadListener.onLoadSuccess(ImageKnifeData.source,ImageKnifeData.imageWidth,ImageKnifeData.imageHeight); + LogUtil.log("ImageKnife_DataTime_getAndShowImage_onLoadSuccess:"+currentRequest.imageKnifeOption.loadSrc) } } else if (requestWithSource.source == ImageKnifeRequestSource.ERROR_HOLDER) { requestWithSource.request.requestState = ImageKnifeRequestState.ERROR @@ -241,12 +259,14 @@ export class ImageKnifeDispatcher { LogUtil.log("error: no requestlist need to draw for key = " + memoryKey) } // }) - + LogUtil.log("ImageKnife_DataTime_getAndShowImage_CallBack.end:"+currentRequest.imageKnifeOption.loadSrc) }); + LogUtil.log("ImageKnife_DataTime_getAndShowImage_execute.end:"+currentRequest.imageKnifeOption.loadSrc) + LogUtil.log("ImageKnife_DataTime_getAndShowImage.end:"+currentRequest.imageKnifeOption.loadSrc) } dispatchNextJob() { - + LogUtil.log("ImageKnife_DataTime_dispatchNextJob.start") while (true) { let request = this.jobQueue.pop() if (request === undefined) { @@ -254,6 +274,7 @@ export class ImageKnifeDispatcher { } else if (request.requestState === ImageKnifeRequestState.PROGRESS) { this.executeJob(request) + LogUtil.log("ImageKnife_DataTime_dispatchNextJob.end:" + request.imageKnifeOption.loadSrc) break } } @@ -282,6 +303,7 @@ export class ImageKnifeDispatcher { */ @Concurrent async function requestJob(request: RequestJobRequest): Promise { + LogUtil.log("ImageKnife_DataTime_requestJob.start:"+request.src) let resBuf: ArrayBuffer | undefined let bufferSize: number = 0 let loadError: string = ''; @@ -315,6 +337,7 @@ async function requestJob(request: RequestJobRequest): Promise() @@ -359,12 +382,14 @@ async function requestJob(request: RequestJobRequest): Promise { resPixelmap = pixelmap @@ -443,11 +472,13 @@ async function requestJob(request: RequestJobRequest): Promise void; // 请求成功 - onLoadSuccess?: (data: string | PixelMap | undefined) => void; + onLoadSuccess?: (data: string | PixelMap | undefined,width?:number,height?:number) => void; // 请求结束 onLoadFailed?: (err: string) => void; } \ No newline at end of file diff --git a/library/src/main/ets/model/ImageKnifeData.ets b/library/src/main/ets/model/ImageKnifeData.ets index f2abd25..97cff7b 100644 --- a/library/src/main/ets/model/ImageKnifeData.ets +++ b/library/src/main/ets/model/ImageKnifeData.ets @@ -17,6 +17,7 @@ import { ImageKnifeRequest } from '../ImageKnifeRequest' import { IEngineKey } from '../key/IEngineKey' import { PixelMapTransformation } from '../transform/PixelMapTransformation' import common from '@ohos.app.ability.common'; +import { Size } from '@kit.ArkUI' export interface ImageKnifeData { source: PixelMap | string, @@ -59,6 +60,7 @@ export interface RequestJobResult { bufferSize: number fileKey: string loadFail?: string, + size?:Size } /** diff --git a/library/src/main/ets/utils/MemoryLruCache.ets b/library/src/main/ets/utils/MemoryLruCache.ets index fa0d513..50b78af 100644 --- a/library/src/main/ets/utils/MemoryLruCache.ets +++ b/library/src/main/ets/utils/MemoryLruCache.ets @@ -108,6 +108,7 @@ export class MemoryLruCache implements IMemoryCache { this.currentMemory -= value.source.length } else { this.currentMemory -= value.source.getPixelBytesNumber(); + value.source.release() } // LogUtil.info("MemoryCache removeMemorySize: " + value.source.getPixelBytesNumber() + " currentMemory:" + this.currentMemory) } diff --git a/sharedlibrary/.gitignore b/sharedlibrary/.gitignore new file mode 100644 index 0000000..e2713a2 --- /dev/null +++ b/sharedlibrary/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/sharedlibrary/Index.ets b/sharedlibrary/Index.ets new file mode 100644 index 0000000..b25707a --- /dev/null +++ b/sharedlibrary/Index.ets @@ -0,0 +1,33 @@ +export { add } from './src/main/ets/utils/Calc' + +export { InitImageKnife } from "./src/main/ets/pages/InitImageKnife" + +export { IndexComponent } from "./src/main/ets/pages/Index" + +export { ImageKnifeComponent } from '@ohos/imageknife' + +export { ImageKnife } from '@ohos/imageknife' + +export { ImageKnifeOption } from '@ohos/imageknife' + +export { ImageKnifeRequest } from '@ohos/imageknife' + +export { FileUtils } from '@ohos/imageknife' + +export { LogUtil } from '@ohos/imageknife' + +export { IEngineKey } from '@ohos/imageknife' + +export { ImageKnifeData , CacheStrategy} from "@ohos/imageknife" + +export { PixelMapTransformation } from '@ohos/imageknife' + +export { MultiTransTransformation } from '@ohos/imageknife' + +export { BrightnessTransformation } from '@ohos/imageknife' + +export { BlurTransformation } from '@ohos/imageknife' + +export { SparkMD5 } from "@ohos/imageknife" + +export { ImageKnifeRequestSource } from "@ohos/imageknife" \ No newline at end of file diff --git a/sharedlibrary/build-profile.json5 b/sharedlibrary/build-profile.json5 new file mode 100644 index 0000000..170d980 --- /dev/null +++ b/sharedlibrary/build-profile.json5 @@ -0,0 +1,28 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] +} \ No newline at end of file diff --git a/sharedlibrary/hvigorfile.ts b/sharedlibrary/hvigorfile.ts new file mode 100644 index 0000000..d993120 --- /dev/null +++ b/sharedlibrary/hvigorfile.ts @@ -0,0 +1,6 @@ +import { hspTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hspTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/sharedlibrary/obfuscation-rules.txt b/sharedlibrary/obfuscation-rules.txt new file mode 100644 index 0000000..985b2ae --- /dev/null +++ b/sharedlibrary/obfuscation-rules.txt @@ -0,0 +1,18 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope \ No newline at end of file diff --git a/sharedlibrary/oh-package.json5 b/sharedlibrary/oh-package.json5 new file mode 100644 index 0000000..65115c7 --- /dev/null +++ b/sharedlibrary/oh-package.json5 @@ -0,0 +1,12 @@ +{ + "name": "sharedlibrary", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "packageType": "InterfaceHar", + "dependencies": { + "@ohos/imageknife": "file:../library" + } +} \ No newline at end of file diff --git a/sharedlibrary/src/main/ets/pages/Index.ets b/sharedlibrary/src/main/ets/pages/Index.ets new file mode 100644 index 0000000..ad35007 --- /dev/null +++ b/sharedlibrary/src/main/ets/pages/Index.ets @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { ImageKnife , ImageKnifeComponent ,ImageKnifeOption } from "@ohos/imageknife" + +@Component +export struct IndexComponent { + @State imageKnifeOption: ImageKnifeOption = { + loadSrc: $r('app.media.startIcon') + } + build() { + Column() { + Button("预加载").onClick((event: ClickEvent) => { + ImageKnife.getInstance() + .preLoadCache('https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp') + .then((data) => { + console.log("preLoadImage_FileCache:" + data) + this.imageKnifeOption.loadSrc = data + }) + }) + ImageKnifeComponent({ + imageKnifeOption:this.imageKnifeOption + }).width(300).height(300) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/sharedlibrary/src/main/ets/pages/InitImageKnife.ets b/sharedlibrary/src/main/ets/pages/InitImageKnife.ets new file mode 100644 index 0000000..405914c --- /dev/null +++ b/sharedlibrary/src/main/ets/pages/InitImageKnife.ets @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { ImageKnife } from '@ohos/imageknife' +import common from '@ohos.app.ability.common' +export class InitImageKnife{ + static async init(entryContext:common.UIAbilityContext){ + await ImageKnife.getInstance().initFileCache(entryContext, 256, 256 * 1024 * 1024) + } +} \ No newline at end of file diff --git a/sharedlibrary/src/main/ets/utils/Calc.ets b/sharedlibrary/src/main/ets/utils/Calc.ets new file mode 100644 index 0000000..e6b7cf2 --- /dev/null +++ b/sharedlibrary/src/main/ets/utils/Calc.ets @@ -0,0 +1,3 @@ +export function add(a:number, b:number) { + return a + b; +} \ No newline at end of file diff --git a/sharedlibrary/src/main/module.json5 b/sharedlibrary/src/main/module.json5 new file mode 100644 index 0000000..5ff0ab4 --- /dev/null +++ b/sharedlibrary/src/main/module.json5 @@ -0,0 +1,14 @@ +{ + "module": { + "name": "sharedlibrary", + "type": "shared", + "description": "$string:shared_desc", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "pages": "$profile:main_pages" + } +} \ No newline at end of file diff --git a/sharedlibrary/src/main/resources/base/element/color.json b/sharedlibrary/src/main/resources/base/element/color.json new file mode 100644 index 0000000..1bbc9aa --- /dev/null +++ b/sharedlibrary/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/sharedlibrary/src/main/resources/base/element/string.json b/sharedlibrary/src/main/resources/base/element/string.json new file mode 100644 index 0000000..98e1d8a --- /dev/null +++ b/sharedlibrary/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "shared_desc", + "value": "description" + } + ] +} \ No newline at end of file diff --git a/sharedlibrary/src/main/resources/base/profile/main_pages.json b/sharedlibrary/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000..1898d94 --- /dev/null +++ b/sharedlibrary/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/sharedlibrary/src/mock/mock-config.json5 b/sharedlibrary/src/mock/mock-config.json5 new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/sharedlibrary/src/mock/mock-config.json5 @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/sharedlibrary/src/ohosTest/ets/test/Ability.test.ets b/sharedlibrary/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000..85c78f6 --- /dev/null +++ b/sharedlibrary/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,35 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/sharedlibrary/src/ohosTest/ets/test/List.test.ets b/sharedlibrary/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000..794c7dc --- /dev/null +++ b/sharedlibrary/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,5 @@ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/sharedlibrary/src/ohosTest/ets/testability/TestAbility.ets b/sharedlibrary/src/ohosTest/ets/testability/TestAbility.ets new file mode 100644 index 0000000..3e04349 --- /dev/null +++ b/sharedlibrary/src/ohosTest/ets/testability/TestAbility.ets @@ -0,0 +1,47 @@ +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { abilityDelegatorRegistry } from '@kit.TestKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; + +export default class TestAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); + let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator; + abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs; + abilityDelegatorArguments = abilityDelegatorRegistry.getArguments(); + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('testability/pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/sharedlibrary/src/ohosTest/ets/testability/pages/Index.ets b/sharedlibrary/src/ohosTest/ets/testability/pages/Index.ets new file mode 100644 index 0000000..423b427 --- /dev/null +++ b/sharedlibrary/src/ohosTest/ets/testability/pages/Index.ets @@ -0,0 +1,17 @@ +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/sharedlibrary/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets b/sharedlibrary/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets new file mode 100644 index 0000000..713592f --- /dev/null +++ b/sharedlibrary/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets @@ -0,0 +1,90 @@ +import { abilityDelegatorRegistry, TestRunner } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { resourceManager } from '@kit.LocalizationKit'; +import { util } from '@kit.ArkTS'; + +let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator; +let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs; +let jsonPath: string = 'mock/mock-config.json'; +let tag: string = 'testTag'; + +async function onAbilityCreateCallback(data: UIAbility) { + hilog.info(0x0000, 'testTag', 'onAbilityCreateCallback, data: ${}', JSON.stringify(data)); +} + +async function addAbilityMonitorCallback(err: BusinessError) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare'); + } + + async onRun() { + let tag = 'testTag'; + hilog.info(0x0000, tag, '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = abilityDelegatorRegistry.getArguments() + abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator() + let moduleName = abilityDelegatorArguments.parameters['-m']; + let context = abilityDelegator.getAppContext().getApplicationContext().createModuleContext(moduleName); + let mResourceManager = context.resourceManager; + await checkMock(abilityDelegator, mResourceManager); + const bundleName = abilityDelegatorArguments.bundleName; + const testAbilityName: string = 'TestAbility'; + let lMonitor: abilityDelegatorRegistry.AbilityMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + moduleName: moduleName + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + const want: Want = { + bundleName: bundleName, + abilityName: testAbilityName, + moduleName: moduleName + }; + abilityDelegator.startAbility(want, (err: BusinessError, data: void) => { + hilog.info(0x0000, tag, 'startAbility : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, tag, 'startAbility : data : %{public}s', JSON.stringify(data) ?? ''); + }) + hilog.info(0x0000, tag, '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} + +async function checkMock(abilityDelegator: abilityDelegatorRegistry.AbilityDelegator, resourceManager: resourceManager.ResourceManager) { + let rawFile: Uint8Array; + try { + rawFile = resourceManager.getRawFileContentSync(jsonPath); + hilog.info(0x0000, tag, 'MockList file exists'); + let mockStr: string = util.TextDecoder.create('utf-8', { ignoreBOM: true }).decodeWithStream(rawFile); + let mockMap: Record = getMockList(mockStr); + try { + abilityDelegator.setMockList(mockMap) + } catch (error) { + let code = (error as BusinessError).code; + let message = (error as BusinessError).message; + hilog.error(0x0000, tag, `abilityDelegator.setMockList failed, error code: ${code}, message: ${message}.`); + } + } catch (error) { + let code = (error as BusinessError).code; + let message = (error as BusinessError).message; + hilog.error(0x0000, tag, `ResourceManager:callback getRawFileContent failed, error code: ${code}, message: ${message}.`); + } +} + +function getMockList(jsonStr: string) { + let jsonObj: Record = JSON.parse(jsonStr); + let map: Map = new Map(Object.entries(jsonObj)); + let mockList: Record = {}; + map.forEach((value: object, key: string) => { + let realValue: string = value['source'].toString(); + mockList[key] = realValue; + }); + hilog.info(0x0000, tag, '%{public}s', 'mock-json value:' + JSON.stringify(mockList) ?? ''); + return mockList; +} \ No newline at end of file diff --git a/sharedlibrary/src/ohosTest/module.json5 b/sharedlibrary/src/ohosTest/module.json5 new file mode 100644 index 0000000..4cca4a0 --- /dev/null +++ b/sharedlibrary/src/ohosTest/module.json5 @@ -0,0 +1,38 @@ +{ + "module": { + "name": "sharedlibrary_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/sharedlibrary/src/ohosTest/resources/base/element/color.json b/sharedlibrary/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000..3c71296 --- /dev/null +++ b/sharedlibrary/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/sharedlibrary/src/ohosTest/resources/base/element/string.json b/sharedlibrary/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000..65d8fa5 --- /dev/null +++ b/sharedlibrary/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/sharedlibrary/src/ohosTest/resources/base/media/icon.png b/sharedlibrary/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000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BNF_79BzvZ!TeIP)exdk3)kSHjYdW1P10ZJ_NCJSlrCuIU#gqw f88(SSw!Z%ZUzhC#9QlKF00000NkvXXu0mjfG$}gK literal 0 HcmV?d00001 diff --git a/sharedlibrary/src/ohosTest/resources/base/profile/test_pages.json b/sharedlibrary/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 0000000..b7e7343 --- /dev/null +++ b/sharedlibrary/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/sharedlibrary/src/test/List.test.ets b/sharedlibrary/src/test/List.test.ets new file mode 100644 index 0000000..bb5b5c3 --- /dev/null +++ b/sharedlibrary/src/test/List.test.ets @@ -0,0 +1,5 @@ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/sharedlibrary/src/test/LocalUnit.test.ets b/sharedlibrary/src/test/LocalUnit.test.ets new file mode 100644 index 0000000..165fc16 --- /dev/null +++ b/sharedlibrary/src/test/LocalUnit.test.ets @@ -0,0 +1,33 @@ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file