mirror of
https://gitee.com/openharmony-tpc/ImageKnife.git
synced 2026-05-24 17:25:44 +08:00
Merge remote-tracking branch 'origin/3.x'
# Conflicts: # CHANGELOG.md # README.md # README_zh.md # entry/src/main/ets/common/CustomEngineKeyImpl.ets # entry/src/main/ets/pages/DownSamplePage.ets # entry/src/main/ets/pages/ImageAnimatorPage.ets # entry/src/main/ets/pages/Index.ets # entry/src/main/ets/pages/LoadStatePage.ets # entry/src/main/ets/pages/ObjectFitPage.ets # entry/src/main/ets/pages/SingleImage.ets # entry/src/main/ets/pages/TestCacheDataPage.ets # entry/src/main/ets/pages/TestChangeColorPage.ets # entry/src/main/ets/pages/TestLoadCancelListenerPage.ets # entry/src/main/ets/pages/TestSetCustomImagePage.ets # entry/src/main/ets/pages/TestTaskResourcePage.ets # entry/src/main/ets/pages/TestWriteCacheStage.ets # entry/src/main/ets/pages/UserPage.ets # entry/src/main/resources/base/element/string.json # entry/src/main/resources/base/profile/main_pages.json # entry/src/main/resources/zh_CN/element/string.json # entry/src/ohosTest/ets/test/List.test.ets # entry/src/ohosTest/ets/test/SamplingTest.test.ets # entry/src/ohosTest/ets/test/imageFormatAndSize.test.ets # library/oh-package.json5 # library/src/main/ets/ImageKnife.ets # library/src/main/ets/ImageKnifeDispatcher.ets # library/src/main/ets/ImageKnifeLoader.ets # library/src/main/ets/components/ImageKnifeAnimatorComponent.ets # library/src/main/ets/components/ImageKnifeComponent.ets # library/src/main/ets/downsampling/BaseDownsampling.ets # library/src/main/ets/downsampling/DownsampleStartegy.ets # library/src/main/ets/downsampling/Downsampler.ets # library/src/main/ets/key/DefaultEngineKey.ets # library/src/main/ets/model/ImageKnifeData.ets # library/src/main/ets/model/ImageKnifeOption.ets # library/src/main/ets/model/ImageKnifeRequest.ets # sharedlibrary/src/main/ets/pages/Index.ets
This commit is contained in:
@@ -12,8 +12,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { DownsampleStrategy } from '@ohos/imageknife';
|
||||
import { IEngineKey, ImageKnifeOption, PixelMapTransformation,SparkMD5 ,ImageKnifeRequestSource} from '@ohos/libraryimageknife';
|
||||
import { IEngineKey, ImageKnifeOption, PixelMapTransformation,SparkMD5 ,ImageKnifeRequestSource,
|
||||
DownsampleStrategy} from '@ohos/libraryimageknife';
|
||||
|
||||
//全局自定义key demo
|
||||
@Sendable
|
||||
@@ -36,8 +36,8 @@ export class CustomEngineKeyImpl implements IEngineKey {
|
||||
if (imageKnifeOption.transformation) {
|
||||
key += "transformation=" + this.getTransformation(imageKnifeOption.transformation) + ";"
|
||||
}
|
||||
if ((imageKnifeOption.downsampleOf !== DownsampleStrategy.NONE && imageKnifeOption.downsampleOf !== undefined)) {
|
||||
key += "downsampleOf" + imageKnifeOption.downsampleOf +"width="+width+"height="+ height
|
||||
if ((imageKnifeOption.downsampleOf !== DownsampleStrategy.NONE && imageKnifeOption.downsampleOf !== undefined)) {
|
||||
key += "downsampleOf" + imageKnifeOption.downsampleOf + "width=" + width + "height=" + height
|
||||
}
|
||||
}
|
||||
return key
|
||||
|
||||
@@ -17,7 +17,7 @@ import hilog from '@ohos.hilog';
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import window from '@ohos.window';
|
||||
import { ImageKnife, InitImageKnife, LogUtil } from '@ohos/libraryimageknife';
|
||||
import { ImageKnife, InitImageKnife } from '@ohos/libraryimageknife';
|
||||
import { CustomEngineKeyImpl } from '../common/CustomEngineKeyImpl';
|
||||
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
|
||||
import { BusinessError } from '@ohos.base'
|
||||
|
||||
78
entry/src/main/ets/pages/CustomNetImagePage.ets
Normal file
78
entry/src/main/ets/pages/CustomNetImagePage.ets
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 { InfoItem } from './model/DataSourcePrefetching';
|
||||
import { PageViewModel } from './model/PageViewModel';
|
||||
import { ImageKnifeComponent, ImageKnife } from '@ohos/libraryimageknife';
|
||||
import { CommonDataSource, GetSession } from './model/CommonDataSource';
|
||||
import { rcp } from '@kit.RemoteCommunicationKit';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
export struct CustomNetImagePage {
|
||||
@State hotCommendList:CommonDataSource<InfoItem> = new CommonDataSource<InfoItem>([])
|
||||
aboutToAppear(): void {
|
||||
ImageKnife.getInstance().setMaxRequests(32)
|
||||
this.hotCommendList.addData(this.hotCommendList.totalCount(),PageViewModel.getItems())
|
||||
}
|
||||
aboutToDisappear(): void {
|
||||
ImageKnife.getInstance().setMaxRequests(8)
|
||||
}
|
||||
build() {
|
||||
Column() {
|
||||
WaterFlow() {
|
||||
LazyForEach(this.hotCommendList,(item: InfoItem)=>{
|
||||
FlowItem() {
|
||||
Column(){
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: {
|
||||
loadSrc: item.albumUrl,
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.failed"),
|
||||
customGetImage:custom
|
||||
}
|
||||
}).width("50%").height(200)
|
||||
}
|
||||
}.height(200)
|
||||
.backgroundColor("#95efd2")
|
||||
},(item: string) => item)
|
||||
}.columnsTemplate("1fr 1fr")
|
||||
.columnsGap(10)
|
||||
.rowsGap(5)
|
||||
.backgroundColor(0xFAEEE0)
|
||||
.width("100%").height("100%")
|
||||
}
|
||||
}
|
||||
}
|
||||
// 自定义下载方法
|
||||
@Concurrent
|
||||
async function custom(context: Context, src: string | PixelMap | Resource,headers?: Record<string,Object>): Promise<ArrayBuffer | undefined> {
|
||||
return new Promise((resolve,reject)=>{
|
||||
if (typeof src == "string") {
|
||||
let session = GetSession.session
|
||||
let req = new rcp.Request(src,"GET");
|
||||
session.fetch(req).then((response)=>{
|
||||
if(response.statusCode == 200) {
|
||||
let buffer = response.body
|
||||
resolve(buffer)
|
||||
} else {
|
||||
reject("rcp code:"+response.statusCode)
|
||||
}
|
||||
}).catch((err:BusinessError)=>{
|
||||
reject("error rcp src:"+src+",err:"+JSON.stringify(err))
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -20,18 +20,18 @@ import { Downsampler } from '@ohos/imageknife/src/main/ets/downsampling/Downsamp
|
||||
import { FileTypeUtil } from '@ohos/imageknife/src/main/ets/utils/FileTypeUtil';
|
||||
|
||||
@Entry
|
||||
@ComponentV2
|
||||
@Component
|
||||
struct DownSamplePage {
|
||||
@Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
|
||||
@State imageKnifeOption: ImageKnifeOption = {
|
||||
loadSrc: $r('app.media.startIcon'),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
objectFit: ImageFit.Contain
|
||||
})
|
||||
}
|
||||
isBrightness: boolean = false
|
||||
@Local beforeSampling: number = 0
|
||||
@Local afterSampling: number = 0
|
||||
@Local SamplingList: SamplingType[] = [
|
||||
@State beforeSampling: number = 0
|
||||
@State afterSampling: number = 0
|
||||
@State SamplingList: SamplingType[] = [
|
||||
|
||||
new SamplingType(7, "AT_LEAST"),
|
||||
new SamplingType(1, "AT_MOST"),
|
||||
@@ -43,77 +43,77 @@ struct DownSamplePage {
|
||||
new SamplingType(0, "NONE"),
|
||||
|
||||
]
|
||||
@Local checked: boolean = false
|
||||
@State checked: boolean = false
|
||||
|
||||
updateImageKnifeOption(value: string) {
|
||||
if (value === 'NONE') {
|
||||
this.imageKnifeOption = new ImageKnifeOption({
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
objectFit: ImageFit.Contain,
|
||||
downsampleOf: DownsampleStrategy.NONE
|
||||
})
|
||||
}
|
||||
this.originalPixMap($r('app.media.pngSample'))
|
||||
this.afterSamplingFunc($r('app.media.pngSample'))
|
||||
} else if (value === 'AT_MOST') {
|
||||
this.imageKnifeOption = new ImageKnifeOption({
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
objectFit: ImageFit.Contain,
|
||||
downsampleOf: DownsampleStrategy.AT_MOST
|
||||
})
|
||||
}
|
||||
this.originalPixMap($r('app.media.pngSample'))
|
||||
this.afterSamplingFunc($r('app.media.pngSample'))
|
||||
} else if (value === 'FIT_CENTER_MEMORY') {
|
||||
this.imageKnifeOption = new ImageKnifeOption({
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
objectFit: ImageFit.Contain,
|
||||
downsampleOf: DownsampleStrategy.FIT_CENTER_MEMORY
|
||||
})
|
||||
}
|
||||
this.originalPixMap($r('app.media.pngSample'))
|
||||
this.afterSamplingFunc($r('app.media.pngSample'))
|
||||
} else if (value === 'FIT_CENTER_QUALITY') {
|
||||
this.imageKnifeOption = new ImageKnifeOption({
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
objectFit: ImageFit.Contain,
|
||||
downsampleOf: DownsampleStrategy.FIT_CENTER_QUALITY
|
||||
})
|
||||
}
|
||||
this.originalPixMap($r('app.media.pngSample'))
|
||||
this.afterSamplingFunc($r('app.media.pngSample'))
|
||||
} else if (value === 'CENTER_OUTSIDE_MEMORY') {
|
||||
this.imageKnifeOption = new ImageKnifeOption({
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
objectFit: ImageFit.Contain,
|
||||
downsampleOf: DownsampleStrategy.CENTER_OUTSIDE_MEMORY
|
||||
})
|
||||
}
|
||||
this.originalPixMap($r('app.media.pngSample'))
|
||||
this.afterSamplingFunc($r('app.media.pngSample'))
|
||||
} else if (value === 'CENTER_OUTSIDE_QUALITY') {
|
||||
this.imageKnifeOption = new ImageKnifeOption({
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
objectFit: ImageFit.Contain,
|
||||
downsampleOf: DownsampleStrategy.CENTER_OUTSIDE_QUALITY
|
||||
})
|
||||
}
|
||||
this.originalPixMap($r('app.media.pngSample'))
|
||||
this.afterSamplingFunc($r('app.media.pngSample'))
|
||||
} else {
|
||||
this.imageKnifeOption = new ImageKnifeOption({
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
objectFit: ImageFit.Contain,
|
||||
downsampleOf: DownsampleStrategy.AT_LEAST
|
||||
})
|
||||
}
|
||||
this.originalPixMap($r('app.media.pngSample'))
|
||||
this.afterSamplingFunc($r('app.media.pngSample'))
|
||||
}
|
||||
@@ -130,7 +130,7 @@ struct DownSamplePage {
|
||||
}
|
||||
let imageInfo = await imageSource.getImageInfo()
|
||||
|
||||
if (this.imageKnifeOption.downsampleOf !== DownsampleStrategy.NONE){
|
||||
if (this.imageKnifeOption.downsampleOf !== DownsampleStrategy.NONE && this.imageKnifeOption.downsampleOf != undefined ) {
|
||||
let reqSize =
|
||||
new Downsampler().calculateScaling(typeValue, imageInfo.size.width, imageInfo.size.height, 300,
|
||||
300, this.imageKnifeOption.downsampleOf)
|
||||
|
||||
@@ -12,14 +12,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { AnimatorOption, ImageKnifeAnimatorComponent,ImageKnifeOption } from "@ohos/libraryimageknife"
|
||||
import { AnimatorOption, ImageKnifeAnimatorComponent } from "@ohos/libraryimageknife"
|
||||
|
||||
@Entry
|
||||
@ComponentV2
|
||||
@Component
|
||||
struct ImageAnimatorPage {
|
||||
@Local animatorOption: AnimatorOption = new AnimatorOption({
|
||||
@State animatorOption: AnimatorOption = {
|
||||
state: AnimationStatus.Running,
|
||||
iterations: -1,
|
||||
iterations: 1,
|
||||
onFinish:()=>{
|
||||
console.log("ImageKnifeAnimatorComponent animatorOption onFinish")
|
||||
},
|
||||
@@ -35,14 +35,14 @@ struct ImageAnimatorPage {
|
||||
onRepeat:()=>{
|
||||
console.log("ImageKnifeAnimatorComponent animatorOption onRepeat")
|
||||
}
|
||||
})
|
||||
@Local animatorOption1: AnimatorOption = new AnimatorOption({
|
||||
}
|
||||
@State animatorOption1: AnimatorOption = {
|
||||
state: AnimationStatus.Initial
|
||||
})
|
||||
@Local animatorOption2: AnimatorOption = new AnimatorOption({
|
||||
}
|
||||
@State animatorOption2: AnimatorOption = {
|
||||
state: AnimationStatus.Initial,
|
||||
reverse: true
|
||||
})
|
||||
}
|
||||
build() {
|
||||
Column(){
|
||||
Flex(){
|
||||
@@ -66,27 +66,27 @@ struct ImageAnimatorPage {
|
||||
})
|
||||
}
|
||||
ImageKnifeAnimatorComponent({
|
||||
imageKnifeOption:new ImageKnifeOption({
|
||||
imageKnifeOption:{
|
||||
loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
|
||||
placeholderSrc:$r('app.media.loading'),
|
||||
errorholderSrc:$r('app.media.failed')
|
||||
}),animatorOption:this.animatorOption
|
||||
}).width(200).height(200).backgroundColor(Color.Orange).margin({top:30})
|
||||
},animatorOption:this.animatorOption
|
||||
}).width(300).height(300).backgroundColor(Color.Orange).margin({top:30})
|
||||
Text($r('app.string.Display_the_first_frame')).fontSize(20)
|
||||
ImageKnifeAnimatorComponent({
|
||||
imageKnifeOption:new ImageKnifeOption({
|
||||
imageKnifeOption:{
|
||||
loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
|
||||
placeholderSrc:$r('app.media.loading'),
|
||||
errorholderSrc:$r('app.media.failed')
|
||||
}),animatorOption:this.animatorOption1
|
||||
},animatorOption:this.animatorOption1
|
||||
}).width(200).height(200).backgroundColor(Color.Orange).margin({top:30})
|
||||
Text($r('app.string.Display_the_last_frame')).fontSize(20)
|
||||
ImageKnifeAnimatorComponent({
|
||||
imageKnifeOption:new ImageKnifeOption({
|
||||
imageKnifeOption:{
|
||||
loadSrc:"https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658",
|
||||
placeholderSrc:$r('app.media.loading'),
|
||||
errorholderSrc:$r('app.media.failed')
|
||||
}),animatorOption:this.animatorOption2
|
||||
},animatorOption:this.animatorOption2
|
||||
}).width(200).height(200).backgroundColor(Color.Orange).margin({top:30})
|
||||
}.width("100%").height("100%")
|
||||
}
|
||||
|
||||
82
entry/src/main/ets/pages/ImageKnifeReload.ets
Normal file
82
entry/src/main/ets/pages/ImageKnifeReload.ets
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 { connection } from '@kit.NetworkKit'
|
||||
import { List } from '@kit.ArkTS'
|
||||
import { ImageKnifeRequest,ImageKnife,ImageKnifeComponent } from '@ohos/libraryimageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct ImageKnifeReload {
|
||||
aboutToAppear(): void {
|
||||
NetWatchState.init()
|
||||
}
|
||||
build() {
|
||||
Column() {
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption:{
|
||||
loadSrc:"https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp",
|
||||
placeholderSrc:$r('app.media.loading'),
|
||||
errorholderSrc:$r('app.media.failed'),
|
||||
onLoadListener:{
|
||||
onLoadFailed(err,request){
|
||||
NetWatchState.requestList.add(request)
|
||||
}
|
||||
}
|
||||
}
|
||||
}).width(200).height(200)
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption:{
|
||||
loadSrc:"https://img-blog.csdn.net/20140514114029140",
|
||||
placeholderSrc:$r('app.media.loading'),
|
||||
errorholderSrc:$r('app.media.failed'),
|
||||
onLoadListener:{
|
||||
onLoadFailed(err,request){
|
||||
NetWatchState.requestList.add(request)
|
||||
}
|
||||
}
|
||||
}
|
||||
}).width(200).height(200).margin({top:10})
|
||||
}.width("100%")
|
||||
.height("100%")
|
||||
}
|
||||
}
|
||||
|
||||
class NetWatchState {
|
||||
public static netConnection: connection.NetConnection | undefined = undefined
|
||||
public static requestList: List<ImageKnifeRequest> = new List()
|
||||
|
||||
static init() {
|
||||
NetWatchState.netConnection = connection.createNetConnection()
|
||||
// 注册订阅事件
|
||||
NetWatchState.netConnection.register(()=>{
|
||||
})
|
||||
// 订阅网络能力变化事件。调用register后,才能接收到此事件通知
|
||||
NetWatchState.netConnection.on("netCapabilitiesChange",(data:connection.NetCapabilityInfo)=>{
|
||||
if(NetWatchState.requestList.length > 0 && data.netHandle.netId >= 100) {
|
||||
NetWatchState.requestList.forEach((request)=>{
|
||||
ImageKnife.getInstance().reload(request)
|
||||
NetWatchState.requestList.remove(request)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static cancel(){
|
||||
if(NetWatchState.netConnection != undefined) {
|
||||
// 取消订阅
|
||||
NetWatchState.netConnection.unregister(()=>{})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,153 +15,176 @@
|
||||
import router from '@system.router';
|
||||
|
||||
@Entry
|
||||
@ComponentV2
|
||||
@Component
|
||||
struct Index {
|
||||
getResourceString(res: Resource) {
|
||||
|
||||
getResourceString(res:Resource){
|
||||
return getContext().resourceManager.getStringSync(res.id)
|
||||
}
|
||||
|
||||
|
||||
aboutToAppear(): void {
|
||||
|
||||
}
|
||||
|
||||
build() {
|
||||
Scroll() {
|
||||
Scroll(){
|
||||
Column() {
|
||||
Button($r('app.string.Test_ImageAnimator')).onClick(() => {
|
||||
Button($r('app.string.Test_ImageAnimator')).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/ImageAnimatorPage',
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_multiple_images')).margin({ top: 10 }).onClick(() => {
|
||||
Button($r('app.string.Network_reload')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/ImageKnifeReload',
|
||||
});
|
||||
})
|
||||
Button($r('app.string.preloading_prefetch')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/PrefetchAndCacheCount',
|
||||
});
|
||||
})
|
||||
Button($r('app.string.request_concurrency')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/SetMaxRequestPage',
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_multiple_images')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/TestCommonImage',
|
||||
});
|
||||
})
|
||||
Button(this.getResourceString($r('app.string.Multiple_images')) + " + reuse + LazyForeach")
|
||||
.margin({ top: 10 })
|
||||
.onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/UserPage',
|
||||
Button($r('app.string.Customize_RCP_network')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/CustomNetImagePage',
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_Task_error')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/TestTaskResourcePage',
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_HSP')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/TestHspPreLoadImage',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_SingleImage')).margin({ top: 10 }).onClick(() => {
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_SingleImage')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/SingleImage',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_custom_download')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/TestSetCustomImagePage',
|
||||
|
||||
});
|
||||
})
|
||||
// Button(this.getResourceString($r('app.string.Multiple_images')) + " + LazyForEach").margin({top:10}).onClick(()=>{
|
||||
// router.push({
|
||||
// uri: 'pages/ManyPhotoShowPage',
|
||||
//
|
||||
// });
|
||||
// })
|
||||
Button(this.getResourceString($r('app.string.Multiple_images')) + " + reuse + LazyForeach").margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/UserPage',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Image_Downsampling_Functionality')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/DownSamplePage',
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Display_long_image')).margin({ top: 10 }).onClick(() => {
|
||||
Button($r('app.string.Display_long_image')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/LongImagePage',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Image_Transformation')).margin({ top: 10 }).onClick(() => {
|
||||
Button($r('app.string.Image_scaling')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/TransformPage',
|
||||
|
||||
});
|
||||
})
|
||||
Button(this.getResourceString($r('app.string.Message_list')) + " + List").margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/TestImageFlash',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Custom_cache_key')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/SignatureTestPage',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Preloading_images_to_cache')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/TestPrefetchToFileCache',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Retrieve_image_display_from_cache')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/TestIsUrlExist',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_single_request_header')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/TestHeader',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_write_cache_strategy')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/TestWriteCacheStage',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Image_Transformation')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/ImageTransformation',
|
||||
|
||||
});
|
||||
|
||||
})
|
||||
Button($r('app.string.Test_media_URL')).margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/dataShareUriLoadPage',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Different_ObjectFit')).margin({ top: 10 }).onClick(() => {
|
||||
Button($r('app.string.Different_ObjectFit')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/ObjectFitPage',
|
||||
|
||||
});
|
||||
|
||||
})
|
||||
Button($r('app.string.Custom_cache_key')).margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/SignatureTestPage',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_image_loading_success_or_failure_events')).margin({ top: 10 }).onClick(() => {
|
||||
Button($r('app.string.Test_image_loading_success_or_failure_events')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/LoadStatePage',
|
||||
})
|
||||
})
|
||||
Button($r('app.string.Image_scaling')).margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TransformPage',
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
Button($r('app.string.Test_HSP')).margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestHspPreLoadImage',
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
Button($r('app.string.Test_custom_download')).margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestSetCustomImagePage',
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
Button(this.getResourceString($r('app.string.Message_list')) + " + List").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestImageFlash',
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
Button($r('app.string.Preloading_images_to_cache')).margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestPrefetchToFileCache',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Retrieve_image_display_from_cache')).margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestIsUrlExist',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_single_request_header')).margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestHeader',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_write_cache_strategy')).margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestWriteCacheStage',
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
Button($r('app.string.Test_removing_image_cache_interface')).margin({ top: 10 }).onClick(() => {
|
||||
Button($r('app.string.Test_removing_image_cache_interface')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/TestRemoveCache',
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_error_image_display')).margin({ top: 10 }).onClick(() => {
|
||||
Button($r('app.string.Test_error_image_display')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/TestErrorHolderPage',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.Test_Task_error')).margin({ top: 10 }).onClick(() => {
|
||||
Button($r('app.string.Test_media_URL')).margin({top:10}).onClick(()=>{
|
||||
router.push({
|
||||
uri: 'pages/TestTaskResourcePage',
|
||||
uri: 'pages/dataShareUriLoadPage',
|
||||
|
||||
});
|
||||
})
|
||||
Button($r('app.string.test_cache_btn')).margin({ top: 10 }).onClick(() => {
|
||||
@@ -179,8 +202,14 @@ struct Index {
|
||||
uri: 'pages/TestLoadCancelListenerPage',
|
||||
});
|
||||
})
|
||||
Button($r('app.string.test_callback')).margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestImageKnifeCallbackPage',
|
||||
|
||||
});
|
||||
})
|
||||
}
|
||||
}.width('100%')
|
||||
} .width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
51
entry/src/main/ets/pages/LazyForEachCache.ets
Normal file
51
entry/src/main/ets/pages/LazyForEachCache.ets
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 { InfoItem } from './model/DataSourcePrefetching';
|
||||
import { PageViewModel } from './model/PageViewModel';
|
||||
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
|
||||
import { CommonDataSource } from './model/CommonDataSource';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
export struct LazyForEachCache {
|
||||
@State hotCommendList:CommonDataSource<InfoItem> = new CommonDataSource<InfoItem>([])
|
||||
aboutToAppear(): void {
|
||||
this.hotCommendList.addData(this.hotCommendList.totalCount(),PageViewModel.getItems())
|
||||
}
|
||||
build() {
|
||||
Column() {
|
||||
List({ space: 16 }) {
|
||||
LazyForEach(this.hotCommendList, (item: InfoItem,index) => {
|
||||
ListItem() {
|
||||
Column({ space: 12 }) {
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption:{
|
||||
loadSrc: item.albumUrl,
|
||||
placeholderSrc:$r('app.media.loading')
|
||||
}
|
||||
}).width(100).height(100)
|
||||
Text(`${index}`)
|
||||
}.border({ width: 5 , color: "#000000"})
|
||||
}
|
||||
})
|
||||
}
|
||||
.cachedCount(5)
|
||||
.width("100%")
|
||||
.height("100%")
|
||||
.margin({ left: 10, right: 10 })
|
||||
.layoutWeight(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
51
entry/src/main/ets/pages/LazyForEachCount.ets
Normal file
51
entry/src/main/ets/pages/LazyForEachCount.ets
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 { InfoItem } from './model/DataSourcePrefetching';
|
||||
import { PageViewModel } from './model/PageViewModel';
|
||||
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
|
||||
import { CommonDataSource } from './model/CommonDataSource';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
export struct LazyForEachCount {
|
||||
@State hotCommendList:CommonDataSource<InfoItem> = new CommonDataSource<InfoItem>([])
|
||||
aboutToAppear(): void {
|
||||
this.hotCommendList.addData(this.hotCommendList.totalCount(),PageViewModel.getItems())
|
||||
}
|
||||
build() {
|
||||
Column() {
|
||||
List({ space: 16 }) {
|
||||
LazyForEach(this.hotCommendList, (item: InfoItem,index) => {
|
||||
ListItem() {
|
||||
Column({ space: 12 }) {
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption:{
|
||||
loadSrc: item.albumUrl,
|
||||
placeholderSrc:$r('app.media.loading')
|
||||
}
|
||||
}).width(100).height(100)
|
||||
Text(`${index}`)
|
||||
}.border({ width: 5 , color: "#000000"})
|
||||
}
|
||||
})
|
||||
}
|
||||
.cachedCount(30)
|
||||
.width("100%")
|
||||
.height("100%")
|
||||
.margin({ left: 10, right: 10 })
|
||||
.layoutWeight(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,12 @@ import { ImageKnifeComponent, ImageKnifeOption } from "@ohos/libraryimageknife"
|
||||
import matrix4 from '@ohos.matrix4'
|
||||
|
||||
@Entry
|
||||
@ComponentV2
|
||||
@Component
|
||||
struct LoadStatePage {
|
||||
|
||||
starTime:number = new Date().getTime()
|
||||
|
||||
@Local ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
|
||||
@State ImageKnifeOption: ImageKnifeOption = {
|
||||
loadSrc: $r("app.media.rabbit"),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
@@ -35,14 +35,14 @@ struct LoadStatePage {
|
||||
},
|
||||
},
|
||||
border: { radius: 50 }
|
||||
})
|
||||
@Local imageKnifeOption1: ImageKnifeOption = new ImageKnifeOption({
|
||||
}
|
||||
@State imageKnifeOption1: ImageKnifeOption = {
|
||||
loadSrc: $r('app.media.startIcon')
|
||||
})
|
||||
@Local message: string = ""
|
||||
@Local currentWidth: number = 200
|
||||
@Local currentHeight: number = 200
|
||||
@Local typeValue: string = ""
|
||||
}
|
||||
@State message: string = ""
|
||||
@State currentWidth: number = 200
|
||||
@State currentHeight: number = 200
|
||||
@State typeValue: string = ""
|
||||
build() {
|
||||
Column() {
|
||||
Text($r('app.string.TIPS'))
|
||||
@@ -50,7 +50,7 @@ struct LoadStatePage {
|
||||
Row() {
|
||||
Button($r('app.string.Test_failure_success'))
|
||||
.onClick(() => {
|
||||
this.ImageKnifeOption = new ImageKnifeOption({
|
||||
this.ImageKnifeOption = {
|
||||
loadSrc: "https://www.openharmony.cn/_nuxt/img/logo.dcf95b3.png",
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
@@ -75,7 +75,7 @@ struct LoadStatePage {
|
||||
onComplete:(event)=>{
|
||||
console.error("Load onComplete width:"+event?.width , " height:"+event?.height , " componentWidth:"+event?.componentWidth," componentHeight:" + event?.componentHeight);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
.margin({ top: 20 })
|
||||
@@ -85,7 +85,7 @@ struct LoadStatePage {
|
||||
ImageKnifeComponent({ imageKnifeOption: this.ImageKnifeOption }).height(this.currentHeight).width(this.currentWidth)
|
||||
.margin({ top: 20 })
|
||||
Button($r('app.string.Custom_download_failed')).onClick(()=>{
|
||||
this.imageKnifeOption1 = new ImageKnifeOption({
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: "abc",
|
||||
placeholderSrc:$r('app.media.loading'),
|
||||
errorholderSrc:$r('app.media.failed'),
|
||||
@@ -95,7 +95,7 @@ struct LoadStatePage {
|
||||
this.message = "err:" + err
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}).margin({ top: 20 })
|
||||
Text(this.message).fontSize(20).margin({ top: 20 })
|
||||
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).height(this.currentHeight).width(this.currentWidth)
|
||||
@@ -109,7 +109,7 @@ struct LoadStatePage {
|
||||
}
|
||||
// 自定义下载方法
|
||||
@Concurrent
|
||||
async function custom(context: Context, src: string | PixelMap | Resource): Promise<ArrayBuffer | undefined> {
|
||||
async function custom(context: Context, src: string | PixelMap | Resource,headers?: Record<string,Object>): Promise<ArrayBuffer | undefined> {
|
||||
console.info("ImageKnife:: custom download:" + src)
|
||||
// 举例写死从本地文件读取,也可以自己请求网络图片
|
||||
return undefined
|
||||
|
||||
55
entry/src/main/ets/pages/MaxRequest1.ets
Normal file
55
entry/src/main/ets/pages/MaxRequest1.ets
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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,ImageKnife } from '@ohos/libraryimageknife';
|
||||
import { CommonDataSource } from './model/CommonDataSource';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct MaxRequest1 {
|
||||
@State hotCommendList:CommonDataSource<string> = new CommonDataSource<string>([])
|
||||
private data: Array<string> = []
|
||||
aboutToAppear(): void {
|
||||
ImageKnife.getInstance().setMaxRequests(8)
|
||||
for (let index = 0; index < 200; index++) {
|
||||
this.data.push(`https://img-blog.csdn.net/20140514114029140?${index}`)
|
||||
}
|
||||
this.hotCommendList.addData(this.hotCommendList.totalCount(),this.data)
|
||||
}
|
||||
build() {
|
||||
Column() {
|
||||
WaterFlow() {
|
||||
LazyForEach(this.hotCommendList,(item: string)=>{
|
||||
FlowItem() {
|
||||
Column(){
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: {
|
||||
loadSrc: item,
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.failed"),
|
||||
}
|
||||
}).width("50%").height(160)
|
||||
}
|
||||
}.height(200)
|
||||
.backgroundColor("#95efd2")
|
||||
},(item: string) => item)
|
||||
}.columnsTemplate("1fr 1fr")
|
||||
.cachedCount(8)
|
||||
.columnsGap(10)
|
||||
.rowsGap(5)
|
||||
.backgroundColor(0xFAEEE0)
|
||||
.width("100%").height("100%")
|
||||
}
|
||||
}
|
||||
}
|
||||
55
entry/src/main/ets/pages/MaxRequest2.ets
Normal file
55
entry/src/main/ets/pages/MaxRequest2.ets
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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,ImageKnife } from '@ohos/libraryimageknife';
|
||||
import { CommonDataSource } from './model/CommonDataSource';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct MaxRequest2 {
|
||||
@State hotCommendList:CommonDataSource<string> = new CommonDataSource<string>([])
|
||||
private data: Array<string> = []
|
||||
aboutToAppear(): void {
|
||||
ImageKnife.getInstance().setMaxRequests(20)
|
||||
for (let index = 200; index < 400; index++) {
|
||||
this.data.push(`https://img-blog.csdn.net/20140514114029140?${index}`)
|
||||
}
|
||||
this.hotCommendList.addData(this.hotCommendList.totalCount(),this.data)
|
||||
}
|
||||
build() {
|
||||
Column() {
|
||||
WaterFlow() {
|
||||
LazyForEach(this.hotCommendList,(item: string)=>{
|
||||
FlowItem() {
|
||||
Column(){
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: {
|
||||
loadSrc: item,
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.failed"),
|
||||
}
|
||||
}).width("50%").height(160)
|
||||
}
|
||||
}.height(200)
|
||||
.backgroundColor("#95efd2")
|
||||
},(item: string) => item)
|
||||
}.columnsTemplate("1fr 1fr")
|
||||
.cachedCount(20)
|
||||
.columnsGap(10)
|
||||
.rowsGap(5)
|
||||
.backgroundColor(0xFAEEE0)
|
||||
.width("100%").height("100%")
|
||||
}
|
||||
}
|
||||
}
|
||||
55
entry/src/main/ets/pages/MaxRequest3.ets
Normal file
55
entry/src/main/ets/pages/MaxRequest3.ets
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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,ImageKnife } from '@ohos/libraryimageknife';
|
||||
import { CommonDataSource } from './model/CommonDataSource';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct MaxRequest3 {
|
||||
@State hotCommendList:CommonDataSource<string> = new CommonDataSource<string>([])
|
||||
private data: Array<string> = []
|
||||
aboutToAppear(): void {
|
||||
ImageKnife.getInstance().setMaxRequests(32)
|
||||
for (let index = 400; index < 600; index++) {
|
||||
this.data.push(`https://img-blog.csdn.net/20140514114029140?${index}`)
|
||||
}
|
||||
this.hotCommendList.addData(this.hotCommendList.totalCount(),this.data)
|
||||
}
|
||||
build() {
|
||||
Column() {
|
||||
WaterFlow() {
|
||||
LazyForEach(this.hotCommendList,(item: string)=>{
|
||||
FlowItem() {
|
||||
Column(){
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: {
|
||||
loadSrc: item,
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.failed"),
|
||||
}
|
||||
}).width("50%").height(160)
|
||||
}
|
||||
}.height(200)
|
||||
.backgroundColor("#95efd2")
|
||||
},(item: string) => item)
|
||||
}.columnsTemplate("1fr 1fr")
|
||||
.cachedCount(40)
|
||||
.columnsGap(10)
|
||||
.rowsGap(5)
|
||||
.backgroundColor(0xFAEEE0)
|
||||
.width("100%").height("100%")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,49 +15,49 @@
|
||||
import { ImageKnife, ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife'
|
||||
|
||||
@Entry
|
||||
@ComponentV2
|
||||
@Component
|
||||
struct ObjectFitPage {
|
||||
@Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
|
||||
@State imageKnifeOption: ImageKnifeOption = {
|
||||
loadSrc: $r("app.media.app_icon"),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
objectFit: ImageFit.Fill
|
||||
})
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
|
||||
Button($r('app.string.Main_image_Fill')).onClick(()=>{
|
||||
this.imageKnifeOption = new ImageKnifeOption({
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: $r("app.media.app_icon"),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
objectFit: ImageFit.Fill
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
Button($r('app.string.Maintain_proportion_filling')).margin({top:10}).onClick(async () => {
|
||||
ImageKnife.getInstance().removeAllMemoryCache()
|
||||
await ImageKnife.getInstance().removeAllFileCache()
|
||||
|
||||
this.imageKnifeOption = new ImageKnifeOption({
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: "https://wx2.sinaimg.cn/mw690/006HyQKGgy1hnqp08dw09j30u04twu0x.jpg",
|
||||
placeholderSrc: $r("app.media.app_icon"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
objectFit: ImageFit.Fill,
|
||||
placeholderObjectFit: ImageFit.Contain
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Button($r('app.string.Error_graph_None')).margin({top:10}).onClick(() => {
|
||||
this.imageKnifeOption = new ImageKnifeOption({
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: "http://xxxxx",
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.app_icon"),
|
||||
objectFit: ImageFit.Fill,
|
||||
errorholderObjectFit: ImageFit.None
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
ImageKnifeComponent({
|
||||
|
||||
39
entry/src/main/ets/pages/PrefetchAndCacheCount.ets
Normal file
39
entry/src/main/ets/pages/PrefetchAndCacheCount.ets
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 { router } from '@kit.ArkUI'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct PrefetchAndCacheCount {
|
||||
build() {
|
||||
Column() {
|
||||
Button("cacheCount == 5")
|
||||
.onClick(()=>{
|
||||
router.pushUrl({url:"pages/LazyForEachCache"})
|
||||
})
|
||||
Button("cacheCount == 30")
|
||||
.margin({top:10})
|
||||
.onClick(()=>{
|
||||
router.pushUrl({url:"pages/LazyForEachCount"})
|
||||
})
|
||||
Button("prefetch + preload")
|
||||
.margin({top:10})
|
||||
.onClick(()=>{
|
||||
router.pushUrl({url:"pages/PrefetchAndPreload"})
|
||||
})
|
||||
}.width("100%")
|
||||
.height("100%")
|
||||
}
|
||||
}
|
||||
56
entry/src/main/ets/pages/PrefetchAndPreload.ets
Normal file
56
entry/src/main/ets/pages/PrefetchAndPreload.ets
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 { BasicPrefetcher } from '@kit.ArkUI';
|
||||
import DataSourcePrefetchingImageKnife, { InfoItem } from './model/DataSourcePrefetching';
|
||||
import { PageViewModel } from './model/PageViewModel';
|
||||
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
|
||||
@Entry
|
||||
@Component
|
||||
export struct PrefetchAndPreload {
|
||||
// 创建DataSourcePrefetchingImageKnife对象,具备任务预取、取消能力的数据源
|
||||
private readonly dataSource = new DataSourcePrefetchingImageKnife(PageViewModel.getItems());
|
||||
// 创建BasicPrefetcher对象,默认的动态预取算法实现
|
||||
private readonly prefetcher = new BasicPrefetcher(this.dataSource);
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
List({ space: 16 }) {
|
||||
LazyForEach(this.dataSource, (item: InfoItem,index:number) => {
|
||||
ListItem() {
|
||||
Column({ space: 12 }) {
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption:{
|
||||
loadSrc: item.albumUrl,
|
||||
placeholderSrc:$r('app.media.loading')
|
||||
}
|
||||
}).width(100).height(100)
|
||||
Text(`${index}`)
|
||||
}.border({ width: 5 , color: "#000000"})
|
||||
}
|
||||
.reuseId('imageKnife')
|
||||
})
|
||||
}
|
||||
.cachedCount(5)
|
||||
.onScrollIndex((start: number, end: number) => {
|
||||
// 列表滚动触发visibleAreaChanged,实时更新预取范围,触发调用prefetch、cancel接口
|
||||
this.prefetcher.visibleAreaChanged(start, end)
|
||||
})
|
||||
.width("100%")
|
||||
.height("100%")
|
||||
.margin({ left: 10, right: 10 })
|
||||
.layoutWeight(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
23
entry/src/main/ets/pages/SetMaxRequestPage.ets
Normal file
23
entry/src/main/ets/pages/SetMaxRequestPage.ets
Normal file
@@ -0,0 +1,23 @@
|
||||
import { router } from '@kit.ArkUI'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct SetMaxRequestPage {
|
||||
build() {
|
||||
Column() {
|
||||
Button("maxRequest = 8")
|
||||
.onClick(()=>{
|
||||
router.pushUrl({url:"pages/MaxRequest1"})
|
||||
})
|
||||
Button("maxRequest = 20")
|
||||
.onClick(()=>{
|
||||
router.pushUrl({url:"pages/MaxRequest2"})
|
||||
}).margin({top:20})
|
||||
Button("maxRequest = 32")
|
||||
.onClick(()=>{
|
||||
router.pushUrl({url:"pages/MaxRequest2"})
|
||||
}).margin({top:20})
|
||||
}.width("100%")
|
||||
.height("100%")
|
||||
}
|
||||
}
|
||||
@@ -12,19 +12,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { ImageKnifeComponent,BlurTransformation,ImageKnifeOption } from '@ohos/libraryimageknife';
|
||||
import { ImageKnifeComponent,BlurTransformation } from '@ohos/libraryimageknife';
|
||||
import fs from '@ohos.file.fs';
|
||||
import image from '@ohos.multimedia.image';
|
||||
import { common2D, drawing } from '@kit.ArkGraphics2D';
|
||||
|
||||
@Entry
|
||||
@ComponentV2
|
||||
@Component
|
||||
struct SingleImage {
|
||||
resource: string = "app.media.svgSample"
|
||||
scroller: Scroller = new Scroller;
|
||||
localFile: string = getContext(this).filesDir + "/icon.png"
|
||||
@Local pixelMap:PixelMap | undefined = undefined;
|
||||
@Local DrawingColorFilter: ColorFilter | undefined = undefined
|
||||
@State pixelMap:PixelMap | undefined = undefined;
|
||||
@State DrawingColorFilter: ColorFilter | undefined = undefined
|
||||
private color: common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
|
||||
aboutToAppear(): void {
|
||||
// 拷贝本地文件
|
||||
@@ -46,12 +46,12 @@ struct SingleImage {
|
||||
.fontSize(30)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: new ImageKnifeOption({
|
||||
imageKnifeOption: {
|
||||
loadSrc: $r("app.media.svgSample"),
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.failed"),
|
||||
objectFit: ImageFit.Contain
|
||||
})
|
||||
}
|
||||
}).width(100).height(100)
|
||||
.onClick(()=>{
|
||||
this.DrawingColorFilter = drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN);
|
||||
@@ -60,48 +60,54 @@ struct SingleImage {
|
||||
.fontSize(30)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: new ImageKnifeOption({
|
||||
imageKnifeOption: {
|
||||
loadSrc: this.localFile,
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.failed"),
|
||||
objectFit: ImageFit.Contain
|
||||
})
|
||||
}
|
||||
}).width(100).height(100)
|
||||
Text($r('app.string.Network_images'))
|
||||
.fontSize(30)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: new ImageKnifeOption({
|
||||
imageKnifeOption: {
|
||||
loadSrc:"https://www.openharmony.cn/_nuxt/img/logo.dcf95b3.png",
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.failed"),
|
||||
objectFit: ImageFit.Contain,
|
||||
progressListener:(progress:number)=>{console.info("ImageKnife:: call back progress = " + progress)}
|
||||
})
|
||||
progressListener:(progress:number)=>{console.info("ImageKnife:: call back progress = " + progress)},
|
||||
// 通过https协议进行连接时,默认使用系统预设CA证书。若希望使用自定义证书进行https连接,则需要将自定义证书上传至应用沙箱目录中,并在caPath中指定该证书所在的应用沙箱路径
|
||||
// caPath: "/data/storage/el1/bundle/ca.pem",
|
||||
}
|
||||
}).width(100).height(100)
|
||||
Text($r('app.string.Custom_network_download'))
|
||||
.fontSize(30)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: new ImageKnifeOption({
|
||||
imageKnifeOption: {
|
||||
loadSrc: "https://file.atomgit.com/uploads/user/1704857786989_8994.jpeg",
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.failed"),
|
||||
objectFit: ImageFit.Contain,
|
||||
headerOption:[{
|
||||
key:"refer",
|
||||
value:"xx.xx.xx.xx"
|
||||
}],
|
||||
customGetImage: custom,
|
||||
transformation: new BlurTransformation(10)
|
||||
})
|
||||
}
|
||||
}).width(100).height(100)
|
||||
Text($r('app.string.PixelMap_loads_images'))
|
||||
.fontSize(30)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: new ImageKnifeOption({
|
||||
imageKnifeOption: {
|
||||
loadSrc: this.pixelMap!,
|
||||
placeholderSrc: $r("app.media.loading"),
|
||||
errorholderSrc: $r("app.media.failed"),
|
||||
objectFit: ImageFit.Contain,
|
||||
})
|
||||
}
|
||||
}).width(100).height(100)
|
||||
}
|
||||
.width('100%')
|
||||
@@ -124,9 +130,11 @@ struct SingleImage {
|
||||
|
||||
// 自定义下载方法
|
||||
@Concurrent
|
||||
async function custom(context: Context, src: string | PixelMap | Resource): Promise<ArrayBuffer | undefined> {
|
||||
console.info("ImageKnife:: custom download:" + src)
|
||||
async function custom(context: Context, src: string | PixelMap | Resource,headers?: Record<string,Object>): Promise<ArrayBuffer | undefined> {
|
||||
let refer = headers!["refer"] as string
|
||||
console.info("ImageKnife:: custom download:" + src,"refer:"+refer)
|
||||
// 举例写死从本地文件读取,也可以自己请求网络图片
|
||||
return context.resourceManager.getMediaContentSync($r("app.media.startIcon").id).buffer as ArrayBuffer
|
||||
let buffer = context.resourceManager.getMediaContentSync($r("app.media.startIcon").id).buffer as ArrayBuffer
|
||||
return buffer
|
||||
}
|
||||
|
||||
|
||||
@@ -13,20 +13,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ImageKnife, CacheStrategy, ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife';
|
||||
import { ImageKnife, CacheStrategy, ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
|
||||
|
||||
@Entry
|
||||
@ComponentV2
|
||||
@Component
|
||||
struct TestCacheDataPage {
|
||||
@Local cacheUpLimit: number = 0;
|
||||
@Local currentNum: number = 0;
|
||||
@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({
|
||||
@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: {
|
||||
@@ -38,7 +38,7 @@ struct TestCacheDataPage {
|
||||
},
|
||||
},
|
||||
border: { radius: 50 }
|
||||
})
|
||||
}
|
||||
|
||||
aboutToAppear(): void {
|
||||
ImageKnife.getInstance().initFileCache(getContext(this), 256, 256 * 1024 * 1024, "ImageKnifeCache1")
|
||||
@@ -55,21 +55,21 @@ struct TestCacheDataPage {
|
||||
|
||||
Button($r('app.string.load_memory'))
|
||||
.onClick(() => {
|
||||
this.ImageKnifeOption = new ImageKnifeOption({
|
||||
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 = new ImageKnifeOption({
|
||||
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)
|
||||
@@ -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;
|
||||
|
||||
@@ -74,17 +74,17 @@ struct TestChangeColorPage {
|
||||
|
||||
Text($r('app.string.master_image')).margin({ top: 20 })
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: new ImageKnifeOption({
|
||||
imageKnifeOption: {
|
||||
loadSrc: this.src
|
||||
})
|
||||
}
|
||||
}).width(110).height(110)
|
||||
|
||||
Text($r('app.string.click_img_to_change_color')).margin({ top: 30 })
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: new ImageKnifeOption({
|
||||
imageKnifeOption: {
|
||||
loadSrc: this.src,
|
||||
drawingColorFilter: this.DrawingColorFilterFirst
|
||||
})
|
||||
}
|
||||
})
|
||||
.onClick(() => {
|
||||
this.DrawingColorFilterFirst =
|
||||
@@ -93,18 +93,18 @@ struct TestChangeColorPage {
|
||||
|
||||
Text($r('app.string.test_non_svg_color')).margin({ top: 30 })
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: new ImageKnifeOption({
|
||||
imageKnifeOption: {
|
||||
loadSrc: $r('app.media.ic_test_change_color_png'),
|
||||
drawingColorFilter: drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN)
|
||||
})
|
||||
}
|
||||
}).width(110).height(110)
|
||||
|
||||
Text($r('app.string.test_svg_color')).margin({ top: 30 })
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: new ImageKnifeOption({
|
||||
imageKnifeOption: {
|
||||
loadSrc: $r("app.media.ic_test_change_color_svg"),
|
||||
drawingColorFilter: drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.SRC_IN)
|
||||
})
|
||||
}
|
||||
}).width(110).height(110)
|
||||
|
||||
}.width('100%').height('100%')
|
||||
|
||||
412
entry/src/main/ets/pages/TestImageKnifeCallbackPage.ets
Normal file
412
entry/src/main/ets/pages/TestImageKnifeCallbackPage.ets
Normal file
@@ -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/libraryimageknife';
|
||||
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;
|
||||
}
|
||||
}
|
||||
101
entry/src/main/ets/pages/TestListImageKnifeCallbackPage.ets
Normal file
101
entry/src/main/ets/pages/TestListImageKnifeCallbackPage.ets
Normal file
@@ -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/libraryimageknife';
|
||||
|
||||
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,20 +13,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife';
|
||||
import { ImageKnife, ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife';
|
||||
|
||||
|
||||
@Entry
|
||||
@ComponentV2
|
||||
@Component
|
||||
struct TestLoadCancelListenerPage {
|
||||
@Local currentWidth: number = 200
|
||||
@Local currentHeight: number = 200
|
||||
@Local showChild: boolean = true;
|
||||
@Local text: string = "";
|
||||
@Local ImageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
|
||||
@State currentWidth: number = 200
|
||||
@State currentHeight: number = 200
|
||||
@State showChild: boolean = true;
|
||||
@State text: string = "";
|
||||
@State ImageKnifeOption: ImageKnifeOption = {
|
||||
loadSrc: "",
|
||||
objectFit: ImageFit.Contain,
|
||||
border: { radius: 50 }
|
||||
})
|
||||
};
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
@@ -34,7 +35,8 @@ struct TestLoadCancelListenerPage {
|
||||
Button($r('app.string.rm_component_of_net'))
|
||||
.margin(20)
|
||||
.onClick(() => {
|
||||
this.ImageKnifeOption = new ImageKnifeOption({
|
||||
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,
|
||||
onLoadListener: {
|
||||
@@ -47,23 +49,24 @@ struct TestLoadCancelListenerPage {
|
||||
}
|
||||
},
|
||||
border: { radius: 50 }
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
Button($r('app.string.component_display'))
|
||||
.margin(20).onClick(() => {
|
||||
this.text = "";
|
||||
this.showChild = true;
|
||||
this.ImageKnifeOption = new ImageKnifeOption({
|
||||
this.ImageKnifeOption = {
|
||||
loadSrc: "",
|
||||
objectFit: ImageFit.Contain,
|
||||
border: { radius: 50 }
|
||||
})
|
||||
}
|
||||
})
|
||||
Button($r('app.string.rm_component_of_local'))
|
||||
.margin(20)
|
||||
.onClick(() => {
|
||||
this.ImageKnifeOption = new ImageKnifeOption({
|
||||
this.clearCache();
|
||||
this.ImageKnifeOption = {
|
||||
loadSrc: $r('app.media.loading'),
|
||||
objectFit: ImageFit.Contain,
|
||||
onLoadListener: {
|
||||
@@ -76,7 +79,7 @@ struct TestLoadCancelListenerPage {
|
||||
}
|
||||
},
|
||||
border: { radius: 50 }
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
if (this.showChild) {
|
||||
@@ -91,4 +94,8 @@ struct TestLoadCancelListenerPage {
|
||||
.height('100%')
|
||||
.width('100%')
|
||||
}
|
||||
|
||||
clearCache(){
|
||||
ImageKnife.getInstance().removeAllMemoryCache();
|
||||
}
|
||||
}
|
||||
@@ -15,42 +15,40 @@
|
||||
import { ImageKnifeComponent, ImageKnife, ImageKnifeOption } from '@ohos/libraryimageknife'
|
||||
|
||||
@Entry
|
||||
@ComponentV2
|
||||
@Component
|
||||
struct TestSetCustomImagePage {
|
||||
|
||||
getResourceString(res:Resource){
|
||||
return getContext().resourceManager.getStringSync(res.id)
|
||||
}
|
||||
|
||||
@Local imageKnifeOption: ImageKnifeOption = new ImageKnifeOption({
|
||||
@State imageKnifeOption: ImageKnifeOption = {
|
||||
loadSrc: $r('app.media.startIcon'),
|
||||
placeholderSrc: $r('app.media.loading')
|
||||
})
|
||||
}
|
||||
aboutToAppear(): void {
|
||||
ImageKnife.getInstance().setCustomGetImage(custom)
|
||||
}
|
||||
aboutToDisappear(): void {
|
||||
ImageKnife.getInstance().setCustomGetImage()
|
||||
}
|
||||
getResourceString(res:Resource){
|
||||
return getContext().resourceManager.getStringSync(res.id)
|
||||
}
|
||||
build() {
|
||||
Column() {
|
||||
Button(this.getResourceString($r('app.string.Custom_network_download')) + " a").onClick(()=>{
|
||||
this.imageKnifeOption = new ImageKnifeOption({
|
||||
this.imageKnifeOption ={
|
||||
loadSrc: "aaa",
|
||||
placeholderSrc: $r('app.media.loading')
|
||||
})
|
||||
}
|
||||
})
|
||||
Button(this.getResourceString($r('app.string.Custom_network_download')) + " b").onClick(()=>{
|
||||
this.imageKnifeOption = new ImageKnifeOption({
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: "bbb",
|
||||
placeholderSrc: $r('app.media.loading')
|
||||
})
|
||||
}
|
||||
})
|
||||
Button(this.getResourceString($r('app.string.Custom_network_download')) + " c").onClick(()=>{
|
||||
this.imageKnifeOption = new ImageKnifeOption({
|
||||
this.imageKnifeOption = {
|
||||
loadSrc: "ccc",
|
||||
placeholderSrc: $r('app.media.loading')
|
||||
})
|
||||
}
|
||||
})
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: this.imageKnifeOption
|
||||
@@ -62,8 +60,9 @@ struct TestSetCustomImagePage {
|
||||
}
|
||||
}
|
||||
@Concurrent
|
||||
async function custom(context: Context, src: string | PixelMap | Resource): Promise<ArrayBuffer | undefined> {
|
||||
async function custom(context: Context, src: string | PixelMap | Resource,headers?: Record<string,Object>): Promise<ArrayBuffer | undefined> {
|
||||
console.info("ImageKnife:: custom download:" + src)
|
||||
// 举例写死从本地文件读取,也可以自己请求网络图片
|
||||
return context.resourceManager.getMediaContentSync($r("app.media.pngSample").id).buffer as ArrayBuffer
|
||||
let buffer = context.resourceManager.getMediaContentSync($r("app.media.pngSample").id).buffer as ArrayBuffer
|
||||
return buffer
|
||||
}
|
||||
@@ -24,12 +24,12 @@ export struct ZuImage {
|
||||
if (this.src) {
|
||||
//当前版本存在bug
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: new ImageKnifeOption({
|
||||
imageKnifeOption: {
|
||||
loadSrc: this.src,
|
||||
placeholderSrc: this.placeholderSrc,
|
||||
errorholderSrc: this.errorholderSrc ?? this.placeholderSrc,
|
||||
objectFit: ImageFit.Cover
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Image(this.placeholderSrc)
|
||||
|
||||
@@ -15,55 +15,55 @@
|
||||
import { ImageKnifeComponent,CacheStrategy,ImageKnifeOption } from '@ohos/libraryimageknife'
|
||||
|
||||
@Entry
|
||||
@ComponentV2
|
||||
@Component
|
||||
struct TestWriteCacheStage {
|
||||
@Local imageKnifeOption1: ImageKnifeOption = new ImageKnifeOption({
|
||||
@State imageKnifeOption1: ImageKnifeOption = {
|
||||
loadSrc:$r('app.media.startIcon'),
|
||||
placeholderSrc:$r('app.media.loading'),
|
||||
errorholderSrc:$r('app.media.failed')
|
||||
})
|
||||
@Local imageKnifeOption2: ImageKnifeOption = new ImageKnifeOption({
|
||||
}
|
||||
@State imageKnifeOption2: ImageKnifeOption = {
|
||||
loadSrc:$r('app.media.startIcon'),
|
||||
placeholderSrc:$r('app.media.loading'),
|
||||
errorholderSrc:$r('app.media.failed')
|
||||
})
|
||||
@Local imageKnifeOption3: ImageKnifeOption = new ImageKnifeOption({
|
||||
}
|
||||
@State imageKnifeOption3: ImageKnifeOption = {
|
||||
loadSrc:$r('app.media.startIcon'),
|
||||
placeholderSrc:$r('app.media.loading'),
|
||||
errorholderSrc:$r('app.media.failed')
|
||||
})
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Button($r('app.string.Write_memory_and_file')).margin({top:10}).onClick(async ()=>{
|
||||
this.imageKnifeOption1 = new ImageKnifeOption({
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc:'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
|
||||
placeholderSrc:$r('app.media.loading'),
|
||||
errorholderSrc:$r('app.media.failed'),
|
||||
writeCacheStrategy:CacheStrategy.Default
|
||||
})
|
||||
}
|
||||
})
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: this.imageKnifeOption1
|
||||
}).width(200).height(200).margin({top:10})
|
||||
Button($r('app.string.Write_memory')).margin({top:10}).onClick(async ()=>{
|
||||
this.imageKnifeOption2 = new ImageKnifeOption({
|
||||
this.imageKnifeOption2 = {
|
||||
loadSrc:"https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
|
||||
placeholderSrc:$r('app.media.loading'),
|
||||
errorholderSrc:$r('app.media.failed'),
|
||||
writeCacheStrategy:CacheStrategy.Memory
|
||||
})
|
||||
}
|
||||
})
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: this.imageKnifeOption2
|
||||
}).width(200).height(200).margin({top:10})
|
||||
Button($r('app.string.Write_file')).margin({top:10}).onClick(async ()=>{
|
||||
this.imageKnifeOption3 = new ImageKnifeOption({
|
||||
this.imageKnifeOption3 = {
|
||||
loadSrc:'https://img-blog.csdn.net/20140514114029140',
|
||||
placeholderSrc:$r('app.media.loading'),
|
||||
errorholderSrc:$r('app.media.failed'),
|
||||
writeCacheStrategy:CacheStrategy.File
|
||||
})
|
||||
}
|
||||
})
|
||||
ImageKnifeComponent({
|
||||
imageKnifeOption: this.imageKnifeOption3
|
||||
|
||||
@@ -12,52 +12,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { MyStorage, UserAvatar } from './User'
|
||||
import { CommonDataSource } from './model/CommonDataSource'
|
||||
import { UserAvatar } from './User'
|
||||
|
||||
class CommonDataSource <T> implements IDataSource {
|
||||
private dataArray: T[] = []
|
||||
private listeners: DataChangeListener[] = []
|
||||
|
||||
constructor(element: []) {
|
||||
this.dataArray = element
|
||||
}
|
||||
|
||||
public getData(index: number) {
|
||||
return this.dataArray[index]
|
||||
}
|
||||
|
||||
public totalCount(): number {
|
||||
return this.dataArray.length
|
||||
}
|
||||
|
||||
public addData(index: number, data: T[]): void {
|
||||
this.dataArray = this.dataArray.concat(data)
|
||||
this.notifyDataAdd(index)
|
||||
}
|
||||
|
||||
unregisterDataChangeListener(listener: DataChangeListener): void {
|
||||
const pos = this.listeners.indexOf(listener);
|
||||
if (pos >= 0) {
|
||||
this.listeners.splice(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
registerDataChangeListener(listener: DataChangeListener): void {
|
||||
if (this.listeners.indexOf(listener) < 0) {
|
||||
this.listeners.push(listener)
|
||||
}
|
||||
}
|
||||
|
||||
notifyDataAdd(index: number): void {
|
||||
this.listeners.forEach((listener: DataChangeListener) => {
|
||||
listener.onDataAdd(index)
|
||||
})
|
||||
}
|
||||
}
|
||||
@Entry
|
||||
@ComponentV2
|
||||
@Component
|
||||
struct Index {
|
||||
@Local hotCommendList:CommonDataSource<string> = new CommonDataSource<string>([])
|
||||
@State hotCommendList:CommonDataSource<string> = new CommonDataSource<string>([])
|
||||
private data:string[] = [
|
||||
"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/e2/v3/4zI1Xm_3STmV30aZXWRrKw/6aN7WodDRUiBApgffiLPCg.jpg",
|
||||
@@ -85,42 +46,26 @@ struct Index {
|
||||
'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
|
||||
]
|
||||
aboutToAppear(): void {
|
||||
MyStorage.getInstance().WeLink_Mob_fontSize_multiple = 1
|
||||
this.hotCommendList.addData(this.hotCommendList.totalCount(),this.data)
|
||||
AppStorage.set("WeLink_Mob_fontSize_multiple",1)
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Button("bigger").onClick(()=>{
|
||||
MyStorage.getInstance().WeLink_Mob_fontSize_multiple = 1.6
|
||||
AppStorage.set("WeLink_Mob_fontSize_multiple",1.6)
|
||||
})
|
||||
Button("small").onClick(()=>{
|
||||
MyStorage.getInstance().WeLink_Mob_fontSize_multiple = 0.8
|
||||
AppStorage.set("WeLink_Mob_fontSize_multiple",0.8)
|
||||
})
|
||||
List(){
|
||||
// LazyForEach(this.hotCommendList,(item:string)=>{
|
||||
// ListItem(){
|
||||
// ReuseImage({
|
||||
// userInfo:item
|
||||
// }).width("100%").height("100%").backgroundColor(Color.Yellow)
|
||||
// }.width(200).height(200).margin({bottom:5})
|
||||
// })
|
||||
Repeat(this.data)
|
||||
.each((repeatItem)=>{
|
||||
ListItem(){
|
||||
ReuseImage({
|
||||
userInfo:repeatItem.item
|
||||
}).width("100%").height("100%").backgroundColor(Color.Yellow)
|
||||
}.width(200).height(200).margin({bottom:5}).key("reuse")
|
||||
})
|
||||
.key(item => item+"reuse")
|
||||
.virtualScroll()
|
||||
.template("1",(repeatItem)=>{
|
||||
ListItem(){
|
||||
ReuseImage({
|
||||
userInfo:repeatItem.item
|
||||
}).width("100%").height("100%").backgroundColor(Color.Yellow)
|
||||
}.width(200).height(200).margin({bottom:5}).key("reuse")
|
||||
})
|
||||
LazyForEach(this.hotCommendList,(item:string)=>{
|
||||
ListItem(){
|
||||
ReuseImage({
|
||||
userInfo:item
|
||||
}).width("100%").height("100%").backgroundColor(Color.Yellow)
|
||||
}.width(200).height(200).margin({bottom:5})
|
||||
})
|
||||
}
|
||||
// .cachedCount(20)
|
||||
.width("100%")
|
||||
@@ -131,13 +76,13 @@ struct Index {
|
||||
}
|
||||
|
||||
|
||||
// @Reusable
|
||||
@ComponentV2
|
||||
@Reusable
|
||||
@Component
|
||||
struct ReuseImage {
|
||||
@Param userInfo:string = ""
|
||||
// aboutToReuse(params: ESObject): void {
|
||||
// this.userInfo = params.userInfo
|
||||
// }
|
||||
@State userInfo:string = ""
|
||||
aboutToReuse(params: ESObject): void {
|
||||
this.userInfo = params.userInfo
|
||||
}
|
||||
|
||||
build() {
|
||||
Column(){
|
||||
|
||||
60
entry/src/main/ets/pages/model/CommonDataSource.ets
Normal file
60
entry/src/main/ets/pages/model/CommonDataSource.ets
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 { statfs } from '@kit.CoreFileKit'
|
||||
import { rcp } from '@kit.RemoteCommunicationKit'
|
||||
|
||||
export class CommonDataSource <T> implements IDataSource {
|
||||
private dataArray: T[] = []
|
||||
private listeners: DataChangeListener[] = []
|
||||
|
||||
constructor(element: []) {
|
||||
this.dataArray = element
|
||||
}
|
||||
|
||||
public getData(index: number) {
|
||||
return this.dataArray[index]
|
||||
}
|
||||
|
||||
public totalCount(): number {
|
||||
return this.dataArray.length
|
||||
}
|
||||
|
||||
public addData(index: number, data: T[]): void {
|
||||
this.dataArray = this.dataArray.concat(data)
|
||||
this.notifyDataAdd(index)
|
||||
}
|
||||
|
||||
unregisterDataChangeListener(listener: DataChangeListener): void {
|
||||
const pos = this.listeners.indexOf(listener);
|
||||
if (pos >= 0) {
|
||||
this.listeners.splice(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
registerDataChangeListener(listener: DataChangeListener): void {
|
||||
if (this.listeners.indexOf(listener) < 0) {
|
||||
this.listeners.push(listener)
|
||||
}
|
||||
}
|
||||
|
||||
notifyDataAdd(index: number): void {
|
||||
this.listeners.forEach((listener: DataChangeListener) => {
|
||||
listener.onDataAdd(index)
|
||||
})
|
||||
}
|
||||
}
|
||||
export class GetSession {
|
||||
static session:rcp.Session = rcp.createSession()
|
||||
}
|
||||
93
entry/src/main/ets/pages/model/DataSourcePrefetching.ets
Normal file
93
entry/src/main/ets/pages/model/DataSourcePrefetching.ets
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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, ImageKnifeRequest} from "@ohos/libraryimageknife"
|
||||
import { IDataSourcePrefetching } from '@kit.ArkUI';
|
||||
import { HashMap } from '@kit.ArkTS';
|
||||
|
||||
const IMADE_UNAVAILABLE = $r('app.media.failed')
|
||||
export interface InfoItem {
|
||||
albumUrl: string | Resource
|
||||
}
|
||||
export default class DataSourcePrefetchingImageKnife implements IDataSourcePrefetching {
|
||||
private dataArray: Array<InfoItem>
|
||||
private readonly requestList: HashMap<number,ImageKnifeRequest> = new HashMap()
|
||||
private listeners: DataChangeListener[] = [];
|
||||
|
||||
constructor(dataArray: Array<InfoItem>) {
|
||||
this.dataArray = dataArray;
|
||||
}
|
||||
public getData(index: number) {
|
||||
return this.dataArray[index]
|
||||
}
|
||||
|
||||
public totalCount(): number {
|
||||
return this.dataArray.length
|
||||
}
|
||||
|
||||
public addData(index: number, data: InfoItem[]): void {
|
||||
this.dataArray = this.dataArray.concat(data)
|
||||
this.notifyDataAdd(index)
|
||||
}
|
||||
|
||||
unregisterDataChangeListener(listener: DataChangeListener): void {
|
||||
const pos = this.listeners.indexOf(listener);
|
||||
if (pos >= 0) {
|
||||
this.listeners.splice(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
registerDataChangeListener(listener: DataChangeListener): void {
|
||||
if (this.listeners.indexOf(listener) < 0) {
|
||||
this.listeners.push(listener)
|
||||
}
|
||||
}
|
||||
|
||||
notifyDataAdd(index: number): void {
|
||||
this.listeners.forEach((listener: DataChangeListener) => {
|
||||
listener.onDataAdd(index)
|
||||
})
|
||||
}
|
||||
async prefetch(index: number): Promise<void> {
|
||||
let item = this.dataArray[index]
|
||||
if (typeof item.albumUrl == "string") {
|
||||
// 图片预加载
|
||||
let request = ImageKnife.getInstance().preload({
|
||||
loadSrc:item.albumUrl,
|
||||
onLoadListener:{
|
||||
onLoadSuccess:()=>{
|
||||
// 预加载成功,删除成功请求
|
||||
this.requestList.remove(index)
|
||||
},
|
||||
onLoadFailed:()=>{
|
||||
// 移除失败请求
|
||||
this.requestList.remove(index)
|
||||
}
|
||||
}
|
||||
})
|
||||
this.requestList.set(index,request)
|
||||
}
|
||||
}
|
||||
// 取消请求处理
|
||||
cancel(index: number) {
|
||||
if(this.requestList.hasKey(index)) {
|
||||
// 返回MAP对象指定元素
|
||||
const request = this.requestList.get(index)
|
||||
// 取消请求
|
||||
ImageKnife.getInstance().cancel(request)
|
||||
// 移除被取消的请求对象
|
||||
this.requestList.remove(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
146
entry/src/main/ets/pages/model/PageViewModel.ets
Normal file
146
entry/src/main/ets/pages/model/PageViewModel.ets
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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 { InfoItem } from './DataSourcePrefetching'
|
||||
|
||||
export class PageViewModel {
|
||||
private static dataArray: Array<InfoItem> = [
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e2/v3/4zI1Xm_3STmV30aZXWRrKw/6aN7WodDRUiBApgffiLPCg.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/42/v3/2dSQCqERTP2TTPyssOMEbQ/zL1ebnKKQ_ilqTDcwCAkOw.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/78/v3/qQJpAtRGQe2e_VhbGHDgIw/b3zlit99S6GybD3XdNwqJw.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/55/v3/5DZ2LLqYSsK85-shqgLveQ/7ZXcyCWNTvOzQP5FFLBGkg.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3e/v3/LqRoLI-PRSu9Nqa8KdJ-pQ/dSqskBpSR9eraAMn7NBdqA.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/25/v3/jgB2ekkTRX-3yTYZalnANQ/xff_x9cbSPqb7fbNwgJa7A.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/alXwXLHKSyCAIWt_ydgD2g/BCCuu25TREOitQxM7eYOEw.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/63/v3/qbe6NZkCQyGcITvdWoZBgg/Y-5U1z3GT_yaK8CBD3jkwg.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/16/v3/fm2tO4TsRH6mv_D_nSSd5w/FscLpLwQQ-KuV7oaprFK2Q.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/89/v3/UAUvtPHqRD-GWWANsEC57Q/zcRJCQebQ322Aby4jzmwmQ.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/tUUzzx73R4yp8G--lMhuWQ/EBbcu_dLTT-Jj68XAh6mtA.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/76/v3/EyF6z4FISpCHhae38eEexw/OtyAiu-zSSevNQYvUdtVmA.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/37/v3/12rH1yiEQmK9wlOOcy5avQ/RzBXiEBRRqOC7LRkwNj6VA.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/9a/v3/TpRN4AIzRoyUXIqWdKoE0g/ShOnD_tfS46HDbpSWhbCkQ.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/03/v3/H3X17s8eTdS2w56JgbB5jQ/a45sT-j8Sbe8sSQXTzeYvQ.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/10/v3/qaEzwkU0QeKb1yehnP2Xig/q7fxAlgMQKup-HUBayRLGQ.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/96/v3/rMJJoAflTDSWa1z2pHs2wg/8dOqD0GlQBOCL5AvQok9FQ.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/ed/v3/KMO4D6D2QGuVOCLX4AhOFA/ef51xAaLQuK7BsnuD9abog.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/d9/v3/FSZH0aTdSqWxeAaxoPvi0g/RqxPxUCXQFiTMBfKTF9kkw.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/bf/v3/lSjrRwFcS-ez6jp1ALSQFg/0n7R7XinSPyrYLqDu_1dfw.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/8a/v3/ZKzYV5BJTuCk5hCE0y_xNA/8JT95OQnSZSd6_xQQUONhQ.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/1/v3/sTXb_I7URBKjdMyLDYa19w/qpcwa_FNQmi3-EzjbGsJ8A.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e5/v3/m7wFvw_eQIuDV0Mk0IKi8g/gJU4migzTHKYk5KrgdZbBw.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/3f/v3/k_UWbB5_RGW7JemQZ0OQdw/_DUdmaZRQyG-Oyvkb663Bw.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/39/v3/rFRN7G_VSo-p4mBjTZtkRw/gBwTI-ieSIqSsSmLNBEcgw.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/04/v3/6K8BPYKVQFOr7KCuAG9nog/qKd3pZlrQy2M-feB3ycVPA.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/7d/v3/f0GQFzm1T6eduVeMUhO3Wg/-4cvzIJiRCegjIno3ofIbQ.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e4/v3/C0xxsSeySxW-2iYR5OEbpQ/f1GlaD3zTeKPX8Vd-M1oVQ.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/c2/v3/32LCyXN4TuWKWcdf9gAwWw/ej14_BCJQNCaWOKoI9aZAw.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fd/v3/LyYJMdMmQNaC5GyBYEZ5Pw/uFLiovypRSagKyIS-UJPVw.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/15/v3/MHM9KaWGTgubn6M8-B_6nw/1YO9JyYhTHSBWsoiqYkGZw.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/4c/v3/UdYfbv1_QYqn_ulDHp89OA/VkjexMluTqGO3yt3gPK1DA.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/e8/v3/N8blT_7qSK-tRtahIyov7g/M_kjGEEmSzOlTc47Zrfozg.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/28/v3/VS_h3m4YRrSgbgxnqE3vtQ/h-2Q1Qy2SSGEuXM36-Rq_w.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/2e/v3/R-BaM5ToRNGq5rwtNTcnww/Q2e01VHiR2y9KtFaZmpmNQ.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/88/v3/3djkAJKKTdC539XqMdstSg/wHO7DxvXQS2xbt2Y_-4BNg.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/fb/v3/guw4eiggR3uWjscFTxITYg/TzRB35iPTdCztrZUUaNuFg.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/93/v3/UvSh_f1LT66i0-3hvsYN_A/eYnE3Z8YT5Sk7F-vS2ZmCQ.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/5/v3/tv8Vqf9hQrKpozGeZWg2mw/VEICB-bmQYi0Iv6TGADbhw.jpg"
|
||||
},
|
||||
{
|
||||
albumUrl: "https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/30/v3/4v1Ot5BRR6OFVQ9MGn9Xxg/xrPgRn0LS1ep-r7ewIuwiw.jpg"
|
||||
},
|
||||
]
|
||||
static getItems() {
|
||||
return PageViewModel.dataArray
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,15 @@
|
||||
],
|
||||
"when": "always"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.GET_NETWORK_INFO",
|
||||
"usedScene": {
|
||||
"abilities": [
|
||||
"EntryAbility"
|
||||
],
|
||||
"when": "always"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -369,20 +369,12 @@
|
||||
"value": "Please shut down the network first and ensure that there is no cache of images from this network in the test failure scenario locally"
|
||||
},
|
||||
{
|
||||
"name": "Image_Downsampling_Functionality",
|
||||
"value": "Downscale Image effect"
|
||||
"name": "Network_reload",
|
||||
"value": "Network recovery reload"
|
||||
},
|
||||
{
|
||||
"name": "Sampling_pecification",
|
||||
"value": "降采样规格"
|
||||
},
|
||||
{
|
||||
"name": "Unreal_samples",
|
||||
"value": "未降采样大小"
|
||||
},
|
||||
{
|
||||
"name": "After_the_sampling",
|
||||
"value": "降采样后大小"
|
||||
"name": "preloading_prefetch",
|
||||
"value": "Dynamic preloading prefetch"
|
||||
},
|
||||
{
|
||||
"name": "image_format",
|
||||
@@ -511,6 +503,150 @@
|
||||
{
|
||||
"name": "disk",
|
||||
"value": "Disk"
|
||||
},
|
||||
{
|
||||
"name": "Customize_RCP_network",
|
||||
"value": "Customize RCP network request"
|
||||
},
|
||||
{
|
||||
"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 "
|
||||
},
|
||||
{
|
||||
"name": "Image_Downsampling_Functionality",
|
||||
"value": "Downsampling function"
|
||||
},
|
||||
{
|
||||
"name": "Sampling_pecification",
|
||||
"value": "Downsampling specification"
|
||||
},
|
||||
{
|
||||
"name": "Unreal_samples",
|
||||
"value": "Unsampled size"
|
||||
},
|
||||
{
|
||||
"name": "After_the_sampling",
|
||||
"value": "Size after downsampling"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
"pages/Index",
|
||||
"pages/ListPage",
|
||||
"pages/SingleImage",
|
||||
"pages/ManyPhotoShowPage",
|
||||
"pages/LongImagePage",
|
||||
"pages/TransformPage",
|
||||
"pages/UserPage",
|
||||
@@ -23,9 +24,21 @@
|
||||
"pages/TestSetCustomImagePage",
|
||||
"pages/TestErrorHolderPage",
|
||||
"pages/TestTaskResourcePage",
|
||||
"pages/DownSamplePage",
|
||||
"pages/ImageKnifeReload",
|
||||
"pages/LazyForEachCount",
|
||||
"pages/LazyForEachCache",
|
||||
"pages/PrefetchAndCacheCount",
|
||||
"pages/PrefetchAndPreload",
|
||||
"pages/TestCacheDataPage",
|
||||
"pages/TestChangeColorPage",
|
||||
"pages/TestLoadCancelListenerPage"
|
||||
"pages/TestLoadCancelListenerPage",
|
||||
"pages/CustomNetImagePage",
|
||||
"pages/SetMaxRequestPage",
|
||||
"pages/MaxRequest1",
|
||||
"pages/MaxRequest2",
|
||||
"pages/MaxRequest3",
|
||||
"pages/TestImageKnifeCallbackPage",
|
||||
"pages/TestListImageKnifeCallbackPage",
|
||||
"pages/DownSamplePage"
|
||||
]
|
||||
}
|
||||
@@ -19,6 +19,362 @@
|
||||
{
|
||||
"name": "app_permission_READ_IMAGEVIDEO",
|
||||
"value": "获取读媒体资源权限"
|
||||
},
|
||||
{
|
||||
"name": "Test_ImageAnimator",
|
||||
"value": "Test ImageAnimator component"
|
||||
},
|
||||
{
|
||||
"name": "Test_multiple_images",
|
||||
"value": "Test loading multiple identical images"
|
||||
},
|
||||
{
|
||||
"name": "Test_Task_error",
|
||||
"value": "Test placeholder map Task error"
|
||||
},
|
||||
{
|
||||
"name": "Test_HSP",
|
||||
"value": "Test HSP scene preloading"
|
||||
},
|
||||
{
|
||||
"name": "Test_SingleImage",
|
||||
"value": "SingleImage"
|
||||
},
|
||||
{
|
||||
"name": "Test_custom_download",
|
||||
"value": "Global custom download"
|
||||
},
|
||||
{
|
||||
"name": "Multiple_images",
|
||||
"value": "Multiple images"
|
||||
},
|
||||
{
|
||||
"name": "Display_long_image",
|
||||
"value": "Display long image"
|
||||
},
|
||||
{
|
||||
"name": "Image_scaling",
|
||||
"value": "Image scaling"
|
||||
},
|
||||
{
|
||||
"name": "Message_list",
|
||||
"value": "Message list"
|
||||
},
|
||||
{
|
||||
"name": "Custom_cache_key",
|
||||
"value": "Custom cache key"
|
||||
},
|
||||
{
|
||||
"name": "Preloading_images_to_cache",
|
||||
"value": "Preloading images to file cache"
|
||||
},
|
||||
{
|
||||
"name": "Retrieve_image_display_from_cache",
|
||||
"value": "Retrieve image display from cache"
|
||||
},
|
||||
{
|
||||
"name": "Test_single_request_header",
|
||||
"value": "Test a single request header"
|
||||
},
|
||||
{
|
||||
"name": "Test_write_cache_strategy",
|
||||
"value": "Test write cache strategy"
|
||||
},
|
||||
{
|
||||
"name": "Image_Transformation",
|
||||
"value": "Image Transformation"
|
||||
},
|
||||
{
|
||||
"name": "Different_ObjectFit",
|
||||
"value": "Different ObjectFit"
|
||||
},
|
||||
{
|
||||
"name": "Test_image_loading_success_or_failure_events",
|
||||
"value": "Test image loading success/failure events"
|
||||
},
|
||||
{
|
||||
"name": "Test_removing_image_cache_interface",
|
||||
"value": "Test removing image cache interface"
|
||||
},
|
||||
{
|
||||
"name": "Test_error_image_display",
|
||||
"value": "Test error image display"
|
||||
},
|
||||
{
|
||||
"name": "Test_media_URL",
|
||||
"value": "Test media URL"
|
||||
},
|
||||
{
|
||||
"name": "Display_the_first_frame",
|
||||
"value": "Display the first frame of the animation"
|
||||
},
|
||||
{
|
||||
"name": "Display_the_last_frame",
|
||||
"value": "Display the last frame of the animation"
|
||||
},
|
||||
{
|
||||
"name": "Play",
|
||||
"value": "Play"
|
||||
},
|
||||
{
|
||||
"name": "Pause",
|
||||
"value": "Pause"
|
||||
},
|
||||
{
|
||||
"name": "Stop",
|
||||
"value": "Stop"
|
||||
},
|
||||
{
|
||||
"name": "Infinite_loop",
|
||||
"value": "Infinite loop"
|
||||
},
|
||||
{
|
||||
"name": "Play_once",
|
||||
"value": "Play once"
|
||||
},
|
||||
{
|
||||
"name": "Play_twice",
|
||||
"value": "Play twice"
|
||||
},
|
||||
{
|
||||
"name": "Local_SVG",
|
||||
"value": "Local SVG image"
|
||||
},
|
||||
{
|
||||
"name": "Under_context_file",
|
||||
"value": "Files under context file"
|
||||
},
|
||||
{
|
||||
"name": "Network_images",
|
||||
"value": "Network images"
|
||||
},
|
||||
{
|
||||
"name": "Custom_network_download",
|
||||
"value": "Custom network download"
|
||||
},
|
||||
{
|
||||
"name": "PixelMap_loads_images",
|
||||
"value": "PixelMap loads images"
|
||||
},
|
||||
{
|
||||
"name": "Enlarge",
|
||||
"value": "Enlarge"
|
||||
},
|
||||
{
|
||||
"name": "Reduce",
|
||||
"value": "Reduce"
|
||||
},
|
||||
{
|
||||
"name": "Click_on_add",
|
||||
"value": "Click on the size to add 50"
|
||||
},
|
||||
{
|
||||
"name": "Click_on_reduce",
|
||||
"value": "Click to reduce size by 50"
|
||||
},
|
||||
{
|
||||
"name": "The_key_fixed_1",
|
||||
"value": "The key is fixed at 1"
|
||||
},
|
||||
{
|
||||
"name": "The_key_changes_timestamp",
|
||||
"value": "Key changes every time: timestamp"
|
||||
},
|
||||
{
|
||||
"name": "Load",
|
||||
"value": "Load"
|
||||
},
|
||||
{
|
||||
"name": "Preloading_images_to_file_cache_using_URL",
|
||||
"value": "Preloading images to file cache using URL"
|
||||
},
|
||||
{
|
||||
"name": "Preloading_images_to_file_cache_using_option",
|
||||
"value": "Preloading images to file cache using option"
|
||||
},
|
||||
{
|
||||
"name": "Load_image_offline_after_preloading",
|
||||
"value": "Load image (can be loaded offline after preloading)"
|
||||
},
|
||||
{
|
||||
"name": "Preloading_GIF",
|
||||
"value": "Preloading GIF"
|
||||
},
|
||||
{
|
||||
"name": "Retrieve_GIF_from_memory",
|
||||
"value": "Retrieve GIF from memory cache"
|
||||
},
|
||||
{
|
||||
"name": "Retrieve_GIF_from_disk",
|
||||
"value": "Retrieve GIF from disk cache"
|
||||
},
|
||||
{
|
||||
"name": "Preloading_static_images",
|
||||
"value": "Preloading static images"
|
||||
},
|
||||
{
|
||||
"name": "Retrieve_images_from_memory",
|
||||
"value": "Retrieve images from memory cache"
|
||||
},
|
||||
{
|
||||
"name": "Retrieve_images_from_disk",
|
||||
"value": "Retrieve images from memory disk"
|
||||
},
|
||||
{
|
||||
"name": "Write_memory_and_file",
|
||||
"value": "Write to memory and file cache"
|
||||
},
|
||||
{
|
||||
"name": "Write_memory",
|
||||
"value": "Write to memory cache"
|
||||
},
|
||||
{
|
||||
"name": "Write_file",
|
||||
"value": "Write to file cache"
|
||||
},
|
||||
{
|
||||
"name": "Main_image_Fill",
|
||||
"value": "Main image Fill Stretch Fill"
|
||||
},
|
||||
{
|
||||
"name": "Maintain_proportion_filling",
|
||||
"value": "Maintain proportion filling in the placeholder map 'Include'"
|
||||
},
|
||||
{
|
||||
"name": "Error_graph_None",
|
||||
"value": "Error graph None remains unchanged"
|
||||
},
|
||||
{
|
||||
"name": "Test_failure_success",
|
||||
"value": "Test failure/success"
|
||||
},
|
||||
{
|
||||
"name": "Custom_download_failed",
|
||||
"value": "Custom download failed"
|
||||
},
|
||||
{
|
||||
"name": "Retrieve_media_gallery",
|
||||
"value": "Retrieve the URI of the media gallery and display it using ImageKnife"
|
||||
},
|
||||
{
|
||||
"name": "Click_load_Uri",
|
||||
"value": "Click to load Uri and display"
|
||||
},
|
||||
{
|
||||
"name": "Delete_all_caches",
|
||||
"value": "Delete all caches"
|
||||
},
|
||||
{
|
||||
"name": "Delete_all_memory_caches",
|
||||
"value": "Delete all memory caches"
|
||||
},
|
||||
{
|
||||
"name": "Delete_all_file_caches",
|
||||
"value": "Delete all file caches"
|
||||
},
|
||||
{
|
||||
"name": "Delete_all_custom_memory_caches",
|
||||
"value": "Delete all custom memory caches"
|
||||
},
|
||||
{
|
||||
"name": "Delete_all_custom_file_caches",
|
||||
"value": "Delete all custom file caches"
|
||||
},
|
||||
{
|
||||
"name": "Blur_effect",
|
||||
"value": "Blur effect"
|
||||
},
|
||||
{
|
||||
"name": "Highlighting_effect",
|
||||
"value": "Highlighting effect"
|
||||
},
|
||||
{
|
||||
"name": "Ashing_effect",
|
||||
"value": "Ashing effect"
|
||||
},
|
||||
{
|
||||
"name": "Inverse_effect",
|
||||
"value": "Inverse effect"
|
||||
},
|
||||
{
|
||||
"name": "Animation_filter_effect",
|
||||
"value": "Animation filter effect"
|
||||
},
|
||||
{
|
||||
"name": "Crop_circular_effect",
|
||||
"value": "Crop circular effect"
|
||||
},
|
||||
{
|
||||
"name": "Crop_circular_with_border_effect",
|
||||
"value": "Crop circular with border effect"
|
||||
},
|
||||
{
|
||||
"name": "Contrast_effect",
|
||||
"value": "Contrast effect"
|
||||
},
|
||||
{
|
||||
"name": "Black_ink_filtering_effect",
|
||||
"value": "Black ink filtering effect"
|
||||
},
|
||||
{
|
||||
"name": "Rotate",
|
||||
"value": "Rotate"
|
||||
},
|
||||
{
|
||||
"name": "Corners",
|
||||
"value": "Corners"
|
||||
},
|
||||
{
|
||||
"name": "Kuwahara_Filter_effect",
|
||||
"value": "Kuwahara filter effect"
|
||||
},
|
||||
{
|
||||
"name": "Pixelated_Filter_effect",
|
||||
"value": "Pixelated filtering effect"
|
||||
},
|
||||
{
|
||||
"name": "Sketch_Filter_effect",
|
||||
"value": "Sketch Filter effect"
|
||||
},
|
||||
{
|
||||
"name": "Distortion_Filter_effect",
|
||||
"value": "Distortion Filter effect"
|
||||
},
|
||||
{
|
||||
"name": "Decorative_Filter_effect",
|
||||
"value": "Decorative Filter effect"
|
||||
},
|
||||
{
|
||||
"name": "Square_cutting_effect",
|
||||
"value": "Square cutting effect"
|
||||
},
|
||||
{
|
||||
"name": "Top_cutting_effect",
|
||||
"value": "Top cutting effect"
|
||||
},
|
||||
{
|
||||
"name": "Middle_cutting_effect",
|
||||
"value": "Middle cutting effect"
|
||||
},
|
||||
{
|
||||
"name": "Bottom_cutting_effect",
|
||||
"value": "Bottom cutting effect"
|
||||
},
|
||||
{
|
||||
"name": "Mask_effect",
|
||||
"value": "Mask effect"
|
||||
},
|
||||
{
|
||||
"name": "TIPS",
|
||||
"value": "Please shut down the network first and ensure that there is no cache of images from this network in the test failure scenario locally"
|
||||
},
|
||||
{
|
||||
"name": "Network_reload",
|
||||
"value": "Network recovery reload"
|
||||
},
|
||||
{
|
||||
"name": "preloading_prefetch",
|
||||
"value": "Dynamic preloading prefetch"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -365,20 +365,12 @@
|
||||
"value": "测试失败场景请先关闭网络,并保证本地没有此网络图片的缓存"
|
||||
},
|
||||
{
|
||||
"name": "Image_Downsampling_Functionality",
|
||||
"value": "降采样功能"
|
||||
"name": "Network_reload",
|
||||
"value": "网络恢复reload"
|
||||
},
|
||||
{
|
||||
"name": "Sampling_pecification",
|
||||
"value": "降采样规格"
|
||||
},
|
||||
{
|
||||
"name": "Unreal_samples",
|
||||
"value": "未降采样大小"
|
||||
},
|
||||
{
|
||||
"name": "After_the_sampling",
|
||||
"value": "降采样后大小"
|
||||
"name": "preloading_prefetch",
|
||||
"value": "动态预加载prefetch"
|
||||
},
|
||||
{
|
||||
"name": "image_format",
|
||||
@@ -507,6 +499,150 @@
|
||||
{
|
||||
"name": "disk",
|
||||
"value": "磁盘"
|
||||
},
|
||||
{
|
||||
"name": "Customize_RCP_network",
|
||||
"value": "自定义rcp网络请求"
|
||||
},
|
||||
{
|
||||
"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 "
|
||||
},
|
||||
{
|
||||
"name": "Image_Downsampling_Functionality",
|
||||
"value": "降采样功能"
|
||||
},
|
||||
{
|
||||
"name": "Sampling_pecification",
|
||||
"value": "降采样规格"
|
||||
},
|
||||
{
|
||||
"name": "Unreal_samples",
|
||||
"value": "未降采样大小"
|
||||
},
|
||||
{
|
||||
"name": "After_the_sampling",
|
||||
"value": "降采样后大小"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -55,12 +55,12 @@ export default function DefaultJobQueueTest() {
|
||||
|
||||
expect(job.getQueueLength()).assertEqual(7)
|
||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("high1")
|
||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium4")
|
||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium3")
|
||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium2")
|
||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium1")
|
||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("low2")
|
||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium2")
|
||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium3")
|
||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("medium4")
|
||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("low1")
|
||||
expect(job.pop()!.imageKnifeOption.loadSrc).assertEqual("low2")
|
||||
expect(job.pop()).assertEqual(undefined)
|
||||
expect(job.getQueueLength()).assertEqual(0)
|
||||
|
||||
|
||||
@@ -18,8 +18,9 @@ import ImageKnifeOptionTest from './ImageKnifeOption.test';
|
||||
import MemoryLruCacheTest from './MemoryLruCache.test';
|
||||
import ImageKnifeTest from './ImageKnife.test';
|
||||
import Transform from './transform.test';
|
||||
import SamplingTest from './SamplingTest.test';
|
||||
import imageFormatAndSize from './imageFormatAndSize.test'
|
||||
import loadCallBackData from './loadCallBackData.test'
|
||||
import SamplingTest from './SamplingTest.test';
|
||||
|
||||
export default function testsuite() {
|
||||
MemoryLruCacheTest();
|
||||
@@ -30,4 +31,5 @@ export default function testsuite() {
|
||||
Transform();
|
||||
SamplingTest()
|
||||
imageFormatAndSize();
|
||||
loadCallBackData();
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
|
||||
import { image } from '@kit.ImageKit'
|
||||
import { BusinessError } from '@kit.BasicServicesKit'
|
||||
import { calculateScaleType, Downsampler } from '@ohos/imageknife/src/main/ets/downsampling/Downsampler'
|
||||
import { Downsampler } from '@ohos/imageknife/src/main/ets/downsampling/Downsampler'
|
||||
import { DownsampleStrategy } from '@ohos/imageknife'
|
||||
|
||||
export default function SamplingTest() {
|
||||
@@ -39,41 +39,48 @@ export default function SamplingTest() {
|
||||
// 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('NONE', 0, () => {
|
||||
let reqSize: calculateScaleType =
|
||||
new Downsampler().calculateScaling('jpg', 1024, 1024, 200,
|
||||
200, DownsampleStrategy.NONE,)
|
||||
let req = (reqSize.targetWidth == 1024 && reqSize.targetHeight == 1024)
|
||||
expect(req).assertEqual(true);
|
||||
})
|
||||
it('AT_MOST', 1, () => {
|
||||
let reqSize: calculateScaleType =
|
||||
it('AT_MOST', 0, () => {
|
||||
let reqSize: Size =
|
||||
new Downsampler().calculateScaling('jpg', 1024, 1024, 200,
|
||||
200, DownsampleStrategy.AT_MOST)
|
||||
let req = (reqSize.targetWidth < 1024 && reqSize.targetHeight < 1024)
|
||||
let req = (reqSize.width < 1024 && reqSize.height < 1024)
|
||||
expect(req).assertEqual(true);
|
||||
})
|
||||
it('FIT_CENTER', 2, () => {
|
||||
let reqSize: calculateScaleType =
|
||||
it('FIT_CENTER_MEMORY', 1, () => {
|
||||
let reqSize: Size =
|
||||
new Downsampler().calculateScaling('jpg', 1024, 1024, 200,
|
||||
200, DownsampleStrategy.FIT_CENTER_MEMORY)
|
||||
let req = (reqSize.targetWidth < 1024 && reqSize.targetHeight < 1024)
|
||||
let req = (reqSize.width < 1024 && reqSize.height < 1024)
|
||||
expect(req).assertEqual(true);
|
||||
})
|
||||
it('CENTER_OUTSIDE', 3, () => {
|
||||
let reqSize: calculateScaleType =
|
||||
it('FIT_CENTER_QUALITY', 2, () => {
|
||||
let reqSize: Size =
|
||||
new Downsampler().calculateScaling('jpg', 1024, 1024, 200,
|
||||
200, DownsampleStrategy.FIT_CENTER_QUALITY)
|
||||
let req = (reqSize.width < 1024 && reqSize.height < 1024)
|
||||
expect(req).assertEqual(true);
|
||||
})
|
||||
it('CENTER_OUTSIDE_MEMORY', 3, () => {
|
||||
let reqSize: Size =
|
||||
new Downsampler().calculateScaling('jpg', 1024, 1024, 200,
|
||||
200, DownsampleStrategy.CENTER_OUTSIDE_MEMORY)
|
||||
let req = (reqSize.targetWidth < 1024 && reqSize.targetHeight < 1024)
|
||||
let req = (reqSize.width < 1024 && reqSize.height < 1024)
|
||||
expect(req).assertEqual(true);
|
||||
})
|
||||
it('AT_LEAST', 4, () => {
|
||||
let reqSize: calculateScaleType =
|
||||
it('CENTER_OUTSIDE_QUALITY', 4, () => {
|
||||
let reqSize: Size =
|
||||
new Downsampler().calculateScaling('jpg', 1024, 1024, 200,
|
||||
200, DownsampleStrategy.CENTER_OUTSIDE_QUALITY)
|
||||
let req = (reqSize.width < 1024 && reqSize.height < 1024)
|
||||
expect(req).assertEqual(true);
|
||||
})
|
||||
it('AT_LEAST', 5, () => {
|
||||
let reqSize: Size =
|
||||
new Downsampler().calculateScaling('jpg', 1024, 1024, 200,
|
||||
200, DownsampleStrategy.AT_LEAST)
|
||||
let req = (reqSize.targetWidth < 1024 && reqSize.targetHeight < 1024)
|
||||
let req = (reqSize.width < 1024 && reqSize.height < 1024)
|
||||
expect(req).assertEqual(true);
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -49,9 +49,9 @@ export default function imageFormatAndSize() {
|
||||
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({
|
||||
let imageKnifeOption: ImageKnifeOption = {
|
||||
loadSrc: url,
|
||||
})
|
||||
}
|
||||
await new Promise<string>((resolve, reject) => {
|
||||
imageKnifeOption.onLoadListener = {
|
||||
onLoadSuccess: (data, imageknifeData) => {
|
||||
|
||||
117
entry/src/ohosTest/ets/test/loadCallBackData.test.ets
Normal file
117
entry/src/ohosTest/ets/test/loadCallBackData.test.ets
Normal file
@@ -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();
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user