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 0000000..592d50b Binary files /dev/null and b/sharedlibrary2/src/main/resources/base/media/icon_loading.png differ diff --git a/sharedlibrary2/src/main/resources/base/profile/main_pages.json b/sharedlibrary2/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000..1898d94 --- /dev/null +++ b/sharedlibrary2/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +}