1.适配SDK4.0.10.9严格类型检查IDE编译错误的问题

Signed-off-by: zhoulisheng1 <zhoulisheng1@huawei.com>
This commit is contained in:
zhoulisheng1 2023-09-27 14:59:40 +08:00
parent 283b805f28
commit da1d9c22df
23 changed files with 128 additions and 164 deletions

View File

@ -7,6 +7,6 @@
"version": "2.0.5-rc.0", "version": "2.0.5-rc.0",
"dependencies": { "dependencies": {
"@ohos/imageknife": "file:../imageknife", "@ohos/imageknife": "file:../imageknife",
"@ohos/disklrucache": "^2.0.0" "@ohos/disklrucache": "^2.0.1"
} }
} }

View File

@ -18,17 +18,15 @@ import window from '@ohos.window';
import { ImageKnifeGlobal,ImageKnife,ImageKnifeDrawFactory,LogUtil } from '@ohos/imageknife' import { ImageKnifeGlobal,ImageKnife,ImageKnifeDrawFactory,LogUtil } from '@ohos/imageknife'
import { CustomEngineKeyImpl } from './CustomEngineKeyImpl' import { CustomEngineKeyImpl } from './CustomEngineKeyImpl'
import abilityAccessCtrl,{Permissions} from '@ohos.abilityAccessCtrl'; import abilityAccessCtrl,{Permissions} from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base'
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage: window.WindowStage) { onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability // Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
let list : Array<Permissions> = ['ohos.permission.MEDIA_LOCATION','ohos.permission.READ_MEDIA']; let list : Array<Permissions> = ['ohos.permission.MEDIA_LOCATION','ohos.permission.READ_MEDIA'];
let permissionRequestResult; let permissionRequestResult:Object;
let atManager = abilityAccessCtrl.createAtManager(); let atManager = abilityAccessCtrl.createAtManager();
atManager.requestPermissionsFromUser(this.context, list, (err,result)=>{ atManager.requestPermissionsFromUser(this.context, list, (err:BusinessError,result:Object)=>{
if(err){ if(err){
console.log("dodo requestPermissionsFromUserError:"+JSON.stringify(err)); console.log("dodo requestPermissionsFromUserError:"+JSON.stringify(err));
}else{ }else{
@ -37,19 +35,19 @@ export default class EntryAbility extends UIAbility {
} }
}) })
windowStage.loadContent('pages/index', (err, data) => { windowStage.loadContent('pages/index', (err:BusinessError, data:void) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
}); });
ImageKnife.with(this.context); ImageKnife.with(this.context);
// 全局配置网络加载进度条
ImageKnifeGlobal.getInstance().getImageKnife().setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5)) let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife()
// 全局配置缓存key if(imageKnife != undefined) {
ImageKnifeGlobal.getInstance().getImageKnife().setEngineKeyImpl(new CustomEngineKeyImpl()) // 全局配置网络加载进度条
imageKnife
.setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5))
// 全局配置缓存key
imageKnife.setEngineKeyImpl(new CustomEngineKeyImpl())
}
//开启ImageKnife所有级别日志开关 //开启ImageKnife所有级别日志开关
LogUtil.mLogLevel = LogUtil.ALL LogUtil.mLogLevel = LogUtil.ALL
} }

View File

