diff --git a/ETSUI/TransitionAnimation/entry/src/main/ets/pages/page/CustomTransition2.ets b/ETSUI/TransitionAnimation/entry/src/main/ets/pages/page/CustomTransition2.ets index b18dcec06eb521c975dfa004de484524469c9c01..f68cf913aa27d03cc72f20d1a96a3dda364b885e 100644 --- a/ETSUI/TransitionAnimation/entry/src/main/ets/pages/page/CustomTransition2.ets +++ b/ETSUI/TransitionAnimation/entry/src/main/ets/pages/page/CustomTransition2.ets @@ -38,14 +38,18 @@ struct CustomTransition2 { pageTransition() { // 页面入场组件: 进场过程中会逐帧触发onEnter回调,入参为动效的归一化进度(0% -- 100%) PageTransitionEnter({ duration: 800, curve: Curve.Smooth }) - .onEnter((type: RouteType, progress: number) => { - this.myProgress = progress // 页面入场时myProgress从0变化到1 + .onEnter((type?: RouteType, progress?: number) => { + if(progress !== undefined){ + this.myProgress = progress // 页面入场时myProgress从0变化到1 + } }) // 页面退场组件: 进场过程中会逐帧触发onExit回调,入参为动效的归一化进度(0% -- 100%) PageTransitionExit({ duration: 1000, curve: Curve.Smooth }) - .onExit((type: RouteType, progress: number) => { - this.myProgress = 1 - progress // 页面退场式myProgress从1变化到0 + .onExit((type?: RouteType, progress?: number) => { + if(progress !== undefined){ + this.myProgress = 1 - progress // 页面退场式myProgress从1变化到0 + } }) } } \ No newline at end of file diff --git a/ETSUI/TransitionAnimation/entry/src/main/ets/pages/share/ShareItem.ets b/ETSUI/TransitionAnimation/entry/src/main/ets/pages/share/ShareItem.ets index 3235da9f3a040a2f75a257ddd66e9d5cce447955..f6e2f173e1e96616ec0ad8804724b1396ee86757 100644 --- a/ETSUI/TransitionAnimation/entry/src/main/ets/pages/share/ShareItem.ets +++ b/ETSUI/TransitionAnimation/entry/src/main/ets/pages/share/ShareItem.ets @@ -33,7 +33,7 @@ class BasicDataSource implements IDataSource { return 0 } - public getData(index: number) { + public getData(index: number):undefined | Resource{ return undefined } @@ -51,31 +51,31 @@ class BasicDataSource implements IDataSource { } notifyDataReload() { - this.listeners.forEach(listener => { + this.listeners.forEach((listener:DataChangeListener) => { listener.onDataReloaded() }) } notifyDataAdd(index: number) { - this.listeners.forEach(listener => { + this.listeners.forEach((listener:DataChangeListener) => { listener.onDataAdd(index) }) } notifyDataChange(index: number) { - this.listeners.forEach(listener => { + this.listeners.forEach((listener:DataChangeListener) => { listener.onDataChange(index) }) } notifyDataDelete(index: number) { - this.listeners.forEach(listener => { + this.listeners.forEach((listener:DataChangeListener) => { listener.onDataDelete(index) }) } notifyDataMove(from: number, to: number) { - this.listeners.forEach(listener => { + this.listeners.forEach((listener:DataChangeListener) => { listener.onDataMove(from, to) }) } @@ -88,7 +88,7 @@ class MyDataSource extends BasicDataSource { return this.dataArray.length } - public getData(index: number) { + public getData(index: number) :undefined | Resource{ return this.dataArray[index] } @@ -102,7 +102,7 @@ class MyDataSource extends BasicDataSource { this.notifyDataAdd(this.dataArray.length - 1) } - public replaceData(result: any[]) { + public replaceData(result:Resource[]) { this.dataArray = result } } @@ -122,12 +122,14 @@ struct ShareItem { .textAlign(TextAlign.Center) .margin(10) Grid() { - LazyForEach(this.info, (item, index) => { + LazyForEach(this.info, (item: MyDataSource, index?:number) => { GridItem() { - Image(item) - .width(120) - .aspectRatio(1) - .sharedTransition(index.toString(), { duration: 600, curve: Curve.Smooth, delay: 100 }) + if(index !== undefined){ + Image(item) + .width(120) + .aspectRatio(1) + .sharedTransition(index.toString(), { duration: 600, curve: Curve.Smooth, delay: 100 }) + } } .padding(10) .backgroundColor('#F5F5F5') @@ -140,7 +142,7 @@ struct ShareItem { } }) }) - }, item => JSON.stringify(item)) + }, (item: MyDataSource) => JSON.stringify(item)) } .columnsTemplate('1fr 1fr 1fr') .columnsGap(10) diff --git a/ETSUI/TransitionAnimation/entry/src/main/ets/pages/share/SharePage.ets b/ETSUI/TransitionAnimation/entry/src/main/ets/pages/share/SharePage.ets index 2c5de8ae6a855fa83b02b5a516e2596ca99bbe78..fd23c873e640df880a23e34e9a057a4991eeb146 100644 --- a/ETSUI/TransitionAnimation/entry/src/main/ets/pages/share/SharePage.ets +++ b/ETSUI/TransitionAnimation/entry/src/main/ets/pages/share/SharePage.ets @@ -16,10 +16,15 @@ import router from '@ohos.router' import TitleBar from '../../common/TitleBar' import { SHARE_IMAGES } from './ShareItem' +interface Params extends Object{ + index: number +} + + @Entry @Component struct SharePage { - private index: number = router.getParams()['index'] + private index: number = (router.getParams() as Params).index build() { Column() { diff --git a/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/test/Ability.test.ets b/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100644 index 675703dceca9d362fc1c820e2b8968cd7d086002..0000000000000000000000000000000000000000 --- a/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022 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 hilog from '@ohos.hilog' -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' - -export default function abilityTest() { - describe('ActsAbilityTest', function () { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(function () { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }) - beforeEach(function () { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }) - afterEach(function () { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }) - afterAll(function () { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }) - it('assertContain', 0, function () { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'it begin') - let a = 'abc' - let b = 'b' - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b) - expect(a).assertEqual(a) - }) - }) -} \ No newline at end of file diff --git a/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/test/List.test.ets b/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index 7e05ea60952f76d30ba3268f238352215f062110..0000000000000000000000000000000000000000 --- a/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 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 abilityTest from './Ability.test' - -export default function testsuite() { - abilityTest() -} \ No newline at end of file diff --git a/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/testability/TestAbility.ets b/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/testability/TestAbility.ets deleted file mode 100644 index c400b428b2058d8a4c1919fdeed93bc307a67670..0000000000000000000000000000000000000000 --- a/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/testability/TestAbility.ets +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2022 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 hilog from '@ohos.hilog' -import Ability from '@ohos.application.Ability' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' -import { Hypium } from '@ohos/hypium' -import testsuite from '../test/List.test' -import Window from '@ohos.window' - -export default class TestAbility extends Ability { - onCreate(want, launchParam) { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - 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 - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var abilityDelegatorArguments: any - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!') - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - } - - onDestroy() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy') - } - - onWindowStageCreate(windowStage: Window.WindowStage) { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate') - windowStage.loadContent('testability/pages/Index', (err, data) => { - if (err.code) { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR) - hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '') - return - } - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', - JSON.stringify(data) ?? '') - }) - } - - onWindowStageDestroy() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy') - } - - onForeground() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground') - } - - onBackground() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground') - } -} \ No newline at end of file diff --git a/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/testability/pages/Index.ets b/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/testability/pages/Index.ets deleted file mode 100644 index 7bdfcfcf3943f76b1f47f763f0560d617ddb0dba..0000000000000000000000000000000000000000 --- a/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/testability/pages/Index.ets +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022 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 hilog from '@ohos.hilog' - -@Entry -@Component -struct Index { - aboutToAppear() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear') - } - - @State message: string = 'Hello World' - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('next page') - .fontSize(20) - .fontWeight(FontWeight.Bold) - } - .type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .width('35%') - .height('5%') - .onClick(() => { - }) - } - .width('100%') - } - .height('100%') - } -} \ No newline at end of file diff --git a/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts deleted file mode 100644 index 14767fdacb742db467f82739f89965c85a423e60..0000000000000000000000000000000000000000 --- a/ETSUI/TransitionAnimation/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2022 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 hilog from '@ohos.hilog' -import TestRunner from '@ohos.application.testRunner' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' - -var abilityDelegator = undefined -var abilityDelegatorArguments = undefined - -function translateParamsToString(parameters) { - const keySet = new Set([ - '-s class', '-s notClass', '-s suite', '-s it', - '-s level', '-s testType', '-s size', '-s timeout', - '-s dryRun' - ]) - let targetParams = '' - for (const key in parameters) { - if (keySet.has(key)) { - targetParams = `${targetParams} ${key} ${parameters[key]}` - } - } - return targetParams.trim() -} - -async function onAbilityCreateCallback() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback') -} - -async function addAbilityMonitorCallback(err: any) { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '') -} - -export default class OpenHarmonyTestRunner implements TestRunner { - constructor() { - } - - onPrepare() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ') - } - - async onRun() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run') - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' - let lMonitor = { - abilityName: testAbilityName, - onAbilityCreate: onAbilityCreateCallback, - } - abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) - var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName - cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) - var debug = abilityDelegatorArguments.parameters['-D'] - if (debug == 'true') { - cmd += ' -D' - } - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd) - abilityDelegator.executeShellCommand(cmd, - (err: any, d: any) => { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '') - hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '') - hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '') - }) - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end') - } -} \ No newline at end of file diff --git a/ETSUI/TransitionAnimation/entry/src/ohosTest/module.json5 b/ETSUI/TransitionAnimation/entry/src/ohosTest/module.json5 deleted file mode 100644 index fd36ba53c20316b267de39f8dfd0e2063ba5eda1..0000000000000000000000000000000000000000 --- a/ETSUI/TransitionAnimation/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022 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. - */ - -{ - "module": { - "name": "entry_test", - "type": "feature", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "phone" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntrance": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "visible": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} diff --git a/ETSUI/TransitionAnimation/entry/src/ohosTest/resources/base/element/color.json b/ETSUI/TransitionAnimation/entry/src/ohosTest/resources/base/element/color.json deleted file mode 100644 index 3c712962da3c2751c2b9ddb53559afcbd2b54a02..0000000000000000000000000000000000000000 --- a/ETSUI/TransitionAnimation/entry/src/ohosTest/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/ETSUI/TransitionAnimation/entry/src/ohosTest/resources/base/element/string.json b/ETSUI/TransitionAnimation/entry/src/ohosTest/resources/base/element/string.json deleted file mode 100644 index 65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c..0000000000000000000000000000000000000000 --- a/ETSUI/TransitionAnimation/entry/src/ohosTest/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_test_desc", - "value": "test ability description" - }, - { - "name": "TestAbility_desc", - "value": "the test ability" - }, - { - "name": "TestAbility_label", - "value": "test label" - } - ] -} \ No newline at end of file diff --git a/ETSUI/TransitionAnimation/entry/src/ohosTest/resources/base/media/icon.png b/ETSUI/TransitionAnimation/entry/src/ohosTest/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 Binary files a/ETSUI/TransitionAnimation/entry/src/ohosTest/resources/base/media/icon.png and /dev/null differ diff --git a/ETSUI/TransitionAnimation/entry/src/ohosTest/resources/base/profile/test_pages.json b/ETSUI/TransitionAnimation/entry/src/ohosTest/resources/base/profile/test_pages.json deleted file mode 100644 index b7e7343cacb32ce982a45e76daad86e435e054fe..0000000000000000000000000000000000000000 --- a/ETSUI/TransitionAnimation/entry/src/ohosTest/resources/base/profile/test_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "testability/pages/Index" - ] -} diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/common/PlayList.ets b/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/common/PlayList.ets index 5e738fcfdfdb6ab9c7b0f0b2a3e7c095f76563cc..7fad28d20364a3f37d254d33dc2b2137cfea13d0 100644 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/common/PlayList.ets +++ b/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/common/PlayList.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { songList } from '../model/SongList' +import { songList, SongListType } from '../model/SongList' import MyDataSource from '../model/SongModule' @Component @@ -79,7 +79,7 @@ export default struct PlayList { this.PlayAll() Scroll() { List() { - LazyForEach(new MyDataSource(songList), item => { + LazyForEach(new MyDataSource(songList), (item:SongListType) => { ListItem() { Column() { this.SongItem(item.title, item.label, item.singer) @@ -89,7 +89,7 @@ export default struct PlayList { .opacity(0.1) }.padding({ left: 14, right: 14 }) } - }, item => item.id) + }, (item:SongListType) => item.id.toString()) } .width('100%') .height('100%') diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/common/PlayListCover.ets b/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/common/PlayListCover.ets index c99ee0e6f83cab715b7d0628b892ed641f4ea3e1..1df22f8f48fbfebb5d1a50a8aa6fc48e7266d264 100644 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/common/PlayListCover.ets +++ b/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/common/PlayListCover.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { optionList } from '../model/SongList' +import { optionList, OptionListType } from '../model/SongList' @Component export default struct PlayListCover { @@ -71,7 +71,7 @@ export default struct PlayListCover { @Builder CoverOptions() { Flex({ justifyContent: FlexAlign.SpaceBetween }) { - ForEach(optionList, item => { + ForEach(optionList, (item:OptionListType) => { Column({ space: 4 }) { Image(item.image).height(30).width(30) Text(item.text) diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/model/MediaData.ets b/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/model/MediaData.ets index 67cf961c3ec93a00561ae52975485a8205991502..34b47848ff128e1fa8d7c51275bbdc0efde398fa 100644 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/model/MediaData.ets +++ b/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/model/MediaData.ets @@ -14,12 +14,15 @@ */ import mediaQuery from '@ohos.mediaquery' +interface MediaQueryResult { + matches: boolean +} export default class BreakpointSystem { private currentBreakpoint: string = 'md' - private smListener: mediaQuery.MediaQueryListener - private mdListener: mediaQuery.MediaQueryListener - private lgListener: mediaQuery.MediaQueryListener + private smListener: mediaQuery.MediaQueryListener = {} as mediaQuery.MediaQueryListener + private mdListener: mediaQuery.MediaQueryListener = {} as mediaQuery.MediaQueryListener + private lgListener: mediaQuery.MediaQueryListener = {} as mediaQuery.MediaQueryListener private updateCurrentBreakpoint(breakpoint: string) { if (this.currentBreakpoint !== breakpoint) { @@ -28,21 +31,21 @@ export default class BreakpointSystem { } } - private isBreakpointSM = (mediaQueryResult) => { + private isBreakpointSM = (mediaQueryResult:MediaQueryResult) => { if (mediaQueryResult.matches) { this.updateCurrentBreakpoint('sm') AppStorage.Set('fontSize', 14) AppStorage.Set('coverMargin', 10) } } - private isBreakpointMD = (mediaQueryResult) => { + private isBreakpointMD = (mediaQueryResult:MediaQueryResult) => { if (mediaQueryResult.matches) { this.updateCurrentBreakpoint('md') AppStorage.Set('fontSize', 16) AppStorage.Set('coverMargin', 30) } } - private isBreakpointLG = (mediaQueryResult) => { + private isBreakpointLG = (mediaQueryResult:MediaQueryResult) => { if (mediaQueryResult.matches) { this.updateCurrentBreakpoint('lg') AppStorage.Set('fontSize', 18) diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/model/SongList.ets b/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/model/SongList.ets index 133711c3f41bd63d978501ea0b51f02ca8797338..cf6917784e9dc1a7bc0535be2733cac978dcaaca 100644 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/model/SongList.ets +++ b/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/model/SongList.ets @@ -12,8 +12,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +interface SongListType { + id: number + title: string + singer: string + label: Resource +} +interface OptionListType { + image:Resource + text: Resource | string +} -const songList = [ +const songList:SongListType[] = [ { id: 1, title: '不知道', singer: '小碗你好', label: $r('app.media.ic_vip') }, { id: 2, title: '歌名你好', singer: '张三-你好我好都好', label: $r('app.media.ic_SQ') }, { id: 3, title: '还是歌名', singer: '不知道你是谁', label: $r('app.media.ic_SQ') }, @@ -39,11 +49,11 @@ const songList = [ { id: 24, title: '安心安心', singer: '小安安', label: $r('app.media.ic_SQ') }, { id: 25, title: 'Notebook', singer: '小安安', label: $r('app.media.ic_SQ') } ] -const optionList = [ +const optionList:OptionListType[] = [ { image: $r('app.media.ic_collect'), text: '999+' }, { image: $r('app.media.ic_download'), text: $r('app.string.download') }, { image: $r("app.media.icon_comments"), text: $r('app.string.comment') }, { image: $r('app.media.icon_share'), text: $r('app.string.share') } ] -export { songList, optionList } \ No newline at end of file +export { songList, optionList, OptionListType, SongListType } \ No newline at end of file diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/model/SongModule.ets b/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/model/SongModule.ets index c030c27c43067e84733077e1bd077c83a6c245c4..d6faa71c792feefaf97165a412c8ace9740ce4e0 100644 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/model/SongModule.ets +++ b/MultiDeviceAppDev/MusicAlbum/entry/src/main/ets/model/SongModule.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -type SongItem = { +interface SongItem { id: number, title: string, singer: string, diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/test/Ability.test.ets b/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100644 index 675703dceca9d362fc1c820e2b8968cd7d086002..0000000000000000000000000000000000000000 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022 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 hilog from '@ohos.hilog' -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' - -export default function abilityTest() { - describe('ActsAbilityTest', function () { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(function () { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }) - beforeEach(function () { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }) - afterEach(function () { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }) - afterAll(function () { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }) - it('assertContain', 0, function () { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'it begin') - let a = 'abc' - let b = 'b' - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b) - expect(a).assertEqual(a) - }) - }) -} \ No newline at end of file diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/test/List.test.ets b/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index 7e05ea60952f76d30ba3268f238352215f062110..0000000000000000000000000000000000000000 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 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 abilityTest from './Ability.test' - -export default function testsuite() { - abilityTest() -} \ No newline at end of file diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/testability/TestAbility.ets b/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/testability/TestAbility.ets deleted file mode 100644 index aec33414f0292acf62b7e566bad6a6f91e45f86a..0000000000000000000000000000000000000000 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/testability/TestAbility.ets +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2022 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 hilog from '@ohos.hilog' -import Ability from '@ohos.application.Ability' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' -import { Hypium } from '@ohos/hypium' -import testsuite from '../test/List.test' -import Window from '@ohos.window' - -export default class TestAbility extends Ability { - onCreate(want, launchParam) { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - 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 - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var abilityDelegatorArguments: any - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!') - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - } - - onDestroy() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy') - } - - onWindowStageCreate(windowStage: Window.WindowStage) { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate') - windowStage.loadContent('testability/pages/Index', (err, data) => { - if (err.code) { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR) - hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '') - return - } - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', - JSON.stringify(data) ?? '') - }) - } - - onWindowStageDestroy() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy') - } - - onForeground() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground') - } - - onBackground() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground') - } -} \ No newline at end of file diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/testability/pages/Index.ets b/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/testability/pages/Index.ets deleted file mode 100644 index db9979b60e7dfe437a9a0e9fcd4668151dd8a261..0000000000000000000000000000000000000000 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/testability/pages/Index.ets +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022 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 hilog from '@ohos.hilog' - -@Entry -@Component -struct Index { - aboutToAppear() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear') - } - - @State message: string = 'Hello World' - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('next page') - .fontSize(20) - .fontWeight(FontWeight.Bold) - } - .type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .width('35%') - .height('5%') - .onClick(() => { - }) - } - .width('100%') - } - .height('100%') - } -} \ No newline at end of file diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts deleted file mode 100644 index c333570074880fc4f68af1b9089f2bba3488a2d4..0000000000000000000000000000000000000000 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2022 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 hilog from '@ohos.hilog' -import TestRunner from '@ohos.application.testRunner' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' - -var abilityDelegator = undefined -var abilityDelegatorArguments = undefined - -function translateParamsToString(parameters) { - const keySet = new Set([ - '-s class', '-s notClass', '-s suite', '-s it', - '-s level', '-s testType', '-s size', '-s timeout', - '-s dryRun' - ]) - let targetParams = '' - for (const key in parameters) { - if (keySet.has(key)) { - targetParams = `${targetParams} ${key} ${parameters[key]}` - } - } - return targetParams.trim() -} - -async function onAbilityCreateCallback() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback') -} - -async function addAbilityMonitorCallback(err: any) { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '') -} - -export default class OpenHarmonyTestRunner implements TestRunner { - constructor() { - } - - onPrepare() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ') - } - - async onRun() { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run') - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' - let lMonitor = { - abilityName: testAbilityName, - onAbilityCreate: onAbilityCreateCallback, - }; - abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) - var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName - cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) - var debug = abilityDelegatorArguments.parameters['-D'] - if (debug == 'true') { - cmd += ' -D' - } - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd) - abilityDelegator.executeShellCommand(cmd, - (err: any, d: any) => { - hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO) - hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '') - hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '') - hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '') - }) - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end') - } -} \ No newline at end of file diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/module.json5 b/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/module.json5 deleted file mode 100644 index fd36ba53c20316b267de39f8dfd0e2063ba5eda1..0000000000000000000000000000000000000000 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022 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. - */ - -{ - "module": { - "name": "entry_test", - "type": "feature", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "phone" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntrance": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "visible": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/resources/base/element/color.json b/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/resources/base/element/color.json deleted file mode 100644 index 3c712962da3c2751c2b9ddb53559afcbd2b54a02..0000000000000000000000000000000000000000 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/resources/base/element/string.json b/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/resources/base/element/string.json deleted file mode 100644 index 65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c..0000000000000000000000000000000000000000 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_test_desc", - "value": "test ability description" - }, - { - "name": "TestAbility_desc", - "value": "the test ability" - }, - { - "name": "TestAbility_label", - "value": "test label" - } - ] -} \ No newline at end of file diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/resources/base/media/icon.png b/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 Binary files a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/resources/base/media/icon.png and /dev/null differ diff --git a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/resources/base/profile/test_pages.json b/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/resources/base/profile/test_pages.json deleted file mode 100644 index b7e7343cacb32ce982a45e76daad86e435e054fe..0000000000000000000000000000000000000000 --- a/MultiDeviceAppDev/MusicAlbum/entry/src/ohosTest/resources/base/profile/test_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "testability/pages/Index" - ] -} diff --git a/media/Image/entry/src/main/ets/pages/Index.ets b/media/Image/entry/src/main/ets/pages/Index.ets index 6acb9af81c98cf54cbeb9d3b43fdc1f664efd0a3..7bd928055859f6ed9a2784e25b144c4441aad661 100644 --- a/media/Image/entry/src/main/ets/pages/Index.ets +++ b/media/Image/entry/src/main/ets/pages/Index.ets @@ -16,9 +16,13 @@ import router from '@ohos.router' import image from '@ohos.multimedia.image' import { logger } from '@ohos/photomodify' - +import {terminateSelf} from '../utils/utils' const TAG: string = 'Index' + +interface IsShowCamera extends Object{ + isShowCamera:boolean +} @Entry @Component struct Index { @@ -26,16 +30,13 @@ struct Index { @State isShowCamera: boolean = false @State isShowComment: boolean = true - terminateSelf(context: any) { - context.terminateSelf() - } aboutToAppear() { logger.info(TAG, 'enter aboutToAppear') - if (AppStorage.Get('pixelMaps')) { - this.pixelMaps.push(undefined) + if (AppStorage.Get('pixelMaps') as boolean) { + this.pixelMaps.push({} as image.PixelMap) } - if (router.getParams() && router.getParams()['isShowCamera']) { + if (router.getParams() && (router.getParams() as IsShowCamera).isShowCamera) { this.isShowCamera = true } } @@ -49,7 +50,7 @@ struct Index { .objectFit(ImageFit.Contain) .onClick(() => { let context = getContext(this) - this.terminateSelf(context) + terminateSelf(context) }) Text($r('app.string.publish_comments')) @@ -100,13 +101,13 @@ struct Index { if (this.isShowCamera) { Grid() { - ForEach(this.pixelMaps, (item, index) => { - GridItem() { - if (index < this.pixelMaps.length - 1) { - Image(item) - .width('100%') - .height(100) - .borderRadius(10) + ForEach(this.pixelMaps, (item:image.PixelMap,index?:number) => { + GridItem() { + if (index !==undefined && (index < this.pixelMaps.length - 1)) { + Image(item) + .width('100%') + .height(100) + .borderRadius(10) } else { Column() { diff --git a/media/Image/entry/src/main/ets/utils/utils.ts b/media/Image/entry/src/main/ets/utils/utils.ts new file mode 100644 index 0000000000000000000000000000000000000000..ea9a1531b8f511894b9f4ef4ad3b958057480efe --- /dev/null +++ b/media/Image/entry/src/main/ets/utils/utils.ts @@ -0,0 +1,3 @@ +export function terminateSelf(context:any) { + context.terminateSelf() +} \ No newline at end of file diff --git a/media/Image/entry/src/ohosTest/ets/Application/AbilityStage.ts b/media/Image/entry/src/ohosTest/ets/Application/AbilityStage.ts deleted file mode 100644 index be959bc43e37bf4dc1339541bcfb92df8680c1aa..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/ets/Application/AbilityStage.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2022 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 AbilityStage from "@ohos.application.AbilityStage" - -export default class TestAbilityStage extends AbilityStage { - onCreate() { - console.log("[Demo] TestAbilityStage onCreate") - } -} diff --git a/media/Image/entry/src/ohosTest/ets/Application/TestAbilityStage.ts b/media/Image/entry/src/ohosTest/ets/Application/TestAbilityStage.ts deleted file mode 100644 index 8fb2fb85202833e6bc71a99d86e5418c1029b729..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/ets/Application/TestAbilityStage.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2022 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 AbilityStage from '@ohos.application.AbilityStage' -import { logger } from '../../../../../photomodify/src/main/ets/components/util/Logger' - -const TAG: string = 'TestAbilityStage' - -export default class TestAbilityStage extends AbilityStage { - onCreate() { - logger.info(TAG, `[Demo] TestAbilityStage onCreate`) - } -} \ No newline at end of file diff --git a/media/Image/entry/src/ohosTest/ets/module.json5.ftl b/media/Image/entry/src/ohosTest/ets/module.json5.ftl deleted file mode 100644 index 57569df303042010dcf0648ec4818dd40ea4caf5..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/ets/module.json5.ftl +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022 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. - */ - -{ - "module": { - "name": "${moduleName}_test", - "type": "feature", - "srcEntrance": "./ets/Application/AbilityStage.ts", - "description": "$string:entry_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [${deviceTypes ?replace("[","")?replace("]","")}], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "uiSyntax": "ets", - "abilities": [ - { - "name": "TestAbility", - "srcEntrance": "./ets/TestAbility/TestAbility.ts", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "visible": true, - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} diff --git a/media/Image/entry/src/ohosTest/ets/test/Ability.test.ets b/media/Image/entry/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100644 index 8abf7f2f44c0e56110df8c09b2524a4ca37bc993..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,35 +0,0 @@ -import hilog from '@ohos.hilog'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' - -export default function abilityTest() { - describe('ActsAbilityTest', function () { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(function () { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }) - beforeEach(function () { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }) - afterEach(function () { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }) - afterAll(function () { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }) - it('assertContain',0, function () { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); - let a = 'abc' - let b = 'b' - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b) - expect(a).assertEqual(a) - }) - }) -} \ No newline at end of file diff --git a/media/Image/entry/src/ohosTest/ets/test/List.test.ets b/media/Image/entry/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index f7a71bf395c801c8818b06f2a486660ed9f25eee..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 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 appTest from './app.test' - -export default function testsuite() { - appTest() -} diff --git a/media/Image/entry/src/ohosTest/ets/test/app.test.ets b/media/Image/entry/src/ohosTest/ets/test/app.test.ets deleted file mode 100644 index b252103856315c6556f40c65bfefa847283ecd59..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/ets/test/app.test.ets +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2022 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -import { UiDriver, BY, UiComponent, MatchPattern } from '@ohos.uitest' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' -import featureAbility from '@ohos.ability.featureAbility' -import hilog from '@ohos.hilog' - -const TAG = '[Sample_Image]' -const DOMAIN = 0xF811 -const BUNDLE = 'Image_' - -export default function appTest() { - describe('appTest', function () { - it(BUNDLE + 'StartAbility_001', 0, async function (done) { - hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 begin') - let want = { - bundleName: "ohos.samples.image", - abilityName: "MainAbility" - } - var abilityDelegator: any - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - await abilityDelegator.startAbility(want, (err, data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001,err.code:' + err.code) - expect(0).assertEqual(err.code) - done() - hilog.info(DOMAIN, TAG, BUNDLE + 'StartAbility_001 end') - }) - }) - - /** - * 进入预置相机进行拍照 - */ - it(BUNDLE + 'CameraFunction_001', 0, async function () { - hilog.info(DOMAIN, TAG, BUNDLE + 'CameraFunction_001 begin') - let driver = await UiDriver.create() - await driver.delayMs(1000) - hilog.info(DOMAIN, TAG, BUNDLE + 'CameraFunction_001 enter') - await driver.assertComponentExist(BY.text('允许', MatchPattern.CONTAINS)) - let btnEnter = await driver.findComponent(BY.text('允许', MatchPattern.CONTAINS)) - await btnEnter.click() - await driver.delayMs(2000) - hilog.info(DOMAIN, TAG, BUNDLE + 'CameraFunction_001 end') - }) - }) -} \ No newline at end of file diff --git a/media/Image/entry/src/ohosTest/ets/testability/TestAbility.ets b/media/Image/entry/src/ohosTest/ets/testability/TestAbility.ets deleted file mode 100644 index e3f6e911d3fffba1e1795c60ed1ee4db15b386fd..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/ets/testability/TestAbility.ets +++ /dev/null @@ -1,48 +0,0 @@ -import UIAbility from '@ohos.app.ability.UIAbility'; -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -import hilog from '@ohos.hilog'; -import { Hypium } from '@ohos/hypium'; -import testsuite from '../test/List.test'; -import window from '@ohos.window'; - -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 - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var abilityDelegatorArguments: any - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - } - - 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) ?? ''); - }); - } - - onWindowStageDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); - } - - onForeground() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); - } - - onBackground() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); - } -} \ No newline at end of file diff --git a/media/Image/entry/src/ohosTest/ets/testability/TestAbility.ts b/media/Image/entry/src/ohosTest/ets/testability/TestAbility.ts deleted file mode 100644 index 6f7f80c18f9d3b1981ee1ff3845950770080392e..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/ets/testability/TestAbility.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2022 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 Ability from '@ohos.application.Ability' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' -import { Hypium } from '@ohos/hypium' -import testsuite from '../test/List.test' - -export default class TestAbility extends Ability { - onCreate(want, launchParam) { - console.log('TestAbility onCreate') - } - - onDestroy() { - console.log('TestAbility onDestroy') - } - - onWindowStageCreate(windowStage) { - console.log('TestAbility onWindowStageCreate') - windowStage.loadContent("TestAbility/pages/index", (err, data) => { - if (err.code) { - console.error('Failed to load the content. Cause:' + JSON.stringify(err)) - return - } - console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) - }) - - globalThis.abilityContext = this.context - var abilityDelegator: any - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var abilityDelegatorArguments: any - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - console.info('start run testcase!!!') - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - } - - onWindowStageDestroy() { - console.log('TestAbility onWindowStageDestroy') - } - - onForeground() { - console.log('TestAbility onForeground') - } - - onBackground() { - console.log('TestAbility onBackground') - } -} \ No newline at end of file diff --git a/media/Image/entry/src/ohosTest/ets/testability/pages/index.ets b/media/Image/entry/src/ohosTest/ets/testability/pages/index.ets deleted file mode 100644 index 7d93696fbcc27bfa21f70894e650da12023734ca..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/ets/testability/pages/index.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022 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 router from '@ohos.router' - -@Entry -@Component -struct Index { - aboutToAppear() { - console.info('TestAbility index aboutToAppear') - } - - @State message: string = 'Hello World' - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('next page') - .fontSize(20) - .fontWeight(FontWeight.Bold) - } - .type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .width('35%') - .height('5%') - .onClick(() => { - }) - } - .width('100%') - } - .height('100%') - } -} \ No newline at end of file diff --git a/media/Image/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/media/Image/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts deleted file mode 100644 index 7b0f409c3e76cdbfac374a5fed8463a5d6ec9834..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2022 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 TestRunner from '@ohos.application.testRunner' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' - -var abilityDelegator = undefined -var abilityDelegatorArguments = undefined - -function translateParamsToString(parameters) { - const keySet = new Set([ - '-s class', '-s notClass', '-s suite', '-s it', - '-s level', '-s testType', '-s size', '-s timeout', - '-s dryRun' - ]) - let targetParams = '' - for (const key in parameters) { - if (keySet.has(key)) { - targetParams = `${targetParams} ${key} ${parameters[key]}` - } - } - return targetParams.trim() -} - -async function onAbilityCreateCallback() { - console.log("onAbilityCreateCallback") -} - -async function addAbilityMonitorCallback(err: any) { - console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) -} - -export default class OpenHarmonyTestRunner implements TestRunner { - constructor() { - } - - onPrepare() { - console.info("OpenHarmonyTestRunner OnPrepare ") - } - - async onRun() { - console.log('OpenHarmonyTestRunner onRun run') - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' - let lMonitor = { - abilityName: testAbilityName, - onAbilityCreate: onAbilityCreateCallback, - } - abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) - var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName - cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) - var debug = abilityDelegatorArguments.parameters["-D"] - if (debug == 'true') { - cmd += ' -D' - } - console.info('cmd : ' + cmd) - abilityDelegator.executeShellCommand(cmd, - (err: any, d: any) => { - console.info('executeShellCommand : err : ' + JSON.stringify(err)) - console.info('executeShellCommand : data : ' + d.stdResult) - console.info('executeShellCommand : data : ' + d.exitCode) - }) - console.info('OpenHarmonyTestRunner onRun end') - } -} \ No newline at end of file diff --git a/media/Image/entry/src/ohosTest/module.json5 b/media/Image/entry/src/ohosTest/module.json5 deleted file mode 100644 index 187f19d5b8dfc89ba6cbd5c98b8317da0155eb16..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022 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. - */ - -{ - "module": { - "name": "entry_test", - "type": "feature", - "srcEntrance": "./ets/TestAbility/TestAbility.ts", - "description": "$string:entry_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "uiSyntax": "ets", - "abilities": [ - { - "name": "TestAbility", - "srcEntrance": "./ets/TestAbility/TestAbility.ts", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:white", - "visible": true, - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} diff --git a/media/Image/entry/src/ohosTest/resources/base/element/color.json b/media/Image/entry/src/ohosTest/resources/base/element/color.json deleted file mode 100644 index 1bbc9aa9617e97c45440e1d3d66afc1154837012..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "white", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/media/Image/entry/src/ohosTest/resources/base/element/string.json b/media/Image/entry/src/ohosTest/resources/base/element/string.json deleted file mode 100644 index 36d4230c53e9f5a07ae343ad8dc9808341975e3b..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "entry_test_desc", - "value": "test ability description" - }, - { - "name": "TestAbility_desc", - "value": "the test ability" - }, - { - "name": "TestAbility_label", - "value": "test label" - } - ] -} \ No newline at end of file diff --git a/media/Image/entry/src/ohosTest/resources/base/media/icon.png b/media/Image/entry/src/ohosTest/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 Binary files a/media/Image/entry/src/ohosTest/resources/base/media/icon.png and /dev/null differ diff --git a/media/Image/entry/src/ohosTest/resources/base/profile/test_pages.json b/media/Image/entry/src/ohosTest/resources/base/profile/test_pages.json deleted file mode 100644 index fcef82b4dfc18e28106ff9ecd1c8b48ec74d18a4..0000000000000000000000000000000000000000 --- a/media/Image/entry/src/ohosTest/resources/base/profile/test_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "TestAbility/pages/index" - ] -} diff --git a/media/Image/photomodify/src/main/ets/components/pages/ChoicePhoto.ets b/media/Image/photomodify/src/main/ets/components/pages/ChoicePhoto.ets index 0e65eb612064263b662c60bfde93f0a90b5da24b..48a6738dcaf32f23c5eefcb9b07ab658c93e38d2 100644 --- a/media/Image/photomodify/src/main/ets/components/pages/ChoicePhoto.ets +++ b/media/Image/photomodify/src/main/ets/components/pages/ChoicePhoto.ets @@ -23,20 +23,21 @@ const TAG: string = 'ChoicePhoto' @Component export struct ChoicePhoto { - @State whichShow: Array = [true, false] - @State medias: Array = [] - @State choiceShow: Array = [$r('app.string.choice_photo'), $r('app.string.choice_video')] - @State taskShow: Array = [$r('app.media.photo'), $r('app.media.video')] - @State textShow: Array = [$r('app.string.photograph'), $r('app.string.take_video')] - @State isShowChoices: Array = new Array(this.medias.length).fill(false) - @State @Watch('choiceChange') choiceMedias: Array = [] - @State mediaUris: Array = [] - @State isChoice: boolean = false - @State nextText: string = '' - @State isLand: boolean = false - private mediaLibraryInstance: mediaLibrary.MediaLibrary = mediaLibrary.getMediaLibrary(getContext(this) as any) + @State whichShow:boolean[] = [true, false] + @State medias:Array = [] + @State choiceShow:Array = [$r('app.string.choice_photo'), $r('app.string.choice_video')] + @State taskShow:Array = [$r('app.media.photo'), $r('app.media.video')] + @State textShow:Array = [$r('app.string.photograph'), $r('app.string.take_video')] + @State isShowChoices:Array = new Array(this.medias.length).fill(false) + @State @Watch('choiceChange') choiceMedias:Array = [] + @State mediaUris:Array = [] + @State isChoice:boolean = false + @State nextText:string = '' + @State isLand:boolean = false + private mediaLibraryInstance:mediaLibrary.MediaLibrary = mediaLibrary.getMediaLibrary(getContext(this)) private listener = mediaQuery.matchMediaSync('screen and (min-aspect-ratio: 1.5) or (orientation: landscape)') - onLand = (mediaQueryResult) => { + + onLand(mediaQueryResult:mediaQuery.MediaQueryResult) { if (mediaQueryResult.matches) { this.isLand = true } else { @@ -52,7 +53,8 @@ export struct ChoicePhoto { } } - @Builder showChoiceBuild(backGround: string, showNumber: number) { + @Builder + showChoiceBuild(backGround:string, showNumber:number) { Column() { Text(showNumber === 0 ? '' : `${showNumber}`) .fontSize(14) @@ -68,16 +70,16 @@ export struct ChoicePhoto { .backgroundColor(backGround) } - async getFileAssetsFromType(mediaType: mediaLibrary.MediaType) { + async getFileAssetsFromType(mediaType:mediaLibrary.MediaType) { logger.info(TAG, `getFileAssetsFromType`) - let context = getContext(this) as any + let context = getContext(this) as Context let mediaLibraryInstance = mediaLibrary.getMediaLibrary(context) if (!mediaLibraryInstance) { return } logger.info(TAG, `mediaLibraryInstance = ${JSON.stringify(mediaLibraryInstance)}`) let fileKeyObj = mediaLibrary.FileKey - let fetchOp = { + let fetchOp:mediaLibrary.MediaFetchOptions = { selections: `${fileKeyObj.MEDIA_TYPE}=?`, selectionArgs: [`${mediaType}`], } @@ -89,12 +91,12 @@ export struct ChoicePhoto { logger.info(TAG, `this.medias = ${JSON.stringify(this.medias)}`) } - convertContext(context: any) { + convertContext(context:Context):Context { return context } - async convertResourceToString(resource: Resource) { - return await this.convertContext(getContext(this)).resourceManager.getString(resource) + async convertResourceToString(resource:Resource):Promise { + return await this.convertContext(getContext(this)).resourceManager.getString(resource.id) } async aboutToAppear() { @@ -104,14 +106,14 @@ export struct ChoicePhoto { this.getFileAssetsFromType(mediaLibrary.MediaType.IMAGE) } - getMaxHeight() { + getMaxHeight():ConstraintSizeOptions { if (!this.isLand && this.isChoice) { return { maxHeight: '64%' } } else if (!this.isLand && !this.isChoice) { return { maxHeight: '75%' } } else if (this.isLand && this.isChoice) { return { maxHeight: '62%' } - } else if (this.isLand && !this.isChoice) { + } else { return { maxHeight: '73%' } } } @@ -150,7 +152,7 @@ export struct ChoicePhoto { if (this.isChoice === false) { return } - this.mediaUris = this.choiceMedias.map((item) => { + this.mediaUris = this.choiceMedias.map((item:mediaLibrary.FileAsset) => { return item.uri }) router.push({ @@ -167,37 +169,40 @@ export struct ChoicePhoto { Column() { Row() { - ForEach(this.choiceShow, (item, index) => { + ForEach(this.choiceShow, (item:Resource, index?:number) => { Column() { - Text(item) - .fontSize(20) - .fontWeight(500) - .fontColor(this.whichShow[index] === true ? '#0000000' : '#99182431') - .onClick(() => { - this.whichShow.fill(false) - if (this.whichShow.length > index) { - this.whichShow[index] = true - } - this.medias = [] - if (index == 0) { - this.getFileAssetsFromType(mediaLibrary.MediaType.IMAGE) - } else { - prompt.showDialog({ message: $r('app.string.user_tip') }) - this.choiceMedias = [] - this.isShowChoices = new Array(this.medias.length).fill(false) - } - }) - if (this.whichShow[index]) { - Divider() - .vertical(false) - .strokeWidth(3) - .color('#ffff0000') - .lineCap(LineCapStyle.Round) - .width('40%') - .margin({ top: 4 }) + if (index !== undefined) { + Text(item) + .fontSize(20) + .fontWeight(500) + .fontColor(this.whichShow[index] === true ? '#0000000' : '#99182431') + .onClick(() => { + this.whichShow.fill(false) + if (this.whichShow.length > index) { + if (index) { + this.whichShow[index] = true + } + } + this.medias = [] + if (index == 0) { + this.getFileAssetsFromType(mediaLibrary.MediaType.IMAGE) + } else { + prompt.showDialog({ message: $r('app.string.user_tip') }) + this.choiceMedias = [] + this.isShowChoices = new Array(this.medias.length).fill(false) + } + }) + if (this.whichShow[index]) { + Divider() + .vertical(false) + .strokeWidth(3) + .color('#ffff0000') + .lineCap(LineCapStyle.Round) + .width('40%') + .margin({ top: 4 }) + } } - } - .width('30%') + }.width('30%') }) } .margin({ top: 20 }) @@ -206,7 +211,7 @@ export struct ChoicePhoto { Scroll() { Column() { Grid() { - ForEach(this.medias, (item, index) => { + ForEach(this.medias, (item:mediaLibrary.FileAsset, index?:number) => { GridItem() { Stack({ alignContent: Alignment.TopEnd }) { Image(item.uri) @@ -214,8 +219,7 @@ export struct ChoicePhoto { .height('100%') .borderRadius(10) .objectFit(ImageFit.Fill) - - if (this.isShowChoices[index]) { + if (index !== undefined && this.isShowChoices[index]) { this.showChoiceBuild('#e92f4f', this.choiceMedias.indexOf(item) + 1) } else { this.showChoiceBuild('#ffb7b4b4', 0) @@ -224,22 +228,24 @@ export struct ChoicePhoto { .width('100%') .height('100%') .onClick(() => { - this.isShowChoices[index] = !this.isShowChoices[index] - if (this.isShowChoices[index]) { - if (this.choiceMedias.length > 5) { - prompt.showDialog({ message: $r('app.string.choice_number') }) - this.isShowChoices[index] = !this.isShowChoices[index] - return - } - this.choiceMedias.push(item) - } else { - if (this.choiceMedias.indexOf(item) != -1) { - this.choiceMedias.splice(this.choiceMedias.indexOf(item), 1) + if (index !== undefined) { + this.isShowChoices[index] = !this.isShowChoices[index] + if (this.isShowChoices[index]) { + if (this.choiceMedias.length > 5) { + prompt.showDialog({ message: $r('app.string.choice_number') }) + this.isShowChoices[index] = !this.isShowChoices[index] + return + } + this.choiceMedias.push(item) + } else { + if (this.choiceMedias.indexOf(item) != -1) { + this.choiceMedias.splice(this.choiceMedias.indexOf(item), 1) + } } } }) - } - .aspectRatio(1) + }.aspectRatio(1) + }) } .columnsTemplate('1fr 1fr 1fr 1fr') @@ -257,7 +263,7 @@ export struct ChoicePhoto { if (this.isChoice) { Grid() { - ForEach(this.choiceMedias, (item, index) => { + ForEach(this.choiceMedias, (item:mediaLibrary.FileAsset, index?:number) => { GridItem() { Stack({ alignContent: Alignment.TopEnd }) { Image(item.uri) @@ -269,12 +275,14 @@ export struct ChoicePhoto { .height(20) .margin({ top: 5, right: 5 }) .onClick(() => { - for (let i = 0;i < this.medias.length; i++) { - if (this.choiceMedias[index] && this.isShowChoices.length > i && this.medias[i] === this.choiceMedias[index]) { - this.isShowChoices[i] = false + if (index !== undefined) { + for (let i = 0;i < this.medias.length; i++) { + if (this.choiceMedias[index] && this.isShowChoices.length > i && this.medias[i] === this.choiceMedias[index]) { + this.isShowChoices[i] = false + } } + this.choiceMedias.splice(index, 1) } - this.choiceMedias.splice(index, 1) }) } .width('100%') @@ -298,18 +306,19 @@ export struct ChoicePhoto { } Row() { - ForEach(this.taskShow, (item, index) => { - Column() { - Image(item) - .width(30) - .height(30) + ForEach(this.taskShow, (item:Resource, index?:number) => { + if (index !== undefined) { + Column() { + Image(item) + .width(30) + .height(30) - Text(this.textShow[index]) - .fontSize(14) - .fontColor('#99182431') - .margin({ top: 2 }) + Text(this.textShow[index]) + .fontSize(14) + .fontColor('#99182431') + .margin({ top: 2 }) + }.width('50%') } - .width('50%') }) } .margin({ top: 8 }) diff --git a/media/Image/photomodify/src/main/ets/components/pages/EditPage.ets b/media/Image/photomodify/src/main/ets/components/pages/EditPage.ets index ddf525dcec41a6f663c6f259504b6bf2aa2ac1be..506db42f7b65e7a653705bee0d4ab4a50b94cbcc 100644 --- a/media/Image/photomodify/src/main/ets/components/pages/EditPage.ets +++ b/media/Image/photomodify/src/main/ets/components/pages/EditPage.ets @@ -18,47 +18,52 @@ import image from '@ohos.multimedia.image' import mediaLibrary from '@ohos.multimedia.mediaLibrary' import { logger } from '../util/Logger' -const TAG: string = 'EditPage' +const TAG:string = 'EditPage' + + +interface MediaUris extends Object { + mediaUris:Array + isLand:boolean +} @Component export struct EditPage { - @State mediaUris: Array = router.getParams()['mediaUris'] - @State pixelMaps: Array = [] - @State tasks: Array = [$r('app.media.scale'), $r('app.media.crop'), $r('app.media.rotate')] - @State tempTasks: Array = [$r('app.media.scale'), $r('app.media.crop'), $r('app.media.rotate')] - @State choiceTasks: Array = [$r('app.media.scale_red'), $r('app.media.crop_red'), $r('app.media.rotate_red')] - @State taskText: Array = [$r('app.string.scale'), $r('app.string.crop'), $r('app.string.rotate')] - @State cropRatios: Array = [$r('app.string.origin_photo'), $r('app.string.proportion_one_one'), $r('app.string.proportion_three_four'), $r('app.string.proportion_nine_sixth')] - @State cropMedias: Array = [$r('app.media.origin_gray'), $r('app.media.one_one_gray'), $r('app.media.three_four_gray'), $r('app.media.nine_sixth_gray')] - @State tempCropMedias: Array = [$r('app.media.origin_gray'), $r('app.media.one_one_gray'), $r('app.media.three_four_gray'), $r('app.media.nine_sixth_gray')] - @State cropChoiceMedias: Array = [$r('app.media.origin_red'), $r('app.media.one_one_red'), $r('app.media.three_four_red'), $r('app.media.nine_sixth_red')] - @State scaleTexts: Array = [$r('app.string.narrow'), $r('app.string.amplification')] - @State scaleMedias: Array = [$r('app.media.scale_small'), $r('app.media.scale_big')] - @State cropFrontShows: Array = new Array(4).fill(false) - @State tasksFrontShows: Array = new Array(3).fill(false) - @State borderShows: Array = new Array(this.mediaUris.length).fill(false) - @State pixelMap: image.PixelMap = undefined - @State tempPixelMap: image.PixelMap = undefined - @State single: number = 0 - @State isCrop: boolean = false - @State isScale: boolean = false - @State scaleSliderValue: number = 0 - @State selectIndex: number = 0 - @State isLand: boolean = false - private mediaLibraryInstance: mediaLibrary.MediaLibrary = mediaLibrary.getMediaLibrary(getContext(this) as any) - + @State mediaUris:Array = (router.getParams() as MediaUris).mediaUris + @State pixelMaps:Array = [] + @State tasks:Array = [$r('app.media.scale'), $r('app.media.crop'), $r('app.media.rotate')] + @State tempTasks:Array = [$r('app.media.scale'), $r('app.media.crop'), $r('app.media.rotate')] + @State choiceTasks:Array = [$r('app.media.scale_red'), $r('app.media.crop_red'), $r('app.media.rotate_red')] + @State taskText:Array = [$r('app.string.scale'), $r('app.string.crop'), $r('app.string.rotate')] + @State cropRatios:Array = [$r('app.string.origin_photo'), $r('app.string.proportion_one_one'), $r('app.string.proportion_three_four'), $r('app.string.proportion_nine_sixth')] + @State cropMedias:Array = [$r('app.media.origin_gray'), $r('app.media.one_one_gray'), $r('app.media.three_four_gray'), $r('app.media.nine_sixth_gray')] + @State tempCropMedias:Array = [$r('app.media.origin_gray'), $r('app.media.one_one_gray'), $r('app.media.three_four_gray'), $r('app.media.nine_sixth_gray')] + @State cropChoiceMedias:Array = [$r('app.media.origin_red'), $r('app.media.one_one_red'), $r('app.media.three_four_red'), $r('app.media.nine_sixth_red')] + @State scaleTexts:Array = [$r('app.string.narrow'), $r('app.string.amplification')] + @State scaleMedias:Array = [$r('app.media.scale_small'), $r('app.media.scale_big')] + @State cropFrontShows:Array = new Array(4).fill(false) + @State tasksFrontShows:Array = new Array(3).fill(false) + @State borderShows:Array = new Array(this.mediaUris.length).fill(false) + @State pixelMap:image.PixelMap = {} as image.PixelMap + @State tempPixelMap:image.PixelMap = {} as image.PixelMap + @State single:number = 0 + @State isCrop:boolean = false + @State isScale:boolean = false + @State scaleSliderValue:number = 0 + @State selectIndex:number = 0 + @State isLand:boolean = false + private mediaLibraryInstance:mediaLibrary.MediaLibrary = mediaLibrary.getMediaLibrary(getContext(this) as Context) flushPage() { this.tempPixelMap = this.pixelMap - this.pixelMap = undefined + this.pixelMap = {} as image.PixelMap this.pixelMap = this.tempPixelMap } - async queryFile(dataUri: string) { + async queryFile(dataUri:string):Promise { logger.info(TAG, `enter queryFile`) let fileKeyObj = mediaLibrary.FileKey logger.info(TAG, `fileKeyObj = ${fileKeyObj}`) - let fetchOp = { + let fetchOp:mediaLibrary.MediaFetchOptions = { selections: '', selectionArgs: [], uri: dataUri @@ -66,39 +71,39 @@ export struct EditPage { const fetchFileResult = await this.mediaLibraryInstance.getFileAssets(fetchOp) logger.info(TAG, `fetchFileResult = ${JSON.stringify(fetchFileResult)} ,count = ${JSON.stringify(fetchFileResult.getCount())}`) if (!fetchFileResult) { - return + return {} as mediaLibrary.FileAsset } const fileAsset = await fetchFileResult.getFirstObject() if (!fileAsset) { - return + return {} as mediaLibrary.FileAsset } logger.info(TAG, `fileAsset = ${JSON.stringify(fileAsset)}`) return fileAsset } - async getPixelMap(uri: string) { - let fileAssert: mediaLibrary.FileAsset = await this.queryFile(uri) + async getPixelMap(uri:string):Promise { + let fileAssert:mediaLibrary.FileAsset = await this.queryFile(uri) if (!fileAssert) { - return + return {} as image.PixelMap } let fd = await fileAssert.open('Rw') if (!fd) { - return + return {} as image.PixelMap } logger.info(TAG, `fd = ${fd}`) let imageSourceApi = image.createImageSource(fd) if (!imageSourceApi) { - return + return {} as image.PixelMap } let pixmap = await imageSourceApi.createPixelMap() if (!pixmap) { - return + return {} as image.PixelMap } return pixmap } - async cropImage(proportion: number) { - let imageInfo: image.ImageInfo = await this.pixelMap.getImageInfo() + async cropImage(proportion:number) { + let imageInfo:image.ImageInfo = await this.pixelMap.getImageInfo() if (!imageInfo) { return } @@ -127,10 +132,11 @@ export struct EditPage { } async aboutToAppear() { - logger.info(TAG, `enter aboutToAppear uris = ${JSON.stringify(router.getParams()['mediaUris'])}`) + logger.info(TAG, `enter aboutToAppear uris = ${JSON.stringify(this.mediaUris)}`) this.pixelMaps = [] - if(router.getParams() && router.getParams()['isLand']){ - this.isLand = router.getParams()['isLand'] + + if (router.getParams() && (router.getParams() as MediaUris).isLand) { + this.isLand = (router.getParams() as MediaUris).isLand } for (let i = 0; i < this.mediaUris.length; i++) { let pixelMap = await this.getPixelMap(this.mediaUris[i]) @@ -198,29 +204,31 @@ export struct EditPage { if (!this.isCrop && !this.isScale) { Row() { - ForEach(this.pixelMaps, (item, index) => { - Image(item) - .width(60) - .height(60) - .borderRadius(15) - .margin({ left: 8 }) - .border({ - style: BorderStyle.Solid, - width: 2, - color: (this.borderShows[index] === true ? '#e92f4f' : '#ffffff') - }) - .onClick(async () => { - if (this.pixelMap === item) { - return - } - this.borderShows.fill(false) - if (this.borderShows.length > index) { - this.borderShows[index] = true - } - this.single = 0 - this.pixelMap = item - this.selectIndex = index - }) + ForEach(this.pixelMaps, (item:image.PixelMap, index?:number) => { + if (index !== undefined) { + Image(item) + .width(60) + .height(60) + .borderRadius(15) + .margin({ left: 8 }) + .border({ + style: BorderStyle.Solid, + width: 2, + color: (this.borderShows[index] === true ? '#e92f4f' : '#ffffff') + }) + .onClick(async () => { + if (this.pixelMap === item) { + return + } + this.borderShows.fill(false) + if (this.borderShows.length > index) { + this.borderShows[index] = true + } + this.single = 0 + this.pixelMap = item + this.selectIndex = index + }) + } }) Row() { Image($r('app.media.add')) @@ -244,40 +252,44 @@ export struct EditPage { } else if (this.isCrop) { Row() { - ForEach(this.cropMedias, (item, index) => { + ForEach(this.cropMedias, (item:Resource, index?:number) => { Column() { Image(item) .width(30) .height(30) - Text(this.cropRatios[index]) - .fontSize(15) - .fontColor(this.cropFrontShows[index] === true ? '#e92f4f' : '#acabab') - .margin({ top: 5 }) + if (index !== undefined) { + Text(this.cropRatios[index]) + .fontSize(15) + .fontColor(this.cropFrontShows[index] === true ? '#e92f4f' : '#acabab') + .margin({ top: 5 }) + } } .layoutWeight(1) .onClick(async () => { - this.cropMedias = this.tempCropMedias.map((item) => { + this.cropMedias = this.tempCropMedias.map((item:Resource) => { return item }) - if (index === 0) { - if (this.mediaUris.length > this.selectIndex && this.pixelMaps.length > this.selectIndex) { - this.pixelMap = await this.getPixelMap(this.mediaUris[this.selectIndex]) - this.pixelMaps[this.selectIndex] = this.pixelMap + if (index !== undefined) { + if (index === 0) { + if (this.mediaUris.length > this.selectIndex && this.pixelMaps.length > this.selectIndex) { + this.pixelMap = await this.getPixelMap(this.mediaUris[this.selectIndex]) + this.pixelMaps[this.selectIndex] = this.pixelMap + } + } + else if (index === 1) { + await this.cropImage(1) + } else if (index === 2) { + await this.cropImage(3 / 4) + } else if (index === 3) { + await this.cropImage(9 / 16) + } + if (this.cropMedias.length > index && this.cropChoiceMedias.length > index) { + this.cropMedias[index] = this.cropChoiceMedias[index] + } + this.cropFrontShows.fill(false) + if (this.cropFrontShows.length > index) { + this.cropFrontShows[index] = true } - } - else if (index === 1) { - await this.cropImage(1) - } else if (index === 2) { - await this.cropImage(3 / 4) - } else if (index === 3) { - await this.cropImage(9 / 16) - } - if (this.cropMedias.length > index && this.cropChoiceMedias.length > index) { - this.cropMedias[index] = this.cropChoiceMedias[index] - } - this.cropFrontShows.fill(false) - if (this.cropFrontShows.length > index) { - this.cropFrontShows[index] = true } }) }) @@ -286,24 +298,26 @@ export struct EditPage { .margin({ top: 15 }) } else if (this.isScale) { Row() { - ForEach(this.scaleMedias, (item, index) => { - Column() { - Image(item) - .height(30) - .width(30) - Text(this.scaleTexts[index]) - .fontSize(15) - .margin({ top: 5 }) - } - .layoutWeight(1) - .onClick(async () => { - if (index === 0) { - await this.pixelMap.scale(0.8, 0.8) - } else if (index === 1) { - await this.pixelMap.scale(1.25, 1.25) + ForEach(this.scaleMedias, (item:Resource, index?:number) => { + if (index !== undefined) { + Column() { + Image(item) + .height(30) + .width(30) + Text(this.scaleTexts[index]) + .fontSize(15) + .margin({ top: 5 }) } - this.flushPage() - }) + .layoutWeight(1) + .onClick(async () => { + if (index === 0) { + await this.pixelMap.scale(0.8, 0.8) + } else if (index === 1) { + await this.pixelMap.scale(1.25, 1.25) + } + this.flushPage() + }) + } }) } .width('100%') @@ -325,47 +339,49 @@ export struct EditPage { .margin({ top: 8 }) Row() { - ForEach(this.tasks, (item, index) => { - Column() { - Image(item) - .width(30) - .height(30) - Text(this.taskText[index]) - .fontSize(15) - .fontColor(this.tasksFrontShows[index] === true ? '#e92f4f' : '#acabab') - } - .height(60) - .width(60) - .layoutWeight(1) - .onClick(async () => { - if (index === 0) { - this.isScale = !this.isScale - this.isCrop = false - } else if (index === 1) { - this.isCrop = !this.isCrop - this.isScale = false - } else if (index === 2) { - await this.pixelMap.rotate(90) - this.isCrop = false - this.isScale = false - this.flushPage() - - } - this.tasksFrontShows.fill(false) - if (this.tasksFrontShows.length > index) { - this.tasksFrontShows[index] = true - } - this.tasks = this.tempTasks.map((item) => { - return item - }) - if (this.tasks.length > index && this.choiceTasks.length > index) { - this.tasks[index] = this.choiceTasks[index] + ForEach(this.tasks, (item:Resource, index?:number) => { + if (index !== undefined) { + Column() { + Image(item) + .width(30) + .height(30) + Text(this.taskText[index]) + .fontSize(15) + .fontColor(this.tasksFrontShows[index] === true ? '#e92f4f' : '#acabab') } - this.cropFrontShows.fill(false) - this.cropMedias = this.tempCropMedias.map((item) => { - return item + .height(60) + .width(60) + .layoutWeight(1) + .onClick(async () => { + if (index === 0) { + this.isScale = !this.isScale + this.isCrop = false + } else if (index === 1) { + this.isCrop = !this.isCrop + this.isScale = false + } else if (index === 2) { + await this.pixelMap.rotate(90) + this.isCrop = false + this.isScale = false + this.flushPage() + + } + this.tasksFrontShows.fill(false) + if (this.tasksFrontShows.length > index) { + this.tasksFrontShows[index] = true + } + this.tasks = this.tempTasks.map((item:Resource) => { + return item + }) + if (this.tasks.length > index && this.choiceTasks.length > index) { + this.tasks[index] = this.choiceTasks[index] + } + this.cropFrontShows.fill(false) + this.cropMedias = this.tempCropMedias.map((item:Resource) => { + return item + }) }) - }) + } }) } .width('100%') diff --git a/media/ImageShow/entry/src/main/ets/MainAbility/MainAbility.ts b/media/ImageShow/entry/src/main/ets/MainAbility/MainAbility.ts index 33d8802cee9a0a49d56a963e9c42cc0875015a48..5febe675b7b8b713ac725d84ba7efba951cda65b 100644 --- a/media/ImageShow/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/media/ImageShow/entry/src/main/ets/MainAbility/MainAbility.ts @@ -16,6 +16,7 @@ import Ability from '@ohos.app.ability.UIAbility' import abilityAccessCtrl from '@ohos.abilityAccessCtrl' import Logger from '../../../../../imagelibrary/src/main/ets/components/data/Logger' +import window from '@ohos.window' const TAG: string = 'MainAbility' diff --git a/media/ImageShow/entry/src/main/ets/pages/Index.ets b/media/ImageShow/entry/src/main/ets/pages/Index.ets index 8f5d898829f04010ab6998dd0448fe8a4d552a1e..5723eb4ec919bc90f9df2208a86681f9ecef214f 100644 --- a/media/ImageShow/entry/src/main/ets/pages/Index.ets +++ b/media/ImageShow/entry/src/main/ets/pages/Index.ets @@ -14,36 +14,48 @@ */ import router from '@ohos.router' +import { DrawableDescriptor } from '@ohos.arkui.drawableDescriptor'; import Logger from '../../../../../imagelibrary/src/main/ets/components/data/Logger' - +import {terminateSelf} from '../utils/utils' const TAG: string = 'Index' + + +interface paramsType{ + mediaUris: Array +} +class routerParamsType{ + isShowCamera?:boolean; + mediaUris?: Array +} + @Entry @Component struct Index { - @State mediaUris: Array = [] + @State mediaUris: Array= [] @State stars: Array = new Array(5).fill(false) @State countStar: number = 0 @State isShowCamera: boolean = false @State isShowComment: boolean = true + private params = router.getParams() as routerParamsType + private paramsObj: paramsType = { + mediaUris: this.mediaUris + } async onPageShow() { Logger.info(TAG, 'enter onPageShow') - if (router.getParams()['isShowCamera'] !== undefined && router.getParams()['isShowCamera'] !== null) { - this.isShowCamera = router.getParams()['isShowCamera'] + if (this.params.isShowCamera !== undefined && this.params.isShowCamera !== null ) { + this.isShowCamera = this.params.isShowCamera Logger.info(TAG, `this.isShowCamera = ${this.isShowCamera}`) } - if (router.getParams()['mediaUris'] !== undefined && router.getParams()['mediaUris'] !== null) { - this.mediaUris = router.getParams()['mediaUris'] + if (this.params.mediaUris !== undefined && this.params.mediaUris !== null) { + this.mediaUris = this.params.mediaUris this.mediaUris.push('') } Logger.info(TAG, 'end onPageShow') } - terminateSelf(context: any) { - context.terminateSelf() - } build() { Column() { @@ -54,16 +66,14 @@ struct Index { .objectFit(ImageFit.Contain) .onClick(() => { let context = getContext(this) - this.terminateSelf(context) + terminateSelf(context) }) Text($r('app.string.publish_comments')) .fontSize(22) .margin({ left: 130 }) .textAlign(TextAlign.Center) - Blank() - Button($r('app.string.submit')) .fontSize(20) .height(32) @@ -106,34 +116,36 @@ struct Index { if (this.isShowCamera) { Grid() { - ForEach(this.mediaUris, (item, index) => { - GridItem() { - if (index < this.mediaUris.length - 1) { - Image(item) + ForEach(this.mediaUris, (item: PixelMap | ResourceStr | DrawableDescriptor, index?: number) => { + if(typeof index !=="undefined"){ + GridItem() { + if (index < this.mediaUris.length - 1) { + Image(item) + .width('100%') + .height(100) + .borderRadius(10) + + } else { + Column() { + Image($r('app.media.photo')) + .height(40) + .width(40) + .onClick(() => { + router.push({ + url: 'pages/ChoicePhoto', + params: this.paramsObj + }) + }) + Text($r('app.string.add_picture')) + .fontSize(13) + } + .alignItems(HorizontalAlign.Center) + .justifyContent(FlexAlign.Center) .width('100%') .height(100) .borderRadius(10) - - } else { - Column() { - Image($r('app.media.photo')) - .height(40) - .width(40) - .onClick(() => { - router.push({ - url: 'pages/ChoicePhoto', - params: { 'mediaUris': this.mediaUris } - }) - }) - Text($r('app.string.add_picture')) - .fontSize(13) + .backgroundColor('#F1F3F5') } - .alignItems(HorizontalAlign.Center) - .justifyContent(FlexAlign.Center) - .width('100%') - .height(100) - .borderRadius(10) - .backgroundColor('#F1F3F5') } } }) diff --git a/media/ImageShow/entry/src/main/ets/utils/utils.ts b/media/ImageShow/entry/src/main/ets/utils/utils.ts new file mode 100644 index 0000000000000000000000000000000000000000..003caa6b98708531fc7b793da53d3d91f35dadec --- /dev/null +++ b/media/ImageShow/entry/src/main/ets/utils/utils.ts @@ -0,0 +1,4 @@ + +export function terminateSelf(context:any) { + context.terminateSelf() +} diff --git a/media/ImageShow/entry/src/ohosTest/ets/Application/AbilityStage.ts b/media/ImageShow/entry/src/ohosTest/ets/Application/AbilityStage.ts deleted file mode 100644 index 50cd4e95d7cdc6288293317c71af29fd305a2736..0000000000000000000000000000000000000000 --- a/media/ImageShow/entry/src/ohosTest/ets/Application/AbilityStage.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2022 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 AbilityStage from "@ohos.application.AbilityStage" -import Logger from '../../../../../imagelibrary/src/main/ets/components/data/Logger' - -const TAG: string = 'TestAbilityStage' - -export default class TestAbilityStage extends AbilityStage { - onCreate() { - Logger.info(TAG, `[Demo] TestAbilityStage onCreate`) - } -} \ No newline at end of file diff --git a/media/ImageShow/entry/src/ohosTest/ets/Application/TestAbilityStage.ts b/media/ImageShow/entry/src/ohosTest/ets/Application/TestAbilityStage.ts deleted file mode 100644 index fc6f95c57a657212b5b97e538c9a422cbae2a41e..0000000000000000000000000000000000000000 --- a/media/ImageShow/entry/src/ohosTest/ets/Application/TestAbilityStage.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2022 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 AbilityStage from '@ohos.application.AbilityStage' -import Logger from '../../../../../imagelibrary/src/main/ets/components/data/Logger' - -const TAG: string = 'TestAbilityStage' - -export default class TestAbilityStage extends AbilityStage { - onCreate() { - Logger.info(TAG, `[Demo] TestAbilityStage onCreate`) - } -} \ No newline at end of file diff --git a/media/ImageShow/entry/src/ohosTest/ets/module.json5.ftl b/media/ImageShow/entry/src/ohosTest/ets/module.json5.ftl deleted file mode 100644 index 57569df303042010dcf0648ec4818dd40ea4caf5..0000000000000000000000000000000000000000 --- a/media/ImageShow/entry/src/ohosTest/ets/module.json5.ftl +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022 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. - */ - -{ - "module": { - "name": "${moduleName}_test", - "type": "feature", - "srcEntrance": "./ets/Application/AbilityStage.ts", - "description": "$string:entry_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [${deviceTypes ?replace("[","")?replace("]","")}], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "uiSyntax": "ets", - "abilities": [ - { - "name": "TestAbility", - "srcEntrance": "./ets/TestAbility/TestAbility.ts", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "visible": true, - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} diff --git a/media/ImageShow/entry/src/ohosTest/ets/test/Ability.test.ets b/media/ImageShow/entry/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100644 index a33c8ba837d572a06f683304346a165bd3d225ee..0000000000000000000000000000000000000000 --- a/media/ImageShow/entry/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2022 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 { describe, it, expect } from '@ohos/hypium' -import Logger from '../../../../../imagelibrary/src/main/ets/components/data/Logger' - -const TAG: string = 'abilityTest' - -export default function abilityTest() { - describe('ActsAbilityTest', function () { - it('assertContain', 0, function () { - Logger.info(TAG, `it begin`) - let a = 'abc' - let b = 'b' - expect(a).assertContain(b) - expect(a).assertEqual(a) - }) - }) -} \ No newline at end of file diff --git a/media/ImageShow/entry/src/ohosTest/ets/test/List.test.ets b/media/ImageShow/entry/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index 7e05ea60952f76d30ba3268f238352215f062110..0000000000000000000000000000000000000000 --- a/media/ImageShow/entry/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2022 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 abilityTest from './Ability.test' - -export default function testsuite() { - abilityTest() -} \ No newline at end of file diff --git a/media/ImageShow/entry/src/ohosTest/ets/testability/TestAbility.ets b/media/ImageShow/entry/src/ohosTest/ets/testability/TestAbility.ets deleted file mode 100644 index e3f6e911d3fffba1e1795c60ed1ee4db15b386fd..0000000000000000000000000000000000000000 --- a/media/ImageShow/entry/src/ohosTest/ets/testability/TestAbility.ets +++ /dev/null @@ -1,48 +0,0 @@ -import UIAbility from '@ohos.app.ability.UIAbility'; -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -import hilog from '@ohos.hilog'; -import { Hypium } from '@ohos/hypium'; -import testsuite from '../test/List.test'; -import window from '@ohos.window'; - -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 - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var abilityDelegatorArguments: any - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - } - - 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) ?? ''); - }); - } - - onWindowStageDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); - } - - onForeground() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); - } - - onBackground() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); - } -} \ No newline at end of file diff --git a/media/ImageShow/entry/src/ohosTest/ets/testability/TestAbility.ts b/media/ImageShow/entry/src/ohosTest/ets/testability/TestAbility.ts deleted file mode 100644 index bd19028636af9ee6860e93fddc6fad43a5a36f6d..0000000000000000000000000000000000000000 --- a/media/ImageShow/entry/src/ohosTest/ets/testability/TestAbility.ts +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2022 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 Ability from '@ohos.application.Ability' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' -import { Hypium } from '@ohos/hypium' -import testsuite from '../test/List.test' -import Logger from '../../../../../imagelibrary/src/main/ets/components/data/Logger' - -const TAG: string = 'TestAbility' - -export default class TestAbility extends Ability { - onCreate(want, launchParam) { - Logger.info(TAG, `TestAbility onCreate`) - let abilityDelegator: any - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - let abilityDelegatorArguments: any - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - Logger.info(TAG, `start run testcase!!!`) - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - } - - onDestroy() { - Logger.info(TAG, `TestAbility onDestroy`) - } - - onWindowStageCreate(windowStage) { - Logger.info(TAG, `TestAbility onWindowStageCreate`) - windowStage.loadContent("TestAbility/pages/index", (err, data) => { - if (err.code) { - Logger.info(TAG, `Failed to load the content. Cause = ${JSON.stringify(err)}`); - return - } - Logger.info(TAG, `Succeeded in loading the content. Data = ${JSON.stringify(data)}`) - }) - } - - onWindowStageDestroy() { - Logger.info(TAG, `TestAbility onWindowStageDestroy`) - } - - onForeground() { - Logger.info(TAG, `TestAbility onForeground`) - } - - onBackground() { - Logger.info(TAG, `TestAbility onBackground`) - } -} \ No newline at end of file diff --git a/media/ImageShow/entry/src/ohosTest/ets/testability/pages/index.ets b/media/ImageShow/entry/src/ohosTest/ets/testability/pages/index.ets deleted file mode 100644 index 47ce04c248303b82302f70f0d2ac6f633043a409..0000000000000000000000000000000000000000 --- a/media/ImageShow/entry/src/ohosTest/ets/testability/pages/index.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022 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 Logger from '../../../../../../imagelibrary/src/main/ets/components/data/Logger' - -const TAG: string = 'Index' - -@Entry -@Component -struct Index { - @State message: string = 'Hello World' - - aboutToAppear() { - Logger.info(TAG, `TestAbility index aboutToAppear`) - } - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('next page') - .fontSize(20) - .fontWeight(FontWeight.Bold) - } - .type(ButtonType.Capsule) - .margin({ top: 20 }) - .backgroundColor('#0D9FFB') - .width('35%') - .height('5%') - .onClick(() => { - }) - } - .width('100%') - } - .height('100%') - } -} \ No newline at end of file diff --git a/media/ImageShow/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/media/ImageShow/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts deleted file mode 100644 index 2d1370d8e30cef2fee05d2f84a84562101dbf207..0000000000000000000000000000000000000000 --- a/media/ImageShow/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2022 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 TestRunner from '@ohos.application.testRunner' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' -import Logger from '../../../../../imagelibrary/src/main/ets/components/data/Logger' - -let abilityDelegator = undefined -let abilityDelegatorArguments = undefined -const TAG: string = 'OpenHarmonyTestRunner' - -function translateParamsToString(parameters) { - const keySet = new Set([ - '-s class', '-s notClass', '-s suite', '-s it', - '-s level', '-s testType', '-s size', '-s timeout', - '-s dryRun' - ]) - let targetParams = ''; - for (const key in parameters) { - if (keySet.has(key)) { - targetParams = `${targetParams} ${key} ${parameters[key]}` - } - } - return targetParams.trim() -} - -async function onAbilityCreateCallback() { - Logger.info(TAG, `onAbilityCreateCallback`); -} - -async function addAbilityMonitorCallback(err: any) { - Logger.info(TAG, `addAbilityMonitorCallback = ${JSON.stringify(err)}`) -} - -export default class OpenHarmonyTestRunner implements TestRunner { - constructor() { - } - - onPrepare() { - Logger.info(TAG, `OpenHarmonyTestRunner OnPrepare`) - } - - async onRun() { - Logger.info(TAG, `OpenHarmonyTestRunner onRun run`) - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - let testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' - let lMonitor = { - abilityName: testAbilityName, - onAbilityCreate: onAbilityCreateCallback, - }; - abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) - let cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName - cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) - let debug = abilityDelegatorArguments.parameters["-D"] - if (debug == 'true') { - cmd += ' -D' - } - Logger.info(TAG, `cmd = ${cmd}`) - abilityDelegator.executeShellCommand(cmd, - (err: any, d: any) => { - Logger.info(TAG, `executeShellCommand : err = ${JSON.stringify(err)}`) - Logger.info(TAG, `executeShellCommand : data = ${d.stdResult}`) - Logger.info(TAG, `executeShellCommand : data = ${d.exitCode}`) - }) - Logger.info(TAG, `OpenHarmonyTestRunner onRun end`) - } -} \ No newline at end of file diff --git a/media/ImageShow/entry/src/ohosTest/module.json5 b/media/ImageShow/entry/src/ohosTest/module.json5 deleted file mode 100644 index 187f19d5b8dfc89ba6cbd5c98b8317da0155eb16..0000000000000000000000000000000000000000 --- a/media/ImageShow/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022 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. - */ - -{ - "module": { - "name": "entry_test", - "type": "feature", - "srcEntrance": "./ets/TestAbility/TestAbility.ts", - "description": "$string:entry_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "uiSyntax": "ets", - "abilities": [ - { - "name": "TestAbility", - "srcEntrance": "./ets/TestAbility/TestAbility.ts", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:white", - "visible": true, - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} diff --git a/media/ImageShow/entry/src/ohosTest/resources/base/element/color.json b/media/ImageShow/entry/src/ohosTest/resources/base/element/color.json deleted file mode 100644 index 1bbc9aa9617e97c45440e1d3d66afc1154837012..0000000000000000000000000000000000000000 --- a/media/ImageShow/entry/src/ohosTest/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "white", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/media/ImageShow/entry/src/ohosTest/resources/base/element/string.json b/media/ImageShow/entry/src/ohosTest/resources/base/element/string.json deleted file mode 100644 index 36d4230c53e9f5a07ae343ad8dc9808341975e3b..0000000000000000000000000000000000000000 --- a/media/ImageShow/entry/src/ohosTest/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "entry_test_desc", - "value": "test ability description" - }, - { - "name": "TestAbility_desc", - "value": "the test ability" - }, - { - "name": "TestAbility_label", - "value": "test label" - } - ] -} \ No newline at end of file diff --git a/media/ImageShow/entry/src/ohosTest/resources/base/media/icon.png b/media/ImageShow/entry/src/ohosTest/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 Binary files a/media/ImageShow/entry/src/ohosTest/resources/base/media/icon.png and /dev/null differ diff --git a/media/ImageShow/entry/src/ohosTest/resources/base/profile/test_pages.json b/media/ImageShow/entry/src/ohosTest/resources/base/profile/test_pages.json deleted file mode 100644 index fcef82b4dfc18e28106ff9ecd1c8b48ec74d18a4..0000000000000000000000000000000000000000 --- a/media/ImageShow/entry/src/ohosTest/resources/base/profile/test_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "TestAbility/pages/index" - ] -} diff --git a/media/ImageShow/imagelibrary/src/main/ets/components/pages/ChoicePhotos.ets b/media/ImageShow/imagelibrary/src/main/ets/components/pages/ChoicePhotos.ets index 65eb3cade6dee5e5dff220e3a76ad98ccc9a331f..bca49f8796c46c72c64e033f6c1aa1fe1e0d2382 100644 --- a/media/ImageShow/imagelibrary/src/main/ets/components/pages/ChoicePhotos.ets +++ b/media/ImageShow/imagelibrary/src/main/ets/components/pages/ChoicePhotos.ets @@ -21,6 +21,24 @@ import Logger from '../data/Logger' const TAG: string = 'ChoicePhoto' +class mediaQueryResultType { + matches: boolean | undefined +} + +interface fetchOpType { + selections: string; + selectionArgs: Array +} + +interface maxHeightType { + maxHeight: string +} + +interface paramsType { + mediaUris: Array; + isShowCamera: boolean; +} + @Entry @Component export struct ChoicePhotos { @@ -36,7 +54,19 @@ export struct ChoicePhotos { @State nextText: string = '' @State isLand: boolean = false private listener = mediaQuery.matchMediaSync('screen and (min-aspect-ratio: 1.5) or (orientation: landscape)') - onLand = (mediaQueryResult) => { + private maxHeightObj1: maxHeightType = { + maxHeight: '64%' + } + private maxHeightObj2: maxHeightType = { + maxHeight: '75.5%' + } + private maxHeightObj3: maxHeightType = { + maxHeight: '60%' + } + private maxHeightObj4: maxHeightType = { + maxHeight: '71%' + } + onLand = (mediaQueryResult: mediaQueryResultType) => { if (mediaQueryResult.matches) { this.isLand = true } else { @@ -70,10 +100,10 @@ export struct ChoicePhotos { async getFileAssetsFromType(mediaType: mediaLibrary.MediaType) { Logger.info(TAG, `getFileAssetsFromType`) - let mediaLibraryInstance = mediaLibrary.getMediaLibrary(getContext(this) as any) + let mediaLibraryInstance = mediaLibrary.getMediaLibrary(getContext(this) as Context) Logger.info(TAG, `mediaLibraryInstance = ${JSON.stringify(mediaLibraryInstance)}`) let fileKeyObj = mediaLibrary.FileKey - let fetchOp = { + let fetchOp:mediaLibrary.MediaFetchOptions = { selections: `${fileKeyObj.MEDIA_TYPE}=?`, selectionArgs: [`${mediaType}`], } @@ -85,24 +115,26 @@ export struct ChoicePhotos { Logger.info(TAG, `this.medias = ${JSON.stringify(this.medias)}`) } - convertContext(context: any) { + convertContext(context: Context) { return context } async convertResourceToString(resource: Resource) { - Logger.info(TAG, `result = ${JSON.stringify(await this.convertContext(getContext(this)).resourceManager.getString(resource))}`) - return await this.convertContext(getContext(this)).resourceManager.getString(resource) + Logger.info(TAG, `result = ${JSON.stringify(await this.convertContext(getContext(this)) + .resourceManager + .getString(resource.id))}`) + return await this.convertContext(getContext(this)).resourceManager.getString(resource.id) } - getMaxHeight() { + getMaxHeight():ConstraintSizeOptions { if (!this.isLand && this.isChoice) { - return { maxHeight: '64%' } + return this.maxHeightObj1 } else if (!this.isLand && !this.isChoice) { - return { maxHeight: '75.5%' } + return this.maxHeightObj2 } else if (this.isLand && this.isChoice) { - return { maxHeight: '60%' } - } else if (this.isLand && !this.isChoice) { - return { maxHeight: '71%' } + return this.maxHeightObj3 + } else{ + return this.maxHeightObj4 } } @@ -147,13 +179,16 @@ export struct ChoicePhotos { if (this.isChoice === false) { return } - this.mediaUris = this.choiceMedias.map((item) => { + this.mediaUris = this.choiceMedias.map((item: mediaLibrary.FileAsset) => { return item.uri }) + let paramsObj: paramsType = { + mediaUris: this.mediaUris, + isShowCamera: true + } router.push({ url: 'pages/Index', - params: { mediaUris: this.mediaUris, isShowCamera: true } - + params: paramsObj }) }) } @@ -164,33 +199,35 @@ export struct ChoicePhotos { Column() { Row() { - ForEach(this.choiceShow, (item, index) => { - Column() { - Text(item) - .fontSize(20) - .fontWeight(500) - .fontColor(this.whichShow[index] === true ? '#0000000' : '#99182431') - .onClick(() => { - this.whichShow.fill(false) - this.whichShow[index] = true - this.medias = [] - if (index == 0) { - this.getFileAssetsFromType(mediaLibrary.MediaType.IMAGE) - } else { - prompt.showDialog({ message: $r('app.string.user_tip') }) - this.choiceMedias = [] - this.isShowChoices = new Array(this.medias.length).fill(false) - } - }) - if (this.whichShow[index]) { - Divider() - .vertical(false) - .strokeWidth(3) - .color('#ffff0000') - .lineCap(LineCapStyle.Round) - .width('40%') - .margin({ top: 4 }) - } + ForEach(this.choiceShow, (item: Resource, index?: number) => { + if(typeof index!=="undefined"){ + Column() { + Text(item) + .fontSize(20) + .fontWeight(500) + .fontColor(this.whichShow[index] === true ? '#0000000' : '#99182431') + .onClick(() => { + this.whichShow.fill(false) + this.whichShow[index] = true + this.medias = [] + if (index == 0) { + this.getFileAssetsFromType(mediaLibrary.MediaType.IMAGE) + } else { + prompt.showDialog({ message: $r('app.string.user_tip') }) + this.choiceMedias = [] + this.isShowChoices = new Array(this.medias.length).fill(false) + } + }) + if (this.whichShow[index]) { + Divider() + .vertical(false) + .strokeWidth(3) + .color('#ffff0000') + .lineCap(LineCapStyle.Round) + .width('40%') + .margin({ top: 4 }) + } + }.width('30%') } .width('30%') }) @@ -201,37 +238,39 @@ export struct ChoicePhotos { Scroll() { Column() { Grid() { - ForEach(this.medias, (item, index) => { - GridItem() { - Stack({ alignContent: Alignment.TopEnd }) { - Image(item.uri) - .width('100%') - .height('100%') - .borderRadius(10) - .objectFit(ImageFit.Fill) - if (this.isShowChoices[index]) { - this.showChoiceBuild('#fffc0303', this.choiceMedias.indexOf(item) + 1) - } else { - this.showChoiceBuild('#ffb7b4b4', 0) - } - } - .width('100%') - .height('100%') - .onClick(() => { - this.isShowChoices[index] = !this.isShowChoices[index] - if (this.isShowChoices[index]) { - if (this.choiceMedias.length > 5) { - prompt.showDialog({ message: $r('app.string.choice_number') }) - this.isShowChoices[index] = !this.isShowChoices[index] - return - } - this.choiceMedias.push(item) - } else { - if (this.choiceMedias.indexOf(item) != -1) { - this.choiceMedias.splice(this.choiceMedias.indexOf(item), 1) + ForEach(this.medias, (item: mediaLibrary.FileAsset, index?: number) => { + if(typeof index !=="undefined"){ + GridItem() { + Stack({ alignContent: Alignment.TopEnd }) { + Image(item.uri) + .width('100%') + .height('100%') + .borderRadius(10) + .objectFit(ImageFit.Fill) + if (this.isShowChoices[index]) { + this.showChoiceBuild('#fffc0303', this.choiceMedias.indexOf(item) + 1) + } else { + this.showChoiceBuild('#ffb7b4b4', 0) } } - }) + .width('100%') + .height('100%') + .onClick(() => { + this.isShowChoices[index] = !this.isShowChoices[index] + if (this.isShowChoices[index]) { + if (this.choiceMedias.length > 5) { + prompt.showDialog({ message: $r('app.string.choice_number') }) + this.isShowChoices[index] = !this.isShowChoices[index] + return + } + this.choiceMedias.push(item) + } else { + if (this.choiceMedias.indexOf(item) != -1) { + this.choiceMedias.splice(this.choiceMedias.indexOf(item), 1) + } + } + }) + }.aspectRatio(1) } .aspectRatio(1) }) @@ -251,27 +290,29 @@ export struct ChoicePhotos { if (this.isChoice) { Grid() { - ForEach(this.choiceMedias, (item, index) => { - GridItem() { - Stack({ alignContent: Alignment.TopEnd }) { - Image(item.uri) - .width('100%') - .height(70) - .borderRadius(10) - Image($r('app.media.delete')) - .width(20) - .height(20) - .margin({ top: 5, right: 5 }) - .onClick(() => { - for (let i = 0;i < this.medias.length; i++) { - if (this.medias[i] === this.choiceMedias[index]) { - this.isShowChoices[i] = false + ForEach(this.choiceMedias, (item: mediaLibrary.FileAsset, index?: number) => { + if(typeof index !=="undefined"){ + GridItem() { + Stack({ alignContent: Alignment.TopEnd }) { + Image(item.uri) + .width('100%') + .height(70) + .borderRadius(10) + Image($r('app.media.delete')) + .width(20) + .height(20) + .margin({ top: 5, right: 5 }) + .onClick(() => { + for (let i = 0;i < this.medias.length; i++) { + if (this.medias[i] === this.choiceMedias[index]) { + this.isShowChoices[i] = false + } } - } - this.choiceMedias.splice(index, 1) - }) + this.choiceMedias.splice(index, 1) + }) + } + .width('100%') } - .width('100%') } }) } @@ -292,18 +333,20 @@ export struct ChoicePhotos { } Row() { - ForEach(this.taskShow, (item, index) => { - Column() { - Image(item) - .width(30) - .height(30) + ForEach(this.taskShow, (item: Resource, index?: number) => { + if(typeof index !=="undefined"){ + Column() { + Image(item) + .width(30) + .height(30) - Text(this.textShow[index]) - .fontSize(14) - .fontColor('#99182431') - .margin({ top: 2 }) + Text(this.textShow[index]) + .fontSize(14) + .fontColor('#99182431') + .margin({ top: 2 }) + } + .width('50%') } - .width('50%') }) } .margin({ top: 8 })