diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 index ba65afa..716e31e 100644 --- a/entry/oh-package.json5 +++ b/entry/oh-package.json5 @@ -7,6 +7,6 @@ "version": "2.0.5-rc.0", "dependencies": { "@ohos/imageknife": "file:../imageknife", - "@ohos/disklrucache": "^2.0.0" + "@ohos/disklrucache": "^2.0.1" } } diff --git a/entry/src/main/ets/entryability/EntryAbility.ts b/entry/src/main/ets/entryability/EntryAbility.ets similarity index 68% rename from entry/src/main/ets/entryability/EntryAbility.ts rename to entry/src/main/ets/entryability/EntryAbility.ets index b251a00..c3d114b 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ts +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -18,17 +18,15 @@ import window from '@ohos.window'; import { ImageKnifeGlobal,ImageKnife,ImageKnifeDrawFactory,LogUtil } from '@ohos/imageknife' import { CustomEngineKeyImpl } from './CustomEngineKeyImpl' import abilityAccessCtrl,{Permissions} from '@ohos.abilityAccessCtrl'; - +import { BusinessError } from '@ohos.base' export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage) { // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - let list : Array = ['ohos.permission.MEDIA_LOCATION','ohos.permission.READ_MEDIA']; - let permissionRequestResult; + let permissionRequestResult:Object; let atManager = abilityAccessCtrl.createAtManager(); - atManager.requestPermissionsFromUser(this.context, list, (err,result)=>{ + atManager.requestPermissionsFromUser(this.context, list, (err:BusinessError,result:Object)=>{ if(err){ console.log("dodo requestPermissionsFromUserError:"+JSON.stringify(err)); }else{ @@ -37,19 +35,19 @@ export default class EntryAbility extends UIAbility { } }) - windowStage.loadContent('pages/index', (err, data) => { - 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) ?? ''); + windowStage.loadContent('pages/index', (err:BusinessError, data:void) => { }); ImageKnife.with(this.context); - // 全局配置网络加载进度条 - ImageKnifeGlobal.getInstance().getImageKnife().setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5)) - // 全局配置缓存key - ImageKnifeGlobal.getInstance().getImageKnife().setEngineKeyImpl(new CustomEngineKeyImpl()) + + let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife() + if(imageKnife != undefined) { + // 全局配置网络加载进度条 + imageKnife + .setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5)) + // 全局配置缓存key + imageKnife.setEngineKeyImpl(new CustomEngineKeyImpl()) + } //开启ImageKnife所有级别日志开关 LogUtil.mLogLevel = LogUtil.ALL } diff --git a/entry/src/main/ets/pages/compressPage.ets b/entry/src/main/ets/pages/compressPage.ets index e0cb3ad..b76a7ba 100644 --- a/entry/src/main/ets/pages/compressPage.ets +++ b/entry/src/main/ets/pages/compressPage.ets @@ -64,7 +64,7 @@ struct CompressPage { .onClick(() => { this.cropressRecource(); }); - Image(this.mRPixelMap ) + Image(this.mRPixelMap == undefined?'': this.mRPixelMap!) .width(200) .height(200) .margin({ top: 10 }) @@ -82,7 +82,7 @@ struct CompressPage { .margin({ top: 10 }) .onClick(() => { }); - Image(this.mFPixelMap ) + Image(this.mFPixelMap == undefined ?'':this.mFPixelMap!) .width(200) .height(200) .margin({ top: 10 }); @@ -139,7 +139,7 @@ struct CompressPage { console.info("asasd start compress") let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife() if(imageKnife != undefined) { - (ImageKnifeGlobal.getInstance().getImageKnife()) + imageKnife .compressBuilder() .load(data) .ignoreBy(100) diff --git a/entry/src/main/ets/pages/dataShareUriLoadPage.ets b/entry/src/main/ets/pages/dataShareUriLoadPage.ets index c94b854..2a22952 100644 --- a/entry/src/main/ets/pages/dataShareUriLoadPage.ets +++ b/entry/src/main/ets/pages/dataShareUriLoadPage.ets @@ -39,11 +39,10 @@ struct DataShareUriLoadPage { const context = getContext(this); let media = mediaLibrary.getMediaLibrary(context); - let fileKeyObj = mediaLibrary.FileKey; let imageType = mediaLibrary.MediaType.IMAGE; // 创建文件获取选项,此处参数为获取image类型的文件资源 let imagesFetchOp:mediaLibrary.MediaFetchOptions = { - selections: fileKeyObj.MEDIA_TYPE + '= ?', + selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ?', selectionArgs: [imageType.toString()], }; // 获取文件资源,使用callback方式返回异步结果 diff --git a/entry/src/main/ets/pages/gifTestCasePage.ets b/entry/src/main/ets/pages/gifTestCasePage.ets index cb5bf16..771a395 100644 --- a/entry/src/main/ets/pages/gifTestCasePage.ets +++ b/entry/src/main/ets/pages/gifTestCasePage.ets @@ -106,7 +106,7 @@ struct gifTestCasePage { Text("下面为展示图片区域").margin({top:5}) Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){ - Image(this.pixels) + Image(this.pixels == undefined?'':this.pixels!) .width(400) .height(400) .backgroundColor(Color.Pink) diff --git a/entry/src/main/ets/pages/svgTestCasePage.ets b/entry/src/main/ets/pages/svgTestCasePage.ets index 974c129..6157a96 100644 --- a/entry/src/main/ets/pages/svgTestCasePage.ets +++ b/entry/src/main/ets/pages/svgTestCasePage.ets @@ -51,7 +51,7 @@ struct svgTestCasePage { Text("下面为展示图片区域").margin({top:5}) Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){ - Image(this.svgSamplePixelMap) + Image(this.svgSamplePixelMap == undefined ? '':this.svgSamplePixelMap!) .width(400) .height(400) .backgroundColor(Color.Pink) @@ -81,7 +81,7 @@ struct svgTestCasePage { Text("下面为展示图片区域").margin({top:5}) Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }){ - Image(this.svgIconPixelMap) + Image(this.svgIconPixelMap == undefined ? '':this.svgIconPixelMap!) .width(400) .height(400) .backgroundColor(Color.Pink) diff --git a/entry/src/main/ets/pages/testAllCacheInfoPage.ets b/entry/src/main/ets/pages/testAllCacheInfoPage.ets index 0646c02..9d5003f 100644 --- a/entry/src/main/ets/pages/testAllCacheInfoPage.ets +++ b/entry/src/main/ets/pages/testAllCacheInfoPage.ets @@ -88,7 +88,7 @@ struct TestAllCacheInfoPage { Scroll() { Text(this.cacheinfo1).fontSize(15) }.width(300).height(200) - Image(this.nativePixelMap ) + Image(this.nativePixelMap == undefined ? '':this.nativePixelMap!) .width(300) .height(300) .objectFit(ImageFit.Contain) @@ -101,7 +101,7 @@ struct TestAllCacheInfoPage { Scroll() { Text(this.cacheinfo2).fontSize(15) }.width(300).height(200) - Image(this.networkPixelMap ) + Image(this.networkPixelMap==undefined?'':this.networkPixelMap! ) .width(300) .height(300) .objectFit(ImageFit.Contain) diff --git a/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets b/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets index e2e7e3b..3f044a4 100644 --- a/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets +++ b/entry/src/main/ets/pages/testGifLoadWithWorkerPage.ets @@ -100,10 +100,11 @@ struct TestGifLoadWithWorkerPage { Button('加载gif') .margin({ top: 16 }) .onClick(() => { - - - (ImageKnifeGlobal.getInstance().getImageKnife()).setGifWorker(undefined) + let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife(); + if(imageKnife != undefined) { + imageKnife.setGifWorker(undefined) + } //主线程加载gif,阻塞toast的消失 this.options = { loadSrc: $r("app.media.test"), diff --git a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage3.ets b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage3.ets index ccb6b5a..8871b1a 100644 --- a/entry/src/main/ets/pages/testImageKnifeOptionChangedPage3.ets +++ b/entry/src/main/ets/pages/testImageKnifeOptionChangedPage3.ets @@ -54,19 +54,7 @@ struct TestImageKnifeOptionChangedPage3 { thumbSizeMultiplier:0.1, 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) Button("本地png") .onClick(()=>{ @@ -80,19 +68,7 @@ struct TestImageKnifeOptionChangedPage3 { thumbSizeMultiplier:0.1, 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({top:15}) Flex({direction:FlexDirection.Row}){ @@ -106,19 +82,7 @@ struct TestImageKnifeOptionChangedPage3 { thumbSizeMultiplier:0.1, 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) Button("本地webp") .onClick(()=>{ @@ -130,19 +94,7 @@ struct TestImageKnifeOptionChangedPage3 { thumbSizeMultiplier:0.1, 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({top:15}) Flex({direction:FlexDirection.Row}){ diff --git a/entry/src/main/ets/pages/transformPixelMapPage.ets b/entry/src/main/ets/pages/transformPixelMapPage.ets index ba4016e..e9cabbb 100644 --- a/entry/src/main/ets/pages/transformPixelMapPage.ets +++ b/entry/src/main/ets/pages/transformPixelMapPage.ets @@ -101,7 +101,7 @@ struct TransformPixelMapPage { }); }.margin({ top: 10 }) - Image(this.mCropPixelMap) + Image(this.mCropPixelMap == undefined ? '':this.mCropPixelMap!) .objectFit(ImageFit.None) .width(100) .height(100) @@ -154,7 +154,7 @@ struct TransformPixelMapPage { }); }.margin({ top: 10 }) - Image(this.mRoundPixelMap) + Image(this.mRoundPixelMap == undefined ? '': this.mRoundPixelMap!) .objectFit(ImageFit.Fill) .width(100) .height(100) @@ -173,7 +173,7 @@ struct TransformPixelMapPage { .onClick(() => { this.circleTransformation(); }); - Image(this.mCirclePixelMap) + Image(this.mCirclePixelMap == undefined ? '':this.mCirclePixelMap!) .width(200) .height(200) .margin({ top: 10 }) @@ -191,7 +191,7 @@ struct TransformPixelMapPage { .onClick(() => { this.circleBorderTransformation(5); }); - Image(this.mCircleBorderPixelMap) + Image(this.mCircleBorderPixelMap == undefined ? '':this.mCircleBorderPixelMap!) .width(200) .height(200) .margin({ top: 10 }) @@ -213,7 +213,7 @@ struct TransformPixelMapPage { } this.transformRotate(mRotate); }); - Image(this.mRotatePixelMap) + Image(this.mRotatePixelMap == undefined ? '':this.mRotatePixelMap!) .width(200) .height(200) .margin({ top: 10 }) @@ -231,7 +231,7 @@ struct TransformPixelMapPage { .onClick(() => { this.transformSquare(); }); - Image(this.mSquarePixelMap) + Image(this.mSquarePixelMap == undefined ? '' : this.mSquarePixelMap!) .objectFit(ImageFit.Fill) .width(200) .height(200) @@ -269,17 +269,17 @@ struct TransformPixelMapPage { }.margin({ top: 10 }) Row({ space: 1 }) { - Image(this.mClipTopPixelMap) + Image(this.mClipTopPixelMap == undefined ? '':this.mClipTopPixelMap!) .objectFit(ImageFit.Fill) .width(100) .height(100) .margin({ top: 10 }) - Image(this.mClipCenterPixelMap) + Image(this.mClipCenterPixelMap == undefined ? '':this.mClipCenterPixelMap!) .objectFit(ImageFit.Fill) .width(100) .height(100) .margin({ top: 10 }) - Image(this.mClipBottomPixelMap) + Image(this.mClipBottomPixelMap == undefined ? '':this.mClipBottomPixelMap!) .objectFit(ImageFit.Fill) .width(100) .height(100) @@ -298,7 +298,7 @@ struct TransformPixelMapPage { .onClick(() => { this.grayscalePixelMap(); }); - Image(this.mGrayscalePixelMap) + Image(this.mGrayscalePixelMap == undefined ? '': this.mGrayscalePixelMap!) .objectFit(ImageFit.Fill) .width(200) .height(200) @@ -316,7 +316,7 @@ struct TransformPixelMapPage { .onClick(() => { this.brightnessPixelMap(0.8); }); - Image(this.mBrightnessPixelMap) + Image(this.mBrightnessPixelMap == undefined?'':this.mBrightnessPixelMap!) .objectFit(ImageFit.Fill) .width(200) .height(200) @@ -334,7 +334,7 @@ struct TransformPixelMapPage { .onClick(() => { this.contrastPixelMap(4); }); - Image(this.mContrastPixelMap) + Image(this.mContrastPixelMap == undefined?'':this.mContrastPixelMap!) .objectFit(ImageFit.Fill) .width(200) .height(200) @@ -352,7 +352,7 @@ struct TransformPixelMapPage { .onClick(() => { this.invertPixelMap(); }); - Image(this.mInvertPixelMap) + Image(this.mInvertPixelMap == undefined ? '':this.mInvertPixelMap!) .objectFit(ImageFit.Fill) .width(200) .height(200) @@ -371,7 +371,7 @@ struct TransformPixelMapPage { .onClick(() => { this.sepiaPixelMap(); }); - Image(this.mSepiaPixelMap) + Image(this.mSepiaPixelMap == undefined ? '':this.mSepiaPixelMap!) .objectFit(ImageFit.Fill) .width(200) .height(200) @@ -389,7 +389,7 @@ struct TransformPixelMapPage { .onClick(() => { this.sketchPixelMap(); }); - Image(this.mSketchPixelMap) + Image(this.mSketchPixelMap == undefined ? '':this.mSketchPixelMap!) .objectFit(ImageFit.Fill) .width(200) .height(200) @@ -408,7 +408,7 @@ struct TransformPixelMapPage { .onClick(() => { this.blurHandlePixelMap(20); }); - Image(this.mBlurPixelMap) + Image(this.mBlurPixelMap==undefined?'':this.mBlurPixelMap!) .objectFit(ImageFit.Fill) .width(200) .height(200) @@ -428,7 +428,7 @@ struct TransformPixelMapPage { .onClick(() => { this.pixelHandlePixelMap(20); }); - Image(this.mPixelPixelMap) + Image(this.mPixelPixelMap == undefined ? '':this.mPixelPixelMap!) .objectFit(ImageFit.Fill) .width(200) .height(200) @@ -447,7 +447,7 @@ struct TransformPixelMapPage { .onClick(() => { this.swirlHandlePixelMap(); }); - Image(this.mSwirlPixelMap) + Image(this.mSwirlPixelMap == undefined ? '':this.mSwirlPixelMap!) .objectFit(ImageFit.Fill) .width(200) .height(200) @@ -466,7 +466,7 @@ struct TransformPixelMapPage { .onClick(() => { this.maskHandlePixelMap($r('app.media.mask_starfish')); }); - Image(this.mMaskPixelMap) + Image(this.mMaskPixelMap == undefined ? '':this.mMaskPixelMap!) .objectFit(ImageFit.Fill) .width(200) .height(200) @@ -485,7 +485,7 @@ struct TransformPixelMapPage { .onClick(() => { this.kuwaharaHandlePixelMap(); }); - Image(this.mKuwaharaPixelMap) + Image(this.mKuwaharaPixelMap == undefined? '':this.mKuwaharaPixelMap!) .objectFit(ImageFit.Fill) .width(200) .height(200) @@ -504,7 +504,7 @@ struct TransformPixelMapPage { .onClick(() => { this.toonHandlePixelMap(); }); - Image(this.mToonPixelMap) + Image(this.mToonPixelMap == undefined?'':this.mToonPixelMap!) .objectFit(ImageFit.Fill) .width(200) .height(200) @@ -523,7 +523,7 @@ struct TransformPixelMapPage { .onClick(() => { this.vignetteHandlePixelMap(); }); - Image(this.mVignettePixelMap) + Image(this.mVignettePixelMap == undefined ? '':this.mVignettePixelMap) .objectFit(ImageFit.Fill) .width(200) .height(200) diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 index f15f6f5..9a567c5 100644 --- a/entry/src/main/module.json5 +++ b/entry/src/main/module.json5 @@ -22,7 +22,7 @@ "abilities": [ { "name": "MainAbility", - "srcEntrance": "./ets/entryability/EntryAbility.ts", + "srcEntrance": "./ets/entryability/EntryAbility.ets", "description": "$string:MainAbility_desc", "icon": "$media:icon", "label": "$string:MainAbility_label", diff --git a/entry/src/ohosTest/ets/test/Ability.test.ets b/entry/src/ohosTest/ets/test/Ability.test.ets index 47b99a5..91d458b 100644 --- a/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/entry/src/ohosTest/ets/test/Ability.test.ets @@ -17,7 +17,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from export default function abilityTest() { - describe('ActsAbilityTest', function () { + describe('ActsAbilityTest', ()=> { // Defines a test suite. Two parameters are supported: test suite name and test suite function. beforeAll( ()=> { // Presets an action, which is performed only once before all test cases of the test suite start. diff --git a/entry/src/ohosTest/ets/test/imageknife.test.ets b/entry/src/ohosTest/ets/test/imageknife.test.ets index 88a937e..368a7a6 100644 --- a/entry/src/ohosTest/ets/test/imageknife.test.ets +++ b/entry/src/ohosTest/ets/test/imageknife.test.ets @@ -17,7 +17,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from import {ImageKnife,ImageKnifeDrawFactory,ImageKnifeGlobal} from '@ohos/imageknife' export default function ImageKnifeTest() { - describe('ImageKnifeTest', function () { + describe('ImageKnifeTest', ()=> { // Defines a test suite. Two parameters are supported: test suite name and test suite function. beforeAll( ()=> { // Presets an action, which is performed only once before all test cases of the test suite start. @@ -40,16 +40,22 @@ export default function ImageKnifeTest() { it('TestGlobalImageKnife',0, ()=> { - let global:ImageKnifeGlobal = ImageKnife.with(ImageKnifeGlobal.getInstance().getHapContext()) - expect(global.getImageKnife()).not().assertUndefined() + let context:Object|undefined = ImageKnifeGlobal.getInstance().getHapContext(); + if(context != undefined) { + let global: ImageKnifeGlobal = ImageKnife.with(context) + expect(global.getImageKnife()).not().assertUndefined() + } }) it('TestGlobalDefaultLifeCycle',1, ()=> { - ImageKnife.with(ImageKnifeGlobal.getInstance().getHapContext()) - (ImageKnifeGlobal.getInstance().getImageKnife()).setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5)) - let globalLifeCycle = (ImageKnifeGlobal.getInstance().getImageKnife()).getDefaultLifeCycle(); - expect(globalLifeCycle).not().assertUndefined() + let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife() + if(imageKnife != undefined){ + imageKnife.setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5)) + let globalLifeCycle = imageKnife.getDefaultLifeCycle(); + expect(globalLifeCycle).not().assertUndefined() + } + }) diff --git a/entry/src/ohosTest/ets/test/requestoption.test.ets b/entry/src/ohosTest/ets/test/requestoption.test.ets index fcf48f7..e2b0621 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} from '@ohos/imageknife' +import {RequestOption,Size} from '@ohos/imageknife' export default function RequestOptionTest() { describe('RequestOptionTest', ()=> { @@ -40,7 +40,9 @@ export default function RequestOptionTest() { }) it('TestRequestOption',0, ()=> { let option = new RequestOption(); - expect(option.requestListeners.length == 0).assertTrue() + if(option.requestListeners != undefined) { + expect(option.requestListeners.length == 0).assertTrue() + } }) it('TestConfigLoadSrc',1, ()=> { let option = new RequestOption(); @@ -50,9 +52,10 @@ export default function RequestOptionTest() { }) it('TestConfigViewSize',2, ()=> { let option = new RequestOption(); - option.loadSrc = $r('app.media.icon') - option.setImageViewSize({width:100,height:100}) - expect(JSON.stringify(option.size)).assertEqual(JSON.stringify({width:100,height:100})) + option.loadSrc = '' + let size:Size = {width:100,height:100} + option.setImageViewSize(size) + expect(JSON.stringify(option.size)).assertEqual(JSON.stringify(size)) }) it('TestNormalConfigInfo',3, ()=>{ let option = new RequestOption(); diff --git a/entry/src/ohosTest/ets/testability/TestAbility.ets b/entry/src/ohosTest/ets/testability/TestAbility.ets index a105b2e..22b0877 100644 --- a/entry/src/ohosTest/ets/testability/TestAbility.ets +++ b/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -19,34 +19,30 @@ import { Hypium } from '@ohos/hypium'; import testsuite from '../test/List.test'; import window from '@ohos.window'; 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 { - onCreate(want, launchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); - hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); - hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); - var abilityDelegator: any + onCreate(want: Want, param: AbilityConstant.LaunchParam) { + + let abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var abilityDelegatorArguments: any + let abilityDelegatorArguments: AbilityDelegatorRegistry.AbilityDelegatorArgs abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) // 初始化xts的ImageKnife ImageKnife.with(this.context.createModuleContext("entry_test")); } onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } onWindowStageCreate(windowStage: window.WindowStage) { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); - windowStage.loadContent('testability/pages/Index', (err, data) => { - 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) ?? ''); + + windowStage.loadContent('testability/pages/Index', (err:BusinessError, data:void) => { + }); } diff --git a/imageknife/oh-package.json5 b/imageknife/oh-package.json5 index 3df7f67..1df2e5d 100644 --- a/imageknife/oh-package.json5 +++ b/imageknife/oh-package.json5 @@ -16,8 +16,8 @@ "type": "module", "version": "2.1.0", "dependencies": { - "@ohos/disklrucache": "^2.0.0", - "@ohos/svg": "^2.0.0", + "@ohos/disklrucache": "^2.0.1", + "@ohos/svg": "^2.1.0", "@ohos/gpu_transform": "^1.0.0" }, "tags": [ diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnife.ets b/imageknife/src/main/ets/components/imageknife/ImageKnife.ets index ea18f4e..3145d07 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnife.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnife.ets @@ -41,31 +41,31 @@ import common from '@ohos.app.ability.common' export class ImageKnife { static readonly SEPARATOR: string = '/' - private memoryCache: LruCache; - private diskMemoryCache: DiskLruCache; - private dataFetch: IDataFetch; - private resourceFetch: IResourceFetch; - private filesPath: string = ""; // data/data/包名/files目录 + memoryCache: LruCache; + diskMemoryCache: DiskLruCache; + dataFetch: IDataFetch; + resourceFetch: IResourceFetch; + filesPath: string = ""; // data/data/包名/files目录 - private placeholderCache: string = "placeholderCache" - private runningRequest: Array; - private pendingRequest: Array; - private fileTypeUtil: FileTypeUtil; // 通用文件格式辨别 - private diskCacheFolder: string = "ImageKnifeDiskCache" + placeholderCache: string = "placeholderCache" + runningRequest: Array; + pendingRequest: Array; + fileTypeUtil: FileTypeUtil; // 通用文件格式辨别 + diskCacheFolder: string = "ImageKnifeDiskCache" - private defaultListener: AsyncCallback = { + defaultListener: AsyncCallback = { callback:(err: string, data: ImageKnifeData)=>{return false} }; // 全局监听器 // 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() { diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets index 5012101..1866bbb 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent.ets @@ -651,7 +651,7 @@ export struct ImageKnifeComponent { renderFrames_compWidth: number = 0; renderFrames_compHeight: number = 0 - renderFrames = ()=> { + renderFrames:()=>void = ()=> { LogUtil.log('ImageKnifeComponent renderFrames frames length =' + this.renderFrames_frames?.length) let start = new Date().getTime(); if (this.renderFrames_index === 0) { diff --git a/imageknife/src/main/ets/components/imageknife/ImageKnifeGlobal.ets b/imageknife/src/main/ets/components/imageknife/ImageKnifeGlobal.ets index d33c890..1672a8f 100644 --- a/imageknife/src/main/ets/components/imageknife/ImageKnifeGlobal.ets +++ b/imageknife/src/main/ets/components/imageknife/ImageKnifeGlobal.ets @@ -53,7 +53,7 @@ export class ImageKnifeGlobal { } } - setImageKnife(imageKnife:ImageKnife):void{ + setImageKnife(imageKnife:Object):void{ this._objects.set(GlobalEnum.IMAGE_KNIFE_KEY, imageKnife); } diff --git a/imageknife/src/main/ets/components/imageknife/RequestOption.ets b/imageknife/src/main/ets/components/imageknife/RequestOption.ets index 3ffa238..466e350 100644 --- a/imageknife/src/main/ets/components/imageknife/RequestOption.ets +++ b/imageknife/src/main/ets/components/imageknife/RequestOption.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +import {ImageKnife} from './ImageKnife' import { DiskStrategy } from "../cache/diskstrategy/DiskStrategy" import { AsyncCallback } from "../imageknife/interface/AsyncCallback" import { AsyncSuccess } from "../imageknife/interface/AsyncSuccess" @@ -89,8 +89,8 @@ export class RequestOption { generateCacheKey: string = ""; generateResourceKey: string = ""; generateDataKey: string = ""; - private filesPath: string = ""; // data/data/包名/files目录 - private cachesPath: string = ""; // 网络下载默认存储在data/data/包名/cache/ImageKnifeNetworkFolder/目标md5.img下面 + filesPath: string = ""; // data/data/包名/files目录 + cachesPath: string = ""; // 网络下载默认存储在data/data/包名/cache/ImageKnifeNetworkFolder/目标md5.img下面 // 下载原始文件地址 downloadFilePath: string = ""; @@ -478,14 +478,16 @@ export class RequestOption { // 等落盘结束后主动调用#removeCurrentAndSearchNext方法 }else{ // 非落盘情况,直接进行寻找下一个加载 - if(ImageKnifeGlobal.getInstance().getImageKnife() != undefined) { - (ImageKnifeGlobal.getInstance().getImageKnife())?.removeRunning(this); + let imageKnife:ImageKnife | undefined = ImageKnifeGlobal.getInstance().getImageKnife(); + if(imageKnife != undefined) { + imageKnife.removeRunning(this); } } // 加载成功之后 - if(ImageKnifeGlobal.getInstance().getImageKnife() != undefined) { - (ImageKnifeGlobal.getInstance().getImageKnife())?.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/NetworkDownloadClient.ets b/imageknife/src/main/ets/components/imageknife/networkmanage/NetworkDownloadClient.ets index 5dc5ec7..6733caa 100644 --- a/imageknife/src/main/ets/components/imageknife/networkmanage/NetworkDownloadClient.ets +++ b/imageknife/src/main/ets/components/imageknife/networkmanage/NetworkDownloadClient.ets @@ -25,7 +25,7 @@ import { BusinessError } from '@ohos.base' // 数据加载器 export class NetworkDownloadClient implements IDataFetch { 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 allpath = request.getFilesPath() + "/" + request.networkCacheFolder + "/" + filename + ".img"; if (!FileUtils.getInstance().existFolder(downloadFolder)) { diff --git a/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets b/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets index 04629b9..ac20bca 100644 --- a/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets +++ b/imageknife/src/main/ets/components/imageknife/requestmanage/RequestManager.ets @@ -114,14 +114,14 @@ export class RequestManager { // 变换后缓存 allCacheInfo.resourceCacheInfo = { - key: SparkMD5.hashBinary(this.options.generateResourceKey), - path: (this.mDiskCacheProxy.getCachePath() + SparkMD5.hashBinary(this.options.generateResourceKey)) + key: SparkMD5.hashBinary(this.options.generateResourceKey) as string, + path: (this.mDiskCacheProxy.getCachePath() + SparkMD5.hashBinary(this.options.generateResourceKey)) as string }; // 原图缓存 allCacheInfo.dataCacheInfo = { - key: SparkMD5.hashBinary(this.options.generateDataKey), - path: this.mDiskCacheProxy.getCachePath() + SparkMD5.hashBinary(this.options.generateDataKey) + key: SparkMD5.hashBinary(this.options.generateDataKey) as string, + path: (this.mDiskCacheProxy.getCachePath() + SparkMD5.hashBinary(this.options.generateDataKey)) as string } this.options.allCacheInfoCallback.callback(allCacheInfo) } diff --git a/imageknife/src/main/ets/components/imageknife/utils/svg/SVGParseImpl.ets b/imageknife/src/main/ets/components/imageknife/utils/svg/SVGParseImpl.ets index 9ffbe7d..2559c59 100644 --- a/imageknife/src/main/ets/components/imageknife/utils/svg/SVGParseImpl.ets +++ b/imageknife/src/main/ets/components/imageknife/utils/svg/SVGParseImpl.ets @@ -19,6 +19,13 @@ import {Size} from '../../RequestOption' export class SVGParseImpl implements IParseSvg{ parseSvg(imageinfo: ArrayBuffer,size?:Size): Promise{ 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); } } \ No newline at end of file