@ -64,7 +64,7 @@ struct CompressPage {
.onClick(() => { .onClick(() => {
this.cropressRecource(); this.cropressRecource();
}); });
Image(this.mRPixelMap ) Image(this.mRPixelMap == undefined?'': this.mRPixelMap!)
.width(200) .width(200)
.height(200) .height(200)
.margin({ top: 10 }) .margin({ top: 10 })
@ -82,7 +82,7 @@ struct CompressPage {
.margin({ top: 10 }) .margin({ top: 10 })
.onClick(() => { .onClick(() => {
}); });
Image(this.mFPixelMap ) Image(this.mFPixelMap == undefined ?'':this.mFPixelMap!)
.width(200) .width(200)
.height(200) .height(200)
.margin({ top: 10 }); .margin({ top: 10 });
@ -139,7 +139,7 @@ struct CompressPage {
console.info("asasd start compress") console.info("asasd start compress")
let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife() let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife()
if(imageKnife != undefined) { if(imageKnife != undefined) {
(ImageKnifeGlobal.getInstance().getImageKnife()) imageKnife
.compressBuilder() .compressBuilder()
.load(data) .load(data)
.ignoreBy(100) .ignoreBy(100)

View File

@ -39,11 +39,10 @@ struct DataShareUriLoadPage {
const context = getContext(this); const context = getContext(this);
let media = mediaLibrary.getMediaLibrary(context); let media = mediaLibrary.getMediaLibrary(context);
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE; let imageType = mediaLibrary.MediaType.IMAGE;
// 创建文件获取选项此处参数为获取image类型的文件资源 // 创建文件获取选项此处参数为获取image类型的文件资源
let imagesFetchOp:mediaLibrary.MediaFetchOptions = { let imagesFetchOp:mediaLibrary.MediaFetchOptions = {
selections: fileKeyObj.MEDIA_TYPE + '= ?', selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], selectionArgs: [imageType.toString()],
}; };
// 获取文件资源使用callback方式返回异步结果 // 获取文件资源使用callback方式返回异步结果

View File

@ -106,7 +106,7 @@ struct gifTestCasePage {
Text("下面为展示图片区域").margin({top:5}) Text("下面为展示图片区域").margin({top:5})
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){ Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){
Image(this.pixels) Image(this.pixels == undefined?'':this.pixels!)
.width(400) .width(400)
.height(400) .height(400)
.backgroundColor(Color.Pink) .backgroundColor(Color.Pink)

View File

@ -51,7 +51,7 @@ struct svgTestCasePage {
Text("下面为展示图片区域").margin({top:5}) Text("下面为展示图片区域").margin({top:5})
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){ Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){
Image(this.svgSamplePixelMap) Image(this.svgSamplePixelMap == undefined ? '':this.svgSamplePixelMap!)
.width(400) .width(400)
.height(400) .height(400)
.backgroundColor(Color.Pink) .backgroundColor(Color.Pink)
@ -81,7 +81,7 @@ struct svgTestCasePage {
Text("下面为展示图片区域").margin({top:5}) Text("下面为展示图片区域").margin({top:5})
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){ Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){
Image(this.svgIconPixelMap) Image(this.svgIconPixelMap == undefined ? '':this.svgIconPixelMap!)
.width(400) .width(400)
.height(400) .height(400)
.backgroundColor(Color.Pink) .backgroundColor(Color.Pink)

View File

@ -88,7 +88,7 @@ struct TestAllCacheInfoPage {
Scroll() { Scroll() {
Text(this.cacheinfo1).fontSize(15) Text(this.cacheinfo1).fontSize(15)
}.width(300).height(200) }.width(300).height(200)
Image(this.nativePixelMap ) Image(this.nativePixelMap == undefined ? '':this.nativePixelMap!)
.width(300) .width(300)
.height(300) .height(300)
.objectFit(ImageFit.Contain) .objectFit(ImageFit.Contain)
@ -101,7 +101,7 @@ struct TestAllCacheInfoPage {
Scroll() { Scroll() {
Text(this.cacheinfo2).fontSize(15) Text(this.cacheinfo2).fontSize(15)
}.width(300).height(200) }.width(300).height(200)
Image(this.networkPixelMap ) Image(this.networkPixelMap==undefined?'':this.networkPixelMap! )
.width(300) .width(300)
.height(300) .height(300)
.objectFit(ImageFit.Contain) .objectFit(ImageFit.Contain)

View File

@ -100,10 +100,11 @@ struct TestGifLoadWithWorkerPage {
Button('加载gif') Button('加载gif')
.margin({ top: 16 }) .margin({ top: 16 })
.onClick(() => { .onClick(() => {
(ImageKnifeGlobal.getInstance().getImageKnife()).setGifWorker(undefined)
let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife();
if(imageKnife != undefined) {
imageKnife.setGifWorker(undefined)
}
//主线程加载gif,阻塞toast的消失 //主线程加载gif,阻塞toast的消失
this.options = { this.options = {
loadSrc: $r("app.media.test"), loadSrc: $r("app.media.test"),

View File

@ -54,19 +54,7 @@ struct TestImageKnifeOptionChangedPage3 {
thumbSizeMultiplier:0.1, thumbSizeMultiplier:0.1,
transformation:rotateTrans, transformation:rotateTrans,
}; };
animateTo({
duration: 500,
curve: Curve.EaseInOut,
delay: 100,
iterations: 1,
playMode:PlayMode.Normal,
onFinish:()=>{
console.log('play end!')
}
},()=>{
this.compHeight = 350
this.compWidht = 350
})
}).margin({left:5}).backgroundColor(Color.Blue) }).margin({left:5}).backgroundColor(Color.Blue)
Button("本地png") Button("本地png")
.onClick(()=>{ .onClick(()=>{
@ -80,19 +68,7 @@ struct TestImageKnifeOptionChangedPage3 {
thumbSizeMultiplier:0.1, thumbSizeMultiplier:0.1,
transformation:rotateTrans, transformation:rotateTrans,
}; };
animateTo({
duration: 500,
curve: Curve.EaseInOut,
delay: 100,
iterations: 1,
playMode:PlayMode.Normal,
onFinish:()=>{
console.log('play end!')
}
},()=>{
this.compHeight = 400
this.compWidht = 300
})
}).margin({left:5}).backgroundColor(Color.Blue) }).margin({left:5}).backgroundColor(Color.Blue)
}.margin({top:15}) }.margin({top:15})
Flex({direction:FlexDirection.Row}){ Flex({direction:FlexDirection.Row}){
@ -106,19 +82,7 @@ struct TestImageKnifeOptionChangedPage3 {
thumbSizeMultiplier:0.1, thumbSizeMultiplier:0.1,
transformations:[new GrayscaleTransformation()], transformations:[new GrayscaleTransformation()],
}; };
animateTo({
duration: 500,
curve: Curve.EaseInOut,
delay: 100,
iterations: 1,
playMode:PlayMode.Normal,
onFinish:()=>{
console.log('play end!')
}
},()=>{
this.compHeight = 250
this.compWidht = 350
})
}).margin({left:5}).backgroundColor(Color.Blue) }).margin({left:5}).backgroundColor(Color.Blue)
Button("本地webp") Button("本地webp")
.onClick(()=>{ .onClick(()=>{
@ -130,19 +94,7 @@ struct TestImageKnifeOptionChangedPage3 {
thumbSizeMultiplier:0.1, thumbSizeMultiplier:0.1,
transformations:[new SketchFilterTransformation()], transformations:[new SketchFilterTransformation()],
}; };
animateTo({
duration: 500,
curve: Curve.EaseInOut,
delay: 100,
iterations: 1,
playMode:PlayMode.Normal,
onFinish:()=>{
console.log('play end!')
}
},()=>{
this.compHeight = 400
this.compWidht = 400
})
}).margin({left:5}).backgroundColor(Color.Blue) }).margin({left:5}).backgroundColor(Color.Blue)
}.margin({top:15}) }.margin({top:15})
Flex({direction:FlexDirection.Row}){ Flex({direction:FlexDirection.Row}){

View File

@ -101,7 +101,7 @@ struct TransformPixelMapPage {
}); });
}.margin({ top: 10 }) }.margin({ top: 10 })
Image(this.mCropPixelMap) Image(this.mCropPixelMap == undefined ? '':this.mCropPixelMap!)
.objectFit(ImageFit.None) .objectFit(ImageFit.None)
.width(100) .width(100)
.height(100) .height(100)
@ -154,7 +154,7 @@ struct TransformPixelMapPage {
}); });
}.margin({ top: 10 }) }.margin({ top: 10 })
Image(this.mRoundPixelMap) Image(this.mRoundPixelMap == undefined ? '': this.mRoundPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(100) .width(100)
.height(100) .height(100)
@ -173,7 +173,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.circleTransformation(); this.circleTransformation();
}); });
Image(this.mCirclePixelMap) Image(this.mCirclePixelMap == undefined ? '':this.mCirclePixelMap!)
.width(200) .width(200)
.height(200) .height(200)
.margin({ top: 10 }) .margin({ top: 10 })
@ -191,7 +191,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.circleBorderTransformation(5); this.circleBorderTransformation(5);
}); });
Image(this.mCircleBorderPixelMap) Image(this.mCircleBorderPixelMap == undefined ? '':this.mCircleBorderPixelMap!)
.width(200) .width(200)
.height(200) .height(200)
.margin({ top: 10 }) .margin({ top: 10 })
@ -213,7 +213,7 @@ struct TransformPixelMapPage {
} }
this.transformRotate(mRotate); this.transformRotate(mRotate);
}); });
Image(this.mRotatePixelMap) Image(this.mRotatePixelMap == undefined ? '':this.mRotatePixelMap!)
.width(200) .width(200)
.height(200) .height(200)
.margin({ top: 10 }) .margin({ top: 10 })
@ -231,7 +231,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.transformSquare(); this.transformSquare();
}); });
Image(this.mSquarePixelMap) Image(this.mSquarePixelMap == undefined ? '' : this.mSquarePixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)
@ -269,17 +269,17 @@ struct TransformPixelMapPage {
}.margin({ top: 10 }) }.margin({ top: 10 })
Row({ space: 1 }) { Row({ space: 1 }) {
Image(this.mClipTopPixelMap) Image(this.mClipTopPixelMap == undefined ? '':this.mClipTopPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(100) .width(100)
.height(100) .height(100)
.margin({ top: 10 }) .margin({ top: 10 })
Image(this.mClipCenterPixelMap) Image(this.mClipCenterPixelMap == undefined ? '':this.mClipCenterPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(100) .width(100)
.height(100) .height(100)
.margin({ top: 10 }) .margin({ top: 10 })
Image(this.mClipBottomPixelMap) Image(this.mClipBottomPixelMap == undefined ? '':this.mClipBottomPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(100) .width(100)
.height(100) .height(100)
@ -298,7 +298,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.grayscalePixelMap(); this.grayscalePixelMap();
}); });
Image(this.mGrayscalePixelMap) Image(this.mGrayscalePixelMap == undefined ? '': this.mGrayscalePixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)
@ -316,7 +316,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.brightnessPixelMap(0.8); this.brightnessPixelMap(0.8);
}); });
Image(this.mBrightnessPixelMap) Image(this.mBrightnessPixelMap == undefined?'':this.mBrightnessPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)
@ -334,7 +334,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.contrastPixelMap(4); this.contrastPixelMap(4);
}); });
Image(this.mContrastPixelMap) Image(this.mContrastPixelMap == undefined?'':this.mContrastPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)
@ -352,7 +352,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.invertPixelMap(); this.invertPixelMap();
}); });
Image(this.mInvertPixelMap) Image(this.mInvertPixelMap == undefined ? '':this.mInvertPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)
@ -371,7 +371,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.sepiaPixelMap(); this.sepiaPixelMap();
}); });
Image(this.mSepiaPixelMap) Image(this.mSepiaPixelMap == undefined ? '':this.mSepiaPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)
@ -389,7 +389,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.sketchPixelMap(); this.sketchPixelMap();
}); });
Image(this.mSketchPixelMap) Image(this.mSketchPixelMap == undefined ? '':this.mSketchPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)
@ -408,7 +408,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.blurHandlePixelMap(20); this.blurHandlePixelMap(20);
}); });
Image(this.mBlurPixelMap) Image(this.mBlurPixelMap==undefined?'':this.mBlurPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)
@ -428,7 +428,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.pixelHandlePixelMap(20); this.pixelHandlePixelMap(20);
}); });
Image(this.mPixelPixelMap) Image(this.mPixelPixelMap == undefined ? '':this.mPixelPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)
@ -447,7 +447,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.swirlHandlePixelMap(); this.swirlHandlePixelMap();
}); });
Image(this.mSwirlPixelMap) Image(this.mSwirlPixelMap == undefined ? '':this.mSwirlPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)
@ -466,7 +466,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.maskHandlePixelMap($r('app.media.mask_starfish')); this.maskHandlePixelMap($r('app.media.mask_starfish'));
}); });
Image(this.mMaskPixelMap) Image(this.mMaskPixelMap == undefined ? '':this.mMaskPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)
@ -485,7 +485,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.kuwaharaHandlePixelMap(); this.kuwaharaHandlePixelMap();
}); });
Image(this.mKuwaharaPixelMap) Image(this.mKuwaharaPixelMap == undefined? '':this.mKuwaharaPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)
@ -504,7 +504,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.toonHandlePixelMap(); this.toonHandlePixelMap();
}); });
Image(this.mToonPixelMap) Image(this.mToonPixelMap == undefined?'':this.mToonPixelMap!)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)
@ -523,7 +523,7 @@ struct TransformPixelMapPage {
.onClick(() => { .onClick(() => {
this.vignetteHandlePixelMap(); this.vignetteHandlePixelMap();
}); });
Image(this.mVignettePixelMap) Image(this.mVignettePixelMap == undefined ? '':this.mVignettePixelMap)
.objectFit(ImageFit.Fill) .objectFit(ImageFit.Fill)
.width(200) .width(200)
.height(200) .height(200)

View File

@ -22,7 +22,7 @@
"abilities": [ "abilities": [
{ {
"name": "MainAbility", "name": "MainAbility",
"srcEntrance": "./ets/entryability/EntryAbility.ts", "srcEntrance": "./ets/entryability/EntryAbility.ets",
"description": "$string:MainAbility_desc", "description": "$string:MainAbility_desc",
"icon": "$media:icon", "icon": "$media:icon",
"label": "$string:MainAbility_label", "label": "$string:MainAbility_label",

View File

@ -17,7 +17,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
export default function abilityTest() { export default function abilityTest() {
describe('ActsAbilityTest', function () { describe('ActsAbilityTest', ()=> {
// Defines a test suite. Two parameters are supported: test suite name and test suite function. // Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll( ()=> { beforeAll( ()=> {
// Presets an action, which is performed only once before all test cases of the test suite start. // Presets an action, which is performed only once before all test cases of the test suite start.

View File

@ -17,7 +17,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from
import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/imageknife' import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/imageknife'
export default function ImageKnifeTest() { export default function ImageKnifeTest() {
describe('ImageKnifeTest', function () { describe('ImageKnifeTest', ()=> {
// Defines a test suite. Two parameters are supported: test suite name and test suite function. // Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll( ()=> { beforeAll( ()=> {
// Presets an action, which is performed only once before all test cases of the test suite start. // Presets an action, which is performed only once before all test cases of the test suite start.
@ -40,16 +40,22 @@ export default function ImageKnifeTest() {
it('TestGlobalImageKnife',0, ()=> { it('TestGlobalImageKnife',0, ()=> {
let global:ImageKnifeGlobal = ImageKnife.with(ImageKnifeGlobal.getInstance().getHapContext()) let context:Object|undefined = ImageKnifeGlobal.getInstance().getHapContext();
expect(global.getImageKnife()).not().assertUndefined() if(context != undefined) {
let global: ImageKnifeGlobal = ImageKnife.with(context)
expect(global.getImageKnife()).not().assertUndefined()
}
}) })
it('TestGlobalDefaultLifeCycle',1, ()=> { it('TestGlobalDefaultLifeCycle',1, ()=> {
ImageKnife.with(ImageKnifeGlobal.getInstance().getHapContext()) let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife()
(ImageKnifeGlobal.getInstance().getImageKnife()).setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5)) if(imageKnife != undefined){
let globalLifeCycle = (ImageKnifeGlobal.getInstance().getImageKnife()).getDefaultLifeCycle(); imageKnife.setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5))
expect(globalLifeCycle).not().assertUndefined() let globalLifeCycle = imageKnife.getDefaultLifeCycle();
expect(globalLifeCycle).not().assertUndefined()
}
}) })

View File

@ -15,7 +15,7 @@
*/ */
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import {RequestOption} from '@ohos/imageknife' import {RequestOption,Size} from '@ohos/imageknife'
export default function RequestOptionTest() { export default function RequestOptionTest() {
describe('RequestOptionTest', ()=> { describe('RequestOptionTest', ()=> {
@ -40,7 +40,9 @@ export default function RequestOptionTest() {
}) })
it('TestRequestOption',0, ()=> { it('TestRequestOption',0, ()=> {
let option = new RequestOption(); let option = new RequestOption();
expect(option.requestListeners.length == 0).assertTrue() if(option.requestListeners != undefined) {
expect(option.requestListeners.length == 0).assertTrue()
}
}) })
it('TestConfigLoadSrc',1, ()=> { it('TestConfigLoadSrc',1, ()=> {
let option = new RequestOption(); let option = new RequestOption();
@ -50,9 +52,10 @@ export default function RequestOptionTest() {
}) })
it('TestConfigViewSize',2, ()=> { it('TestConfigViewSize',2, ()=> {
let option = new RequestOption(); let option = new RequestOption();
option.loadSrc = $r('app.media.icon') option.loadSrc = ''
option.setImageViewSize({width:100,height:100}) let size:Size = {width:100,height:100}
expect(JSON.stringify(option.size)).assertEqual(JSON.stringify({width:100,height:100})) option.setImageViewSize(size)
expect(JSON.stringify(option.size)).assertEqual(JSON.stringify(size))
}) })
it('TestNormalConfigInfo',3, ()=>{ it('TestNormalConfigInfo',3, ()=>{
let option = new RequestOption(); let option = new RequestOption();

View File

@ -19,34 +19,30 @@ import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test'; import testsuite from '../test/List.test';
import window from '@ohos.window'; import window from '@ohos.window';
import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/imageknife' import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/imageknife'
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base'
export default class TestAbility extends UIAbility { export default class TestAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want: Want, param: AbilityConstant.LaunchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); let abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any let abilityDelegatorArguments: AbilityDelegatorRegistry.AbilityDelegatorArgs
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
// 初始化xts的ImageKnife // 初始化xts的ImageKnife
ImageKnife.with(this.context.createModuleContext("entry_test")); ImageKnife.with(this.context.createModuleContext("entry_test"));
} }
onDestroy() { onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
} }
onWindowStageCreate(windowStage: window.WindowStage) { onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('testability/pages/Index', (err, data) => { windowStage.loadContent('testability/pages/Index', (err:BusinessError, data:void) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
}); });
} }

View File

@ -16,8 +16,8 @@
"type": "module", "type": "module",
"version": "2.1.0", "version": "2.1.0",
"dependencies": { "dependencies": {
"@ohos/disklrucache": "^2.0.0", "@ohos/disklrucache": "^2.0.1",
"@ohos/svg": "^2.0.0", "@ohos/svg": "^2.1.0",
"@ohos/gpu_transform": "^1.0.0" "@ohos/gpu_transform": "^1.0.0"
}, },
"tags": [ "tags": [

View File

@ -41,31 +41,31 @@ import common from '@ohos.app.ability.common'
export class ImageKnife { export class ImageKnife {
static readonly SEPARATOR: string = '/' static readonly SEPARATOR: string = '/'
private memoryCache: LruCache<string, ImageKnifeData>; memoryCache: LruCache<string, ImageKnifeData>;
private diskMemoryCache: DiskLruCache; diskMemoryCache: DiskLruCache;
private dataFetch: IDataFetch; dataFetch: IDataFetch;
private resourceFetch: IResourceFetch<ArrayBuffer>; resourceFetch: IResourceFetch<ArrayBuffer>;
private filesPath: string = ""; // data/data/包名/files目录 filesPath: string = ""; // data/data/包名/files目录
private placeholderCache: string = "placeholderCache" placeholderCache: string = "placeholderCache"
private runningRequest: Array<RequestOption>; runningRequest: Array<RequestOption>;
private pendingRequest: Array<RequestOption>; pendingRequest: Array<RequestOption>;
private fileTypeUtil: FileTypeUtil; // 通用文件格式辨别 fileTypeUtil: FileTypeUtil; // 通用文件格式辨别
private diskCacheFolder: string = "ImageKnifeDiskCache" diskCacheFolder: string = "ImageKnifeDiskCache"
private defaultListener: AsyncCallback<ImageKnifeData> = { defaultListener: AsyncCallback<ImageKnifeData> = {
callback:(err: string, data: ImageKnifeData)=>{return false} callback:(err: string, data: ImageKnifeData)=>{return false}
}; // 全局监听器 }; // 全局监听器
// gifWorker // gifWorker
private gifWorker: worker.ThreadWorker|undefined = undefined; gifWorker: worker.ThreadWorker|undefined = undefined;
private defaultLifeCycle: IDrawLifeCycle|undefined = undefined; defaultLifeCycle: IDrawLifeCycle|undefined = undefined;
// 开发者可配置全局缓存 // 开发者可配置全局缓存
private engineKeyImpl: EngineKeyInterface; engineKeyImpl: EngineKeyInterface;
private constructor() { private constructor() {

View File

@ -651,7 +651,7 @@ export struct ImageKnifeComponent {
renderFrames_compWidth: number = 0; renderFrames_compWidth: number = 0;
renderFrames_compHeight: number = 0 renderFrames_compHeight: number = 0
renderFrames = ()=> { renderFrames:()=>void = ()=> {
LogUtil.log('ImageKnifeComponent renderFrames frames length =' + this.renderFrames_frames?.length) LogUtil.log('ImageKnifeComponent renderFrames frames length =' + this.renderFrames_frames?.length)
let start = new Date().getTime(); let start = new Date().getTime();
if (this.renderFrames_index === 0) { if (this.renderFrames_index === 0) {

View File

@ -53,7 +53,7 @@ export class ImageKnifeGlobal {
} }
} }
setImageKnife(imageKnife:ImageKnife):void{ setImageKnife(imageKnife:Object):void{
this._objects.set(GlobalEnum.IMAGE_KNIFE_KEY, imageKnife); this._objects.set(GlobalEnum.IMAGE_KNIFE_KEY, imageKnife);
} }

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {ImageKnife} from './ImageKnife'
import { DiskStrategy } from "../cache/diskstrategy/DiskStrategy" import { DiskStrategy } from "../cache/diskstrategy/DiskStrategy"
import { AsyncCallback } from "../imageknife/interface/AsyncCallback" import { AsyncCallback } from "../imageknife/interface/AsyncCallback"
import { AsyncSuccess } from "../imageknife/interface/AsyncSuccess" import { AsyncSuccess } from "../imageknife/interface/AsyncSuccess"
@ -89,8 +89,8 @@ export class RequestOption {
generateCacheKey: string = ""; generateCacheKey: string = "";
generateResourceKey: string = ""; generateResourceKey: string = "";
generateDataKey: string = ""; generateDataKey: string = "";
private filesPath: string = ""; // data/data/包名/files目录 filesPath: string = ""; // data/data/包名/files目录
private cachesPath: string = ""; // 网络下载默认存储在data/data/包名/cache/ImageKnifeNetworkFolder/目标md5.img下面 cachesPath: string = ""; // 网络下载默认存储在data/data/包名/cache/ImageKnifeNetworkFolder/目标md5.img下面
// 下载原始文件地址 // 下载原始文件地址
downloadFilePath: string = ""; downloadFilePath: string = "";
@ -478,14 +478,16 @@ export class RequestOption {
// 等落盘结束后主动调用#removeCurrentAndSearchNext方法 // 等落盘结束后主动调用#removeCurrentAndSearchNext方法
}else{ }else{
// 非落盘情况,直接进行寻找下一个加载 // 非落盘情况,直接进行寻找下一个加载
if(ImageKnifeGlobal.getInstance().getImageKnife() != undefined) { let imageKnife:ImageKnife | undefined = ImageKnifeGlobal.getInstance().getImageKnife();
(ImageKnifeGlobal.getInstance().getImageKnife())?.removeRunning(this); if(imageKnife != undefined) {
imageKnife.removeRunning(this);
} }
} }
// 加载成功之后 // 加载成功之后
if(ImageKnifeGlobal.getInstance().getImageKnife() != undefined) { let imageKnife:ImageKnife | undefined = ImageKnifeGlobal.getInstance().getImageKnife();
(ImageKnifeGlobal.getInstance().getImageKnife())?.removeRunning(this); if(imageKnife != undefined) {
imageKnife.removeRunning(this);
} }
} }

View File

@ -25,7 +25,7 @@ import { BusinessError } from '@ohos.base'
// 数据加载器 // 数据加载器
export class NetworkDownloadClient implements IDataFetch { export class NetworkDownloadClient implements IDataFetch {
loadData(request: RequestOption, onComplete: (img: ArrayBuffer) => void, onError: (err: string) => void) { loadData(request: RequestOption, onComplete: (img: ArrayBuffer) => void, onError: (err: string) => void) {
let filename = SparkMD5.hashBinary(request.generateDataKey); let filename:string = SparkMD5.hashBinary(request.generateDataKey);
let downloadFolder = request.getFilesPath() + "/" + request.networkCacheFolder; let downloadFolder = request.getFilesPath() + "/" + request.networkCacheFolder;
let allpath = request.getFilesPath() + "/" + request.networkCacheFolder + "/" + filename + ".img"; let allpath = request.getFilesPath() + "/" + request.networkCacheFolder + "/" + filename + ".img";
if (!FileUtils.getInstance().existFolder(downloadFolder)) { if (!FileUtils.getInstance().existFolder(downloadFolder)) {

View File

@ -114,14 +114,14 @@ export class RequestManager {
// 变换后缓存 // 变换后缓存
allCacheInfo.resourceCacheInfo = { allCacheInfo.resourceCacheInfo = {
key: SparkMD5.hashBinary(this.options.generateResourceKey), key: SparkMD5.hashBinary(this.options.generateResourceKey) as string,
path: (this.mDiskCacheProxy.getCachePath() + SparkMD5.hashBinary(this.options.generateResourceKey)) path: (this.mDiskCacheProxy.getCachePath() + SparkMD5.hashBinary(this.options.generateResourceKey)) as string
}; };
// 原图缓存 // 原图缓存
allCacheInfo.dataCacheInfo = { allCacheInfo.dataCacheInfo = {
key: SparkMD5.hashBinary(this.options.generateDataKey), key: SparkMD5.hashBinary(this.options.generateDataKey) as string,
path: this.mDiskCacheProxy.getCachePath() + SparkMD5.hashBinary(this.options.generateDataKey) path: (this.mDiskCacheProxy.getCachePath() + SparkMD5.hashBinary(this.options.generateDataKey)) as string
} }
this.options.allCacheInfoCallback.callback(allCacheInfo) this.options.allCacheInfoCallback.callback(allCacheInfo)
} }

View File

@ -19,6 +19,13 @@ import {Size} from '../../RequestOption'
export class SVGParseImpl implements IParseSvg{ export class SVGParseImpl implements IParseSvg{
parseSvg(imageinfo: ArrayBuffer,size?:Size): Promise<PixelMap>{ parseSvg(imageinfo: ArrayBuffer,size?:Size): Promise<PixelMap>{
let model = new SVGImageView.SVGImageViewModel(); let model = new SVGImageView.SVGImageViewModel();
return model.getSVGPixelMap(new Uint8Array(imageinfo),size); let svgSize:SVGImageView.Size = new SVGImageView.Size();
svgSize.width = 0;
svgSize.height = 0;
if(size != undefined){
svgSize.width = size.width;
svgSize.height = size.height;
}
return model.getSVGPixelMap(new Uint8Array(imageinfo),svgSize);
} }
} }