From a766f210b4be64f5ee78bac284380d2eb440e24f Mon Sep 17 00:00:00 2001 From: zhoulisheng <635547767@qq.com> Date: Tue, 24 Oct 2023 16:54:37 +0800 Subject: [PATCH 1/6] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E6=9A=82=E5=81=9C=E5=8A=A0=E8=BD=BD=E5=92=8C=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=8A=A0=E8=BD=BD=E7=9A=84=E8=83=BD=E5=8A=9B?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoulisheng <635547767@qq.com> --- .../src/main/ets/pages/manyPhotoShowPage.ets | 19 + .../ets/components/imageknife/ImageKnife.ets | 368 +++++++++++------- .../imageknife/ImageKnifeComponent.ets | 61 +-- .../components/imageknife/RequestOption.ets | 40 +- .../networkmanage/DownloadClient.ets | 7 +- .../networkmanage/HttpDownloadClient.ets | 113 ++++++ .../requestmanage/RequestManager.ets | 2 + .../imageknife/utils/FileTypeUtil.ets | 183 +++------ .../utils/base/EasyLinkedHashMap.ets | 194 +++++++++ .../imageknife/utils/base/MethodMutex.ets | 40 ++ 10 files changed, 720 insertions(+), 307 deletions(-) create mode 100644 imageknife/src/main/ets/components/imageknife/networkmanage/HttpDownloadClient.ets create mode 100644 imageknife/src/main/ets/components/imageknife/utils/base/EasyLinkedHashMap.ets create mode 100644 imageknife/src/main/ets/components/imageknife/utils/base/MethodMutex.ets diff --git a/entry/src/main/ets/pages/manyPhotoShowPage.ets b/entry/src/main/ets/pages/manyPhotoShowPage.ets index 1841360..c07919f 100644 --- a/entry/src/main/ets/pages/manyPhotoShowPage.ets +++ b/entry/src/main/ets/pages/manyPhotoShowPage.ets @@ -31,7 +31,26 @@ struct ManyPhotoShowPage { build() { Column() { + Button('点击暂停加载') + .margin({top:10,bottom:5}) + .onClick(()=>{ + let imageKnife = ImageKnifeGlobal.getInstance().getImageKnife(); + if(imageKnife!= undefined){ + imageKnife.pauseRequests() + } + }) + + Button('点击重新加载') + .margin({top:10,bottom:5}) + .onClick(()=>{ + let imageKnife = ImageKnifeGlobal.getInstance().getImageKnife(); + if(imageKnife!= undefined){ + imageKnife.resumeRequest() + } + }) + Button('设置磁盘存储为50M') + .margin({top:10,bottom:5}) .onClick(()=>{ if(ImageKnifeGlobal.getInstance().getImageKnife() != undefined) { let disk: DiskLruCache | undefined = (ImageKnifeGlobal.getInstance().getImageKnife())?.getDiskMemoryCache(); diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnife.ets b/imageknife/src/main/ets/components/imageknife/ImageKnife.ets index 464efba..3b9af37 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnife.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnife.ets @@ -15,60 +15,68 @@ import { DiskLruCache } from "@ohos/disklrucache" import { LruCache } from "../cache/LruCache" -import {EngineKeyFactories} from "../cache/key/EngineKeyFactories" -import {EngineKeyInterface} from "../cache/key/EngineKeyInterface" -import {RequestOption} from "../imageknife/RequestOption" -import {AsyncCallback} from "../imageknife/interface/AsyncCallback" -import {PlaceHolderManager} from "../imageknife/holder/PlaceHolderManager" -import {RetryHolderManager} from "../imageknife/holder/RetryHolderManager" -import {ErrorHolderManager} from "../imageknife/holder/ErrorHolderManager" -import {RequestManager} from "../imageknife/requestmanage/RequestManager" -import {NONE} from "../cache/diskstrategy/enum/NONE" -import {FileTypeUtil} from '../imageknife/utils/FileTypeUtil' -import {DownloadClient} from '../imageknife/networkmanage/DownloadClient' -import {IDataFetch} from '../imageknife/networkmanage/IDataFetch' -import {ParseResClient} from '../imageknife/resourcemanage/ParseResClient' -import {IResourceFetch} from '../imageknife/resourcemanage/IResourceFetch' -import {ImageKnifeData,ImageKnifeType} from '../imageknife/ImageKnifeData' -import {ImageKnifeGlobal} from '../imageknife/ImageKnifeGlobal' +import { EngineKeyFactories } from "../cache/key/EngineKeyFactories" +import { EngineKeyInterface } from "../cache/key/EngineKeyInterface" +import { RequestOption } from "../imageknife/RequestOption" +import { AsyncCallback } from "../imageknife/interface/AsyncCallback" +import { PlaceHolderManager } from "../imageknife/holder/PlaceHolderManager" +import { RetryHolderManager } from "../imageknife/holder/RetryHolderManager" +import { ErrorHolderManager } from "../imageknife/holder/ErrorHolderManager" +import { RequestManager } from "../imageknife/requestmanage/RequestManager" +import { NONE } from "../cache/diskstrategy/enum/NONE" +import { FileTypeUtil } from '../imageknife/utils/FileTypeUtil' +import { DownloadClient } from '../imageknife/networkmanage/DownloadClient' +import { IDataFetch } from '../imageknife/networkmanage/IDataFetch' +import { ParseResClient } from '../imageknife/resourcemanage/ParseResClient' +import { IResourceFetch } from '../imageknife/resourcemanage/IResourceFetch' +import { ImageKnifeData, ImageKnifeType } from '../imageknife/ImageKnifeData' +import { ImageKnifeGlobal } from '../imageknife/ImageKnifeGlobal' import image from "@ohos.multimedia.image" -import {CompressBuilder} from "../imageknife/compress/CompressBuilder" +import { CompressBuilder } from "../imageknife/compress/CompressBuilder" import { IDrawLifeCycle } from '../imageknife/interface/IDrawLifeCycle' -import {LogUtil} from '../imageknife/utils/LogUtil' +import { LogUtil } from '../imageknife/utils/LogUtil' +import { EasyLinkedHashMap } from './utils/base/EasyLinkedHashMap' +import { MethodMutex } from './utils/base/MethodMutex' import worker from '@ohos.worker' import common from '@ohos.app.ability.common' +import HashMap from '@ohos.util.HashMap' +import LinkedList from '@ohos.util.LinkedList' export class ImageKnife { static readonly SEPARATOR: string = '/' - - memoryCache: LruCache; - diskMemoryCache: DiskLruCache; - dataFetch: IDataFetch; - resourceFetch: IResourceFetch; - filesPath: string = ""; // data/data/包名/files目录 + memoryCache: LruCache; + diskMemoryCache: DiskLruCache; + dataFetch: IDataFetch; + resourceFetch: IResourceFetch; + filesPath: string = ""; // data/data/包名/files目录 - placeholderCache: string = "placeholderCache" - runningRequest: Array; - pendingRequest: Array; - fileTypeUtil: FileTypeUtil; // 通用文件格式辨别 - diskCacheFolder: string = "ImageKnifeDiskCache" - - - defaultListener: AsyncCallback = { - callback:(err: string, data: ImageKnifeData)=>{return false} + placeholderCache: string = "placeholderCache" + runningMaps: EasyLinkedHashMap; + pendingMaps: EasyLinkedHashMap; + pausedMaps: EasyLinkedHashMap; + isPaused: boolean = false; + mutex: MethodMutex = new MethodMutex(); + fileTypeUtil: FileTypeUtil; // 通用文件格式辨别 + diskCacheFolder: string = "ImageKnifeDiskCache" + defaultListener: AsyncCallback = { + callback: (err: string, data: ImageKnifeData) => { + return false + } }; // 全局监听器 // gifWorker - gifWorker: worker.ThreadWorker|undefined = undefined; - - defaultLifeCycle: IDrawLifeCycle|undefined = undefined; - + gifWorker: worker.ThreadWorker | undefined = undefined; + defaultLifeCycle: IDrawLifeCycle | undefined = undefined; // 开发者可配置全局缓存 - engineKeyImpl: EngineKeyInterface; + engineKeyImpl: EngineKeyInterface; private constructor() { + this.runningMaps = new EasyLinkedHashMap(); + this.pendingMaps = new EasyLinkedHashMap(); + this.pausedMaps = new EasyLinkedHashMap(); + // 构造方法传入size 为保存文件个数 this.memoryCache = new LruCache(100); @@ -84,22 +92,21 @@ export class ImageKnife { // 初始化本地 文件保存 this.filesPath = (ImageKnifeGlobal.getInstance().getHapContext() as common.UIAbilityContext).filesDir as string; - this.runningRequest = new Array(); - this.pendingRequest = new Array(); - // 通用文件格式识别初始化 this.fileTypeUtil = new FileTypeUtil(); this.engineKeyImpl = new EngineKeyFactories(); + + } - getMemoryCache(): LruCache{ + getMemoryCache(): LruCache { return this.memoryCache; } - public static with(context:Object): ImageKnifeGlobal{ + public static with(context: Object): ImageKnifeGlobal { // 存入hapContext; - let global:ImageKnifeGlobal = ImageKnifeGlobal.getInstance(); + let global: ImageKnifeGlobal = ImageKnifeGlobal.getInstance(); global.setHapContext(context) // 初始化ImageKnife @@ -113,7 +120,7 @@ export class ImageKnife { return global; } - getDiskMemoryCache(): DiskLruCache{ + getDiskMemoryCache(): DiskLruCache { return this.diskMemoryCache; }; @@ -121,7 +128,7 @@ export class ImageKnife { this.diskMemoryCache = diskLruCache; }; - getFileTypeUtil(): FileTypeUtil{ + getFileTypeUtil(): FileTypeUtil { return this.fileTypeUtil; } @@ -137,22 +144,23 @@ export class ImageKnife { return this.defaultListener; } - setGifWorker(worker:worker.ThreadWorker){ + setGifWorker(worker: worker.ThreadWorker) { this.gifWorker = worker } - getGifWorker(){ + + getGifWorker() { return this.gifWorker; } - getDefaultLifeCycle(){ + getDefaultLifeCycle() { return this.defaultLifeCycle; } - setDefaultLifeCycle(viewLifeCycle:IDrawLifeCycle){ + setDefaultLifeCycle(viewLifeCycle: IDrawLifeCycle) { this.defaultLifeCycle = viewLifeCycle; } - setEngineKeyImpl(impl:EngineKeyInterface){ + setEngineKeyImpl(impl: EngineKeyInterface) { this.engineKeyImpl = impl; } @@ -162,34 +170,34 @@ export class ImageKnife { this.defaultListener = newDefaultListener; } - public compressBuilder(): CompressBuilder{ + public compressBuilder(): CompressBuilder { return new CompressBuilder(); } // 替代原来的LruCache - public replaceLruCache(size:number){ - if(this.memoryCache.map.size() <= 0) { + public replaceLruCache(size: number) { + if (this.memoryCache.map.size() <= 0) { this.memoryCache = new LruCache(size); - }else{ + } else { let newLruCache = new LruCache(size); - this.memoryCache.foreachLruCache( (value:ImageKnifeData, key:string, map:Object)=> { + this.memoryCache.foreachLruCache((value: ImageKnifeData, key: string, map: Object) => { newLruCache.put(key, value); }) this.memoryCache = newLruCache; } } - public replaceDataFetch(fetch:IDataFetch){ + public replaceDataFetch(fetch: IDataFetch) { this.dataFetch = fetch; } // 替代原来的DiskLruCache - public replaceDiskLruCache(size:number) { + public replaceDiskLruCache(size: number) { if (this.diskMemoryCache.getCacheMap().size() <= 0) { this.diskMemoryCache = DiskLruCache.create(ImageKnifeGlobal.getInstance().getHapContext(), size); } else { let newDiskLruCache = DiskLruCache.create(ImageKnifeGlobal.getInstance().getHapContext(), size); - this.diskMemoryCache.foreachDiskLruCache( (value:string|ArrayBuffer, key:string, map:Object)=> { + this.diskMemoryCache.foreachDiskLruCache((value: string | ArrayBuffer, key: string, map: Object) => { newDiskLruCache.set(key, value); }) this.diskMemoryCache = newDiskLruCache; @@ -197,17 +205,74 @@ export class ImageKnife { } // 预加载 resource资源一级缓存,string资源实现二级缓存 - preload(request: RequestOption):void { + preload(request: RequestOption): void { // 每个request 公共信息补充 request.setFilesPath(this.filesPath); - return this.parseSource(request); } + // 暂停所有请求 + async pauseRequests(): Promise { + await this.mutex.lock(async () => { + this.isPaused = true; + + // 将未删除的所有request [run pend] 放入 [pause] + this.pausedMaps.clear() + console.log('dodo pauseRequests start1 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size()) + + // 将run存入pause + let runNode = this.runningMaps.getHead(); + while (runNode) { + let request = runNode.value; + this.pausedMaps.put(request.uuid, request) + runNode = runNode.next; + } + this.runningMaps.clear(); + console.log('dodo pauseRequests start2 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size()) + + let pendNode = this.pendingMaps.getHead(); + while (pendNode) { + let request = pendNode.value; + this.pausedMaps.put(request.uuid, request) + pendNode = pendNode.next + } + this.pendingMaps.clear() + console.log('dodo pauseRequests start3 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size()) + }) + } + + + async resumeRequest(): Promise { + await this.mutex.lock(async () => { + this.isPaused = false; + console.log('dodo resumeRequest start1 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size()) + // 重启了之后需要把paused 里面的所有request重新发送 + let headNode = this.pausedMaps.getHead(); + while (headNode) { + let request = headNode.value + this.loadCacheManager(request) + headNode = headNode.next + } + this.pausedMaps.clear() + console.log('dodo resumeRequest start1 pausedMaps size=' + this.pausedMaps.size() + ' runMaps Size=' + this.runningMaps.size() + ' pendMaps Size=' + this.pendingMaps.size()) + }) + } + + // 删除 请求 + remove(uuid: string) { + if (this.isPaused) { + this.pausedMaps.remove(uuid) + } else { + // TODO 哪些请求可以删除 + this.pendingMaps.remove(uuid) + this.runningMaps.remove(uuid) + } + } + // 正常加载 - call(request: RequestOption):void { + call(request: RequestOption): void { // 添加全局监听 - if(this.defaultListener) { + if (this.defaultListener) { request.addListener(this.defaultListener) } @@ -231,28 +296,28 @@ export class ImageKnife { } loadResources(request: RequestOption) { - let factories:EngineKeyInterface; - let cacheKey:string; - let transferKey:string; - let dataKey:string; - if(this.engineKeyImpl){ + let factories: EngineKeyInterface; + let cacheKey: string; + let transferKey: string; + let dataKey: string; + if (this.engineKeyImpl) { factories = this.engineKeyImpl; - }else { + } else { factories = new EngineKeyFactories(); } // 生成内存缓存key 内存 变换后磁盘 let loadKey = ''; - if(typeof request.loadSrc == 'string'){ + if (typeof request.loadSrc == 'string') { loadKey = request.loadSrc; - }else{ + } else { loadKey = JSON.stringify(request.loadSrc); } let size = JSON.stringify(request.size); let transformed = ''; - if(request && request.transformations) { + if (request && request.transformations) { for (let i = 0; i < request.transformations.length; i++) { if (i == request.transformations.length - 1) { transformed += request.transformations[i].getName() + ""; @@ -289,120 +354,133 @@ export class ImageKnife { // 删除执行结束的running removeRunning(request: RequestOption) { - let index = -1; - for (let i = 0; i < this.runningRequest.length; i++) { - let tempRunning = this.runningRequest[i]; - if (this.keyEqual(request, tempRunning)) { - // 如果key相同 说明找到执行的request,我们记录下当前request的index位置 - index = i; - break; - } - } - if (index >= 0) { - let request = this.runningRequest.splice(index, 1)[0]; - this.loadNextPending(request); + if (this.isPaused) { + + } else { + this.runningMaps.remove(request.uuid); + console.log('dodo runningMaps length =' + this.runningMaps.size()) + let previousRequest = request; + this.loadNextPending(previousRequest); } } // 执行相同key的pending队列请求 - keyEqualPendingToRun(index:number){ - let nextPending = this.pendingRequest.splice(index, 1)[0]; - this.runningRequest.push(nextPending) + private keyEqualPendingToRun(nextPending: RequestOption) { + // let nextPending = this.pendingRequest.splice(index, 1)[0]; + // this.runningRequest.push(nextPending) + // RequestManager.execute((nextPending as RequestOption), this.memoryCache, this.diskMemoryCache, this.dataFetch, this.resourceFetch) + + this.pendingMaps.remove(nextPending.uuid) + this.runningMaps.put(nextPending.uuid, nextPending); + RequestManager.execute((nextPending as RequestOption), this.memoryCache, this.diskMemoryCache, this.dataFetch, this.resourceFetch) + } - searchNextKeyToRun(){ + private searchNextKeyToRun() { // 其次则寻找pending中第一个和running不重复的requestOrKey - let index2 = -1; - for (let i = 0; i < this.pendingRequest.length; i++) { - let temppending = this.pendingRequest[i]; - let hasKeyEqual = false; - for (let j = 0; j < this.runningRequest.length; j++) { - let temprunning = this.runningRequest[j]; - if (this.requestOrKeyEqual(temppending, temprunning)) { - hasKeyEqual = true; - break; + let pendingTailNode = this.pendingMaps.getTail(); + while (pendingTailNode) { + let pendingRequest = pendingTailNode.value; + let hasEqual = false; + let runningTailNode = this.runningMaps.getTail(); + while (runningTailNode) { + let runningRequest = runningTailNode.value; + if (this.requestOrKeyEqual(pendingRequest, runningRequest)) { + hasEqual = true; + break } + runningTailNode = runningTailNode.prev; } - if (!hasKeyEqual) { - index2 = i; + + if (hasEqual) { break; } + pendingTailNode = pendingTailNode.prev; } - if (index2 >= 0) { - let nextPending = this.pendingRequest.splice(index2, 1)[0]; - this.runningRequest.push(nextPending) + + if (pendingTailNode != null && pendingTailNode.value != null) { + let nextPending = pendingTailNode.value; + this.runningMaps.put(nextPending.uuid, nextPending) + this.pendingMaps.remove(nextPending.uuid) RequestManager.execute((nextPending as RequestOption), this.memoryCache, this.diskMemoryCache, this.dataFetch, this.resourceFetch) - } else { - // 不执行 } } // 加载下一个key的请求 - loadNextPending(request:RequestOption) { - // 首先寻找被移除key相同的request - let index = -1; - for (let i = 0; i < this.pendingRequest.length; i++) { - let temppending = this.pendingRequest[i]; - if (this.requestOrKeyEqual(request, temppending)) { - // 如果key相同 说明目前有任务正在执行,我们记录下当前request 放入pendingRunning - index = i; + private loadNextPending(request: RequestOption) { + let hasEqualRunning = false; + let tailNode = this.pendingMaps.getTail(); + while (tailNode) { + if (this.requestOrKeyEqual(request, tailNode.value)) { + hasEqualRunning = true; break; } + tailNode = tailNode.prev; } - if (index >= 0) { - this.keyEqualPendingToRun(index); + + if (hasEqualRunning) { + this.keyEqualPendingToRun(tailNode.value); } else { this.searchNextKeyToRun(); } } // 启动新线程 去磁盘取 去网络取 - loadCacheManager(request: RequestOption) { - if (this.keyNotEmpty(request)) { - let hasRunningRequest = false; - for (let i = 0; i < this.runningRequest.length; i++) { - let tempRunning = this.runningRequest[i]; - if (this.requestOrKeyEqual(request, tempRunning)) { + private loadCacheManager(request: RequestOption) { + if (this.isPaused) { + // 将当前request存入pausedMaps + this.pausedMaps.put(request.uuid, request); + } else { + // 正常逻辑 + if (this.keyNotEmpty(request)) { + let hasRunningRequest = false; + // 遍历双向链表 从尾巴到头 + let tailNode = this.runningMaps.getTail(); + while (tailNode) { + if (this.requestOrKeyEqual(request, tailNode.value)) { + hasRunningRequest = true; + break; + } + tailNode = tailNode.prev + } - // 如果requestOrKey相同 说明目前有任务正在执行,我们记录下当前request 放入pendingRunning - hasRunningRequest = true; - break; + if (hasRunningRequest) { + this.pendingMaps.put(request.uuid, request); + + // this.pendingRequest.push(request); + } else { + this.runningMaps.put(request.uuid, request) + + // this.runningRequest.push(request); + // 不存在相同key的 任务可以并行 + RequestManager.execute(request, this.memoryCache, this.diskMemoryCache, this.dataFetch, this.resourceFetch) } } - if (hasRunningRequest) { - this.pendingRequest.push(request); - } else { - this.runningRequest.push(request); - // 不存在相同key的 任务可以并行 - RequestManager.execute(request, this.memoryCache, this.diskMemoryCache, this.dataFetch, this.resourceFetch) + else { + LogUtil.log("key没有生成无法进入存取!") } } - else { - LogUtil.log("key没有生成无法进入存取!") - } - - } - private keyNotEmpty(request: RequestOption): boolean{ + private keyNotEmpty(request: RequestOption): boolean { if ( request.generateCacheKey != null && request.generateCacheKey.length > 0 && - request.generateDataKey != null && request.generateDataKey.length > 0 && - request.generateResourceKey != null && request.generateResourceKey.length > 0 + request.generateDataKey != null && request.generateDataKey.length > 0 && + request.generateResourceKey != null && request.generateResourceKey.length > 0 ) { return true; } return false; } - private keyEqual(request1: RequestOption, request2: RequestOption): boolean{ + private keyEqual(request1: RequestOption, request2: RequestOption): boolean { // key 完全相等的情况 if ( request1.generateCacheKey == request2.generateCacheKey && - request1.generateResourceKey == request2.generateResourceKey && - request1.generateDataKey == request2.generateDataKey + request1.generateResourceKey == request2.generateResourceKey && + request1.generateDataKey == request2.generateDataKey ) { return true; } @@ -411,18 +489,18 @@ export class ImageKnife { } // 非严格校验模式,如果所有key相等我们认为一定相等, 如果请求类型是string 网络请求url或者uri相等 我们也认为该请求应该只发送一个即可,后续请求会去缓存或者磁盘读取 - private requestOrKeyEqual(request1: RequestOption, request2: RequestOption): boolean{ + private requestOrKeyEqual(request1: RequestOption, request2: RequestOption): boolean { // key 完全相等的情况 if ( request1.generateCacheKey == request2.generateCacheKey && - request1.generateResourceKey == request2.generateResourceKey && - request1.generateDataKey == request2.generateDataKey + request1.generateResourceKey == request2.generateResourceKey && + request1.generateDataKey == request2.generateDataKey ) { return true; } // 如果加载的是网络url或者是本地文件uri读取,那么loadSrc相同就认为是同一个请求 - if( + if ( typeof request1.loadSrc == 'string' && typeof request2.loadSrc == 'string' && request1.loadSrc == request2.loadSrc ) { return true; @@ -431,7 +509,7 @@ export class ImageKnife { return false; } - parseSource(request: RequestOption):void { + private parseSource(request: RequestOption): void { if ((typeof (request.loadSrc as image.PixelMap).isEditable) == 'boolean') { let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, request.loadSrc as PixelMap) request.loadComplete(imageKnifeData); diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets index ff291ce..6516eb9 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets @@ -16,7 +16,7 @@ import { ImageKnifeOption } from '../imageknife/ImageKnifeOption' import { ImageKnifeGlobal } from '../imageknife/ImageKnifeGlobal' import { TransformType } from '../imageknife/transform/TransformType' -import { RequestOption, Size } from '../imageknife/RequestOption' +import { DetachFromLayout, RequestOption, Size } from '../imageknife/RequestOption' import { ImageKnifeData } from '../imageknife/ImageKnifeData' import { GIFFrame } from '../imageknife/utils/gif/GIFFrame' import { IDrawLifeCycle } from '../imageknife/interface/IDrawLifeCycle' @@ -82,6 +82,8 @@ export struct ImageKnifeComponent { private onReadyNext?: (data:ImageKnifeData|number|undefined) => void = undefined private onReadyNextData:ImageKnifeData|number|undefined = undefined + private detachFromLayout:DetachFromLayout; + build() { Canvas(this.context) .width('100%') @@ -275,6 +277,7 @@ export struct ImageKnifeComponent { } this.resetGifData() let request = new RequestOption(); + this.detachFromLayout = request.detachFromLayout; this.configNecessary(request); this.configCacheStrategy(request); this.configDisplay(request); @@ -421,7 +424,7 @@ export struct ImageKnifeComponent { drawPlaceholder(context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) { LogUtil.log('ImageKnifeComponent default drawPlaceholder start!') - + data.drawPixelMap?.imagePixelMap?.getImageInfo().then((imageInfo) => { LogUtil.log('ImageKnifeComponent imageinfo widht =' + imageInfo.size.width + ' height=' + imageInfo.size.height) let scaleType = (typeof imageKnifeOption.placeholderScaleType == 'number') ? imageKnifeOption.placeholderScaleType : ScaleType.FIT_CENTER @@ -476,7 +479,7 @@ export struct ImageKnifeComponent { drawThumbSizeMultiplier(context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) { LogUtil.log('ImageKnifeComponent default drawThumbSizeMultiplier start!') - + data.drawPixelMap?.imagePixelMap?.getImageInfo().then((imageInfo) => { LogUtil.log('ImageKnifeComponent imageinfo widht =' + imageInfo.size.width + ' height=' + imageInfo.size.height) let scaleType = (typeof imageKnifeOption.thumbSizeMultiplierScaleType == 'number') ? imageKnifeOption.thumbSizeMultiplierScaleType : ScaleType.FIT_CENTER @@ -491,7 +494,7 @@ export struct ImageKnifeComponent { drawMainSource(context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) { LogUtil.log('ImageKnifeComponent default drawMainSource start!') if (data.isPixelMap()) { - + data.drawPixelMap?.imagePixelMap?.getImageInfo().then((imageInfo) => { let scaleType = (typeof imageKnifeOption.mainScaleType == 'number') ? imageKnifeOption.mainScaleType : ScaleType.FIT_CENTER LogUtil.log('ImageKnifeComponent imageinfo width =' + imageInfo.size.width + ' height=' + imageInfo.size.height + 'scaleType=' + scaleType) @@ -508,7 +511,7 @@ export struct ImageKnifeComponent { drawRetryholder(context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) { LogUtil.log('ImageKnifeComponent default drawRetryholder start!') - + data.drawPixelMap?.imagePixelMap?.getImageInfo().then((imageInfo) => { LogUtil.log('ImageKnifeComponent imageinfo width =' + imageInfo.size.width + ' height=' + imageInfo.size.height) let scaleType = (typeof imageKnifeOption.retryholderScaleType == 'number') ? imageKnifeOption.retryholderScaleType : ScaleType.FIT_CENTER @@ -522,7 +525,7 @@ export struct ImageKnifeComponent { drawErrorholder(context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) { LogUtil.log('ImageKnifeComponent default drawErrorholder start!') - + data.drawPixelMap?.imagePixelMap?.getImageInfo().then((imageInfo) => { LogUtil.log('ImageKnifeComponent imageinfo widht =' + imageInfo.size.width + ' height=' + imageInfo.size.height) let scaleType = (typeof imageKnifeOption.errorholderSrcScaleType == 'number') ? imageKnifeOption.errorholderSrcScaleType : ScaleType.FIT_CENTER @@ -584,6 +587,10 @@ export struct ImageKnifeComponent { aboutToDisappear() { LogUtil.log('ImageKnifeComponent aboutToDisappear happened!') + if(this.detachFromLayout){ + this.detachFromLayout.detach(); + } + this.resetGifData(); } @@ -601,7 +608,7 @@ export struct ImageKnifeComponent { } private drawLifeCycleHasConsumed( methodName: string, - context: CanvasRenderingContext2D, data: K, imageKnifeOption: T, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void,drawLifeCycle?: IDrawLifeCycle + context: CanvasRenderingContext2D, data: K, imageKnifeOption: T, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void,drawLifeCycle?: IDrawLifeCycle ):boolean { if (drawLifeCycle && (drawLifeCycle as Record)[methodName]) { return (drawLifeCycle as Record)[methodName](context, data, imageKnifeOption, compWidth, compHeight, setGifTimeId) @@ -677,7 +684,7 @@ export struct ImageKnifeComponent { // 理论上该帧在屏幕上保留的时间 let stayTime:number= 0 if(this.renderFrames_frames != undefined) { - stayTime = this.renderFrames_frames[this.renderFrames_index].delay; + stayTime = this.renderFrames_frames[this.renderFrames_index].delay; } if (this.imageKnifeOption.gif && this.imageKnifeOption.gif.speedFactory) { stayTime = stayTime / (this.imageKnifeOption.gif?.speedFactory * 1.0); @@ -706,9 +713,9 @@ export struct ImageKnifeComponent { } private drawFrame(frames: GIFFrame[]|undefined, index: number, context: CanvasRenderingContext2D|undefined, compWidth: number, compHeight: number) { - if(frames == undefined){ - return - } + if(frames == undefined){ + return + } // get current frame let frame = frames[index]; if (!frame || !context) { @@ -848,9 +855,9 @@ export class ScaleTypeHelper { let dy:number = (compHeight - imageHeight * minScale) / (minScale * 1.0); let dw:number = imageWidth; let dh:number = imageHeight; - if(source!= undefined) { - context.drawImage(source, dx + (imageOffsetX != undefined ? imageOffsetX : 0), dy + (imageOffsetY != undefined ? imageOffsetY : 0)) - } + if(source!= undefined) { + context.drawImage(source, dx + (imageOffsetX != undefined ? imageOffsetX : 0), dy + (imageOffsetY != undefined ? imageOffsetY : 0)) + } } static drawFitCenter(context: CanvasRenderingContext2D, source: PixelMap | undefined, minScale: number, imageWidth: number, imageHeight: number, compWidth: number, compHeight: number, imageOffsetX?: number, imageOffsetY?: number) { @@ -859,9 +866,9 @@ export class ScaleTypeHelper { let dy:number = (compHeight - imageHeight * minScale) / (minScale * 2.0); let dw:number = imageWidth; let dh:number = imageHeight; - if(source!= undefined) { - context.drawImage(source, dx + (imageOffsetX != undefined ? imageOffsetX : 0), dy + (imageOffsetY != undefined ? imageOffsetY : 0)) - } + if(source!= undefined) { + context.drawImage(source, dx + (imageOffsetX != undefined ? imageOffsetX : 0), dy + (imageOffsetY != undefined ? imageOffsetY : 0)) + } } static drawCenter(context: CanvasRenderingContext2D, source: PixelMap | undefined, imageWidth: number, imageHeight: number, compWidth: number, compHeight: number, imageOffsetX?: number, imageOffsetY?: number) { @@ -869,9 +876,9 @@ export class ScaleTypeHelper { let dy:number = (compHeight - imageHeight) / 2.0; let dw:number = imageWidth; let dh:number = imageHeight; - if(source!= undefined) { - context.drawImage(source, dx + (imageOffsetX != undefined ? imageOffsetX : 0), dy + (imageOffsetY != undefined ? imageOffsetY : 0)) - } + if(source!= undefined) { + context.drawImage(source, dx + (imageOffsetX != undefined ? imageOffsetX : 0), dy + (imageOffsetY != undefined ? imageOffsetY : 0)) + } } static drawCenterCrop(context: CanvasRenderingContext2D, source: PixelMap | undefined, maxScale: number, imageWidth: number, imageHeight: number, compWidth: number, compHeight: number, imageOffsetX?: number, imageOffsetY?: number) { @@ -880,9 +887,9 @@ export class ScaleTypeHelper { let dy:number = (compHeight - imageHeight * maxScale) / (maxScale * 2.0); let dw:number = imageWidth; let dh:number = imageHeight; - if(source!= undefined) { - context.drawImage(source, dx + (imageOffsetX != undefined ? imageOffsetX : 0), dy + (imageOffsetY != undefined ? imageOffsetY : 0)) - } + if(source!= undefined) { + context.drawImage(source, dx + (imageOffsetX != undefined ? imageOffsetX : 0), dy + (imageOffsetY != undefined ? imageOffsetY : 0)) + } } static drawFitXY(context: CanvasRenderingContext2D, source: PixelMap | undefined, scaleW: number, scaleH: number, imageWidth: number, imageHeight: number, imageOffsetX?: number, imageOffsetY?: number) { @@ -891,9 +898,9 @@ export class ScaleTypeHelper { let dy:number = 0; let dw:number = imageWidth; let dh:number = imageHeight; - if(source!= undefined) { - context.drawImage(source, dx + (imageOffsetX != undefined ? imageOffsetX : 0), dy + (imageOffsetY != undefined ? imageOffsetY : 0)) - } + if(source!= undefined) { + context.drawImage(source, dx + (imageOffsetX != undefined ? imageOffsetX : 0), dy + (imageOffsetY != undefined ? imageOffsetY : 0)) + } } static drawCenterInside(context: CanvasRenderingContext2D, source: PixelMap | undefined, minScale: number, imageWidth: number, imageHeight: number, compWidth: number, compHeight: number, imageOffsetX?: number, imageOffsetY?: number) { @@ -912,7 +919,7 @@ export class ScaleTypeHelper { if(source!= undefined) { context.drawImage(source, dx + (imageOffsetX != undefined ? imageOffsetX : 0), dy + (imageOffsetY != undefined ? imageOffsetY : 0)) } - } + } } diff --git a/imageknife/src/main/ets/components/imageknife/RequestOption.ets b/imageknife/src/main/ets/components/imageknife/RequestOption.ets index 14665ef..5daad2b 100644 --- a/imageknife/src/main/ets/components/imageknife/RequestOption.ets +++ b/imageknife/src/main/ets/components/imageknife/RequestOption.ets @@ -54,7 +54,12 @@ export interface Size { width: number, height: number } +export interface DetachFromLayout{ + detach:()=>void +} + export class RequestOption { + uuid:string ='' // 唯一标识 loadSrc: string | PixelMap | Resource = ''; strategy: DiskStrategy = new AUTOMATIC(); dontAnimateFlag = false; @@ -117,11 +122,30 @@ export class RequestOption { // 缩略图展示 loadThumbnailReady = false; - + detachFromLayout:DetachFromLayout = { + detach: ()=>{ + let imageKnife:ImageKnife | undefined = ImageKnifeGlobal.getInstance().getImageKnife(); + if(imageKnife != undefined) { + imageKnife.remove(this.uuid); + } + } + } constructor() { // 初始化全局监听 this.requestListeners = new Array(); + // 初始化唯一标识,可以用这个标识找到ImageKnife中的对象 + this.uuid = this.generateUUID(); + } + + generateUUID(): string { + let d = new Date().getTime(); + const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { + const r = (d + Math.random() * 16) % 16 | 0; + d = Math.floor(d / 16); + return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); + }); + return uuid; } /** @@ -149,8 +173,6 @@ export class RequestOption { this.cachesPath = path; } - - load(src: string | PixelMap | Resource) { this.loadSrc = src; return this; @@ -489,15 +511,15 @@ export class RequestOption { // 非落盘情况,直接进行寻找下一个加载 let imageKnife:ImageKnife | undefined = ImageKnifeGlobal.getInstance().getImageKnife(); if(imageKnife != undefined) { - imageKnife.removeRunning(this); + imageKnife.removeRunning(this); } } - // 加载成功之后 - let imageKnife:ImageKnife | undefined = ImageKnifeGlobal.getInstance().getImageKnife(); - if(imageKnife != undefined) { - imageKnife.removeRunning(this); - } + // // 加载成功之后 + // let imageKnife:ImageKnife | undefined = ImageKnifeGlobal.getInstance().getImageKnife(); + // if(imageKnife != undefined) { + // imageKnife.removeRunning(this); + // } } // 图片文件落盘之后会自动去寻找下一个数据加载 diff --git a/imageknife/src/main/ets/components/imageknife/networkmanage/DownloadClient.ets b/imageknife/src/main/ets/components/imageknife/networkmanage/DownloadClient.ets index 820073b..1615075 100644 --- a/imageknife/src/main/ets/components/imageknife/networkmanage/DownloadClient.ets +++ b/imageknife/src/main/ets/components/imageknife/networkmanage/DownloadClient.ets @@ -15,7 +15,8 @@ import { IDataFetch } from '../networkmanage/IDataFetch' import { RequestOption } from '../RequestOption' -import { NetworkDownloadClient } from './NetworkDownloadClient' + +import { HttpDownloadClient } from './HttpDownloadClient' import { LoadLocalFileClient } from './LoadLocalFileClient' import { LoadDataShareFileClient } from './LoadDataShareFileClient' import loadRequest from '@ohos.request'; @@ -24,7 +25,7 @@ import common from '@ohos.app.ability.common' // 数据加载器 export class DownloadClient implements IDataFetch { - private networkClient = new NetworkDownloadClient(); + private httpDownloadClient = new HttpDownloadClient(); private localFileClient = new LoadLocalFileClient(); private dataShareFileClient = new LoadDataShareFileClient(); @@ -41,7 +42,7 @@ export class DownloadClient implements IDataFetch { this.dataShareFileClient.loadData(request, onCompleteFunction, onErrorFunction) } else { // 网络下载 - this.networkClient.loadData(request, onCompleteFunction, onErrorFunction) + this.httpDownloadClient.loadData(request, onCompleteFunction, onErrorFunction) } } } diff --git a/imageknife/src/main/ets/components/imageknife/networkmanage/HttpDownloadClient.ets b/imageknife/src/main/ets/components/imageknife/networkmanage/HttpDownloadClient.ets new file mode 100644 index 0000000..0551f72 --- /dev/null +++ b/imageknife/src/main/ets/components/imageknife/networkmanage/HttpDownloadClient.ets @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2021 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 { IDataFetch } from '../networkmanage/IDataFetch' +import { RequestOption } from '../RequestOption' +import { SparkMD5 } from '../../3rd_party/sparkmd5/spark-md5' +import { FileUtils } from '../../cache/FileUtils' +import loadRequest from '@ohos.request'; +import { LogUtil } from '../utils/LogUtil' +import { ImageKnifeGlobal } from '../ImageKnifeGlobal' +import common from '@ohos.app.ability.common' +import { BusinessError } from '@ohos.base' +import http from '@ohos.net.http' +// 数据加载器 +class RequestData{ + receiveSize: number = 2000 + totalSize: number = 2000 +} + +export class HttpDownloadClient implements IDataFetch { + loadData(request: RequestOption, onComplete: (img: ArrayBuffer) => void, onError: (err: string) => void) { + try { + let httpRequest = http.createHttp() + let arrayBuffers = new Array(); + httpRequest.on('headersReceive', (header: Object) => { + // 跟服务器连接成功准备下载 + if (request.progressFunc) { + // 进度条为0 + request.progressFunc.asyncSuccess(0) + } + }) + httpRequest.on('dataReceive', (data: ArrayBuffer) => { + // 下载数据流多次返回 + arrayBuffers.push(data); + }) + + httpRequest.on('dataReceiveProgress', (data: RequestData) => { + // 下载进度 + let percent = Math.round(((data.receiveSize * 1.0) / (data.totalSize * 1.0)) * 100) + if (request.progressFunc) { + request.progressFunc.asyncSuccess(percent) + } + }) + + httpRequest.on('dataEnd', () => { + // 下载完毕 + let combineArray = this.combineArrayBuffers(arrayBuffers); + onComplete(combineArray) + }) + + httpRequest.requestInStream( + request.loadSrc as string, + { + method: http.RequestMethod.GET, + expectDataType: http.HttpDataType.ARRAY_BUFFER, + connectTimeout: 60000, // 可选 默认60000ms + readTimeout: 0, //可选, 默认为60000ms + usingProtocol: http.HttpProtocol.HTTP1_1, // 可选,协议类型默认值由系统自动指定 + }, + (err: BusinessError, data: number) => { + if (!err && data == 200) { + + } else { + httpRequest.off('headersReceive'); + httpRequest.off('dataReceive'); + httpRequest.off('dataReceiveProgress'); + httpRequest.off('dataEnd'); + httpRequest.destroy() + onError('HttpDownloadClient err message =' + err.message) + } + } + ) + } catch (err) { + onError('HttpDownloadClient catch err request uuid ='+request.uuid) + } + } + + combineArrayBuffers(arrayBuffers: ArrayBuffer[]): ArrayBuffer { + // 计算多个ArrayBuffer的总字节大小 + let totalByteLength = 0; + for (const arrayBuffer of arrayBuffers) { + totalByteLength += arrayBuffer.byteLength; + } + + // 创建一个新的ArrayBuffer + const combinedArrayBuffer = new ArrayBuffer(totalByteLength); + + // 创建一个Uint8Array来操作新的ArrayBuffer + const combinedUint8Array = new Uint8Array(combinedArrayBuffer); + + // 依次复制每个ArrayBuffer的内容到新的ArrayBuffer中 + let offset = 0; + for (const arrayBuffer of arrayBuffers) { + const sourceUint8Array = new Uint8Array(arrayBuffer); + combinedUint8Array.set(sourceUint8Array, offset); + offset += sourceUint8Array.length; + } + + return combinedArrayBuffer; + } +} \ No newline at end of file diff --git a/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets b/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets index ac20bca..33b41d5 100644 --- a/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets +++ b/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets @@ -292,6 +292,8 @@ export class RequestManager { // 处理磁盘加载 网络加载 this.runWrapped(this.options, this.mRunReason, onComplete, onError) } else { + // 需要清理状态 + cache.waitSaveDisk = false; onComplete(cache); return diff --git a/imageknife/src/main/ets/components/imageknife/utils/FileTypeUtil.ets b/imageknife/src/main/ets/components/imageknife/utils/FileTypeUtil.ets index 21e28c7..51ca851 100644 --- a/imageknife/src/main/ets/components/imageknife/utils/FileTypeUtil.ets +++ b/imageknife/src/main/ets/components/imageknife/utils/FileTypeUtil.ets @@ -12,143 +12,80 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {LogUtil} from '../../imageknife/utils/LogUtil' +import { LogUtil } from '../../imageknife/utils/LogUtil' + +// jpg = 'jpg,0,FFD8', +// png = 'png,0,89504E470D0A1A0A', +// bmp = 'bmp,0,424D', +// gif = 'gif,0,474946383961', +// svg = 'svg,0,3C3F786D6C', +// webp = 'webp,0,52494646', +// tiff = 'tiff,0,492049|49492A00|4D4D002A|4D4D002B' + export class FileTypeUtil { - private map:Map = new Map(); - private READ_MIN_LENGTH:number = 0; - private SUPPORT_FORMATS = [ - PhotoFormat.jpg, - PhotoFormat.png, - PhotoFormat.tiff, - PhotoFormat.bmp, - PhotoFormat.webp, - PhotoFormat.svg, - PhotoFormat.gif - ] + private fileSignatureMap: Record> = { + // 添加文件类型和对应的文件头部特征 + 'jpg': [new Uint8Array([0xFF, 0xD8])], + 'png': [new Uint8Array([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A])], + 'gif': [new Uint8Array([0x47, 0x49, 0x46, 0x38, 0x39, 0x61])], + 'bmp': [new Uint8Array([0x42, 0x4D])], + 'svg': [new Uint8Array([0x3C, 0x3F, 0x78, 0x6D, 0x6C])], + 'webp': [new Uint8Array([0x52, 0x49, 0x46, 0x46])], + 'tiff': [new Uint8Array([0x49, 0x20, 0x49]), new Uint8Array([0x49, 0x49, 0x2A, 0x00]), new Uint8Array([0x4D, 0x4D, 0x00, 0x2A]), new Uint8Array([0x4D, 0x4D, 0x00, 0x2B])], + // 添加更多的文件类型和特征 + }; + constructor() { - this.initImageType(); - } - private getDataViewAt(dataView:DataView,index:number): string{ - return this.dec2Hex(dataView.getUint8(index)) - } - - - - getFileType(arraybuffer: ArrayBuffer):string { - let fileType:string = ''; - if (arraybuffer == null || arraybuffer == undefined || arraybuffer.byteLength <= this.READ_MIN_LENGTH) { - return ''; - } - - let dataView = new DataView(arraybuffer); - LogUtil.log('dataView +'+this.getDataViewAt(dataView,0)+this.getDataViewAt(dataView,1)) - let entries: IterableIterator = this.map.entries(); - for (let i = 0; i < this.map.size; i++) { - let entry:Object[] = entries.next().value; - let key = entry[0] as string - let value = entry[1] as string - let keySplit = key.split(',') - if(keySplit.length == 2){ - let offset = Number(keySplit[0]) - let magicStringLength = keySplit[1].length; - let readLength = magicStringLength/2; - let start = 0; - let fileMagic = '' - while(start< readLength){ - fileMagic+=this.getDataViewAt(dataView,offset+start) - start++; - } - if(fileMagic == keySplit[1]){ - LogUtil.log('匹配到了 fileType='+value) - fileType = value - break; - } - } - } - return fileType; - } - - dec2Hex(uint8: number) { - let hex = uint8.toString(16); - if (hex.length <= 1) { - hex = "0" + hex; - } - return hex.toUpperCase(); - } - - private initImageType() { - if(!this.map){ - this.map = new Map() - } - this.SUPPORT_FORMATS.forEach((value,index,arrs)=>{ - let values = value.split(',') - if(values.length == 3){ - let magicSplits = values[2].split("|") - if(magicSplits.length == 1){ - this.map.set(values[1]+','+values[2],values[0]) - }else if(magicSplits.length > 1){ - for(let i=0; i = this.map.entries(); - for (let i = 0; i < this.map.size; i++) { - let entry:Object[] = entries.next().value; - let key = entry[0] as string - let value = entry[1] as string - LogUtil.log('key='+key+'---value='+value) - } - } - - private initReadMinLength(){ - let max = 0; - this.map.forEach((value,key,map)=>{ - let keySplit = key.split(','); - if(keySplit.length == 2){ - let offset = Number(keySplit[0]) - let magicStringLength = keySplit[1].length; - let tempMax = offset + magicStringLength/2; - if(tempMax > max){ - max = tempMax; - } - } - }) - this.READ_MIN_LENGTH =max; - } - - isImage(arraybuffer:ArrayBuffer){ + isImage(arraybuffer: ArrayBuffer) { let value = this.getFileType(arraybuffer); - if( + if ( value == SupportFormat.jpg || - value == SupportFormat.png || - value == SupportFormat.tiff || - value == SupportFormat.webp || - value == SupportFormat.bmp || - value == SupportFormat.gif || - value == SupportFormat.svg - ){ + value == SupportFormat.png || + value == SupportFormat.tiff || + value == SupportFormat.webp || + value == SupportFormat.bmp || + value == SupportFormat.gif || + value == SupportFormat.svg + ) { return true; } return false; } + getFileType(file: ArrayBuffer): string | null { + const fileData = new Uint8Array(file); + for (const fileType in this.fileSignatureMap) { + const bufferList = this.fileSignatureMap[fileType]; + for (let i = 0; i < bufferList.length; i++) { + let signature = bufferList[i]; + if(this.matchesSignature(fileData,signature)){ + return fileType; + } + } + } + + return null; // 若无法识别文件类型,返回null + } + + + matchesSignature(fileData: Uint8Array, signature: Uint8Array): boolean { + if (fileData.length < signature.length) { + return false; // 文件长度不足,无法匹配魔数 + } + + for (let i = 0; i < signature.length; i++) { + if (fileData[i] !== signature[i]) { + return false; // 魔数不匹配 + } + } + return true; // 文件头部魔数匹配 + } } + export enum PhotoFormat { jpg = 'jpg,0,FFD8', png = 'png,0,89504E470D0A1A0A', diff --git a/imageknife/src/main/ets/components/imageknife/utils/base/EasyLinkedHashMap.ets b/imageknife/src/main/ets/components/imageknife/utils/base/EasyLinkedHashMap.ets new file mode 100644 index 0000000..7f19340 --- /dev/null +++ b/imageknife/src/main/ets/components/imageknife/utils/base/EasyLinkedHashMap.ets @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +class Node { + key: K; + value: V; + next: Node | null; + prev: Node | null; + + constructor(key: K, value: V) { + this.key = key; + this.value = value; + this.next = null; + this.prev = null; + } +} +// 链表的tail是最近访问,head是最晚访问,对顺序有要求需要访问tail +export class EasyLinkedHashMap { + private map: Map>; // 存储键值对的哈希映射 + private head: Node | null; // 链表头节点 + private tail: Node | null; // 链表尾节点 + + constructor() { + this.map = new Map>(); + this.head = null; + this.tail = null; + } + + // 添加键值对到映射中,并在链表尾部添加新节点 + put(key: K, value: V) { + if (this.map.has(key)) { + // 如果键已存在,则更新对应的值 + const node = this.map.get(key)!; + node.value = value; + this.moveToTail(node); + } else { + // 创建新节点并加入链表尾部 + const newNode = new Node(key, value); + this.map.set(key, newNode); + if (this.tail) { + this.tail.next = newNode; + newNode.prev = this.tail; + this.tail = newNode; + } else { + this.head = newNode; + this.tail = newNode; + } + } + } + + // 从映射中移除键值对,并从链表中删除对应节点 + remove(key: K) { + if (this.map.has(key)) { + const node = this.map.get(key)!; + this.map.delete(key); + this.removeNode(node); + } + } + + // 获取键对应的值,并将对应节点移到链表尾部(表示最近访问) + get(key: K): V | undefined { + if (this.map.has(key)) { + const node = this.map.get(key)!; + this.moveToTail(node); + return node.value; + } + return undefined; + } + + // 将节点移动到链表尾部 + private moveToTail(node: Node) { + if (node === this.tail) { + return; // 节点已在链表尾部,无需移动 + } + + if (node === this.head) { + this.head = node.next; + } else { + node.prev!.next = node.next; + } + + node.next!.prev = node.prev; + this.tail!.next = node; + node.prev = this.tail; + node.next = null; + this.tail = node; + } + + // 从链表中删除节点 + private removeNode(node: Node) { + if (node === this.head) { + this.head = node.next; + } else { + node.prev!.next = node.next; + } + + if (node === this.tail) { + this.tail = node.prev; + } else { + node.next!.prev = node.prev; + } + } + + // 返回映射中的键值对数量 + size(): number { + return this.map.size; + } + // 返回顺序双向链表 + getTail(){ + return this.tail; + } + + getHead(){ + return this.head; + } + clear(){ + this.map.clear() + this.head = null; + this.tail=null; + } +} + +function testLinkedHashMap(){ + // 创建一个新的 LinkedHashMap 实例 + let linkedHashMap = new EasyLinkedHashMap(); + + // 添加键值对,并验证插入是否正确 + linkedHashMap.put('key1', 1); + linkedHashMap.put('key2', 2); + linkedHashMap.put('key3', 3); + + console.log('dodo '+linkedHashMap.get('key1')); // 1 + console.log('dodo '+linkedHashMap.get('key2')); // 2 + console.log('dodo '+linkedHashMap.get('key3')); // 3 + + // 验证键值对更新是否正确 + linkedHashMap.put('key2', 20); + console.log('dodo '+linkedHashMap.get('key2')); // 20 + + // 验证移除键值对是否正确 + linkedHashMap.remove('key1'); + console.log('dodo '+linkedHashMap.get('key1')); // undefined + console.log('dodo '+linkedHashMap.size()); // 2 + + // 添加更多键值对 + linkedHashMap.put('key4', 4); + linkedHashMap.put('key5', 5); + linkedHashMap.put('key6', 6); + + console.log('dodo '+linkedHashMap.size()); // 5 + + // 验证访问顺序是否正确,最近访问的键值对应该在链表尾部 + console.log('dodo '+linkedHashMap.get('key2')); // 20 + console.log('dodo '+linkedHashMap.get('key3')); // 3 + console.log('dodo '+linkedHashMap.get('key4')); // 4 + + // 添加更多键值对,超出容量限制(假设容量限制为 5) + linkedHashMap.put('key7', 7); + linkedHashMap.put('key8', 8); + linkedHashMap.put('key9', 9); + + console.log('dodo '+linkedHashMap.size()); // 5 + console.log('dodo '+linkedHashMap.get('key1')); // undefined,因为已经超过容量限制,最早访问的键值对被移除 + + // 验证移除最近访问的键值对后,访问顺序是否正确 + linkedHashMap.remove('key4'); + console.log('dodo '+linkedHashMap.get('key4')); // undefined + console.log('dodo '+linkedHashMap.get('key2')); // 20 + console.log('dodo '+linkedHashMap.get('key3')); // 3 + + // 清空 LinkedHashMap + linkedHashMap.remove('key2'); + linkedHashMap.remove('key3'); + linkedHashMap.remove('key5'); + linkedHashMap.remove('key6'); + linkedHashMap.remove('key7'); + linkedHashMap.remove('key8'); + linkedHashMap.remove('key9'); + + console.log('dodo '+linkedHashMap.size()); // 0 +} \ No newline at end of file diff --git a/imageknife/src/main/ets/components/imageknife/utils/base/MethodMutex.ets b/imageknife/src/main/ets/components/imageknife/utils/base/MethodMutex.ets new file mode 100644 index 0000000..e3165d8 --- /dev/null +++ b/imageknife/src/main/ets/components/imageknife/utils/base/MethodMutex.ets @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class MethodMutex { + private mutex: Promise; + private release: () => void; + + constructor() { + this.mutex = Promise.resolve(); + this.release = () => {}; + } + + async lock(fn: () => Promise): Promise { + await this.mutex; + let result: T; + + try { + this.mutex = new Promise((resolve) => { + this.release = resolve; + }); + result = await fn(); + } finally { + this.release(); + } + + return result; + } +} \ No newline at end of file From fc4ab718bb6410fd2cbb4bc2b393bc029ac48651 Mon Sep 17 00:00:00 2001 From: zhoulisheng <635547767@qq.com> Date: Wed, 25 Oct 2023 11:31:14 +0800 Subject: [PATCH 2/6] =?UTF-8?q?1.Hsp=E9=80=82=E9=85=8D,=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=88=B0resourceManager=E7=9A=84=E5=9C=B0=E6=96=B9=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E8=BF=9B=E8=A1=8C=E6=95=B4=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoulisheng <635547767@qq.com> --- .../components/imageknife/ImageKnifeComponent.ets | 10 ++++++++++ .../ets/components/imageknife/ImageKnifeOption.ets | 3 ++- .../main/ets/components/imageknife/RequestOption.ets | 12 ++++++++++++ .../imageknife/holder/ErrorHolderManager.ets | 2 +- .../imageknife/holder/PlaceHolderManager.ets | 2 +- .../imageknife/holder/RetryHolderManager.ets | 2 +- .../networkmanage/NetworkDownloadClient.ets | 2 +- .../imageknife/requestmanage/RequestManager.ets | 4 +++- .../imageknife/resourcemanage/IResourceFetch.ets | 4 +++- .../imageknife/resourcemanage/ParseResClient.ets | 4 ++-- .../resourcemanage/ParseResClientBase64.ets | 6 +++--- .../imageknife/transform/MaskTransformation.ets | 6 +++--- 12 files changed, 42 insertions(+), 15 deletions(-) diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets index 6516eb9..353d7cb 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets @@ -22,6 +22,7 @@ import { GIFFrame } from '../imageknife/utils/gif/GIFFrame' import { IDrawLifeCycle } from '../imageknife/interface/IDrawLifeCycle' import { LogUtil } from '../imageknife/utils/LogUtil' import { BusinessError } from '@ohos.base' +import common from '@ohos.app.ability.common' @Component export struct ImageKnifeComponent { @@ -256,6 +257,14 @@ export struct ImageKnifeComponent { } } + configHspContext(request: RequestOption){ + if(this.imageKnifeOption.context != undefined){ + request.setModuleContext(this.imageKnifeOption.context) + }else{ + request.setModuleContext(getContext(this) as common.UIAbilityContext) + } + } + configRenderGpu(request: RequestOption) { if (this.imageKnifeOption.enableGpu) { request.enableGPU() @@ -281,6 +290,7 @@ export struct ImageKnifeComponent { this.configNecessary(request); this.configCacheStrategy(request); this.configDisplay(request); + this.configHspContext(request) this.configRenderGpu(request); if(ImageKnifeGlobal.getInstance().getImageKnife()!=undefined) { ImageKnifeGlobal.getInstance().getImageKnife()?.call(request); diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnifeOption.ets b/imageknife/src/main/ets/components/imageknife/ImageKnifeOption.ets index 2180386..0c4e00d 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnifeOption.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnifeOption.ets @@ -25,6 +25,7 @@ import { ScaleType } from '../imageknife/ImageKnifeComponent' import { rgbColor } from './transform/CropCircleWithBorderTransformation' import { RoundCorner } from './transform/RoundedCornersTransformation' import { ObjectKey } from './ObjectKey' +import common from '@ohos.app.ability.common' export interface CropCircleWithBorder{ border: number, @@ -125,7 +126,7 @@ export class ImageKnifeOption { allCacheInfoCallback?: IAllCacheInfoCallback; - + context?: common.UIAbilityContext; // sizeAnimate?: AnimateParam 由业务自定义不再支持 constructor() { diff --git a/imageknife/src/main/ets/components/imageknife/RequestOption.ets b/imageknife/src/main/ets/components/imageknife/RequestOption.ets index 5daad2b..b8fb0f2 100644 --- a/imageknife/src/main/ets/components/imageknife/RequestOption.ets +++ b/imageknife/src/main/ets/components/imageknife/RequestOption.ets @@ -49,6 +49,7 @@ import { LogUtil } from '../imageknife/utils/LogUtil' import { ImageKnifeGlobal } from './ImageKnifeGlobal' import { BusinessError } from '@ohos.base' import { ObjectKey } from './ObjectKey' +import common from '@ohos.app.ability.common' export interface Size { width: number, @@ -131,6 +132,9 @@ export class RequestOption { } } + // module资源的需要当前的module context + moduleContext:common.UIAbilityContext; + constructor() { // 初始化全局监听 this.requestListeners = new Array(); @@ -148,6 +152,14 @@ export class RequestOption { return uuid; } + setModuleContext(moduleCtx:common.UIAbilityContext){ + this.moduleContext = moduleCtx; + } + + getModuleContext():common.UIAbilityContext{ + return this.moduleContext; + } + /** * set image Component size */ diff --git a/imageknife/src/main/ets/components/imageknife/holder/ErrorHolderManager.ets b/imageknife/src/main/ets/components/imageknife/holder/ErrorHolderManager.ets index 527d447..fa3a9d4 100644 --- a/imageknife/src/main/ets/components/imageknife/holder/ErrorHolderManager.ets +++ b/imageknife/src/main/ets/components/imageknife/holder/ErrorHolderManager.ets @@ -72,7 +72,7 @@ export class ErrorHolderManager { break; } } - resourceFetch.loadResource(res, suc, onError) + resourceFetch.loadResource(this.options.getModuleContext(),res, suc, onError) } else { onError("ErrorHolderManager 输入参数有问题!") } diff --git a/imageknife/src/main/ets/components/imageknife/holder/PlaceHolderManager.ets b/imageknife/src/main/ets/components/imageknife/holder/PlaceHolderManager.ets index 612a10f..80f4c50 100644 --- a/imageknife/src/main/ets/components/imageknife/holder/PlaceHolderManager.ets +++ b/imageknife/src/main/ets/components/imageknife/holder/PlaceHolderManager.ets @@ -73,7 +73,7 @@ export class PlaceHolderManager { break; } } - resourceFetch.loadResource(res, suc, onError) + resourceFetch.loadResource(this.options.getModuleContext(),res, suc, onError) } else { onError("PlaceHolderManager 输入参数有问题!") } diff --git a/imageknife/src/main/ets/components/imageknife/holder/RetryHolderManager.ets b/imageknife/src/main/ets/components/imageknife/holder/RetryHolderManager.ets index aaf2245..f769ea6 100644 --- a/imageknife/src/main/ets/components/imageknife/holder/RetryHolderManager.ets +++ b/imageknife/src/main/ets/components/imageknife/holder/RetryHolderManager.ets @@ -73,7 +73,7 @@ export class RetryHolderManager { break; } } - resourceFetch.loadResource(res, suc, onError) + resourceFetch.loadResource(this.options.getModuleContext(), res, suc, onError) } else { onError("PlaceHolderManager 输入参数有问题!") } diff --git a/imageknife/src/main/ets/components/imageknife/networkmanage/NetworkDownloadClient.ets b/imageknife/src/main/ets/components/imageknife/networkmanage/NetworkDownloadClient.ets index 6733caa..ae7d9c5 100644 --- a/imageknife/src/main/ets/components/imageknife/networkmanage/NetworkDownloadClient.ets +++ b/imageknife/src/main/ets/components/imageknife/networkmanage/NetworkDownloadClient.ets @@ -43,7 +43,7 @@ export class NetworkDownloadClient implements IDataFetch { enableMetered: true, }; - loadRequest.downloadFile( (ImageKnifeGlobal.getInstance().getHapContext() as common.BaseContext ), downloadConfig).then((downloadTask:loadRequest.DownloadTask) => { + loadRequest.downloadFile( (request.getModuleContext() as common.BaseContext ), downloadConfig).then((downloadTask:loadRequest.DownloadTask) => { if (downloadTask) { let loadTask:loadRequest.DownloadTask | null = downloadTask; diff --git a/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets b/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets index 33b41d5..55d22a0 100644 --- a/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets +++ b/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets @@ -241,7 +241,7 @@ export class RequestManager { } } } - this.mIResourceFetch.loadResource(request.loadSrc as Resource, success, onError); + this.mIResourceFetch.loadResource(request.getModuleContext(),request.loadSrc as Resource, success, onError); } // 加载磁盘缓存 原图 private loadDiskFromSource(request: RequestOption, onComplete:(value:ImageKnifeData)=>void|PromiseLike, onError:(reason?:BusinessError|string)=>void) { @@ -323,6 +323,7 @@ export class RequestManager { width: Math.round(this.options.thumbSizeMultiplier * this.options.size.width), height: Math.round(this.options.thumbSizeMultiplier * this.options.size.height) }) + thumbOption.setModuleContext(this.options.getModuleContext()) let thumbCallback = this.options.thumbholderOnComplete; let thumbError = this.options.thumbholderOnError; this.options.transformations[0].transform(source, thumbOption,{asyncTransform: (error:BusinessError|string, pixelMap: PixelMap|null) => { @@ -539,6 +540,7 @@ export class RequestManager { thumbnailProcess(source:ArrayBuffer, filetype:string, onComplete:(value:ImageKnifeData)=>void|PromiseLike, onError:(reason?:BusinessError|string)=>void){ let thumbOption = new RequestOption(); + thumbOption.setModuleContext(this.options.getModuleContext()) thumbOption.setImageViewSize({ width: Math.round(this.options.thumbSizeMultiplier * this.options.size.width), height: Math.round(this.options.thumbSizeMultiplier * this.options.size.height) diff --git a/imageknife/src/main/ets/components/imageknife/resourcemanage/IResourceFetch.ets b/imageknife/src/main/ets/components/imageknife/resourcemanage/IResourceFetch.ets index 70057e5..1c65221 100644 --- a/imageknife/src/main/ets/components/imageknife/resourcemanage/IResourceFetch.ets +++ b/imageknife/src/main/ets/components/imageknife/resourcemanage/IResourceFetch.ets @@ -14,7 +14,9 @@ */ import { BusinessError } from '@ohos.base' +import common from '@ohos.app.ability.common'; + // 本地资源解析抽象接口 export interface IResourceFetch { - loadResource:(res: Resource, onCompleteFunction:(value:T)=>void | PromiseLike, onErrorFunction:(reason?:BusinessError|string)=>void)=>void; + loadResource:(context:common.UIAbilityContext ,res: Resource, onCompleteFunction:(value:T)=>void | PromiseLike, onErrorFunction:(reason?:BusinessError|string)=>void)=>void; } \ No newline at end of file diff --git a/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClient.ets b/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClient.ets index fd27e74..6faadc2 100644 --- a/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClient.ets +++ b/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClient.ets @@ -20,11 +20,11 @@ import { ImageKnifeGlobal } from '../ImageKnifeGlobal'; import { BusinessError } from '@ohos.base' import common from '@ohos.app.ability.common'; export class ParseResClient implements IResourceFetch { - loadResource(res: Resource, onCompleteFunction:(value:ArrayBuffer)=>void | PromiseLike, onErrorFunction:(reason?:BusinessError|string)=>void) { + loadResource(context:common.UIAbilityContext,res: Resource, onCompleteFunction:(value:ArrayBuffer)=>void | PromiseLike, onErrorFunction:(reason?:BusinessError|string)=>void) { let resId = res.id; let resType = res.type; if (resType == ResourceTypeEts.MEDIA) { - ((ImageKnifeGlobal.getInstance().getHapContext() as common.UIAbilityContext).resourceManager as resourceManager.ResourceManager) + (context.resourceManager as resourceManager.ResourceManager) .getMediaContent(resId) .then(data => { let arrayBuffer = this.typedArrayToBuffer(data); diff --git a/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClientBase64.ets b/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClientBase64.ets index 6f563b5..983a982 100644 --- a/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClientBase64.ets +++ b/imageknife/src/main/ets/components/imageknife/resourcemanage/ParseResClientBase64.ets @@ -19,14 +19,14 @@ import { Base64 } from '../../cache/Base64' import { BusinessError } from '@ohos.base' import resourceManager from '@ohos.resourceManager'; import { ImageKnifeGlobal } from '../ImageKnifeGlobal'; +import common from '@ohos.app.ability.common' export class ParseResClientBase64 implements IResourceFetch { - loadResource(res: Resource, onCompleteFunction: (value: ArrayBuffer) => void | PromiseLike, onErrorFunction: (reason?: BusinessError | string) => void) { + loadResource(context:common.UIAbilityContext,res: Resource, onCompleteFunction: (value: ArrayBuffer) => void | PromiseLike, onErrorFunction: (reason?: BusinessError | string) => void) { let resId = res.id; let resType = res.type; if (resType == ResourceTypeEts.MEDIA) { - ((ImageKnifeGlobal.getInstance() - .getHapContext() as Record).resourceManager as resourceManager.ResourceManager) + (context.resourceManager as resourceManager.ResourceManager) .getMediaContentBase64(resId) .then(data => { let matchReg = ';base64,'; diff --git a/imageknife/src/main/ets/components/imageknife/transform/MaskTransformation.ets b/imageknife/src/main/ets/components/imageknife/transform/MaskTransformation.ets index 4c04a40..20a9a2f 100644 --- a/imageknife/src/main/ets/components/imageknife/transform/MaskTransformation.ets +++ b/imageknife/src/main/ets/components/imageknife/transform/MaskTransformation.ets @@ -78,20 +78,20 @@ export class MaskTransformation implements BaseTransform { } imageSource.createPixelMap(options) .then(data => { - this.openInternal(data, targetWidth, targetHeight, func) + this.openInternal(request,data, targetWidth, targetHeight, func) }) .catch((e:BusinessError )=> { func?.asyncTransform(e, null); }) } - private openInternal(bitmap: PixelMap, width: number, height: number, func?: AsyncTransform) { + private openInternal(request: RequestOption,bitmap: PixelMap, width: number, height: number, func?: AsyncTransform) { if (!this._mResourceData) { if(func != undefined){ func.asyncTransform("MaskTransformation resource is empty", null) } } - let context = (ImageKnifeGlobal.getInstance().getHapContext() as common.UIAbilityContext) + let context = (request.getModuleContext() as common.UIAbilityContext) if(context != undefined){ let resourceManager = context.resourceManager as resourceManager.ResourceManager if(resourceManager != undefined && this._mResourceData != undefined) From 219504ea8a8cafb271f0d05ea4061406c13cc096 Mon Sep 17 00:00:00 2001 From: zhoulisheng <635547767@qq.com> Date: Wed, 25 Oct 2023 11:32:41 +0800 Subject: [PATCH 3/6] =?UTF-8?q?1.Hsp=E9=80=82=E9=85=8D,=E6=96=B0=E5=A2=9Eh?= =?UTF-8?q?sp=E7=9A=84library=E6=A8=A1=E5=9D=97,=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E5=90=8E=E7=BB=AD=E6=B5=8B=E8=AF=95hsp=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoulisheng <635547767@qq.com> --- library/.gitignore | 6 ++ library/build-profile.json5 | 10 +++ library/hvigorfile.ts | 2 + library/oh-package.json5 | 11 +++ library/src/main/ets/Index.ets | 14 ++++ library/src/main/ets/pages/Index.ets | 78 ++++++++++++++++++ library/src/main/module.json5 | 13 +++ .../main/resources/base/element/color.json | 8 ++ .../main/resources/base/element/string.json | 8 ++ .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../main/resources/base/media/setting.jpeg | Bin 0 -> 11320 bytes .../resources/base/profile/main_pages.json | 5 ++ 12 files changed, 155 insertions(+) create mode 100644 library/.gitignore create mode 100644 library/build-profile.json5 create mode 100644 library/hvigorfile.ts create mode 100644 library/oh-package.json5 create mode 100644 library/src/main/ets/Index.ets create mode 100644 library/src/main/ets/pages/Index.ets create mode 100644 library/src/main/module.json5 create mode 100644 library/src/main/resources/base/element/color.json create mode 100644 library/src/main/resources/base/element/string.json create mode 100644 library/src/main/resources/base/media/icon.png create mode 100644 library/src/main/resources/base/media/setting.jpeg create mode 100644 library/src/main/resources/base/profile/main_pages.json diff --git a/library/.gitignore b/library/.gitignore new file mode 100644 index 0000000..e2713a2 --- /dev/null +++ b/library/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/library/build-profile.json5 b/library/build-profile.json5 new file mode 100644 index 0000000..befa101 --- /dev/null +++ b/library/build-profile.json5 @@ -0,0 +1,10 @@ +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default" + } + ] +} \ No newline at end of file diff --git a/library/hvigorfile.ts b/library/hvigorfile.ts new file mode 100644 index 0000000..0e65ea8 --- /dev/null +++ b/library/hvigorfile.ts @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').hspTasks diff --git a/library/oh-package.json5 b/library/oh-package.json5 new file mode 100644 index 0000000..beeccdc --- /dev/null +++ b/library/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "library", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "./src/main/ets/Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": { + "@ohos/imageknife": "file:../imageknife" + } +} \ No newline at end of file diff --git a/library/src/main/ets/Index.ets b/library/src/main/ets/Index.ets new file mode 100644 index 0000000..f99aa38 --- /dev/null +++ b/library/src/main/ets/Index.ets @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ \ No newline at end of file diff --git a/library/src/main/ets/pages/Index.ets b/library/src/main/ets/pages/Index.ets new file mode 100644 index 0000000..dc7606c --- /dev/null +++ b/library/src/main/ets/pages/Index.ets @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { ImageKnifeComponent, ImageKnifeOption, FileUtils } from '@ohos/imageknife' +import common from '@ohos.app.ability.common' + +@Entry +@Component +struct Index { + + + @State imageOption1:ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + context: getContext(this).createModuleContext('library') as common.UIAbilityContext + } + @State imageOption2:ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + context: getContext(this).createModuleContext('library') as common.UIAbilityContext + } + @State imageOption3:ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + context: getContext(this).createModuleContext('library') as common.UIAbilityContext + } + + build() { + Scroll() { + Column() { + Button('点击加载Resource').onClick(()=>{ + this.imageOption1 = { + loadSrc: $r('app.media.setting'), + // 只要涉及resource加载 在HSP中都要带上context属性 + context: getContext(this).createModuleContext('library') as common.UIAbilityContext + } + }) + ImageKnifeComponent({imageKnifeOption:this.imageOption1}).width(300).height(300).backgroundColor(Color.Pink) + Button('点击加载网络图片').onClick(()=>{ + this.imageOption2 = { + loadSrc: 'https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB', + context: getContext(this).createModuleContext('library') as common.UIAbilityContext + } + }) + ImageKnifeComponent({imageKnifeOption:this.imageOption2}).width(300).height(300).backgroundColor(Color.Pink) + + Button('点击加载本地文件').onClick(()=>{ + getContext(this).createModuleContext('library').resourceManager.getMediaContent($r('app.media.setting').id).then((data:Uint8Array)=>{ + let path = globalThis.ImageKnife.getImageKnifeContext().filesDir+"/set.jpeg"; + FileUtils.getInstance().writeFile(path,data.buffer) + FileUtils.getInstance().readFilePicAsync(path).then(buffer=>{ + this.imageOption3 = { + loadSrc: path, + context: getContext(this).createModuleContext('library') as common.UIAbilityContext + } + }) + }) + + }) + ImageKnifeComponent({imageKnifeOption:this.imageOption3}).width(300).height(300).backgroundColor(Color.Pink) + + + + }.width('100%') + + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/library/src/main/module.json5 b/library/src/main/module.json5 new file mode 100644 index 0000000..74570f9 --- /dev/null +++ b/library/src/main/module.json5 @@ -0,0 +1,13 @@ +{ + "module": { + "name": "library", + "type": "shared", + "description": "$string:shared_desc", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "pages": "$profile:main_pages" + } +} \ No newline at end of file diff --git a/library/src/main/resources/base/element/color.json b/library/src/main/resources/base/element/color.json new file mode 100644 index 0000000..1bbc9aa --- /dev/null +++ b/library/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/library/src/main/resources/base/element/string.json b/library/src/main/resources/base/element/string.json new file mode 100644 index 0000000..98e1d8a --- /dev/null +++ b/library/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "shared_desc", + "value": "description" + } + ] +} \ No newline at end of file diff --git a/library/src/main/resources/base/media/icon.png b/library/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(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4=BA=AB=E5=8C=85library?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoulisheng <635547767@qq.com> --- build-profile.json5 | 18 ++++- entry/src/main/ets/pages/hspCacheTestPage.ets | 65 +++++++++++++++++++ .../ets/pages/imageknifeTestCaseIndex.ets | 20 ++++++ .../src/main/ets/pages/manyPhotoShowPage.ets | 2 +- .../resources/base/profile/main_pages.json | 3 +- .../ets/components/imageknife/ImageKnife.ets | 2 +- 6 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 entry/src/main/ets/pages/hspCacheTestPage.ets diff --git a/build-profile.json5 b/build-profile.json5 index eca7ce7..fa5c415 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -8,12 +8,12 @@ "compatibleSdkVersion": 9 } ], - "buildModeSet":[ + "buildModeSet": [ { - "name":"debug" + "name": "debug" }, { - "name":"release" + "name": "release" } ] }, @@ -37,6 +37,18 @@ { "name": "gpu_transform", "srcPath": "./gpu_transform" + }, + { + "name": "library", + "srcPath": "./library", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] } ] } \ No newline at end of file diff --git a/entry/src/main/ets/pages/hspCacheTestPage.ets b/entry/src/main/ets/pages/hspCacheTestPage.ets new file mode 100644 index 0000000..f5a981c --- /dev/null +++ b/entry/src/main/ets/pages/hspCacheTestPage.ets @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ImageKnifeComponent, ImageKnifeOption, FileUtils } from '@ohos/imageknife' + +@Entry +@Component +struct Index { + + + @State imageOption1:ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + + } + @State imageOption2:ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + + } + @State imageOption3:ImageKnifeOption = { + loadSrc: $r('app.media.icon'), + + } + + build() { + Scroll() { + Column() { + Button('点击加载网络图片').onClick(()=>{ + this.imageOption2 = { + loadSrc: 'https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB', + } + }) + ImageKnifeComponent({imageKnifeOption:this.imageOption2}).width(300).height(300).backgroundColor(Color.Pink) + + Button('点击加载本地文件').onClick(()=>{ + let path = globalThis.ImageKnife.getImageKnifeContext().filesDir+"/set.jpeg"; + FileUtils.getInstance().readFilePicAsync(path).then(buffer=>{ + this.imageOption3 = { + loadSrc: path + } + }) + + }) + ImageKnifeComponent({imageKnifeOption:this.imageOption3}).width(300).height(300).backgroundColor(Color.Pink) + + + + }.width('100%') + + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets index 5683d4d..87a9c56 100644 --- a/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets +++ b/entry/src/main/ets/pages/imageknifeTestCaseIndex.ets @@ -248,6 +248,26 @@ struct IndexFunctionDemo { router.pushUrl({ url: "pages/testGifLoadWithWorkerPage" }); }).margin({ top: 5, left: 3 }) }.width('100%').height(60).backgroundColor(Color.Pink) + Text("HSP相关测试").fontSize(15) + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + + Button("进入HSP的library共享包") + .onClick(() => { + router.pushUrl({url:'@bundle:com.openharmony.imageknife/library/ets/pages/Index'}) + .then(()=>{ + console.log('push page suceess') + }).catch(err => { + console.log(`pushUrl failed, code is ${err.code}, message is ${err.message}`) + }) + }).margin({ top: 15 }) + Button("hsp加载后缓存情况,先点左侧按钮") + .onClick(() => { + console.log("pages/tempUrlTestPage 页面跳转") + router.pushUrl({ url: "pages/hspCacheTestPage" }); + }).margin({ top: 15 }) + + + }.width('100%').height(60).backgroundColor(Color.Pink) } } .width('100%') diff --git a/entry/src/main/ets/pages/manyPhotoShowPage.ets b/entry/src/main/ets/pages/manyPhotoShowPage.ets index c07919f..ed8d488 100644 --- a/entry/src/main/ets/pages/manyPhotoShowPage.ets +++ b/entry/src/main/ets/pages/manyPhotoShowPage.ets @@ -36,7 +36,7 @@ struct ManyPhotoShowPage { .onClick(()=>{ let imageKnife = ImageKnifeGlobal.getInstance().getImageKnife(); if(imageKnife!= undefined){ - imageKnife.pauseRequests() + imageKnife.pauseRequest() } }) diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index 87811b4..d387c99 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -31,6 +31,7 @@ "pages/testSingleFrameGifPage", "pages/testGifLoadWithWorkerPage", "pages/OptionTestPage", - "pages/SignatureTestPage" + "pages/SignatureTestPage", + "pages/hspCacheTestPage" ] } \ No newline at end of file diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnife.ets b/imageknife/src/main/ets/components/imageknife/ImageKnife.ets index 3b9af37..03575be 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnife.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnife.ets @@ -212,7 +212,7 @@ export class ImageKnife { } // 暂停所有请求 - async pauseRequests(): Promise { + async pauseRequest(): Promise { await this.mutex.lock(async () => { this.isPaused = true; From 8f01a3a3b40a7dec80ce5a49f0e3712a459dda4d Mon Sep 17 00:00:00 2001 From: zhoulisheng <635547767@qq.com> Date: Tue, 31 Oct 2023 10:58:17 +0800 Subject: [PATCH 5/6] =?UTF-8?q?1.imageknife=E5=9C=A8library=E4=B8=AD?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96,=E5=B9=B6=E4=B8=94=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E7=BB=99entry=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoulisheng <635547767@qq.com> --- entry/oh-package.json5 | 2 +- .../ets/entryability/CustomEngineKeyImpl.ets | 4 +- .../main/ets/entryability/EntryAbility.ets | 4 +- .../main/ets/pages/CacheRuleChangedPage.ets | 2 +- entry/src/main/ets/pages/OptionTestPage.ets | 2 +- .../src/main/ets/pages/SignatureTestPage.ets | 2 +- .../ets/pages/basicTestFeatureAbilityPage.ets | 2 +- .../main/ets/pages/basicTestFileIOPage.ets | 2 +- .../main/ets/pages/basicTestMediaImage.ets | 10 +- .../pages/basicTestResourceManagerPage.ets | 8 +- entry/src/main/ets/pages/compressPage.ets | 8 +- entry/src/main/ets/pages/cropImagePage2.ets | 16 +-- .../main/ets/pages/dataShareUriLoadPage.ets | 2 +- .../main/ets/pages/drawFactoryTestPage.ets | 2 +- .../ets/pages/frescoRetryTestCasePage.ets | 8 +- entry/src/main/ets/pages/gifTestCasePage.ets | 6 +- entry/src/main/ets/pages/hspCacheTestPage.ets | 2 +- entry/src/main/ets/pages/index.ets | 2 +- .../src/main/ets/pages/manyPhotoShowPage.ets | 8 +- entry/src/main/ets/pages/pngjTestCasePage.ets | 4 +- .../ets/pages/showErrorholderTestCasePage.ets | 8 +- .../main/ets/pages/storageTestLruCache.ets | 2 +- entry/src/main/ets/pages/svgTestCasePage.ets | 4 +- entry/src/main/ets/pages/tempUrlTestPage.ets | 2 +- .../main/ets/pages/testAllCacheInfoPage.ets | 16 +-- .../main/ets/pages/testGifDontAnimatePage.ets | 10 +- .../ets/pages/testGifLoadWithWorkerPage.ets | 2 +- .../pages/testImageKnifeOptionChangedPage.ets | 10 +- .../testImageKnifeOptionChangedPage2.ets | 12 +- .../testImageKnifeOptionChangedPage3.ets | 18 +-- .../testImageKnifeOptionChangedPage4.ets | 2 +- .../testImageKnifeOptionChangedPage5.ets | 2 +- entry/src/main/ets/pages/testPreloadPage.ets | 10 +- .../main/ets/pages/testSingleFrameGifPage.ets | 4 +- .../main/ets/pages/transformPixelMapPage.ets | 36 +++--- .../src/ohosTest/ets/test/imageknife.test.ets | 2 +- entry/src/ohosTest/ets/test/logutil.test.ets | 2 +- entry/src/ohosTest/ets/test/lrucache.test.ets | 2 +- .../ohosTest/ets/test/requestoption.test.ets | 2 +- .../src/ohosTest/ets/test/transfrom.test.ets | 2 +- .../ohosTest/ets/testability/TestAbility.ets | 2 +- imageknife/index.ets | 1 + library/src/main/ets/Index.ets | 122 +++++++++++++++++- library/src/main/ets/pages/InitImageKnife.ets | 8 ++ 44 files changed, 253 insertions(+), 124 deletions(-) create mode 100644 library/src/main/ets/pages/InitImageKnife.ets diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 index 6d37d6c..70fa217 100644 --- a/entry/oh-package.json5 +++ b/entry/oh-package.json5 @@ -6,7 +6,7 @@ "repository": {}, "version": "2.1.1-rc.0", "dependencies": { - "@ohos/imageknife": "file:../imageknife", + "@ohos/libraryimageknife": "file:../library", "@ohos/disklrucache": "^2.0.2-rc.0" } } diff --git a/entry/src/main/ets/entryability/CustomEngineKeyImpl.ets b/entry/src/main/ets/entryability/CustomEngineKeyImpl.ets index 45d3300..81a6863 100644 --- a/entry/src/main/ets/entryability/CustomEngineKeyImpl.ets +++ b/entry/src/main/ets/entryability/CustomEngineKeyImpl.ets @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { EngineKeyFactories, EngineKeyInterface, RequestOption } from '@ohos/imageknife' -import { ObjectKey } from '@ohos/imageknife/src/main/ets/components/imageknife/ObjectKey'; +import { EngineKeyFactories, EngineKeyInterface, RequestOption } from '@ohos/libraryimageknife' +import { ObjectKey } from '@ohos/libraryimageknife'; export class CustomEngineKeyImpl implements EngineKeyInterface { redefineUrl: (loadSrc: string) => string; diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index c3d114b..3e816e7 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -15,7 +15,7 @@ import UIAbility from '@ohos.app.ability.UIAbility'; import hilog from '@ohos.hilog'; import window from '@ohos.window'; -import { ImageKnifeGlobal,ImageKnife,ImageKnifeDrawFactory,LogUtil } from '@ohos/imageknife' +import {InitImageKnife, ImageKnifeGlobal,ImageKnife,ImageKnifeDrawFactory,LogUtil } from '@ohos/libraryimageknife' import { CustomEngineKeyImpl } from './CustomEngineKeyImpl' import abilityAccessCtrl,{Permissions} from '@ohos.abilityAccessCtrl'; import { BusinessError } from '@ohos.base' @@ -38,7 +38,7 @@ export default class EntryAbility extends UIAbility { windowStage.loadContent('pages/index', (err:BusinessError, data:void) => { }); - ImageKnife.with(this.context); + InitImageKnife.init(this.context); let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife() if(imageKnife != undefined) { diff --git a/entry/src/main/ets/pages/CacheRuleChangedPage.ets b/entry/src/main/ets/pages/CacheRuleChangedPage.ets index a5592c9..ce1ef94 100644 --- a/entry/src/main/ets/pages/CacheRuleChangedPage.ets +++ b/entry/src/main/ets/pages/CacheRuleChangedPage.ets @@ -17,7 +17,7 @@ import { ImageKnifeOption, RotateImageTransformation, RoundedCornersTransformation -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/OptionTestPage.ets b/entry/src/main/ets/pages/OptionTestPage.ets index 1c19004..6f7f6e2 100644 --- a/entry/src/main/ets/pages/OptionTestPage.ets +++ b/entry/src/main/ets/pages/OptionTestPage.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { ImageKnifeComponent, ImageKnifeOption,NONE,DiskStrategy } from '@ohos/imageknife' +import { ImageKnifeComponent, ImageKnifeOption,NONE,DiskStrategy } from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/SignatureTestPage.ets b/entry/src/main/ets/pages/SignatureTestPage.ets index f2a2551..177061d 100644 --- a/entry/src/main/ets/pages/SignatureTestPage.ets +++ b/entry/src/main/ets/pages/SignatureTestPage.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { ImageKnifeComponent, ImageKnifeOption, NONE, DiskStrategy } from '@ohos/imageknife' +import { ImageKnifeComponent, ImageKnifeOption, NONE, DiskStrategy } from '@ohos/libraryimageknife' import { ObjectKey } from '@ohos/imageknife/src/main/ets/components/imageknife/ObjectKey'; @Entry diff --git a/entry/src/main/ets/pages/basicTestFeatureAbilityPage.ets b/entry/src/main/ets/pages/basicTestFeatureAbilityPage.ets index fb31384..cc787cc 100644 --- a/entry/src/main/ets/pages/basicTestFeatureAbilityPage.ets +++ b/entry/src/main/ets/pages/basicTestFeatureAbilityPage.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeOption,ImageKnifeComponent} from '@ohos/imageknife' +import {ImageKnifeOption,ImageKnifeComponent} from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/basicTestFileIOPage.ets b/entry/src/main/ets/pages/basicTestFileIOPage.ets index aabc863..e8f468c 100644 --- a/entry/src/main/ets/pages/basicTestFileIOPage.ets +++ b/entry/src/main/ets/pages/basicTestFileIOPage.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { FileUtils, ImageKnifeGlobal} from '@ohos/imageknife' +import { FileUtils, ImageKnifeGlobal} from '@ohos/libraryimageknife' import resourceManager from '@ohos.resourceManager'; import { BusinessError } from '@ohos.base' import common from '@ohos.app.ability.common'; diff --git a/entry/src/main/ets/pages/basicTestMediaImage.ets b/entry/src/main/ets/pages/basicTestMediaImage.ets index 089eec6..e448f79 100644 --- a/entry/src/main/ets/pages/basicTestMediaImage.ets +++ b/entry/src/main/ets/pages/basicTestMediaImage.ets @@ -13,12 +13,12 @@ * limitations under the License. */ import featureAbility from '@ohos.ability.featureAbility'; -import { FileUtils } from '@ohos/imageknife' -import { FileTypeUtil } from '@ohos/imageknife' +import { FileUtils } from '@ohos/libraryimageknife' +import { FileTypeUtil } from '@ohos/libraryimageknife' import resourceManager from '@ohos.resourceManager'; -import { Base64 } from '@ohos/imageknife' -import { ParseImageUtil } from '@ohos/imageknife' -import { ImageKnifeGlobal } from '@ohos/imageknife' +import { Base64 } from '@ohos/libraryimageknife' +import { ParseImageUtil } from '@ohos/libraryimageknife' +import { ImageKnifeGlobal } from '@ohos/libraryimageknife' import { BusinessError } from '@ohos.base' import common from '@ohos.app.ability.common'; @Entry diff --git a/entry/src/main/ets/pages/basicTestResourceManagerPage.ets b/entry/src/main/ets/pages/basicTestResourceManagerPage.ets index edc59e8..509dd53 100644 --- a/entry/src/main/ets/pages/basicTestResourceManagerPage.ets +++ b/entry/src/main/ets/pages/basicTestResourceManagerPage.ets @@ -13,11 +13,11 @@ * limitations under the License. */ import featureAbility from '@ohos.ability.featureAbility'; -import {FileUtils} from '@ohos/imageknife' -import {FileTypeUtil} from '@ohos/imageknife' +import {FileUtils} from '@ohos/libraryimageknife' +import {FileTypeUtil} from '@ohos/libraryimageknife' import resourceManager from '@ohos.resourceManager'; -import {Base64} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' +import {Base64} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' import { BusinessError } from '@ohos.base' import common from '@ohos.app.ability.common'; @Entry diff --git a/entry/src/main/ets/pages/compressPage.ets b/entry/src/main/ets/pages/compressPage.ets index b76a7ba..578840a 100644 --- a/entry/src/main/ets/pages/compressPage.ets +++ b/entry/src/main/ets/pages/compressPage.ets @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnife} from '@ohos/imageknife' -import {OnRenameListener} from '@ohos/imageknife' -import {OnCompressListener} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' +import {ImageKnife} from '@ohos/libraryimageknife' +import {OnRenameListener} from '@ohos/libraryimageknife' +import {OnCompressListener} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/cropImagePage2.ets b/entry/src/main/ets/pages/cropImagePage2.ets index fc76184..df4ad5d 100644 --- a/entry/src/main/ets/pages/cropImagePage2.ets +++ b/entry/src/main/ets/pages/cropImagePage2.ets @@ -13,14 +13,14 @@ * limitations under the License. */ -import { CropImage } from '@ohos/imageknife' -import { CropOptions } from '@ohos/imageknife' -import { Crop } from '@ohos/imageknife' -import { RecourseProvider } from '@ohos/imageknife' -import { PixelMapCrop,Options } from '@ohos/imageknife' -import { CropCallback } from '@ohos/imageknife' -import { FileUtils } from '@ohos/imageknife' -import { ImageKnifeGlobal } from '@ohos/imageknife' +import { CropImage } from '@ohos/libraryimageknife' +import { CropOptions } from '@ohos/libraryimageknife' +import { Crop } from '@ohos/libraryimageknife' +import { RecourseProvider } from '@ohos/libraryimageknife' +import { PixelMapCrop,Options } from '@ohos/libraryimageknife' +import { CropCallback } from '@ohos/libraryimageknife' +import { FileUtils } from '@ohos/libraryimageknife' +import { ImageKnifeGlobal } from '@ohos/libraryimageknife' import { BusinessError } from '@ohos.base' import resourceManager from '@ohos.resourceManager'; import common from '@ohos.app.ability.common' diff --git a/entry/src/main/ets/pages/dataShareUriLoadPage.ets b/entry/src/main/ets/pages/dataShareUriLoadPage.ets index 2a22952..fd3859f 100644 --- a/entry/src/main/ets/pages/dataShareUriLoadPage.ets +++ b/entry/src/main/ets/pages/dataShareUriLoadPage.ets @@ -13,7 +13,7 @@ * limitations under the License. */ import mediaLibrary from '@ohos.multimedia.mediaLibrary'; -import { ImageKnifeComponent, ImageKnifeOption, } from '@ohos/imageknife' +import { ImageKnifeComponent, ImageKnifeOption, } from '@ohos/libraryimageknife' @Entry diff --git a/entry/src/main/ets/pages/drawFactoryTestPage.ets b/entry/src/main/ets/pages/drawFactoryTestPage.ets index 24bbb35..433475b 100644 --- a/entry/src/main/ets/pages/drawFactoryTestPage.ets +++ b/entry/src/main/ets/pages/drawFactoryTestPage.ets @@ -18,7 +18,7 @@ import { ImageKnifeOption, ImageKnifeDrawFactory, ScaleType -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/frescoRetryTestCasePage.ets b/entry/src/main/ets/pages/frescoRetryTestCasePage.ets index b44bfba..c6ae9d5 100644 --- a/entry/src/main/ets/pages/frescoRetryTestCasePage.ets +++ b/entry/src/main/ets/pages/frescoRetryTestCasePage.ets @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' -import {RoundedCornersTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' +import {RoundedCornersTransformation} from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/gifTestCasePage.ets b/entry/src/main/ets/pages/gifTestCasePage.ets index 771a395..d45ffa3 100644 --- a/entry/src/main/ets/pages/gifTestCasePage.ets +++ b/entry/src/main/ets/pages/gifTestCasePage.ets @@ -12,9 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {GIFParseImpl} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' -import {ImageKnife} from '@ohos/imageknife' +import {GIFParseImpl} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' +import {ImageKnife} from '@ohos/libraryimageknife' import worker from '@ohos.worker'; import resourceManager from '@ohos.resourceManager'; import { BusinessError } from '@ohos.base' diff --git a/entry/src/main/ets/pages/hspCacheTestPage.ets b/entry/src/main/ets/pages/hspCacheTestPage.ets index f5a981c..000f881 100644 --- a/entry/src/main/ets/pages/hspCacheTestPage.ets +++ b/entry/src/main/ets/pages/hspCacheTestPage.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { ImageKnifeComponent, ImageKnifeOption, FileUtils } from '@ohos/imageknife' +import { ImageKnifeComponent, ImageKnifeOption, FileUtils } from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/index.ets b/entry/src/main/ets/pages/index.ets index 7d6dd99..9043edd 100644 --- a/entry/src/main/ets/pages/index.ets +++ b/entry/src/main/ets/pages/index.ets @@ -18,7 +18,7 @@ import { ImageKnifeOption, ImageKnifeGlobal, ImageKnife -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' import worker from '@ohos.worker'; import { ObjectKey } from '@ohos/imageknife/src/main/ets/components/imageknife/ObjectKey'; diff --git a/entry/src/main/ets/pages/manyPhotoShowPage.ets b/entry/src/main/ets/pages/manyPhotoShowPage.ets index ed8d488..2a1e8b6 100644 --- a/entry/src/main/ets/pages/manyPhotoShowPage.ets +++ b/entry/src/main/ets/pages/manyPhotoShowPage.ets @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent, ScaleType} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent, ScaleType} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' import {Material} from './model/Material' import {TestDataSource} from './model/TestDataSource' import {DiskLruCache} from '@ohos/disklrucache' diff --git a/entry/src/main/ets/pages/pngjTestCasePage.ets b/entry/src/main/ets/pages/pngjTestCasePage.ets index 390ddae..d1bcab9 100644 --- a/entry/src/main/ets/pages/pngjTestCasePage.ets +++ b/entry/src/main/ets/pages/pngjTestCasePage.ets @@ -13,9 +13,9 @@ * limitations under the License. */ import router from '@system.router'; -import { Pngj } from '@ohos/imageknife' +import { Pngj } from '@ohos/libraryimageknife' import resourceManager from '@ohos.resourceManager'; -import { FileUtils,ImageKnifeGlobal } from '@ohos/imageknife' +import { FileUtils,ImageKnifeGlobal } from '@ohos/libraryimageknife' import featureability from '@ohos.ability.featureAbility' import ArkWorker from '@ohos.worker' import worker from '@ohos.worker'; diff --git a/entry/src/main/ets/pages/showErrorholderTestCasePage.ets b/entry/src/main/ets/pages/showErrorholderTestCasePage.ets index ad82adf..15ea013 100644 --- a/entry/src/main/ets/pages/showErrorholderTestCasePage.ets +++ b/entry/src/main/ets/pages/showErrorholderTestCasePage.ets @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' -import {RoundedCornersTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' +import {RoundedCornersTransformation} from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/storageTestLruCache.ets b/entry/src/main/ets/pages/storageTestLruCache.ets index abe8e07..018c002 100644 --- a/entry/src/main/ets/pages/storageTestLruCache.ets +++ b/entry/src/main/ets/pages/storageTestLruCache.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import {LruCache} from '@ohos/imageknife' +import {LruCache} from '@ohos/libraryimageknife' function getRandomInt(min:number, max:number):number { min = Math.ceil(min); diff --git a/entry/src/main/ets/pages/svgTestCasePage.ets b/entry/src/main/ets/pages/svgTestCasePage.ets index 6157a96..edcd299 100644 --- a/entry/src/main/ets/pages/svgTestCasePage.ets +++ b/entry/src/main/ets/pages/svgTestCasePage.ets @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {SVGParseImpl} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' +import {SVGParseImpl} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' import resourceManager from '@ohos.resourceManager'; import {BusinessError} from '@ohos.base' import common from '@ohos.app.ability.common'; diff --git a/entry/src/main/ets/pages/tempUrlTestPage.ets b/entry/src/main/ets/pages/tempUrlTestPage.ets index 3353fdc..8057c30 100644 --- a/entry/src/main/ets/pages/tempUrlTestPage.ets +++ b/entry/src/main/ets/pages/tempUrlTestPage.ets @@ -20,7 +20,7 @@ import { ImageKnife, ImageKnifeDrawFactory, ScaleType -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' import worker from '@ohos.worker'; @Entry @Component diff --git a/entry/src/main/ets/pages/testAllCacheInfoPage.ets b/entry/src/main/ets/pages/testAllCacheInfoPage.ets index 9d5003f..f39920a 100644 --- a/entry/src/main/ets/pages/testAllCacheInfoPage.ets +++ b/entry/src/main/ets/pages/testAllCacheInfoPage.ets @@ -12,14 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {RequestOption} from '@ohos/imageknife' -import {ImageKnifeData} from '@ohos/imageknife' -import {AllCacheInfo,IAllCacheInfoCallback} from '@ohos/imageknife' -import {ImageKnifeComponent} from '@ohos/imageknife' -import {TransformType} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' +import {RequestOption} from '@ohos/libraryimageknife' +import {ImageKnifeData} from '@ohos/libraryimageknife' +import {AllCacheInfo,IAllCacheInfoCallback} from '@ohos/libraryimageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {TransformType} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' import {BusinessError} from '@ohos.base' @Entry @Component diff --git a/entry/src/main/ets/pages/testGifDontAnimatePage.ets b/entry/src/main/ets/pages/testGifDontAnimatePage.ets index 69a56cc..3ba4ae7 100644 --- a/entry/src/main/ets/pages/testGifDontAnimatePage.ets +++ b/entry/src/main/ets/pages/testGifDontAnimatePage.ets @@ -12,11 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' -import {ImageKnife} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' +import {ImageKnife} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' import worker from '@ohos.worker' @Entry @Component diff --git a/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets b/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets index 3f044a4..5753429 100644 --- a/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets +++ b/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnife,ImageKnifeGlobal, ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife' +import { ImageKnife,ImageKnifeGlobal, ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife' import worker, { MessageEvents } from '@ohos.worker' import Prompt from '@system.prompt' diff --git a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage.ets b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage.ets index 687a98b..8298de4 100644 --- a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage.ets +++ b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage.ets @@ -12,11 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' -import {ImageKnife} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' +import {ImageKnife} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' import ArkWorker from '@ohos.worker' import worker from '@ohos.worker' @Entry diff --git a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage2.ets b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage2.ets index 1966689..44c646f 100644 --- a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage2.ets +++ b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage2.ets @@ -12,12 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {BaseTransform} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' -import {GrayscaleTransformation} from '@ohos/imageknife' -import {SketchFilterTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {BaseTransform} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' +import {GrayscaleTransformation} from '@ohos/libraryimageknife' +import {SketchFilterTransformation} from '@ohos/libraryimageknife' import image from '@ohos.multimedia.image' @Entry diff --git a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage3.ets b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage3.ets index 8871b1a..0079d94 100644 --- a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage3.ets +++ b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage3.ets @@ -12,17 +12,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {ImageKnifeGlobal} from '@ohos/imageknife' -import {ImageKnife} from '@ohos/imageknife' -import {ScaleType} from '@ohos/imageknife' -import {RotateImageTransformation} from '@ohos/imageknife' -import {GrayscaleTransformation} from '@ohos/imageknife' -import {SketchFilterTransformation} from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal} from '@ohos/libraryimageknife' +import {ImageKnife} from '@ohos/libraryimageknife' +import {ScaleType} from '@ohos/libraryimageknife' +import {RotateImageTransformation} from '@ohos/libraryimageknife' +import {GrayscaleTransformation} from '@ohos/libraryimageknife' +import {SketchFilterTransformation} from '@ohos/libraryimageknife' import ArkWorker from '@ohos.worker' import worker from '@ohos.worker' -import {BaseTransform} from '@ohos/imageknife' +import {BaseTransform} from '@ohos/libraryimageknife' import image from '@ohos.multimedia.image' @Entry @Component diff --git a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage4.ets b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage4.ets index 5585b14..fd11e45 100644 --- a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage4.ets +++ b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage4.ets @@ -24,7 +24,7 @@ import { ScaleType, ImageKnifeGlobal, BaseTransform -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' import ArkWorker from '@ohos.worker' import worker from '@ohos.worker'; import image from '@ohos.multimedia.image'; diff --git a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage5.ets b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage5.ets index ef672cd..d3de95f 100644 --- a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage5.ets +++ b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage5.ets @@ -25,7 +25,7 @@ import { IDrawLifeCycle, ScaleType, ImageKnifeDrawFactory -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' import worker from '@ohos.worker'; @Entry @Component diff --git a/entry/src/main/ets/pages/testPreloadPage.ets b/entry/src/main/ets/pages/testPreloadPage.ets index 7924e71..f8e1098 100644 --- a/entry/src/main/ets/pages/testPreloadPage.ets +++ b/entry/src/main/ets/pages/testPreloadPage.ets @@ -12,11 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeData} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' -import {RequestOption} from '@ohos/imageknife' -import {ImageKnifeGlobal } from '@ohos/imageknife' +import {ImageKnifeComponent} from '@ohos/libraryimageknife' +import {ImageKnifeData} from '@ohos/libraryimageknife' +import {ImageKnifeOption} from '@ohos/libraryimageknife' +import {RequestOption} from '@ohos/libraryimageknife' +import {ImageKnifeGlobal } from '@ohos/libraryimageknife' import worker from '@ohos.worker' import { BusinessError } from '@ohos.base' diff --git a/entry/src/main/ets/pages/testSingleFrameGifPage.ets b/entry/src/main/ets/pages/testSingleFrameGifPage.ets index 0e292c6..7e7a8f7 100644 --- a/entry/src/main/ets/pages/testSingleFrameGifPage.ets +++ b/entry/src/main/ets/pages/testSingleFrameGifPage.ets @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent } from '@ohos/imageknife' -import { ImageKnifeOption } from '@ohos/imageknife' +import { ImageKnifeComponent } from '@ohos/libraryimageknife' +import { ImageKnifeOption } from '@ohos/libraryimageknife' @Entry @Component diff --git a/entry/src/main/ets/pages/transformPixelMapPage.ets b/entry/src/main/ets/pages/transformPixelMapPage.ets index e9cabbb..96d47d7 100644 --- a/entry/src/main/ets/pages/transformPixelMapPage.ets +++ b/entry/src/main/ets/pages/transformPixelMapPage.ets @@ -12,28 +12,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { RequestOption,ImageKnifeGlobal} from '@ohos/imageknife' -import { CropCircleTransformation } from '@ohos/imageknife' -import { RoundedCornersTransformation } from '@ohos/imageknife' +import { RequestOption,ImageKnifeGlobal} from '@ohos/libraryimageknife' +import { CropCircleTransformation } from '@ohos/libraryimageknife' +import { RoundedCornersTransformation } from '@ohos/libraryimageknife' import { CropCircleWithBorderTransformation } from '@ohos/imageknife/src/main/ets/components/imageknife/transform/CropCircleWithBorderTransformation' -import { RotateImageTransformation } from '@ohos/imageknife' -import { CropSquareTransformation } from '@ohos/imageknife' -import { CropTransformation } from '@ohos/imageknife' -import { CropType } from '@ohos/imageknife' -import { GrayscaleTransformation } from '@ohos/imageknife' -import { BrightnessFilterTransformation } from '@ohos/imageknife' -import { ContrastFilterTransformation } from '@ohos/imageknife' -import { InvertFilterTransformation } from '@ohos/imageknife' -import { SepiaFilterTransformation } from '@ohos/imageknife' -import { SketchFilterTransformation } from '@ohos/imageknife' -import { BlurTransformation } from '@ohos/imageknife' -import { PixelationFilterTransformation } from '@ohos/imageknife' -import { MaskTransformation } from '@ohos/imageknife' -import { SwirlFilterTransformation } from '@ohos/imageknife' +import { RotateImageTransformation } from '@ohos/libraryimageknife' +import { CropSquareTransformation } from '@ohos/libraryimageknife' +import { CropTransformation } from '@ohos/libraryimageknife' +import { CropType } from '@ohos/libraryimageknife' +import { GrayscaleTransformation } from '@ohos/libraryimageknife' +import { BrightnessFilterTransformation } from '@ohos/libraryimageknife' +import { ContrastFilterTransformation } from '@ohos/libraryimageknife' +import { InvertFilterTransformation } from '@ohos/libraryimageknife' +import { SepiaFilterTransformation } from '@ohos/libraryimageknife' +import { SketchFilterTransformation } from '@ohos/libraryimageknife' +import { BlurTransformation } from '@ohos/libraryimageknife' +import { PixelationFilterTransformation } from '@ohos/libraryimageknife' +import { MaskTransformation } from '@ohos/libraryimageknife' +import { SwirlFilterTransformation } from '@ohos/libraryimageknife' import { BusinessError } from '@ohos.base' -import {ImageKnifeData} from '@ohos/imageknife' +import {ImageKnifeData} from '@ohos/libraryimageknife' /** * PixelMap transform 示例 */ diff --git a/entry/src/ohosTest/ets/test/imageknife.test.ets b/entry/src/ohosTest/ets/test/imageknife.test.ets index 368a7a6..2186d29 100644 --- a/entry/src/ohosTest/ets/test/imageknife.test.ets +++ b/entry/src/ohosTest/ets/test/imageknife.test.ets @@ -14,7 +14,7 @@ */ import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/imageknife' +import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/libraryimageknife' export default function ImageKnifeTest() { describe('ImageKnifeTest', ()=> { diff --git a/entry/src/ohosTest/ets/test/logutil.test.ets b/entry/src/ohosTest/ets/test/logutil.test.ets index 71f61a1..4ab90ac 100644 --- a/entry/src/ohosTest/ets/test/logutil.test.ets +++ b/entry/src/ohosTest/ets/test/logutil.test.ets @@ -14,7 +14,7 @@ */ import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -import {LogUtil} from '@ohos/imageknife' +import {LogUtil} from '@ohos/libraryimageknife' export default function LogUtilTest() { describe('LogUtilTest', ()=> { diff --git a/entry/src/ohosTest/ets/test/lrucache.test.ets b/entry/src/ohosTest/ets/test/lrucache.test.ets index 3238954..b5ef887 100644 --- a/entry/src/ohosTest/ets/test/lrucache.test.ets +++ b/entry/src/ohosTest/ets/test/lrucache.test.ets @@ -14,7 +14,7 @@ */ import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -import {LruCache} from '@ohos/imageknife' // DiskLruCache用例由DiskLruCache三方库提供 +import {LruCache} from '@ohos/libraryimageknife' // DiskLruCache用例由DiskLruCache三方库提供 export default function lruCacheTest() { describe('lruCacheTest', ()=> { diff --git a/entry/src/ohosTest/ets/test/requestoption.test.ets b/entry/src/ohosTest/ets/test/requestoption.test.ets index e2b0621..b83bd10 100644 --- a/entry/src/ohosTest/ets/test/requestoption.test.ets +++ b/entry/src/ohosTest/ets/test/requestoption.test.ets @@ -15,7 +15,7 @@ */ import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -import {RequestOption,Size} from '@ohos/imageknife' +import {RequestOption,Size} from '@ohos/libraryimageknife' export default function RequestOptionTest() { describe('RequestOptionTest', ()=> { diff --git a/entry/src/ohosTest/ets/test/transfrom.test.ets b/entry/src/ohosTest/ets/test/transfrom.test.ets index 8802154..c1b1e8c 100644 --- a/entry/src/ohosTest/ets/test/transfrom.test.ets +++ b/entry/src/ohosTest/ets/test/transfrom.test.ets @@ -36,7 +36,7 @@ import { ToonFilterTransform, VignetteFilterTransform, -} from '@ohos/imageknife' +} from '@ohos/libraryimageknife' export default function Transform() { describe('Transform', ()=>{ diff --git a/entry/src/ohosTest/ets/testability/TestAbility.ets b/entry/src/ohosTest/ets/testability/TestAbility.ets index 22b0877..140dbda 100644 --- a/entry/src/ohosTest/ets/testability/TestAbility.ets +++ b/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -18,7 +18,7 @@ import hilog from '@ohos.hilog'; import { Hypium } from '@ohos/hypium'; import testsuite from '../test/List.test'; import window from '@ohos.window'; -import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/imageknife' +import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/libraryimageknife' import AbilityConstant from '@ohos.app.ability.AbilityConstant'; import Want from '@ohos.app.ability.Want'; import { BusinessError } from '@ohos.base' diff --git a/imageknife/index.ets b/imageknife/index.ets index 739c6ca..624208a 100644 --- a/imageknife/index.ets +++ b/imageknife/index.ets @@ -96,6 +96,7 @@ export { UPNG } from './src/main/ets/components/3rd_party/upng/UPNG' export { ImageKnife } from './src/main/ets/components/imageknife/ImageKnife' export { ImageKnifeGlobal } from './src/main/ets/components/imageknife/ImageKnifeGlobal' export {RequestOption,Size} from './src/main/ets/components/imageknife/RequestOption' +export {ObjectKey} from './src/main/ets/components/imageknife/ObjectKey' export { ImageKnifeComponent, ScaleType, ScaleTypeHelper } from './src/main/ets/components/imageknife/ImageKnifeComponent' export { ImageKnifeDrawFactory } from './src/main/ets/components/imageknife/ImageKnifeDrawFactory' export {ImageKnifeOption,CropCircleWithBorder,Crop,GifOptions,TransformOptions} from './src/main/ets/components/imageknife/ImageKnifeOption' diff --git a/library/src/main/ets/Index.ets b/library/src/main/ets/Index.ets index f99aa38..1b34845 100644 --- a/library/src/main/ets/Index.ets +++ b/library/src/main/ets/Index.ets @@ -11,4 +11,124 @@ * 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. - */ \ No newline at end of file + */ + + +// ImageKnife 对外暴露的接口由library提供 + +/** + * cache + */ + +export { FileUtils } from '@ohos/imageknife' +export { Base64 } from '@ohos/imageknife' +export { LruCache } from '@ohos/imageknife' +export { DiskStrategy } from '@ohos/imageknife' +export { ALL } from '@ohos/imageknife' +export { AUTOMATIC } from '@ohos/imageknife' +export { DATA } from '@ohos/imageknife' +export { NONE } from '@ohos/imageknife' +export { RESOURCE } from '@ohos/imageknife' +export { EngineKeyInterface } from '@ohos/imageknife' +export { EngineKeyFactories } from '@ohos/imageknife' + +/** + * compress + */ +export { CompressBuilder } from '@ohos/imageknife' +export { OnCompressListener } from '@ohos/imageknife' +export { OnRenameListener } from '@ohos/imageknife' +export { CompressDataListener } from '@ohos/imageknife' +export { CompressionPredicate } from '@ohos/imageknife' +export { CompressAdapter } from '@ohos/imageknife' +export { CompressProvider } from '@ohos/imageknife' +export { DataStringPathProvider } from '@ohos/imageknife' +export { RecourseProvider } from '@ohos/imageknife' + +/** + * crop + */ + +export { CropImage } from '@ohos/imageknife' +export { CropOptions } from '@ohos/imageknife' +export { PixelMapCrop,Options } from '@ohos/imageknife' +export { CropCallback } from '@ohos/imageknife' + +/** + * transform + */ +export { BaseTransform } from '@ohos/imageknife' +export { BlurTransformation } from '@ohos/imageknife' +export { BrightnessFilterTransformation } from '@ohos/imageknife' +export { ContrastFilterTransformation } from '@ohos/imageknife' +export { CropCircleTransformation } from '@ohos/imageknife' +export { CropCircleWithBorderTransformation,rgbColor } from '@ohos/imageknife' +export { CropSquareTransformation } from '@ohos/imageknife' +export { CropTransformation,CropType } from '@ohos/imageknife' +export { GrayscaleTransformation } from '@ohos/imageknife' +export { InvertFilterTransformation } from '@ohos/imageknife' +export { PixelationFilterTransformation } from '@ohos/imageknife' +export { RotateImageTransformation } from '@ohos/imageknife' +export { RoundedCornersTransformation,RoundCorner } from '@ohos/imageknife' +export { SepiaFilterTransformation } from '@ohos/imageknife' +export { SketchFilterTransformation } from '@ohos/imageknife' +export { MaskTransformation } from '@ohos/imageknife' +export { SwirlFilterTransformation } from '@ohos/imageknife' +export { KuwaharaFilterTransform } from '@ohos/imageknife' +export { ToonFilterTransform } from '@ohos/imageknife' +export { VignetteFilterTransform } from '@ohos/imageknife' +export { TransformUtils } from '@ohos/imageknife' +export { TransformType } from '@ohos/imageknife' +export { CenterCrop } from '@ohos/imageknife' +export { CenterInside } from '@ohos/imageknife' +export { FitCenter } from '@ohos/imageknife' + +/** + * pngj + */ +export { Pngj } from '@ohos/imageknife' +export {handler} from '@ohos/imageknife' +export { UPNG } from '@ohos/imageknife' + + + +/** + * ImageKnife + */ +export { ImageKnife } from '@ohos/imageknife' +export { ImageKnifeGlobal } from '@ohos/imageknife' +export {RequestOption,Size} from '@ohos/imageknife' +export {ObjectKey} from '@ohos/imageknife' +export { ImageKnifeComponent, ScaleType, ScaleTypeHelper } from '@ohos/imageknife' +export { ImageKnifeDrawFactory } from '@ohos/imageknife' +export {ImageKnifeOption,CropCircleWithBorder,Crop,GifOptions,TransformOptions} from '@ohos/imageknife' +export { ImageKnifeData } from '@ohos/imageknife' +export {IAllCacheInfoCallback,AllCacheInfo,ResourceCacheInfo,MemoryCacheInfo,DataCacheInfo} from '@ohos/imageknife' +export {IParseImage} from '@ohos/imageknife' +export {IDataFetch} from '@ohos/imageknife' +export {ICache} from '@ohos/imageknife' +export { FileTypeUtil } from '@ohos/imageknife' +export { ParseImageUtil } from '@ohos/imageknife' + +/** + * svg parse + */ +export { SVGParseImpl } from '@ohos/imageknife' + +/** + * gif parse + */ +export { GIFParseImpl } from '@ohos/imageknife' +export { GIFFrame } from '@ohos/imageknife' +// 能力增强worker 解析GIF数据 +export { gifHandler } from '@ohos/imageknife' + +// 自定义组件新增 +// 自定义组件绘制生命周期 +export { IDrawLifeCycle } from '@ohos/imageknife' + +// 日志管理 +export { LogUtil } from '@ohos/imageknife' + +// 额外开放初始化ImageKnife的方法 +export {InitImageKnife} from './src/main/ets/pages/InitImageKnife' \ No newline at end of file diff --git a/library/src/main/ets/pages/InitImageKnife.ets b/library/src/main/ets/pages/InitImageKnife.ets new file mode 100644 index 0000000..b05c84f --- /dev/null +++ b/library/src/main/ets/pages/InitImageKnife.ets @@ -0,0 +1,8 @@ +import common from '@ohos.app.ability.common' +import { ImageKnifeComponent, ImageKnifeOption, FileUtils } from '@ohos/imageknife' +import { ImageKnifeGlobal,ImageKnife,ImageKnifeDrawFactory,LogUtil } from '@ohos/imageknife' +export class InitImageKnife{ + static init(entryContext:common.UIAbilityContext){ + ImageKnife.with(entryContext); + } +} \ No newline at end of file From ff532ec8c16e578bbbffbfce48216135cb92f80c Mon Sep 17 00:00:00 2001 From: zhoulisheng <635547767@qq.com> Date: Tue, 31 Oct 2023 11:30:30 +0800 Subject: [PATCH 6/6] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9library=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E7=9A=84=E4=BB=A3=E7=A0=81,=E8=8E=B7=E5=8F=96context?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoulisheng <635547767@qq.com> --- library/src/main/ets/Index.ets | 2 +- library/src/main/ets/pages/Index.ets | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/library/src/main/ets/Index.ets b/library/src/main/ets/Index.ets index 1b34845..c526015 100644 --- a/library/src/main/ets/Index.ets +++ b/library/src/main/ets/Index.ets @@ -131,4 +131,4 @@ export { IDrawLifeCycle } from '@ohos/imageknife' export { LogUtil } from '@ohos/imageknife' // 额外开放初始化ImageKnife的方法 -export {InitImageKnife} from './src/main/ets/pages/InitImageKnife' \ No newline at end of file +export {InitImageKnife} from '../ets/pages/InitImageKnife' \ No newline at end of file diff --git a/library/src/main/ets/pages/Index.ets b/library/src/main/ets/pages/Index.ets index dc7606c..86f8d60 100644 --- a/library/src/main/ets/pages/Index.ets +++ b/library/src/main/ets/pages/Index.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ImageKnifeComponent, ImageKnifeOption, FileUtils } from '@ohos/imageknife' +import {ImageKnifeGlobal, ImageKnifeComponent, ImageKnifeOption, FileUtils } from '@ohos/imageknife' import common from '@ohos.app.ability.common' @Entry @@ -54,7 +54,8 @@ struct Index { Button('点击加载本地文件').onClick(()=>{ getContext(this).createModuleContext('library').resourceManager.getMediaContent($r('app.media.setting').id).then((data:Uint8Array)=>{ - let path = globalThis.ImageKnife.getImageKnifeContext().filesDir+"/set.jpeg"; + let ctx = ImageKnifeGlobal.getInstance().getHapContext() as common.UIAbilityContext; + let path = ctx.filesDir+"/set.jpeg"; FileUtils.getInstance().writeFile(path,data.buffer) FileUtils.getInstance().readFilePicAsync(path).then(buffer=>{ this.imageOption3 = {