新增图片加载回调信息demo及其xts
Signed-off-by: tyBrave <tianyong21@h-partners.com>
This commit is contained in:
parent
9c0b4ebace
commit
1a2326c691
|
@ -197,6 +197,12 @@ struct Index {
|
|||
uri: 'pages/TestLoadCancelListenerPage',
|
||||
});
|
||||
})
|
||||
Button($r('app.string.test_callback')).margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestImageKnifeCallbackPage',
|
||||
|
||||
});
|
||||
})
|
||||
}
|
||||
} .width('100%')
|
||||
.height('100%')
|
||||
|
|
|
@ -80,7 +80,7 @@ struct TestCacheDataPage {
|
|||
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);
|
||||
let result = ImageKnife.getInstance().getCacheLimitSize(CacheStrategy.Memory);
|
||||
this.markersLimitText = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
|
||||
if (result) {
|
||||
this.cacheUpLimit = result / (1024 * 1024);
|
||||
|
@ -89,7 +89,7 @@ struct TestCacheDataPage {
|
|||
}
|
||||
}).margin({ bottom: 8 });
|
||||
Button($r('app.string.get_img_number_of_cache')).onClick(() => {
|
||||
let result = ImageKnife.getInstance().getCurrentPicturesNum(CacheStrategy.Memory);
|
||||
let result = ImageKnife.getInstance().getCurrentCacheNum(CacheStrategy.Memory);
|
||||
this.markersNumText = getContext(this).resourceManager.getStringSync($r('app.string.memory'))
|
||||
if (result) {
|
||||
this.currentNum = result;
|
||||
|
@ -108,7 +108,7 @@ struct TestCacheDataPage {
|
|||
}).margin({ bottom: 8 });
|
||||
|
||||
Button($r('app.string.get_cur_disk_limit')).onClick(() => {
|
||||
let result = ImageKnife.getInstance().getCacheUpperLimit(CacheStrategy.File);
|
||||
let result = ImageKnife.getInstance().getCacheLimitSize(CacheStrategy.File);
|
||||
this.markersLimitText = getContext(this).resourceManager.getStringSync($r('app.string.disk'))
|
||||
if (result) {
|
||||
this.cacheUpLimit = result / (1024 * 1024);
|
||||
|
@ -117,7 +117,7 @@ struct TestCacheDataPage {
|
|||
}
|
||||
}).margin({ bottom: 8 });
|
||||
Button($r('app.string.get_img_number_of_disk')).onClick(() => {
|
||||
let result = ImageKnife.getInstance().getCurrentPicturesNum(CacheStrategy.File);
|
||||
let result = ImageKnife.getInstance().getCurrentCacheNum(CacheStrategy.File);
|
||||
this.markersNumText = getContext(this).resourceManager.getStringSync($r('app.string.disk'))
|
||||
if (result) {
|
||||
this.currentNum = result;
|
||||
|
|
|
@ -0,0 +1,412 @@
|
|||
/*
|
||||
* 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 { ImageKnifeComponent, ImageKnifeData, ImageKnifeOption, ImageKnifeRequest } from '@ohos/imageknife';
|
||||
import { router } from '@kit.ArkUI';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct TestImageKnifeCallbackPage {
|
||||
@State imageKnifeOption: ImageKnifeOption = {
|
||||
loadSrc: "",
|
||||
objectFit: ImageFit.Contain,
|
||||
border: { radius: 50 }
|
||||
};
|
||||
@State currentWidth: number = 200
|
||||
@State currentHeight: number = 200
|
||||
@State url: string | undefined = ""
|
||||
@State imageType: string | undefined = ""
|
||||
@State imageWidth: number | undefined = 0
|
||||
@State imageHeight: number | undefined = 0
|
||||
@State imageSize: number | undefined = 0
|
||||
@State componentWidth: number | undefined = 0
|
||||
@State componentHeight: number | undefined = 0
|
||||
@State frameNum: number | undefined = 0
|
||||
@State decodeSize: string | undefined = ""
|
||||
@State err_msg: string | undefined = ""
|
||||
@State err_phase: string | undefined = ""
|
||||
@State err_code: number | undefined = 0
|
||||
@State http_code: number | undefined = 0
|
||||
@State reqStartTime: string | undefined = ""
|
||||
@State reqEndTime: string | undefined = ""
|
||||
@State reqCancelTime: string | undefined = ""
|
||||
@State memoryStartTime: string | undefined = ""
|
||||
@State memoryEndTime: string | undefined = ""
|
||||
@State diskStartTime: string | undefined = ""
|
||||
@State diskEndTime: string | undefined = ""
|
||||
@State netStartTime: string | undefined = ""
|
||||
@State netEndTime: string | undefined = ""
|
||||
@State decodeStartTime: string | undefined = ""
|
||||
@State decodeEndTime: string | undefined = ""
|
||||
@State renderTime: string | undefined = ""
|
||||
@State showChild: boolean = true;
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Text($r('app.string.img_url', this.url)).fontSize(14)
|
||||
Text($r('app.string.img_format', this.imageType)).fontSize(14)
|
||||
Text($r('app.string.img_master_size', this.imageWidth, this.imageHeight, this.imageSize)).fontSize(14)
|
||||
Text($r('app.string.componentWH', this.componentWidth, this.componentHeight)).fontSize(14)
|
||||
Text($r('app.string.img_frame', this.frameNum)).fontSize(14)
|
||||
Text($r('app.string.img_content_size', this.decodeSize)).fontSize(14)
|
||||
Text($r('app.string.err_msg', this.err_msg)).fontSize(14)
|
||||
Text($r('app.string.err_phase', this.err_phase)).fontSize(14)
|
||||
Text($r('app.string.err_code', this.err_code)).fontSize(14)
|
||||
Text($r('app.string.http_code', this.http_code)).fontSize(14)
|
||||
Text($r('app.string.req_start_time', this.reqStartTime)).fontSize(14)
|
||||
Text($r('app.string.req_end_time', this.reqEndTime)).fontSize(14)
|
||||
Text($r('app.string.req_cancel_time', this.reqCancelTime)).fontSize(14)
|
||||
Text($r('app.string.memory_start_time', this.memoryStartTime)).fontSize(14)
|
||||
Text($r('app.string.memory_end_time', this.memoryEndTime)).fontSize(14)
|
||||
Text($r('app.string.disk_start_time', this.diskStartTime)).fontSize(14)
|
||||
Text($r('app.string.disk_end_time', this.diskEndTime)).fontSize(14)
|
||||
Text($r('app.string.net_start_time', this.netStartTime)).fontSize(14)
|
||||
Text($r('app.string.net_end_time', this.netEndTime)).fontSize(14)
|
||||
Text($r('app.string.decode_start_time', this.decodeStartTime)).fontSize(14)
|
||||
Text($r('app.string.decode_end_time', this.decodeEndTime)).fontSize(14)
|
||||
Text($r('app.string.render_time', this.renderTime)).fontSize(14)
|
||||
|
||||
Scroll() {
|
||||
Column() {
|
||||
|
||||
Row() {
|
||||
Button($r('app.string.Network_images'))
|
||||
.fontSize(13)
|
||||
.onClick(() => {
|
||||
this.destroy();
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/10/v3/qaEzwkU0QeKb1yehnP2Xig/q7fxAlgMQKup-HUBayRLGQ.jpg",
|
||||
objectFit: ImageFit.Contain,
|
||||
onLoadListener: {
|
||||
onLoadStart: (data) => {
|
||||
this.analyzeStartCallBackData(data);
|
||||
},
|
||||
onLoadFailed: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
},
|
||||
onLoadSuccess: (data, imageData, req) => {
|
||||
this.analyzeSuccessCallBackData(req?.getImageKnifeData());
|
||||
},
|
||||
onLoadCancel: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
}
|
||||
},
|
||||
border: { radius: 50 },
|
||||
onComplete: (event) => {
|
||||
if (event && event.loadingStatus == 0) {
|
||||
this.renderTime = this.formatDate(Date.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Button($r('app.string.gif'))
|
||||
.fontSize(13)
|
||||
.onClick(() => {
|
||||
this.destroy();
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: 'https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658',
|
||||
objectFit: ImageFit.Contain,
|
||||
onLoadListener: {
|
||||
onLoadStart: (data) => {
|
||||
this.analyzeStartCallBackData(data);
|
||||
},
|
||||
onLoadFailed: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
},
|
||||
onLoadSuccess: (data, imageData, req) => {
|
||||
this.analyzeSuccessCallBackData(req?.getImageKnifeData());
|
||||
},
|
||||
onLoadCancel: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
}
|
||||
},
|
||||
border: { radius: 50 },
|
||||
onComplete: (event) => {
|
||||
if (event && event.loadingStatus == 0) {
|
||||
this.renderTime = this.formatDate(Date.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Button($r('app.string.local_pic'))
|
||||
.fontSize(13)
|
||||
.onClick(() => {
|
||||
this.destroy();
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
objectFit: ImageFit.Contain,
|
||||
onLoadListener: {
|
||||
onLoadStart: (data) => {
|
||||
this.analyzeStartCallBackData(data);
|
||||
},
|
||||
onLoadFailed: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
},
|
||||
onLoadSuccess: (data, imageData, req) => {
|
||||
this.analyzeSuccessCallBackData(req?.getImageKnifeData());
|
||||
},
|
||||
onLoadCancel: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
}
|
||||
},
|
||||
border: { radius: 50 },
|
||||
onComplete: (event) => {
|
||||
if (event && event.loadingStatus == 0) {
|
||||
this.renderTime = this.formatDate(Date.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Row() {
|
||||
Button($r('app.string.net_load_failed'))
|
||||
.fontSize(13)
|
||||
.onClick(() => {
|
||||
this.destroy();
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: "https://img-blog.csdn.net/20140514114039140",
|
||||
objectFit: ImageFit.Contain,
|
||||
onLoadListener: {
|
||||
onLoadStart: (data) => {
|
||||
this.analyzeStartCallBackData(data);
|
||||
},
|
||||
onLoadFailed: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
},
|
||||
onLoadSuccess: (data, imageData, req) => {
|
||||
this.analyzeSuccessCallBackData(req?.getImageKnifeData());
|
||||
},
|
||||
onLoadCancel: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
}
|
||||
},
|
||||
border: { radius: 50 },
|
||||
onComplete: (event) => {
|
||||
if (event && event.loadingStatus == 0) {
|
||||
this.renderTime = this.formatDate(Date.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Button($r('app.string.local_load_failed'))
|
||||
.fontSize(13)
|
||||
.onClick(() => {
|
||||
this.destroy();
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: 'app.media.xxx',
|
||||
objectFit: ImageFit.Contain,
|
||||
onLoadListener: {
|
||||
onLoadStart: (data) => {
|
||||
this.analyzeStartCallBackData(data);
|
||||
},
|
||||
onLoadFailed: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
},
|
||||
onLoadSuccess: (data, imageData, req) => {
|
||||
this.analyzeSuccessCallBackData(req?.getImageKnifeData());
|
||||
},
|
||||
onLoadCancel: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
}
|
||||
},
|
||||
border: { radius: 50 },
|
||||
onComplete: (event) => {
|
||||
if (event && event.loadingStatus == 0) {
|
||||
this.renderTime = this.formatDate(Date.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Button($r('app.string.share_load_failed'))
|
||||
.fontSize(13)
|
||||
.onClick(() => {
|
||||
this.destroy();
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: 'datashare://ssas',
|
||||
objectFit: ImageFit.Contain,
|
||||
onLoadListener: {
|
||||
onLoadStart: (data) => {
|
||||
this.analyzeStartCallBackData(data);
|
||||
},
|
||||
onLoadFailed: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
},
|
||||
onLoadSuccess: (data, imageData, req) => {
|
||||
this.analyzeSuccessCallBackData(req?.getImageKnifeData());
|
||||
},
|
||||
onLoadCancel: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
}
|
||||
},
|
||||
border: { radius: 50 },
|
||||
onComplete: (event) => {
|
||||
if (event && event.loadingStatus == 0) {
|
||||
this.renderTime = this.formatDate(Date.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Button($r('app.string.test_cancel_callback_btn'))
|
||||
.fontSize(13)
|
||||
.onClick(() => {
|
||||
this.destroy();
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/bf/v3/lSjrRwFcS-ez6jp1ALSQFg/0n7R7XinSPyrYLqDu_1dfw.jpg",
|
||||
objectFit: ImageFit.Contain,
|
||||
onLoadListener: {
|
||||
onLoadStart: (data) => {
|
||||
this.showChild = false;
|
||||
this.analyzeStartCallBackData(data);
|
||||
},
|
||||
onLoadFailed: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
},
|
||||
onLoadSuccess: (data, imageData, req) => {
|
||||
this.analyzeSuccessCallBackData(req?.getImageKnifeData());
|
||||
},
|
||||
onLoadCancel: (res, req) => {
|
||||
this.analyzeFailedBackData(res, req?.getImageKnifeData());
|
||||
}
|
||||
},
|
||||
border: { radius: 50 },
|
||||
onComplete: (event) => {
|
||||
if (event && event.loadingStatus == 0) {
|
||||
this.renderTime = this.formatDate(Date.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Button($r('app.string.list_pic'))
|
||||
.fontSize(13)
|
||||
.onClick(() => {
|
||||
router.push({
|
||||
url: 'pages/TestListImageKnifeCallbackPage',
|
||||
});
|
||||
})
|
||||
if (this.showChild) {
|
||||
ImageKnifeComponent(
|
||||
{ imageKnifeOption: this.imageKnifeOption })
|
||||
.height(this.currentHeight)
|
||||
.width(this.currentWidth)
|
||||
.margin({ top: 20, bottom: 20 })
|
||||
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
}.alignItems(HorizontalAlign.Start)
|
||||
}
|
||||
|
||||
formatDate(time: number | undefined) {
|
||||
if (!time) {
|
||||
return;
|
||||
}
|
||||
let date = new Date(time);
|
||||
const year = date.getFullYear().toString()
|
||||
let month = (date.getMonth() + 1).toString()
|
||||
let day = date.getDate().toString()
|
||||
let hour = date.getHours().toString()
|
||||
let min = date.getMinutes().toString()
|
||||
let seconds = date.getSeconds().toString()
|
||||
let mill = date.getMilliseconds();
|
||||
return `${year}-${month}-${day} ${hour}:${min}:${seconds}:${mill}`
|
||||
}
|
||||
|
||||
analyzeStartCallBackData(req: ImageKnifeRequest | undefined) {
|
||||
let data = req?.getImageKnifeData();
|
||||
if (data) {
|
||||
if (typeof req?.imageKnifeOption.loadSrc == 'string') {
|
||||
this.url = req?.imageKnifeOption.loadSrc;
|
||||
}
|
||||
this.componentWidth = req?.componentWidth;
|
||||
this.componentHeight = req?.componentHeight;
|
||||
this.reqStartTime = this.formatDate(data.timeInfo?.requestStartTime);
|
||||
this.memoryStartTime = this.formatDate(data.timeInfo?.memoryCheckStartTime);
|
||||
this.memoryEndTime = this.formatDate(data.timeInfo?.memoryCheckEndTime);
|
||||
}
|
||||
}
|
||||
|
||||
analyzeSuccessCallBackData(data: ImageKnifeData | undefined) {
|
||||
if (data) {
|
||||
this.imageWidth = data.imageWidth;
|
||||
this.imageHeight = data.imageHeight;
|
||||
this.imageSize = data.bufSize;
|
||||
this.frameNum = data.frameCount;
|
||||
this.decodeSize = JSON.stringify(data.decodeImages);
|
||||
this.imageType = data.type;
|
||||
this.reqEndTime = this.formatDate(data.timeInfo?.requestEndTime);
|
||||
this.diskStartTime = this.formatDate(data.timeInfo?.diskCheckStartTime);
|
||||
this.diskEndTime = this.formatDate(data.timeInfo?.diskCheckEndTime);
|
||||
this.netStartTime = this.formatDate(data.timeInfo?.netRequestStartTime);
|
||||
this.netEndTime = this.formatDate(data.timeInfo?.netRequestEndTime);
|
||||
this.decodeStartTime = this.formatDate(data.timeInfo?.diskCheckStartTime);
|
||||
this.decodeEndTime = this.formatDate(data.timeInfo?.diskCheckEndTime);
|
||||
}
|
||||
}
|
||||
|
||||
analyzeFailedBackData(res: string, data: ImageKnifeData | undefined) {
|
||||
if (data) {
|
||||
this.err_msg = res;
|
||||
this.err_phase = data.errorInfo?.phase;
|
||||
this.err_code = data.errorInfo?.code;
|
||||
this.http_code = data.errorInfo?.httpCode;
|
||||
this.reqEndTime = this.formatDate(data.timeInfo?.requestEndTime);
|
||||
this.diskStartTime = this.formatDate(data.timeInfo?.diskCheckStartTime);
|
||||
this.diskEndTime = this.formatDate(data.timeInfo?.diskCheckEndTime);
|
||||
this.netStartTime = this.formatDate(data.timeInfo?.netRequestStartTime);
|
||||
this.netEndTime = this.formatDate(data.timeInfo?.netRequestEndTime);
|
||||
this.decodeStartTime = this.formatDate(data.timeInfo?.diskCheckStartTime);
|
||||
this.decodeEndTime = this.formatDate(data.timeInfo?.diskCheckEndTime);
|
||||
this.reqCancelTime = this.formatDate(data.timeInfo?.requestCancelTime)
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.currentWidth = 200
|
||||
this.currentHeight = 200
|
||||
this.url = ""
|
||||
this.imageType = ""
|
||||
this.imageWidth = 0
|
||||
this.imageHeight = 0
|
||||
this.imageSize = 0
|
||||
this.componentWidth = 0
|
||||
this.componentHeight = 0
|
||||
this.frameNum = 0
|
||||
this.decodeSize = ""
|
||||
this.err_msg = ""
|
||||
this.err_phase = ""
|
||||
this.err_code = 0
|
||||
this.http_code = 0
|
||||
this.reqStartTime = ""
|
||||
this.reqEndTime = ""
|
||||
this.reqCancelTime = ""
|
||||
this.memoryStartTime = ""
|
||||
this.memoryEndTime = ""
|
||||
this.diskStartTime = ""
|
||||
this.diskEndTime = ""
|
||||
this.netStartTime = ""
|
||||
this.netEndTime = ""
|
||||
this.decodeStartTime = ""
|
||||
this.decodeEndTime = ""
|
||||
this.renderTime = ""
|
||||
this.showChild = true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* 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 { ImageKnifeComponent} from '@ohos/imageknife';
|
||||
|
||||
class ArrayElement {
|
||||
src: string = "";
|
||||
w: number = 0;
|
||||
h: number = 0;
|
||||
}
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct TestListImageKnifeCallbackPage {
|
||||
private wid: number = 200;
|
||||
private hig: number = 200;
|
||||
private dataArray: ESObject[] = [
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg",
|
||||
"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/78/v3/qQJpAtRGQe2e_VhbGHDgIw/b3zlit99S6GybD3XdNwqJw.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/55/v3/5DZ2LLqYSsK85-shqgLveQ/7ZXcyCWNTvOzQP5FFLBGkg.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/25/v3/jgB2ekkTRX-3yTYZalnANQ/xff_x9cbSPqb7fbNwgJa7A.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/alXwXLHKSyCAIWt_ydgD2g/BCCuu25TREOitQxM7eYOEw.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/63/v3/qbe6NZkCQyGcITvdWoZBgg/Y-5U1z3GT_yaK8CBD3jkwg.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/16/v3/fm2tO4TsRH6mv_D_nSSd5w/FscLpLwQQ-KuV7oaprFK2Q.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/89/v3/UAUvtPHqRD-GWWANsEC57Q/zcRJCQebQ322Aby4jzmwmQ.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/tUUzzx73R4yp8G--lMhuWQ/EBbcu_dLTT-Jj68XAh6mtA.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/37/v3/12rH1yiEQmK9wlOOcy5avQ/RzBXiEBRRqOC7LRkwNj6VA.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/9a/v3/TpRN4AIzRoyUXIqWdKoE0g/ShOnD_tfS46HDbpSWhbCkQ.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/03/v3/H3X17s8eTdS2w56JgbB5jQ/a45sT-j8Sbe8sSQXTzeYvQ.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/10/v3/qaEzwkU0QeKb1yehnP2Xig/q7fxAlgMQKup-HUBayRLGQ.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/96/v3/rMJJoAflTDSWa1z2pHs2wg/8dOqD0GlQBOCL5AvQok9FQ.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/ed/v3/KMO4D6D2QGuVOCLX4AhOFA/ef51xAaLQuK7BsnuD9abog.jpg",
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/d9/v3/FSZH0aTdSqWxeAaxoPvi0g/RqxPxUCXQFiTMBfKTF9kkw.jpg",
|
||||
"https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
|
||||
'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/bf/v3/lSjrRwFcS-ez6jp1ALSQFg/0n7R7XinSPyrYLqDu_1dfw.jpg',
|
||||
'https://img-blog.csdn.net/20140514114029140',
|
||||
'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
|
||||
$r('app.media.pngSample'),
|
||||
$r('app.media.rabbit')
|
||||
]
|
||||
private data: Array<ArrayElement> = [];
|
||||
|
||||
aboutToAppear(): void {
|
||||
for (let i = 0; i < this.dataArray.length; i++) {
|
||||
let element: ArrayElement = {
|
||||
src: this.dataArray[i],
|
||||
w: this.wid -(i*5),
|
||||
h: this.hig -(i*5)
|
||||
}
|
||||
this.data.push(element);
|
||||
}
|
||||
}
|
||||
|
||||
build() {
|
||||
List({ space: 3 }) {
|
||||
ForEach(this.data, (item: ArrayElement) => {
|
||||
ListItem() {
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption:
|
||||
{
|
||||
loadSrc: item.src,
|
||||
objectFit: ImageFit.Contain,
|
||||
onLoadListener: {
|
||||
onLoadStart: (data) => {
|
||||
console.log("listCache start:{ url:"+data?.imageKnifeOption.loadSrc +",componentWidth:"+data?.componentWidth+",componentHeight:"+data?.componentHeight+"},"
|
||||
+ JSON.stringify(data?.getImageKnifeData()))
|
||||
},
|
||||
onLoadFailed: (res, req) => {
|
||||
console.log("listCache onLoadFailed:res:" + res + ";" + JSON.stringify(req?.getImageKnifeData()))
|
||||
},
|
||||
onLoadSuccess: (data, imageData,req) => {
|
||||
console.log("listCache onLoadSuccess:" + JSON.stringify(req?.getImageKnifeData()))
|
||||
},
|
||||
onLoadCancel: (res, req) => {
|
||||
console.log("listCache onLoadCancel:res:" + res + ";" + JSON.stringify(req?.getImageKnifeData()))
|
||||
}
|
||||
},
|
||||
border: { radius: 50 },
|
||||
}
|
||||
}).height(item.w).width(item.h)
|
||||
}.width('100%')
|
||||
}, (item: ArrayElement,index) => (item.src+index))
|
||||
}.width('100%').height('100%')
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife';
|
||||
import { ImageKnife, ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife';
|
||||
|
||||
|
||||
@Entry
|
||||
|
@ -35,6 +35,7 @@ struct TestLoadCancelListenerPage {
|
|||
Button($r('app.string.rm_component_of_net'))
|
||||
.margin(20)
|
||||
.onClick(() => {
|
||||
this.clearCache();
|
||||
this.ImageKnifeOption = {
|
||||
loadSrc: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg",
|
||||
objectFit: ImageFit.Contain,
|
||||
|
@ -64,6 +65,7 @@ struct TestLoadCancelListenerPage {
|
|||
Button($r('app.string.rm_component_of_local'))
|
||||
.margin(20)
|
||||
.onClick(() => {
|
||||
this.clearCache();
|
||||
this.ImageKnifeOption = {
|
||||
loadSrc: $r('app.media.loading'),
|
||||
objectFit: ImageFit.Contain,
|
||||
|
@ -92,4 +94,8 @@ struct TestLoadCancelListenerPage {
|
|||
.height('100%')
|
||||
.width('100%')
|
||||
}
|
||||
|
||||
clearCache(){
|
||||
ImageKnife.getInstance().removeAllMemoryCache();
|
||||
}
|
||||
}
|
|
@ -511,6 +511,126 @@
|
|||
{
|
||||
"name": "request_concurrency",
|
||||
"value": "Set request concurrency"
|
||||
},
|
||||
{
|
||||
"name": "test_callback",
|
||||
"value": "test callback data of load pic"
|
||||
},
|
||||
{
|
||||
"name": "gif",
|
||||
"value": "gif"
|
||||
},
|
||||
{
|
||||
"name": "local_pic",
|
||||
"value": "local picture"
|
||||
},
|
||||
{
|
||||
"name": "share_pic",
|
||||
"value": "share picture"
|
||||
},
|
||||
{
|
||||
"name": "net_load_failed",
|
||||
"value": "netWork load failed"
|
||||
},
|
||||
{
|
||||
"name": "local_load_failed",
|
||||
"value": "local load failed"
|
||||
},
|
||||
{
|
||||
"name": "share_load_failed",
|
||||
"value": "shared load failed"
|
||||
},
|
||||
{
|
||||
"name": "list_pic",
|
||||
"value": "load picture list"
|
||||
},
|
||||
{
|
||||
"name": "img_url",
|
||||
"value": "url of the service setting:%s"
|
||||
},
|
||||
{
|
||||
"name": "img_format",
|
||||
"value": "picture format:%s"
|
||||
},
|
||||
{
|
||||
"name": "img_master_size",
|
||||
"value": "the original width and height of the picture-w:%d ,h:%d, size:%d"
|
||||
},
|
||||
{
|
||||
"name": "componentWH",
|
||||
"value": "component width and height-w:%d ,h:%d "
|
||||
},
|
||||
{
|
||||
"name": "img_frame",
|
||||
"value": "the number of frames of the picture:%d "
|
||||
},
|
||||
{
|
||||
"name": "img_content_size",
|
||||
"value": "picture decoded width and height size:%s "
|
||||
},
|
||||
{
|
||||
"name": "err_msg",
|
||||
"value": "error message:%s "
|
||||
},
|
||||
{
|
||||
"name": "err_phase",
|
||||
"value": "error phase:%s "
|
||||
},
|
||||
{
|
||||
"name": "err_code",
|
||||
"value": "error code:%d "
|
||||
},
|
||||
{
|
||||
"name": "http_code",
|
||||
"value": "http code:%d "
|
||||
},
|
||||
{
|
||||
"name": "req_start_time",
|
||||
"value": "image request start time point:%s "
|
||||
},
|
||||
{
|
||||
"name": "req_end_time",
|
||||
"value": "the point in time at which the image request ends:%s "
|
||||
},
|
||||
{
|
||||
"name": "req_cancel_time",
|
||||
"value": "the point at which the image request is cancelled:%s "
|
||||
},
|
||||
{
|
||||
"name": "memory_start_time",
|
||||
"value": "start checking the memory cache point in time:%s "
|
||||
},
|
||||
{
|
||||
"name": "memory_end_time",
|
||||
"value": "end Check the memory cache time point:%s "
|
||||
},
|
||||
{
|
||||
"name": "disk_start_time",
|
||||
"value": "start checking the disk cache point in time:%s "
|
||||
},
|
||||
{
|
||||
"name": "disk_end_time",
|
||||
"value": "end Check the disk cache time point:%s "
|
||||
},
|
||||
{
|
||||
"name": "net_start_time",
|
||||
"value": "start time of the network request:%s "
|
||||
},
|
||||
{
|
||||
"name": "net_end_time",
|
||||
"value": "end time of the network request:%s:%s "
|
||||
},
|
||||
{
|
||||
"name": "decode_start_time",
|
||||
"value": "decoding start time point:%s "
|
||||
},
|
||||
{
|
||||
"name": "decode_end_time",
|
||||
"value": "decoding end time point:%s "
|
||||
},
|
||||
{
|
||||
"name": "render_time",
|
||||
"value": "render successful time:%s "
|
||||
}
|
||||
]
|
||||
}
|
|
@ -36,6 +36,8 @@
|
|||
"pages/SetMaxRequestPage",
|
||||
"pages/MaxRequest1",
|
||||
"pages/MaxRequest2",
|
||||
"pages/MaxRequest3"
|
||||
"pages/MaxRequest3",
|
||||
"pages/TestImageKnifeCallbackPage",
|
||||
"pages/TestListImageKnifeCallbackPage"
|
||||
]
|
||||
}
|
|
@ -507,6 +507,126 @@
|
|||
{
|
||||
"name": "request_concurrency",
|
||||
"value": "设置请求并发度"
|
||||
},
|
||||
{
|
||||
"name": "test_callback",
|
||||
"value": "测试图片加载回调数据"
|
||||
},
|
||||
{
|
||||
"name": "gif",
|
||||
"value": "gif"
|
||||
},
|
||||
{
|
||||
"name": "local_pic",
|
||||
"value": "本地图片"
|
||||
},
|
||||
{
|
||||
"name": "share_pic",
|
||||
"value": "共享图片"
|
||||
},
|
||||
{
|
||||
"name": "net_load_failed",
|
||||
"value": "网络加载失败"
|
||||
},
|
||||
{
|
||||
"name": "local_load_failed",
|
||||
"value": "本地加载失败"
|
||||
},
|
||||
{
|
||||
"name": "share_load_failed",
|
||||
"value": "共享图片加载失败"
|
||||
},
|
||||
{
|
||||
"name": "list_pic",
|
||||
"value": "加载图片列表"
|
||||
},
|
||||
{
|
||||
"name": "img_url",
|
||||
"value": "业务设置的url:%s"
|
||||
},
|
||||
{
|
||||
"name": "img_format",
|
||||
"value": "图片的格式:%s"
|
||||
},
|
||||
{
|
||||
"name": "img_master_size",
|
||||
"value": "图片的原始宽高大小-宽:%d ,高:%d, 大小:%d"
|
||||
},
|
||||
{
|
||||
"name": "componentWH",
|
||||
"value": "component的宽高-宽:%d ,高:%d "
|
||||
},
|
||||
{
|
||||
"name": "img_frame",
|
||||
"value": "图片的帧数:%d "
|
||||
},
|
||||
{
|
||||
"name": "img_content_size",
|
||||
"value": "图片解码后宽高大小:%s "
|
||||
},
|
||||
{
|
||||
"name": "err_msg",
|
||||
"value": "错误信息:%s "
|
||||
},
|
||||
{
|
||||
"name": "err_phase",
|
||||
"value": "发生错误阶段:%s "
|
||||
},
|
||||
{
|
||||
"name": "err_code",
|
||||
"value": "错误code:%d "
|
||||
},
|
||||
{
|
||||
"name": "http_code",
|
||||
"value": "网络请求code:%d "
|
||||
},
|
||||
{
|
||||
"name": "req_start_time",
|
||||
"value": "图片的请求开始时间点:%s "
|
||||
},
|
||||
{
|
||||
"name": "req_end_time",
|
||||
"value": "图片请求结束的时间点:%s "
|
||||
},
|
||||
{
|
||||
"name": "req_cancel_time",
|
||||
"value": "图片请求取消的时间点:%s "
|
||||
},
|
||||
{
|
||||
"name": "memory_start_time",
|
||||
"value": "开始检查内存缓存时间点:%s "
|
||||
},
|
||||
{
|
||||
"name": "memory_end_time",
|
||||
"value": "结束检查内存缓存时间点:%s "
|
||||
},
|
||||
{
|
||||
"name": "disk_start_time",
|
||||
"value": "开始检查磁盘缓存时间点:%s "
|
||||
},
|
||||
{
|
||||
"name": "disk_end_time",
|
||||
"value": "结束检查磁盘缓存时间点:%s "
|
||||
},
|
||||
{
|
||||
"name": "net_start_time",
|
||||
"value": "网络请求开始时间点:%s "
|
||||
},
|
||||
{
|
||||
"name": "net_end_time",
|
||||
"value": "网络请求结束时间点:%s "
|
||||
},
|
||||
{
|
||||
"name": "decode_start_time",
|
||||
"value": "解码开始时间点:%s "
|
||||
},
|
||||
{
|
||||
"name": "decode_end_time",
|
||||
"value": "解码结束时间点:%s "
|
||||
},
|
||||
{
|
||||
"name": "render_time",
|
||||
"value": "渲染成功的时间:%s "
|
||||
}
|
||||
]
|
||||
}
|
|
@ -19,6 +19,7 @@ import MemoryLruCacheTest from './MemoryLruCache.test';
|
|||
import ImageKnifeTest from './ImageKnife.test';
|
||||
import Transform from './transform.test';
|
||||
import imageFormatAndSize from './imageFormatAndSize.test'
|
||||
import loadCallBackData from './loadCallBackData.test'
|
||||
|
||||
export default function testsuite() {
|
||||
MemoryLruCacheTest();
|
||||
|
@ -28,4 +29,5 @@ export default function testsuite() {
|
|||
ImageKnifeTest();
|
||||
Transform();
|
||||
imageFormatAndSize();
|
||||
loadCallBackData();
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
|
||||
import {
|
||||
ImageKnifeOption,
|
||||
ImageKnife,
|
||||
ImageKnifeRequest,
|
||||
ImageKnifeRequestSource,
|
||||
CacheStrategy
|
||||
} from "@ohos/imageknife"
|
||||
import { common } from '@kit.AbilityKit';
|
||||
|
||||
export default function loadCallBackData() {
|
||||
describe('loadCallBackData', () => {
|
||||
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
||||
beforeAll(() => {
|
||||
// Presets an action, which is performed only once before all test cases of the test suite start.
|
||||
// This API supports only one parameter: preset action function.
|
||||
});
|
||||
beforeEach(() => {
|
||||
// Presets an action, which is performed before each unit test case starts.
|
||||
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||
// This API supports only one parameter: preset action function.
|
||||
});
|
||||
afterEach(() => {
|
||||
// Presets a clear action, which is performed after each unit test case ends.
|
||||
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||
// This API supports only one parameter: clear action function.
|
||||
});
|
||||
afterAll(() => {
|
||||
// Presets a clear action, which is performed after all test cases of the test suite end.
|
||||
// This API supports only one parameter: clear action function.
|
||||
});
|
||||
it('startAndSuccess-CallBack', 0, async () => {
|
||||
let startCallBack: ESObject = undefined;
|
||||
let successCallBack: ESObject = undefined;
|
||||
let url: string =
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/63/v3/qbe6NZkCQyGcITvdWoZBgg/Y-5U1z3GT_yaK8CBD3jkwg.jpg"
|
||||
let imageKnifeOption: ImageKnifeOption = {
|
||||
loadSrc: url,
|
||||
}
|
||||
await new Promise<string>((resolve, reject) => {
|
||||
imageKnifeOption.onLoadListener = {
|
||||
onLoadStart: (data) => {
|
||||
startCallBack = data?.getImageKnifeData();
|
||||
},
|
||||
onLoadSuccess: (data, imageknifeData,req) => {
|
||||
successCallBack = req?.getImageKnifeData();
|
||||
resolve("")
|
||||
},
|
||||
onLoadFailed(err) {
|
||||
reject(err)
|
||||
}
|
||||
}
|
||||
let request = new ImageKnifeRequest(
|
||||
imageKnifeOption,
|
||||
imageKnifeOption.context !== undefined ? imageKnifeOption.context : getContext() as common.UIAbilityContext,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
{
|
||||
showPixelMap(version: number, pixelMap: PixelMap | string) {
|
||||
}
|
||||
}
|
||||
)
|
||||
ImageKnife.getInstance().execute(request);
|
||||
})
|
||||
expect(startCallBack != undefined).assertTrue();
|
||||
expect(successCallBack != undefined).assertTrue();
|
||||
});
|
||||
it('failed-CallBack', 0, async () => {
|
||||
let failedCallBack: ESObject = undefined;
|
||||
let url: string =
|
||||
"https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/163/v3/qbe6NZkCQyGcITvdWoZBgg/Y-5U1z3GT_yaK8CBD3jkwg.jpg"
|
||||
let imageKnifeOption: ImageKnifeOption = {
|
||||
loadSrc: url,
|
||||
}
|
||||
await new Promise<string>((resolve, reject) => {
|
||||
imageKnifeOption.onLoadListener = {
|
||||
onLoadStart: (data) => {
|
||||
},
|
||||
onLoadSuccess: (data, imageknifeData) => {
|
||||
},
|
||||
onLoadFailed(res,req) {
|
||||
failedCallBack = req?.getImageKnifeData();
|
||||
resolve(res)
|
||||
}
|
||||
}
|
||||
let request = new ImageKnifeRequest(
|
||||
imageKnifeOption,
|
||||
imageKnifeOption.context !== undefined ? imageKnifeOption.context : getContext() as common.UIAbilityContext,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
{
|
||||
showPixelMap(version: number, pixelMap: PixelMap | string) {
|
||||
}
|
||||
}
|
||||
)
|
||||
ImageKnife.getInstance().execute(request);
|
||||
})
|
||||
expect(failedCallBack != undefined).assertTrue();
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue