1.Hsp适配,使用到resourceManager的地方需要进行整改。
Signed-off-by: zhoulisheng <635547767@qq.com>
This commit is contained in:
parent
a766f210b4
commit
fc4ab718bb
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -72,7 +72,7 @@ export class ErrorHolderManager<T> {
|
|||
break;
|
||||
}
|
||||
}
|
||||
resourceFetch.loadResource(res, suc, onError)
|
||||
resourceFetch.loadResource(this.options.getModuleContext(),res, suc, onError)
|
||||
} else {
|
||||
onError("ErrorHolderManager 输入参数有问题!")
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ export class PlaceHolderManager<T> {
|
|||
break;
|
||||
}
|
||||
}
|
||||
resourceFetch.loadResource(res, suc, onError)
|
||||
resourceFetch.loadResource(this.options.getModuleContext(),res, suc, onError)
|
||||
} else {
|
||||
onError("PlaceHolderManager 输入参数有问题!")
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ export class RetryHolderManager<T> {
|
|||
break;
|
||||
}
|
||||
}
|
||||
resourceFetch.loadResource(res, suc, onError)
|
||||
resourceFetch.loadResource(this.options.getModuleContext(), res, suc, onError)
|
||||
} else {
|
||||
onError("PlaceHolderManager 输入参数有问题!")
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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<ImageKnifeData>, 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)
|
||||
|
|
|
@ -14,7 +14,9 @@
|
|||
*/
|
||||
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
// 本地资源解析抽象接口
|
||||
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;
|
||||
}
|
|
@ -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<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 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);
|
||||
|
|
|
@ -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<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 resType = res.type;
|
||||
if (resType == ResourceTypeEts.MEDIA) {
|
||||
((ImageKnifeGlobal.getInstance()
|
||||
.getHapContext() as Record<string, Object>).resourceManager as resourceManager.ResourceManager)
|
||||
(context.resourceManager as resourceManager.ResourceManager)
|
||||
.getMediaContentBase64(resId)
|
||||
.then(data => {
|
||||
let matchReg = ';base64,';
|
||||
|
|
|
@ -78,20 +78,20 @@ export class MaskTransformation implements BaseTransform<PixelMap> {
|
|||
}
|
||||
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<PixelMap>) {
|
||||
private openInternal(request: RequestOption,bitmap: PixelMap, width: number, height: number, func?: AsyncTransform<PixelMap>) {
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue