140 lines
5.6 KiB
Plaintext
140 lines
5.6 KiB
Plaintext
/*
|
|
* Copyright (C) 2024 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, CacheStrategy, ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife';
|
|
|
|
@Entry
|
|
@Component
|
|
struct TestCacheDataPage {
|
|
@State cacheUpLimit: number = 0;
|
|
@State currentNum: number = 0;
|
|
@State currentSize: number = 0;
|
|
@State currentWidth: number = 200
|
|
@State currentHeight: number = 200
|
|
@State markersLimitText: string = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
|
|
@State markersNumText: string = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
|
|
@State markersSizeText: string = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
|
|
@State ImageKnifeOption: ImageKnifeOption = {
|
|
loadSrc: "",
|
|
objectFit: ImageFit.Contain,
|
|
onLoadListener: {
|
|
onLoadFailed: (err) => {
|
|
console.error("Load Failed Reason: " + err);
|
|
},
|
|
onLoadSuccess: (data) => {
|
|
return data;
|
|
},
|
|
},
|
|
border: { radius: 50 }
|
|
}
|
|
|
|
aboutToAppear(): void {
|
|
ImageKnife.getInstance().initFileCache(getContext(this), 256, 256 * 1024 * 1024, "ImageKnifeCache1")
|
|
}
|
|
|
|
build() {
|
|
Column() {
|
|
|
|
ImageKnifeComponent(
|
|
{ imageKnifeOption: this.ImageKnifeOption })
|
|
.height(this.currentHeight)
|
|
.width(this.currentWidth)
|
|
.margin({ top: 10 })
|
|
|
|
Button($r('app.string.load_memory'))
|
|
.onClick(() => {
|
|
this.ImageKnifeOption = {
|
|
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 },
|
|
}
|
|
})
|
|
Button($r('app.string.load_disk'))
|
|
.onClick(() => {
|
|
this.ImageKnifeOption = {
|
|
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.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 });
|
|
}
|
|
.height('100%').width('100%').margin({ top: 50 })
|
|
}
|
|
} |