diff --git a/build-profile.json5 b/build-profile.json5 index fe9a36b..0ac1294 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -8,20 +8,7 @@ "signingConfig": "default" } ], - "signingConfigs": [ - { - "name": "default", - "material": { - "certpath": "C:\\Users\\admin\\.ohos\\config\\openharmony\\auto_ohos_default_ImageKnife_com.openharmony.imageknife.cer", - "storePassword": "0000001B3AC9BCC9FC4C1EC6B2F892BA3D039A330151A3AB9DA17BBAACE0F312E52F6D6FC0AE585B7479F8", - "keyAlias": "debugKey", - "keyPassword": "0000001BA819F9A4DDFF14F3529073770609B0607886D8D748670E7BC8A5D0A2F750613562B838B0D78F98", - "profile": "C:\\Users\\admin\\.ohos\\config\\openharmony\\auto_ohos_default_ImageKnife_com.openharmony.imageknife.p7b", - "signAlg": "SHA256withECDSA", - "storeFile": "C:\\Users\\admin\\.ohos\\config\\openharmony\\auto_ohos_default_ImageKnife_com.openharmony.imageknife.p12" - } - } - ] + "signingConfigs": [] }, "modules": [ { diff --git a/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets b/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets new file mode 100644 index 0000000..5e978b3 --- /dev/null +++ b/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2021 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' +import worker, { MessageEvents } from '@ohos.worker' +import Prompt from '@system.prompt' + +@Entry +@Component +struct TestGifLoadWithWorkerPage { + @State message: string = 'Hello Worker' + //@State 双向绑定的意思 + @State options: ImageKnifeOption = { + loadSrc: $r('app.media.icon') + } + private my_worker: worker.ThreadWorker; + private my_gif_worker: worker.ThreadWorker; + + /** + * 界面进入时回调 + */ + aboutToAppear() { + console.log("liyiwei aboutToAppear") + } + + /** + * 界面退出时回调 + */ + aboutToDisappear() { + console.log("liyiwei aboutToDisappear") + if (this.my_worker) { + this.my_worker.terminate() + } + if (this.my_gif_worker) { + this.my_gif_worker.terminate() + } + } + + build() { + Column() { + Column() { + Text(`${this.message}`) + .fontSize("50fp") + .fontWeight(FontWeight.Bold) + + Button('发worker消息') + .margin({ top: 16 }) + .onClick(() => { + console.log("button 发worker消息 onClick()") + + //脚本路径不要添加src/main + if (!this.my_worker) { + this.my_worker = new worker.ThreadWorker('entry/ets/workers/MyWorker.ts') + } + this.my_worker.onmessage = (e: MessageEvents) => { + console.log("liyiwei my_worker.onmessage:" + e.data) + + //接收子线程传来的消息 + //将从后台线程返回的数据通过toast的方式显示出来 + Prompt.showToast({ message: e.data }) + } + //主线程向子线程发送消息 + this.my_worker.postMessage('好好学习') + }) + Text("向子线程发送【好好学习】,并从其得到【天天向上】的应答") + + Button('加载gif') + .margin({ top: 16 }) + .onClick(() => { + console.log("button 加载gif onClick()") + + //初始化自定义worker + if (!this.my_gif_worker) { + this.my_gif_worker = new worker.ThreadWorker('entry/ets/workers/GifLoadWorker.ts') + } + this.my_gif_worker.onmessage = (e: MessageEvents) => { + console.log("liyiwei my_gif_worker.onmessage: " + e.data) + } + globalThis.ImageKnife.setGifWorker(this.my_gif_worker) + + //子线程加载gif,不阻塞toast的消失 + this.options = { + loadSrc: $r('app.media.gifSample'), + } + + Prompt.showToast({ message: '加载gif中,请稍等' }) + }) + Text('worker子线程解析gif,不阻塞主线程中toast的消失,解析耗时近45s,请耐心等待') + + Button('加载gif') + .margin({ top: 16 }) + .onClick(() => { + console.log("ImageKnifeComponent button 加载gif onClick()") + + globalThis.ImageKnife.setGifWorker(undefined) + + //主线程加载gif,阻塞toast的消失 + this.options = { + loadSrc: $r("app.media.honor"), + } + + Prompt.showToast({ message: '加载gif中,请稍等' }) + }) + Text('主线程解析gif,会阻塞主线程中toast的消失,并可能会触发THREAD_BLOCK_6S异常,解析耗时近20s,请耐心等待') + + ImageKnifeComponent({ imageKnifeOption: this.options }) + .width(300) + .height(300) + .margin(16) + } + .width("100%") + .height("100%") + .justifyContent(FlexAlign.Center) + } + .width("100%") + .height("100%") + } +} \ No newline at end of file