From 6144949b8643841f88a2db01f18847531b1af336 Mon Sep 17 00:00:00 2001 From: zhoulisheng <635547767@qq.com> Date: Thu, 28 Dec 2023 16:40:08 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9EImageKnife=E5=8A=A0?= =?UTF-8?q?=E8=BD=BDResource=E6=9D=A5=E8=87=AA=E4=B8=8D=E5=90=8C=E7=9A=84s?= =?UTF-8?q?haredlibrary=E7=9A=84=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoulisheng <635547767@qq.com> --- build-profile.json5 | 12 ++++ entry/oh-package.json5 | 1 + .../ets/pages/imageknifeTestCaseIndex.ets | 8 ++- entry/src/main/ets/pages/multiHspTestPage.ets | 60 ++++++++++++++++++ .../resources/base/profile/main_pages.json | 1 + sharedlibrary/src/main/ets/Index.ets | 4 +- sharedlibrary/src/main/ets/pages/GetRes1.ets | 21 ++++++ sharedlibrary2/.gitignore | 6 ++ sharedlibrary2/build-profile.json5 | 10 +++ sharedlibrary2/hvigorfile.ts | 2 + sharedlibrary2/oh-package.json5 | 11 ++++ sharedlibrary2/src/main/ets/Index.ets | 16 +++++ sharedlibrary2/src/main/ets/pages/GetRes2.ets | 21 ++++++ sharedlibrary2/src/main/ets/pages/Index.ets | 27 ++++++++ sharedlibrary2/src/main/module.json5 | 13 ++++ .../main/resources/base/element/color.json | 8 +++ .../main/resources/base/element/string.json | 8 +++ .../resources/base/media/icon_loading.png | Bin 0 -> 2134 bytes .../resources/base/profile/main_pages.json | 5 ++ 19 files changed, 231 insertions(+), 3 deletions(-) create mode 100644 entry/src/main/ets/pages/multiHspTestPage.ets create mode 100644 sharedlibrary/src/main/ets/pages/GetRes1.ets create mode 100644 sharedlibrary2/.gitignore create mode 100644 sharedlibrary2/build-profile.json5 create mode 100644 sharedlibrary2/hvigorfile.ts create mode 100644 sharedlibrary2/oh-package.json5 create mode 100644 sharedlibrary2/src/main/ets/Index.ets create mode 100644 sharedlibrary2/src/main/ets/pages/GetRes2.ets create mode 100644 sharedlibrary2/src/main/ets/pages/Index.ets create mode 100644 sharedlibrary2/src/main/module.json5 create mode 100644 sharedlibrary2/src/main/resources/base/element/color.json create mode 100644 sharedlibrary2/src/main/resources/base/element/string.json create mode 100644 sharedlibrary2/src/main/resources/base/media/icon_loading.png create mode 100644 sharedlibrary2/src/main/resources/base/profile/main_pages.json diff --git a/build-profile.json5 b/build-profile.json5 index 92ec1aa..aa57008 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -49,6 +49,18 @@ ] } ] + }, + { + "name": "sharedlibrary2", + "srcPath": "./sharedlibrary2", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] } ] } \ No newline at end of file diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 index 9e98a81..9f9f014 100644 --- a/entry/oh-package.json5 +++ b/entry/oh-package.json5 @@ -7,6 +7,7 @@ "version": "2.1.2-rc.3", "dependencies": { "@ohos/libraryimageknife": "file:../sharedlibrary", + "@ohos/sharedlibrary2": "file:../sharedlibrary2", "@ohos/disklrucache": "^2.0.2-rc.0", "@ohos/imageknife": "file:../library" } diff --git a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets index 448e170..a58a9d4 100644 --- a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets +++ b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets @@ -269,10 +269,14 @@ struct IndexFunctionDemo { }).margin({ top: 15 }) Button("hsp加载后缓存情况,先点左侧按钮") .onClick(() => { - console.log("pages/tempUrlTestPage 页面跳转") + console.log("pages/hspCacheTestPage 页面跳转") router.pushUrl({ url: "pages/hspCacheTestPage" }); }).margin({ top: 15 }) - + Button("不同的hsp资源加载") + .onClick(()=>{ + console.log("pages/multiHspTestPage 页面跳转") + router.pushUrl({ url: "pages/multiHspTestPage" }); + }) }.width('100%').height(60).backgroundColor(Color.Pink) Text("测试图片加载稳定").fontSize(15) diff --git a/entry/src/main/ets/pages/multiHspTestPage.ets b/entry/src/main/ets/pages/multiHspTestPage.ets new file mode 100644 index 0000000..c142ef9 --- /dev/null +++ b/entry/src/main/ets/pages/multiHspTestPage.ets @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2023 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 { ImageKnifeComponent, ImageKnifeOption, FileUtils, ImageKnifeGlobal, GetRes1 } from '@ohos/libraryimageknife' +import common from '@ohos.app.ability.common' +import { GetRes2 } from '@ohos/sharedlibrary2' + +@Entry +@Component +struct Index { + @State imageOption1: ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + } + @State imageOption2: ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + } + + build() { + Scroll() { + Column() { + Button('点击HSP1主图,HSP2占位,无context').onClick(() => { + let mainRes = GetRes1.getSample1(); + let placeholderRes = GetRes2.getSample2(); + this.imageOption1 = { + loadSrc:mainRes, + placeholderSrc:placeholderRes + } + }) + ImageKnifeComponent({ imageKnifeOption: this.imageOption1 }).width(300).height(300).backgroundColor(Color.Pink) + Button('点击HSP1主图,HSP2占位,有context ').onClick(() => { + let mainRes = GetRes1.getSample1(); + let placeholderRes = GetRes2.getSample2(); + this.imageOption2 = { + loadSrc:mainRes, + placeholderSrc:placeholderRes, + context:getContext(this) as common.UIAbilityContext + } + }) + ImageKnifeComponent({ imageKnifeOption: this.imageOption2 }).width(300).height(300).backgroundColor(Color.Pink) + + + }.width('100%') + + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index 82b2574..1dfdd2c 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -32,6 +32,7 @@ "pages/OptionTestPage", "pages/SignatureTestPage", "pages/hspCacheTestPage", + "pages/multiHspTestPage", "pages/testManyNetImageLoadWithPage", "pages/testManyGifLoadWithPage", "pages/testImageAntiAliasingWithPage" diff --git a/sharedlibrary/src/main/ets/Index.ets b/sharedlibrary/src/main/ets/Index.ets index 32c769e..6e2450c 100644 --- a/sharedlibrary/src/main/ets/Index.ets +++ b/sharedlibrary/src/main/ets/Index.ets @@ -130,4 +130,6 @@ export { IDrawLifeCycle } from '@ohos/imageknife' export { LogUtil } from '@ohos/imageknife' // 额外开放初始化ImageKnife的方法 -export {InitImageKnife} from '../ets/pages/InitImageKnife' \ No newline at end of file +export {InitImageKnife} from '../ets/pages/InitImageKnife' + +export {GetRes1} from '../ets/pages/GetRes1' \ No newline at end of file diff --git a/sharedlibrary/src/main/ets/pages/GetRes1.ets b/sharedlibrary/src/main/ets/pages/GetRes1.ets new file mode 100644 index 0000000..6a02910 --- /dev/null +++ b/sharedlibrary/src/main/ets/pages/GetRes1.ets @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2023 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 common from '@ohos.app.ability.common' + +export class GetRes1{ + static getSample1():Resource { + return $r('app.media.setting'); + } +} \ No newline at end of file diff --git a/sharedlibrary2/.gitignore b/sharedlibrary2/.gitignore new file mode 100644 index 0000000..e2713a2 --- /dev/null +++ b/sharedlibrary2/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/sharedlibrary2/build-profile.json5 b/sharedlibrary2/build-profile.json5 new file mode 100644 index 0000000..befa101 --- /dev/null +++ b/sharedlibrary2/build-profile.json5 @@ -0,0 +1,10 @@ +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default" + } + ] +} \ No newline at end of file diff --git a/sharedlibrary2/hvigorfile.ts b/sharedlibrary2/hvigorfile.ts new file mode 100644 index 0000000..0e65ea8 --- /dev/null +++ b/sharedlibrary2/hvigorfile.ts @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').hspTasks diff --git a/sharedlibrary2/oh-package.json5 b/sharedlibrary2/oh-package.json5 new file mode 100644 index 0000000..f6d8e3a --- /dev/null +++ b/sharedlibrary2/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "license": "Apache-2.0", + "devDependencies": {}, + "author": "", + "name": "sharedlibrary2", + "description": "Please describe the basic information.", + "main": "./src/main/ets/Index.ets", + "version": "1.0.0", + "dependencies": { + } +} diff --git a/sharedlibrary2/src/main/ets/Index.ets b/sharedlibrary2/src/main/ets/Index.ets new file mode 100644 index 0000000..aeba7a3 --- /dev/null +++ b/sharedlibrary2/src/main/ets/Index.ets @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2023 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. + */ + +export {GetRes2} from '../ets/pages/GetRes2' \ No newline at end of file diff --git a/sharedlibrary2/src/main/ets/pages/GetRes2.ets b/sharedlibrary2/src/main/ets/pages/GetRes2.ets new file mode 100644 index 0000000..36bfdef --- /dev/null +++ b/sharedlibrary2/src/main/ets/pages/GetRes2.ets @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2023 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 common from '@ohos.app.ability.common' + +export class GetRes2{ + static getSample2():Resource { + return $r('app.media.icon_loading'); + } +} \ No newline at end of file diff --git a/sharedlibrary2/src/main/ets/pages/Index.ets b/sharedlibrary2/src/main/ets/pages/Index.ets new file mode 100644 index 0000000..f2894ad --- /dev/null +++ b/sharedlibrary2/src/main/ets/pages/Index.ets @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2023 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. + */ + + +@Entry +@Component +struct Index { + + + build() { + Column(){ + Text('Hello world') + } + } +} \ No newline at end of file diff --git a/sharedlibrary2/src/main/module.json5 b/sharedlibrary2/src/main/module.json5 new file mode 100644 index 0000000..ff37b1a --- /dev/null +++ b/sharedlibrary2/src/main/module.json5 @@ -0,0 +1,13 @@ +{ + "module": { + "name": "sharedlibrary2", + "type": "shared", + "description": "$string:shared_desc", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "pages": "$profile:main_pages" + } +} \ No newline at end of file diff --git a/sharedlibrary2/src/main/resources/base/element/color.json b/sharedlibrary2/src/main/resources/base/element/color.json new file mode 100644 index 0000000..1bbc9aa --- /dev/null +++ b/sharedlibrary2/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/sharedlibrary2/src/main/resources/base/element/string.json b/sharedlibrary2/src/main/resources/base/element/string.json new file mode 100644 index 0000000..98e1d8a --- /dev/null +++ b/sharedlibrary2/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/sharedlibrary2/src/main/resources/base/media/icon_loading.png b/sharedlibrary2/src/main/resources/base/media/icon_loading.png new file mode 100644 index 0000000000000000000000000000000000000000..592d50b21425381cbd1117c67fe195e778bca5e6 GIT binary patch literal 2134 zcmV-c2&wmpP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D2kS{hK~#8N?VQ=G zO;H@j&mW+?E9A+GB9f^n52OeoV+!HHkQY;kTx2Fg<}oryA#=ve^E}V2}r&P>%^yraVwQ7}`H*a2A)~s2ho;-OXrQ$=Z z1ipRyRxMt<*eB1+(xpq)`}gmqbUcWaz#=+UG4i{f_Nwr!hw`SPXwB$!{neoywpFfw<(Qqbk`t<2knw@OV!*}oAsjXYL z`sCqR`r*R|DHY7;&!4F^S;ypT_`1IbL7 z9XtzN;7lND2@_`L1cHSN7gBM^fB^$^Ker_K^y!m2efl&Nhupn;S4u|5sX(xH?OLC_Ns}gpe)hQn zj|x0LZFvtLK9mw}a4ry_!+-YdS#|vQadrRxefhL>Ky5@11h?#uA3x+%cjQE1St6@I zbg%mL>!-SQ?W%?j9jbQk-Yq{#CaA5qZr#$i|BV|r)U#*L+?K?b^7cp#t%YW5Vog-@aY0$ZycsX2R^S zwk#Ehkz^*!4&GErAnX7Hdm~eUXst70W_tAKA*GW6-n2}bms6)ssqf#vOXM+BnLG!Q)?rm zKo7iqP~%>|el4FQ8{DcGj0iLN6iQ%$UoIawMOcfNf2qRyW`pVl++0+HzcX@SFr4Wr`BVC_p;1Is^{JTK^-rO<({ zSg|6NW~M=d24$)ih8^NcVNDAY#)2hmWd*zwm@qr3@#Du+SuC42ZIWM~d_oIcv}h5P z#d7G-A^G*mC-g0R+QyLN5eZ0X&*x7xUIqm(GXC>B`Y|0oEINI_sk3IZb%N+4D$VC@|KEh|%-VaX^E zs}r!uvU26hDwRsT`R2U0}{gc4@ z_3NoPFOZA1Gd4bf*mloE1*J-rDtW)y2)o*uG&|_V+4uww88U>5$`p*~fphHdiQ)ThT@zF#51!=lO}26>`a|HRZ8a`^e#q^9_>57A?(>(VR0f5 zEqRO^GHGTiRjQvT=bEfqnY)p`wD4X|4fp%I3|R`{a3P*RGvjdK(04Hxp)O&YU@N zMKqiUoI7_e6~)q}OP7r8LW~A6ab{-DoGGO_BS(&;(#*Iz%+`rOG#TpEt4D>|S+Zn_ zT*X0Ch)FZkx^-(Q%|V-wN%Mj~k}I4D1egM?Q>PA<<^}!dOsl+bdIl3_2Y;+=peKaI zQMNp^MO~fT2Al~5n3!qWw5d-V=9RIOILsm1jT<+n(#*7I(LzdR1{