1.Hsp适配,新增hsp的library模块,用于后续测试hsp能力

Signed-off-by: zhoulisheng <635547767@qq.com>
This commit is contained in:
zhoulisheng 2023-10-25 11:32:41 +08:00
parent fc4ab718bb
commit 219504ea8a
12 changed files with 155 additions and 0 deletions

6
library/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test

View File

@ -0,0 +1,10 @@
{
"apiType": 'stageMode',
"buildOption": {
},
"targets": [
{
"name": "default"
}
]
}

2
library/hvigorfile.ts Normal file
View File

@ -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

11
library/oh-package.json5 Normal file
View File

@ -0,0 +1,11 @@
{
"name": "library",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "./src/main/ets/Index.ets",
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@ohos/imageknife": "file:../imageknife"
}
}

View File

@ -0,0 +1,14 @@
/*
* 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.
*/

View File

@ -0,0 +1,78 @@
/*
* 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 } from '@ohos/imageknife'
import common from '@ohos.app.ability.common'
@Entry
@Component
struct Index {
@State imageOption1:ImageKnifeOption = {
loadSrc: $r('app.media.icon'),
context: getContext(this).createModuleContext('library') as common.UIAbilityContext
}
@State imageOption2:ImageKnifeOption = {
loadSrc: $r('app.media.icon'),
context: getContext(this).createModuleContext('library') as common.UIAbilityContext
}
@State imageOption3:ImageKnifeOption = {
loadSrc: $r('app.media.icon'),
context: getContext(this).createModuleContext('library') as common.UIAbilityContext
}
build() {
Scroll() {
Column() {
Button('点击加载Resource').onClick(()=>{
this.imageOption1 = {
loadSrc: $r('app.media.setting'),
// 只要涉及resource加载 在HSP中都要带上context属性
context: getContext(this).createModuleContext('library') as common.UIAbilityContext
}
})
ImageKnifeComponent({imageKnifeOption:this.imageOption1}).width(300).height(300).backgroundColor(Color.Pink)
Button('点击加载网络图片').onClick(()=>{
this.imageOption2 = {
loadSrc: 'https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB',
context: getContext(this).createModuleContext('library') as common.UIAbilityContext
}
})
ImageKnifeComponent({imageKnifeOption:this.imageOption2}).width(300).height(300).backgroundColor(Color.Pink)
Button('点击加载本地文件').onClick(()=>{
getContext(this).createModuleContext('library').resourceManager.getMediaContent($r('app.media.setting').id).then((data:Uint8Array)=>{
let path = globalThis.ImageKnife.getImageKnifeContext().filesDir+"/set.jpeg";
FileUtils.getInstance().writeFile(path,data.buffer)
FileUtils.getInstance().readFilePicAsync(path).then(buffer=>{
this.imageOption3 = {
loadSrc: path,
context: getContext(this).createModuleContext('library') as common.UIAbilityContext
}
})
})
})
ImageKnifeComponent({imageKnifeOption:this.imageOption3}).width(300).height(300).backgroundColor(Color.Pink)
}.width('100%')
}
.width('100%')
.height('100%')
}
}

View File

@ -0,0 +1,13 @@
{
"module": {
"name": "library",
"type": "shared",
"description": "$string:shared_desc",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"pages": "$profile:main_pages"
}
}

View File

@ -0,0 +1,8 @@
{
"color": [
{
"name": "white",
"value": "#FFFFFF"
}
]
}

View File

@ -0,0 +1,8 @@
{
"string": [
{
"name": "shared_desc",
"value": "description"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -0,0 +1,5 @@
{
"src": [
"pages/Index"
]
}