update code because of checkcode
Signed-off-by: tyBrave <tianyong21@h-partners.com>
This commit is contained in:
parent
4b1e84f5ec
commit
c05e338ceb
|
@ -23,6 +23,9 @@ struct TestCacheDataPage {
|
|||
@Local currentSize: number = 0;
|
||||
@Local currentWidth: number = 200
|
||||
@Local currentHeight: number = 200
|
||||
@Local markersLimitText: string = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
|
||||
@Local markersNumText: string = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
|
||||
@Local markersSizeText: string = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
|
||||
@Local ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
|
||||
loadSrc: "",
|
||||
objectFit: ImageFit.Contain,
|
||||
|
@ -53,7 +56,7 @@ struct TestCacheDataPage {
|
|||
Button($r('app.string.load_memory'))
|
||||
.onClick(() => {
|
||||
this.ImageKnifeOption = new ImageKnifeOption({
|
||||
loadSrc: "https://img0.baidu.com/it/u=1530797181,174436037&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800",
|
||||
loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg",
|
||||
objectFit: ImageFit.Contain,
|
||||
writeCacheStrategy: CacheStrategy.Memory,
|
||||
border: { radius: 50 },
|
||||
|
@ -62,51 +65,73 @@ struct TestCacheDataPage {
|
|||
Button($r('app.string.load_disk'))
|
||||
.onClick(() => {
|
||||
this.ImageKnifeOption = new ImageKnifeOption({
|
||||
loadSrc: "https://q7.itc.cn/images01/20240223/ce80229bf9934dff97cdf2ad7be1dcb8.jpeg",
|
||||
loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg",
|
||||
objectFit: ImageFit.Contain,
|
||||
writeCacheStrategy: CacheStrategy.File,
|
||||
border: { radius: 50 },
|
||||
})
|
||||
})
|
||||
Text($r('app.string.cur_cache_limit', this.cacheUpLimit)).fontSize(20).margin({ bottom: 8 });
|
||||
Text($r('app.string.cur_cache_image_num', this.currentNum)).fontSize(20).margin({ bottom: 8 });
|
||||
Text($r('app.string.cur_cache_size', this.currentSize)).fontSize(20).margin({ bottom: 20 });
|
||||
Text($r('app.string.cur_cache_limit', this.markersLimitText, this.cacheUpLimit))
|
||||
.fontSize(20)
|
||||
.margin({ bottom: 8 });
|
||||
Text($r('app.string.cur_cache_image_num', this.markersNumText, this.currentNum))
|
||||
.fontSize(20)
|
||||
.margin({ bottom: 8 });
|
||||
Text($r('app.string.cur_cache_size', this.markersSizeText, this.currentSize)).fontSize(20).margin({ bottom: 20 });
|
||||
|
||||
Button($r('app.string.get_cur_memory_limit')).onClick(() => {
|
||||
let result = ImageKnife.getInstance().getCacheUpperLimit(CacheStrategy.Memory);
|
||||
this.markersLimitText = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
|
||||
if (result) {
|
||||
this.cacheUpLimit = result / (1024 * 1024);
|
||||
} else {
|
||||
this.cacheUpLimit = 0;
|
||||
}
|
||||
}).margin({ bottom: 8 });
|
||||
Button($r('app.string.get_img_number_of_cache')).onClick(() => {
|
||||
let result = ImageKnife.getInstance().getCurrentPicturesNum(CacheStrategy.Memory);
|
||||
this.markersNumText = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
|
||||
if (result) {
|
||||
this.currentNum = result;
|
||||
} else {
|
||||
this.currentNum = 0;
|
||||
}
|
||||
}).margin({ bottom: 8 });
|
||||
Button($r('app.string.get_cur_memory_size')).onClick(() => {
|
||||
let result = ImageKnife.getInstance().getCurrentCacheSize(CacheStrategy.Memory);
|
||||
this.markersSizeText = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
|
||||
if (result) {
|
||||
this.currentSize = result / (1024 * 1024);
|
||||
} else {
|
||||
this.currentSize = 0;
|
||||
}
|
||||
}).margin({ bottom: 8 });
|
||||
|
||||
Button($r('app.string.get_cur_disk_limit')).onClick(() => {
|
||||
let result = ImageKnife.getInstance().getCacheUpperLimit(CacheStrategy.File);
|
||||
this.markersLimitText = getContext(this).resourceManager.getStringSync($r('app.string.disk'))
|
||||
if (result) {
|
||||
this.cacheUpLimit = result / (1024 * 1024);
|
||||
} else {
|
||||
this.cacheUpLimit = 0;
|
||||
}
|
||||
}).margin({ bottom: 8 });
|
||||
Button($r('app.string.get_img_number_of_disk')).onClick(() => {
|
||||
let result = ImageKnife.getInstance().getCurrentPicturesNum(CacheStrategy.File);
|
||||
this.markersNumText = getContext(this).resourceManager.getStringSync($r('app.string.disk'))
|
||||
if (result) {
|
||||
this.currentNum = result;
|
||||
} else {
|
||||
this.currentNum = 0;
|
||||
}
|
||||
}).margin({ bottom: 8 });
|
||||
Button($r('app.string.get_cur_disk_size')).onClick(() => {
|
||||
let result = ImageKnife.getInstance().getCurrentCacheSize(CacheStrategy.File);
|
||||
this.markersSizeText = getContext(this).resourceManager.getStringSync($r('app.string.disk'))
|
||||
if (result) {
|
||||
this.currentSize = result / (1024 * 1024);
|
||||
} else {
|
||||
this.currentSize = 0;
|
||||
}
|
||||
}).margin({ bottom: 8 });
|
||||
}
|
||||
|
|
|
@ -382,15 +382,15 @@
|
|||
},
|
||||
{
|
||||
"name": "cur_cache_limit",
|
||||
"value": "current cache limit:%dM"
|
||||
"value": "%s:current cache limit:%fM"
|
||||
},
|
||||
{
|
||||
"name": "cur_cache_image_num",
|
||||
"value": "current cache image number:%d"
|
||||
"value": "%s:current cache image number:%d"
|
||||
},
|
||||
{
|
||||
"name": "cur_cache_size",
|
||||
"value": "current cache size:%dM"
|
||||
"value": "%s:current cache size:%fM"
|
||||
},
|
||||
{
|
||||
"name": "load_memory",
|
||||
|
@ -487,6 +487,14 @@
|
|||
{
|
||||
"name": "test_cancel_callback_btn",
|
||||
"value": "test callback of cancel"
|
||||
},
|
||||
{
|
||||
"name": "memory",
|
||||
"value": "Memory"
|
||||
},
|
||||
{
|
||||
"name": "disk",
|
||||
"value": "Disk"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -378,15 +378,15 @@
|
|||
},
|
||||
{
|
||||
"name": "cur_cache_limit",
|
||||
"value": "当前缓存上限:%dM"
|
||||
"value": "%s:当前缓存上限:%fM"
|
||||
},
|
||||
{
|
||||
"name": "cur_cache_image_num",
|
||||
"value": "当前缓存图片数量:%d"
|
||||
"value": "%s:当前缓存图片数量:%d"
|
||||
},
|
||||
{
|
||||
"name": "cur_cache_size",
|
||||
"value": "当前缓存的大小:%dM"
|
||||
"value": "%s:当前缓存的大小:%fM"
|
||||
},
|
||||
{
|
||||
"name": "load_memory",
|
||||
|
@ -483,6 +483,14 @@
|
|||
{
|
||||
"name": "test_cancel_callback_btn",
|
||||
"value": "测试加载取消回调接口"
|
||||
},
|
||||
{
|
||||
"name": "memory",
|
||||
"value": "内存"
|
||||
},
|
||||
{
|
||||
"name": "disk",
|
||||
"value": "磁盘"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -13,7 +13,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
|
||||
import { ImageKnifeOption, ImageKnife, ImageKnifeRequest, ImageKnifeRequestSource } from "@ohos/imageknife"
|
||||
import {
|
||||
ImageKnifeOption,
|
||||
ImageKnife,
|
||||
ImageKnifeRequest,
|
||||
ImageKnifeRequestSource,
|
||||
CacheStrategy
|
||||
} from "@ohos/imageknife"
|
||||
import { common } from '@kit.AbilityKit';
|
||||
|
||||
export default function imageFormatAndSize() {
|
||||
|
@ -41,16 +47,14 @@ export default function imageFormatAndSize() {
|
|||
let width = 0;
|
||||
let height = 0;
|
||||
let imageFormat: string = "";
|
||||
|
||||
let url: string =
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/ed/v3/KMO4D6D2QGuVOCLX4AhOFA/ef51xAaLQuK7BsnuD9abog.jpg"
|
||||
let imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
|
||||
loadSrc: $r('app.media.icon'),
|
||||
loadSrc: url,
|
||||
})
|
||||
await new Promise<string>((resolve, reject) => {
|
||||
imageKnifeOption.onLoadListener = {
|
||||
onLoadSuccess: (data, imageknifeData) => {
|
||||
width = imageknifeData.imageWidth
|
||||
height = imageknifeData.imageHeight
|
||||
imageFormat = imageknifeData.type!
|
||||
resolve("")
|
||||
},
|
||||
onLoadFailed(err) {
|
||||
|
@ -70,9 +74,16 @@ export default function imageFormatAndSize() {
|
|||
)
|
||||
ImageKnife.getInstance().execute(request);
|
||||
})
|
||||
let data = await ImageKnife.getInstance()
|
||||
.getCacheImage(url, CacheStrategy.Memory);
|
||||
if (data) {
|
||||
width = data.imageWidth
|
||||
height = data.imageHeight
|
||||
imageFormat = data.type!
|
||||
}
|
||||
expect(width != 0).assertTrue();
|
||||
expect(height != 0).assertTrue();
|
||||
expect(imageFormat != "").assertTrue();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue