1.Hsp适配,使用到resourceManager的地方需要进行整改。

Signed-off-by: zhoulisheng <635547767@qq.com>
This commit is contained in:
zhoulisheng 2023-10-25 11:31:14 +08:00
parent a766f210b4
commit fc4ab718bb
12 changed files with 42 additions and 15 deletions

View File

@ -22,6 +22,7 @@ import { GIFFrame } from '../imageknife/utils/gif/GIFFrame'
import { IDrawLifeCycle } from '../imageknife/interface/IDrawLifeCycle' import { IDrawLifeCycle } from '../imageknife/interface/IDrawLifeCycle'
import { LogUtil } from '../imageknife/utils/LogUtil' import { LogUtil } from '../imageknife/utils/LogUtil'
import { BusinessError } from '@ohos.base' import { BusinessError } from '@ohos.base'
import common from '@ohos.app.ability.common'
@Component @Component
export struct ImageKnifeComponent { 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) { configRenderGpu(request: RequestOption) {
if (this.imageKnifeOption.enableGpu) { if (this.imageKnifeOption.enableGpu) {
request.enableGPU() request.enableGPU()
@ -281,6 +290,7 @@ export struct ImageKnifeComponent {
this.configNecessary(request); this.configNecessary(request);
this.configCacheStrategy(request); this.configCacheStrategy(request);
this.configDisplay(request); this.configDisplay(request);
this.configHspContext(request)
this.configRenderGpu(request); this.configRenderGpu(request);
if(ImageKnifeGlobal.getInstance().getImageKnife()!=undefined) { if(ImageKnifeGlobal.getInstance().getImageKnife()!=undefined) {
ImageKnifeGlobal.getInstance().getImageKnife()?.call(request); ImageKnifeGlobal.getInstance().getImageKnife()?.call(request);

View File

@ -25,6 +25,7 @@ import { ScaleType } from '../imageknife/ImageKnifeComponent'
import { rgbColor } from './transform/CropCircleWithBorderTransformation' import { rgbColor } from './transform/CropCircleWithBorderTransformation'
import { RoundCorner } from './transform/RoundedCornersTransformation' import { RoundCorner } from './transform/RoundedCornersTransformation'
import { ObjectKey } from './ObjectKey' import { ObjectKey } from './ObjectKey'
import common from '@ohos.app.ability.common'
export interface CropCircleWithBorder{ export interface CropCircleWithBorder{
border: number, border: number,
@ -125,7 +126,7 @@ export class ImageKnifeOption {
allCacheInfoCallback?: IAllCacheInfoCallback; allCacheInfoCallback?: IAllCacheInfoCallback;
context?: common.UIAbilityContext;
// sizeAnimate?: AnimateParam 由业务自定义不再支持 // sizeAnimate?: AnimateParam 由业务自定义不再支持
constructor() { constructor() {

View File

@ -49,6 +49,7 @@ import { LogUtil } from '../imageknife/utils/LogUtil'
import { ImageKnifeGlobal } from './ImageKnifeGlobal' import { ImageKnifeGlobal } from './ImageKnifeGlobal'
import { BusinessError } from '@ohos.base' import { BusinessError } from '@ohos.base'
import { ObjectKey } from './ObjectKey' import { ObjectKey } from './ObjectKey'
import common from '@ohos.app.ability.common'
export interface Size { export interface Size {
width: number, width: number,
@ -131,6 +132,9 @@ export class RequestOption {
} }
} }
// module资源的需要当前的module context
moduleContext:common.UIAbilityContext;
constructor() { constructor() {
// 初始化全局监听 // 初始化全局监听
this.requestListeners = new Array(); this.requestListeners = new Array();
@ -148,6 +152,14 @@ export class RequestOption {
return uuid; return uuid;
} }
setModuleContext(moduleCtx:common.UIAbilityContext){
this.moduleContext = moduleCtx;
}
getModuleContext():common.UIAbilityContext{
return this.moduleContext;
}
/** /**
* set image Component size * set image Component size
*/ */

View File

@ -72,7 +72,7 @@ export class ErrorHolderManager<T> {
break; break;
} }
} }
resourceFetch.loadResource(res, suc, onError) resourceFetch.loadResource(this.options.getModuleContext(),res, suc, onError)
} else { } else {
onError("ErrorHolderManager 输入参数有问题!") onError("ErrorHolderManager 输入参数有问题!")
} }

View File

@ -73,7 +73,7 @@ export class PlaceHolderManager<T> {
break; break;
} }
} }
resourceFetch.loadResource(res, suc, onError) resourceFetch.loadResource(this.options.getModuleContext(),res, suc, onError)
} else { } else {
onError("PlaceHolderManager 输入参数有问题!") onError("PlaceHolderManager 输入参数有问题!")
} }

View File

@ -73,7 +73,7 @@ export class RetryHolderManager<T> {
break; break;
} }
} }
resourceFetch.loadResource(res, suc, onError) resourceFetch.loadResource(this.options.getModuleContext(), res, suc, onError)
} else { } else {
onError("PlaceHolderManager 输入参数有问题!") onError("PlaceHolderManager 输入参数有问题!")
} }

View File

@ -43,7 +43,7 @@ export class NetworkDownloadClient implements IDataFetch {
enableMetered: true, 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) { if (downloadTask) {
let loadTask:loadRequest.DownloadTask | null = downloadTask; let loadTask:loadRequest.DownloadTask | null = downloadTask;

View File

@ -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<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) { private loadDiskFromSource(request: RequestOption, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
@ -323,6 +323,7 @@ export class RequestManager {
width: Math.round(this.options.thumbSizeMultiplier * this.options.size.width), width: Math.round(this.options.thumbSizeMultiplier * this.options.size.width),
height: Math.round(this.options.thumbSizeMultiplier * this.options.size.height) height: Math.round(this.options.thumbSizeMultiplier * this.options.size.height)
}) })
thumbOption.setModuleContext(this.options.getModuleContext())
let thumbCallback = this.options.thumbholderOnComplete; let thumbCallback = this.options.thumbholderOnComplete;
let thumbError = this.options.thumbholderOnError; let thumbError = this.options.thumbholderOnError;
this.options.transformations[0].transform(source, thumbOption,{asyncTransform: (error:BusinessError|string, pixelMap: PixelMap|null) => { 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<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void){ thumbnailProcess(source:ArrayBuffer, filetype:string, onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void){
let thumbOption = new RequestOption(); let thumbOption = new RequestOption();
thumbOption.setModuleContext(this.options.getModuleContext())
thumbOption.setImageViewSize({ thumbOption.setImageViewSize({
width: Math.round(this.options.thumbSizeMultiplier * this.options.size.width), width: Math.round(this.options.thumbSizeMultiplier * this.options.size.width),
height: Math.round(this.options.thumbSizeMultiplier * this.options.size.height) height: Math.round(this.options.thumbSizeMultiplier * this.options.size.height)

View File

@ -14,7 +14,9 @@
*/ */
import { BusinessError } from '@ohos.base' import { BusinessError } from '@ohos.base'
import common from '@ohos.app.ability.common';
// 本地资源解析抽象接口 // 本地资源解析抽象接口
export interface IResourceFetch<T> { export interface IResourceFetch<T> {
loadResource:(res: Resource, onCompleteFunction:(value:T)=>void | PromiseLike<T>, onErrorFunction:(reason?:BusinessError|string)=>void)=>void; loadResource:(context:common.UIAbilityContext ,res: Resource, onCompleteFunction:(value:T)=>void | PromiseLike<T>, onErrorFunction:(reason?:BusinessError|string)=>void)=>void;
} }

View File

@ -20,11 +20,11 @@ import { ImageKnifeGlobal } from '../ImageKnifeGlobal';
import { BusinessError } from '@ohos.base' import { BusinessError } from '@ohos.base'
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
export class ParseResClient implements IResourceFetch<ArrayBuffer> { export class ParseResClient implements IResourceFetch<ArrayBuffer> {
loadResource(res: Resource, onCompleteFunction:(value:ArrayBuffer)=>void | PromiseLike<ArrayBuffer>, onErrorFunction:(reason?:BusinessError|string)=>void) { loadResource(context:common.UIAbilityContext,res: Resource, onCompleteFunction:(value:ArrayBuffer)=>void | PromiseLike<ArrayBuffer>, onErrorFunction:(reason?:BusinessError|string)=>void) {
let resId = res.id; let resId = res.id;
let resType = res.type; let resType = res.type;
if (resType == ResourceTypeEts.MEDIA) { if (resType == ResourceTypeEts.MEDIA) {
((ImageKnifeGlobal.getInstance().getHapContext() as common.UIAbilityContext).resourceManager as resourceManager.ResourceManager) (context.resourceManager as resourceManager.ResourceManager)
.getMediaContent(resId) .getMediaContent(resId)
.then(data => { .then(data => {
let arrayBuffer = this.typedArrayToBuffer(data); let arrayBuffer = this.typedArrayToBuffer(data);

View File

@ -19,14 +19,14 @@ import { Base64 } from '../../cache/Base64'
import { BusinessError } from '@ohos.base' import { BusinessError } from '@ohos.base'
import resourceManager from '@ohos.resourceManager'; import resourceManager from '@ohos.resourceManager';
import { ImageKnifeGlobal } from '../ImageKnifeGlobal'; import { ImageKnifeGlobal } from '../ImageKnifeGlobal';
import common from '@ohos.app.ability.common'
export class ParseResClientBase64 implements IResourceFetch<ArrayBuffer> { export class ParseResClientBase64 implements IResourceFetch<ArrayBuffer> {
loadResource(res: Resource, onCompleteFunction: (value: ArrayBuffer) => void | PromiseLike<ArrayBuffer>, onErrorFunction: (reason?: BusinessError | string) => void) { loadResource(context:common.UIAbilityContext,res: Resource, onCompleteFunction: (value: ArrayBuffer) => void | PromiseLike<ArrayBuffer>, onErrorFunction: (reason?: BusinessError | string) => void) {
let resId = res.id; let resId = res.id;
let resType = res.type; let resType = res.type;
if (resType == ResourceTypeEts.MEDIA) { if (resType == ResourceTypeEts.MEDIA) {
((ImageKnifeGlobal.getInstance() (context.resourceManager as resourceManager.ResourceManager)
.getHapContext() as Record<string, Object>).resourceManager as resourceManager.ResourceManager)
.getMediaContentBase64(resId) .getMediaContentBase64(resId)
.then(data => { .then(data => {
let matchReg = ';base64,'; let matchReg = ';base64,';

View File

@ -78,20 +78,20 @@ export class MaskTransformation implements BaseTransform<PixelMap> {
} }
imageSource.createPixelMap(options) imageSource.createPixelMap(options)
.then(data => { .then(data => {
this.openInternal(data, targetWidth, targetHeight, func) this.openInternal(request,data, targetWidth, targetHeight, func)
}) })
.catch((e:BusinessError )=> { .catch((e:BusinessError )=> {
func?.asyncTransform(e, null); func?.asyncTransform(e, null);
}) })
} }
private openInternal(bitmap: PixelMap, width: number, height: number, func?: AsyncTransform<PixelMap>) { private openInternal(request: RequestOption,bitmap: PixelMap, width: number, height: number, func?: AsyncTransform<PixelMap>) {
if (!this._mResourceData) { if (!this._mResourceData) {
if(func != undefined){ if(func != undefined){
func.asyncTransform("MaskTransformation resource is empty", null) 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){ if(context != undefined){
let resourceManager = context.resourceManager as resourceManager.ResourceManager let resourceManager = context.resourceManager as resourceManager.ResourceManager
if(resourceManager != undefined && this._mResourceData != undefined) if(resourceManager != undefined && this._mResourceData != undefined)