diff --git a/function/arkui/inspector_test/entry/src/main/ets/pages/IndexJ.ets b/function/arkui/inspector_test/entry/src/main/ets/pages/IndexJ.ets index 5fa11ff68aa0fa35f3caf10714466a9dc5a9b591..acd0c3e1b7677257516f70eaf02158f26e1b4d00 100644 --- a/function/arkui/inspector_test/entry/src/main/ets/pages/IndexJ.ets +++ b/function/arkui/inspector_test/entry/src/main/ets/pages/IndexJ.ets @@ -22,7 +22,13 @@ struct IndexJ { 'CalendarPicker/calendarPicker01', 'DatePicker/datePicker01', 'TextPicker/textPicker01', - 'TimePicker/timePicker01' + 'TimePicker/timePicker01', + 'TextPickerDialog/textPickerDialog01', + "promptAction/promptAction01", + "promptAction/promptAction02", + "promptAction/promptAction03", + "promptAction/promptAction04", + "bindMenu/bindMenu01" ]; @State arrRight: Array = [ diff --git a/function/arkui/inspector_test/entry/src/main/ets/pages/TextPickerDialog/textPickerDialog01.ets b/function/arkui/inspector_test/entry/src/main/ets/pages/TextPickerDialog/textPickerDialog01.ets new file mode 100644 index 0000000000000000000000000000000000000000..22d947d75ce04a91a1152bec64e2d97628ff502f --- /dev/null +++ b/function/arkui/inspector_test/entry/src/main/ets/pages/TextPickerDialog/textPickerDialog01.ets @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2025 Shenzhen Kaihong Digital Industry Development 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. + */ + +@Entry +@Component +struct TextPickerDialogExample { + @State v:string = ''; + private select: number | number[] = 0 + private fruits: string[] = ['apple1', 'orange2', 'peach3', 'grape4', 'banana5'] + private apfruits: string[] = ['apple1', 'apple2', 'apple3', 'apple4'] + private orfruits: string[] = ['orange1', 'orange2', 'orange3', 'orange4'] + private pefruits: string[] = ['peach1', 'peach2', 'peach3', 'peach4'] + private multi: string[][] = [this.apfruits, this.orfruits, this.pefruits] + private cascade: TextCascadePickerRangeContent[] = [ + { + text: '辽宁省', + children: [{ text: '沈阳市', children: [{ text: '沈河区' }, { text: '和平区' }, { text: '浑南区' }] }, + { text: '大连市', children: [{ text: '中山区' }, { text: '金州区' }, { text: '长海县' }] }] + }, + { + text: '吉林省', + children: [{ text: '长春市', children: [{ text: '南关区' }, { text: '宽城区' }, { text: '朝阳区' }] }, + { text: '四平市', children: [{ text: '铁西区' }, { text: '铁东区' }, { text: '梨树县' }] }] + }, + { + text: '黑龙江省', + children: [{ text: '哈尔滨市', children: [{ text: '道里区' }, { text: '道外区' }, { text: '南岗区' }] }, + { text: '牡丹江市', children: [{ text: '东安区' }, { text: '西安区' }, { text: '爱民区' }] }] + } + ] + private rangeContent: TextPickerRangeContent[] = [ + { + icon: $r('app.media.icon'), + text: '01' + }, + { + icon: $r('app.media.icon'), + text: '02' + }, + { + icon: $r('app.media.icon'), + text: '03' + }, + { + icon: $r('app.media.icon'), + text: '04' + }, + ] + + build() { + Scroll() { + Column() { + Text('TextPickerDialog') + .fontSize(24) + .margin({bottom: 24}) + Text('TextPickerDialog') + .fontSize(24) + .margin({bottom: 24}) + + Text("Show TextPickerDialog01 with TextPickerDialogOptions.range\'s type: string[]") + .fontSize(18) + .margin({top: 24}) + Button("Show TextPickerDialog01. Selected: " + this.v) + .margin(20) + .onClick(() => { + TextPickerDialog.show({ + range: this.fruits, + selected: this.select, + disappearTextStyle: {color: Color.Red, font: {size: 15, weight: FontWeight.Lighter}}, + textStyle: {color: Color.Black, font: {size: 20, weight: FontWeight.Normal}}, + selectedTextStyle: {color: Color.Blue, font: {size: 30, weight: FontWeight.Bolder}}, + acceptButtonStyle: { type: ButtonType.Normal, style: ButtonStyleMode.NORMAL, role: ButtonRole.NORMAL, fontColor: Color.Red, + fontSize: '26fp', fontWeight: FontWeight.Bolder, fontStyle: FontStyle.Normal, fontFamily: 'sans-serif', backgroundColor:'#80834511', + borderRadius: 20 }, + cancelButtonStyle: { type: ButtonType.Normal, style: ButtonStyleMode.NORMAL, role: ButtonRole.NORMAL, fontColor: Color.Blue, + fontSize: '16fp', fontWeight: FontWeight.Normal, fontStyle: FontStyle.Italic, fontFamily: 'sans-serif', backgroundColor:'#50182431', + borderRadius: 10 }, + onAccept: (value: TextPickerResult) => { + this.select = value.index + console.log(this.select + '') + this.v = value.value as string + console.info("TextPickerDialog:onAccept()" + JSON.stringify(value)) + }, + onCancel: () => { + console.info("TextPickerDialog:onCancel()") + }, + onChange: (value: TextPickerResult) => { + console.info("TextPickerDialog:onChange()" + JSON.stringify(value)) + }, + onDidAppear: () => { + console.info("TextPickerDialog:onDidAppear()") + }, + onDidDisappear: () => { + console.info("TextPickerDialog:onDidDisappear()") + }, + onWillAppear: () => { + console.info("TextPickerDialog:onWillAppear()") + }, + onWillDisappear: () => { + console.info("TextPickerDialog:onWillDisappear()") + } + }) + }) + + Text("Show TextPickerDialog02 with TextPickerDialogOptions.range\'s type: string[][]") + .fontSize(18) + .margin({top: 24}) + Button("Show TextPickerDialog02") + .margin(20) + .onClick(() => { + TextPickerDialog.show({ + range: this.multi, + selected: [0, 3, 2], + }) + }) + + Text("Show TextPickerDialog03 with TextPickerDialogOptions.range\'s type: TextCascadePickerRangeContent[]") + .fontSize(18) + .margin({top: 24}) + Button("Show TextPickerDialog03") + .margin(20) + .onClick(() => { + TextPickerDialog.show({ + range: this.cascade, + value: ['吉林省', '四平市', '梨树县'], + }) + }) + + Text("Show TextPickerDialog04 with TextPickerDialogOptions.range\'s type: TextPickerRangeContent[]") + .fontSize(18) + .margin({top: 24}) + Button("Show TextPickerDialog04") + .margin(20) + .onClick(() => { + TextPickerDialog.show({ + range: this.rangeContent, + selected: this.select, + }) + }) + + Text("Show TextPickerDialog05 with TextPickerDialogOptions.range\'s type: Resource") + .fontSize(18) + .margin({top: 24}) + Button("Show TextPickerDialog05") + .margin(20) + .onClick(() => { + TextPickerDialog.show({ + range: $r('app.strarray.textPicker_ResourceRange'), + selected: this.select, + }) + }) + + }.width('100%') + }.height('100%') + } +} diff --git a/function/arkui/inspector_test/entry/src/main/ets/pages/bindMenu/bindMenu01.ets b/function/arkui/inspector_test/entry/src/main/ets/pages/bindMenu/bindMenu01.ets new file mode 100644 index 0000000000000000000000000000000000000000..ee4c3771dd98ea53ac215bbdf00f5b9db31287d2 --- /dev/null +++ b/function/arkui/inspector_test/entry/src/main/ets/pages/bindMenu/bindMenu01.ets @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2025 Shenzhen Kaihong Digital Industry Development 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 { SymbolGlyphModifier } from '@kit.ArkUI'; + +@Entry +@Component +struct MenuExample { + @State listData: number[] = [0, 0, 0] + @State symbolIconModifier1: SymbolGlyphModifier = new SymbolGlyphModifier($r('sys.symbol.ohos_photo')).fontSize('24vp'); + @State symbolIconModifier2: SymbolGlyphModifier = new SymbolGlyphModifier($r('sys.symbol.ohos_photo')).fontSize('24vp'); + @State select: boolean = true + private iconStr: ResourceStr = $r("app.media.ImageOne") + private iconStr2: ResourceStr = $r("app.media.ImageTwo") + @State menuTitle: string = "" + @State enableArrow: boolean = false + + @Builder + SubMenu() { + Menu() { + MenuItem({ content: "复制", labelInfo: "Ctrl+C" }) + MenuItem({ content: "粘贴", labelInfo: "Ctrl+V" }) + } + } + + @Builder + MyMenu(){ + Menu() { + MenuItem({ startIcon: $r("app.media.icon"), content: "菜单选项" }) + MenuItem({ startIcon: $r("app.media.icon"), content: "菜单选项" }) + .enabled(false) + MenuItem({ + startIcon: this.iconStr, + content: "菜单选项", + endIcon: this.iconStr2, + builder: ():void=>this.SubMenu() + }) + MenuItemGroup({ header: '小标题' }) { + MenuItem({ + startIcon: this.iconStr, + content: "菜单选项", + endIcon: this.iconStr2, + builder: ():void=>this.SubMenu() + }) + MenuItem({ + startIcon: $r("app.media.app_icon"), + content: "菜单选项", + endIcon: this.iconStr2, + builder: ():void=>this.SubMenu() + }) + } + MenuItem({ + startIcon: this.iconStr, + content: "菜单选项", + }) + } + } + + @Builder MenuBuilder() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + ForEach(this.listData, (item:number, index) => { + Column() { + Row() { + Image($r("app.media.icon")).width(20).height(20).margin({ right: 5 }) + Text(`Menu${index as number + 1}`).fontSize(20) + } + .width('100%') + .height(30) + .justifyContent(FlexAlign.Center) + .align(Alignment.Center) + .onClick(() => { + console.info(`Menu${index as number + 1} Clicked!`) + }) + + if (index != this.listData.length - 1) { + Divider().height(10).width('80%').color('#ccc') + } + }.padding(5).height(40) + }) + }.width(100) + } + + build() { + Column() { + Text("bindMenu") + .fontSize(24) + .margin({bottom: 24}) + + Text("Menu title: " + this.menuTitle) + .fontSize(20) + Button('Set / Clear menu title') + .onClick(() => { + if (this.menuTitle == "") { + this.menuTitle = "Menu Title Info" + } else { + this.menuTitle = "" + } + }) + .margin({bottom: 24}) + + Text("Enable arrow: " + this.enableArrow) + .fontSize(20) + Button('Switch enableArrow') + .onClick(() => { + this.enableArrow = !this.enableArrow + }) + .margin({bottom: 24}) + + Button('Normal Menu01') + .bindMenu( + [ + { + value: 'item1', + action: () => { + console.info('handle Menu1 select') + } + }, + { + value: 'item2', + action: () => { + console.info('handle Menu2 select') + } + }, + ], + { + title: this.menuTitle, + enableArrow: this.enableArrow, + placement: Placement.TopRight + } + ) + .margin({bottom: 24}) + + Button('Normal Menu02 with icon') + .margin({bottom: 24}) + .bindMenu( + [ + { + value: 'Menu item 1', + icon: $r('app.media.icon'), + symbolIcon:this.symbolIconModifier1, + action: () => { + console.info('handle Menu1 select') + } + }, + { + value: 'Menu item 2', + icon: $r('app.media.icon'), + // symbolIcon:this.symbolIconModifier2, + action: () => { + console.info('handle Menu2 select') + } + }, + ], + { + title: this.menuTitle, + enableArrow: this.enableArrow, + transition: TransitionEffect.OPACITY + .animation({ duration: 4000, curve: Curve.Ease }) + .combine(TransitionEffect.rotate({ z: 1, angle: 180 })) + } + ) + + Button('Custom Menu01') + .margin({bottom: 24}) + .bindMenu(this.MenuBuilder) + + Button('Custom Menu02') + .margin({bottom: 24}) + .bindMenu(this.MyMenu) + + } + .width('100%') + .margin({ top: 5 }) + } +} \ No newline at end of file diff --git a/function/arkui/inspector_test/entry/src/main/ets/pages/promptAction/promptAction01.ets b/function/arkui/inspector_test/entry/src/main/ets/pages/promptAction/promptAction01.ets new file mode 100644 index 0000000000000000000000000000000000000000..c0c247ddda0ad2cf275ce147dc03d6151cb3a993 --- /dev/null +++ b/function/arkui/inspector_test/entry/src/main/ets/pages/promptAction/promptAction01.ets @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Shenzhen Kaihong Digital Industry Development 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 { promptAction } from '@kit.ArkUI' +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct toastExample { + build() { + Column() { + Text("promptAction.showToast()") + .fontSize(18) + .margin({top: 24, bottom: 24}) + + Button('Show toast (showMode: DEFAULT)') + .fontSize(20) + .margin({bottom: 20}) + .onClick(() => { + try { + promptAction.showToast({ + message: 'Hello World', + duration: 10000, + showMode: promptAction.ToastShowMode.DEFAULT, + backgroundColor: Color.Green, + textColor: Color.Orange, + }); + } catch (error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code + console.error(`showToast args error code is ${code}, message is ${message}`); + }; + }) + + Button('Show toast (showMode: TOP_MOST)') + .fontSize(20) + .margin({bottom: 20}) + .onClick(() => { + try { + promptAction.showToast({ + message: 'Hello World', + duration: 10000, + showMode: promptAction.ToastShowMode.TOP_MOST, + }); + } catch (error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code + console.error(`showToast args error code is ${code}, message is ${message}`); + }; + }) + + }.height('100%').width('100%').justifyContent(FlexAlign.Center) + } +} diff --git a/function/arkui/inspector_test/entry/src/main/ets/pages/promptAction/promptAction02.ets b/function/arkui/inspector_test/entry/src/main/ets/pages/promptAction/promptAction02.ets new file mode 100644 index 0000000000000000000000000000000000000000..6685432ff96dee64c91b75890b6b8e2a35451b01 --- /dev/null +++ b/function/arkui/inspector_test/entry/src/main/ets/pages/promptAction/promptAction02.ets @@ -0,0 +1,242 @@ +/* + * Copyright (c) 2025 Shenzhen Kaihong Digital Industry Development 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 { promptAction } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct dialogExample { + @State private title: string = ""; + @State private message: string = ""; + + build() { + Scroll() { + Column() { + Text("promptAction.showDialog()") + .fontSize(18) + .margin({top: 24, bottom: 24}) + + Text("title: " + this.title) + .fontSize(18) + .margin({top: 24, bottom: 5}) + Button('Switch whether title exists') + .fontSize(20) + .onClick(() => { + if (this.title == "") { + this.title = "Title Info"; + } else { + this.title = ""; + } + }) + .margin({top: 5, bottom: 5}) + + Text("message: " + this.message) + .fontSize(18) + .margin({top: 5, bottom: 5}) + Button('Switch whether message exists') + .fontSize(20) + .onClick(() => { + if (this.message == "") { + this.message = "Message Info"; + } else { + this.message = ""; + } + }) + .margin({top: 5, bottom: 24}) + + Text("Show dialog01 without buttons") + .fontSize(18) + .margin({top: 24}) + Button('Show dialog01') + .fontSize(20) + .margin({bottom: 20}) + .onClick(() => { + try { + promptAction.showDialog({ + title: this.title, + message: this.message, + }) + .then(data => { + console.info('showDialog success, click button: ' + data.index); + }) + .catch((err:Error) => { + console.info('showDialog error: ' + err); + }) + } catch (error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code + console.error(`showDialog args error code is ${code}, message is ${message}`); + }; + }) + + Text("Show dialog02 with 1 button") + .fontSize(18) + .margin({top: 24}) + Button('Show dialog02') + .fontSize(20) + .margin({bottom: 20}) + .onClick(() => { + try { + promptAction.showDialog({ + title: this.title, + message: this.message, + buttons: [ + { + text: 'button1', + color: '#000000' + }, + ], + }) + .then(data => { + console.info('showDialog success, click button: ' + data.index); + }) + .catch((err:Error) => { + console.info('showDialog error: ' + err); + }) + } catch (error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code + console.error(`showDialog args error code is ${code}, message is ${message}`); + }; + }) + + Text("Show dialog03 with 2 buttons") + .fontSize(18) + .margin({top: 24}) + Button('Show dialog03') + .fontSize(20) + .margin({bottom: 20}) + .onClick(() => { + try { + promptAction.showDialog({ + title: this.title, + message: this.message, + buttons: [ + { + text: 'button1', + color: '#000000' + }, + { + text: 'button2', + color: '#000000' + }, + ], + }) + .then(data => { + console.info('showDialog success, click button: ' + data.index); + }) + .catch((err:Error) => { + console.info('showDialog error: ' + err); + }) + } catch (error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code + console.error(`showDialog args error code is ${code}, message is ${message}`); + }; + }) + + Text("Show dialog04 with 3 buttons") + .fontSize(18) + .margin({top: 24}) + Button('Show dialog04') + .fontSize(20) + .margin({bottom: 20}) + .onClick(() => { + try { + promptAction.showDialog({ + title: this.title, + message: this.message, + buttons: [ + { + text: 'button1', + color: '#000000' + }, + { + text: 'button2', + color: '#000000' + }, + { + text: 'button3', + color: '#000000' + }, + ], + }) + .then(data => { + console.info('showDialog success, click button: ' + data.index); + }) + .catch((err:Error) => { + console.info('showDialog error: ' + err); + }) + } catch (error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code + console.error(`showDialog args error code is ${code}, message is ${message}`); + }; + }) + + Text("Show dialog05 with 4 buttons") + .fontSize(18) + .margin({top: 24}) + Button('Show dialog05') + .fontSize(20) + .margin({bottom: 20}) + .onClick(() => { + try { + promptAction.showDialog({ + title: this.title, + message: this.message, + alignment: DialogAlignment.Top, + offset: {dx: 5, dy: 5}, + isModal: false, + backgroundColor: Color.Orange, + backgroundBlurStyle: BlurStyle.NONE, + buttons: [ + { + text: 'button1', + color: '#000000' + }, + { + text: 'button2', + color: '#000000' + }, + { + text: 'button3', + color: '#000000' + }, + { + text: 'button4', + color: '#000000' + }, + ], + }) + .then(data => { + console.info('showDialog success, click button: ' + data.index); + }) + .catch((err:Error) => { + console.info('showDialog error: ' + err); + }) + } catch (error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code + console.error(`showDialog args error code is ${code}, message is ${message}`); + }; + }) + + }.width('100%') + }.height('100%') + } +} + diff --git a/function/arkui/inspector_test/entry/src/main/ets/pages/promptAction/promptAction03.ets b/function/arkui/inspector_test/entry/src/main/ets/pages/promptAction/promptAction03.ets new file mode 100644 index 0000000000000000000000000000000000000000..6f6638a970dd4c74e6bf89fed1955a9970ae2388 --- /dev/null +++ b/function/arkui/inspector_test/entry/src/main/ets/pages/promptAction/promptAction03.ets @@ -0,0 +1,323 @@ +/* + * Copyright (c) 2025 Shenzhen Kaihong Digital Industry Development 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 { promptAction } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct actionMenuExample { + @State private title: string = ""; + @State private showInSubWindow: boolean = false; + @State private isModal: boolean = true; + + build() { + Scroll() { + Column() { + Text("promptAction.showActionMenu()") + .fontSize(18) + .margin({top: 24, bottom: 24}) + + Text("title: " + this.title) + .fontSize(18) + .margin({top: 24, bottom: 5}) + Button('Switch whether title exists') + .fontSize(20) + .onClick(() => { + if (this.title == "") { + this.title = "Title Info"; + } else { + this.title = ""; + } + }) + .margin({top: 5, bottom: 24}) + + Text("showInSubWindow: " + this.showInSubWindow) + .fontSize(18) + .margin({top: 24, bottom: 5}) + Button('Switch boolean variable: showInSubWindow') + .fontSize(20) + .onClick(() => { + this.showInSubWindow = !this.showInSubWindow; + }) + .margin({top: 5, bottom: 24}) + + Text("isModal: " + this.isModal) + .fontSize(18) + .margin({top: 24, bottom: 5}) + Button('Switch boolean variable: isModal') + .fontSize(20) + .onClick(() => { + this.isModal = !this.isModal; + }) + .margin({top: 5, bottom: 24}) + + Text("Show ActionMenu01 with 1 button") + .fontSize(18) + .margin({top: 24}) + Button('Show ActionMenu01') + .fontSize(20) + .margin({bottom: 20}) + .onClick(() => { + try { + promptAction.showActionMenu({ + title: this.title, + showInSubWindow: this.showInSubWindow, + isModal: this.isModal, + buttons: [ + { + text: 'item1', + color: '#666666' + }, + ] + }, (err, data) => { + if (err) { + console.info('showActionMenu err: ' + err); + return; + } + console.info('showActionMenu success callback, click button: ' + data.index); + }) + } catch (error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code + console.error(`showActionMenu args error code is ${code}, message is ${message}`); + }; + }) + + Text("Show ActionMenu02 with 2 buttons") + .fontSize(18) + .margin({top: 24}) + Button('Show ActionMenu02') + .fontSize(20) + .margin({bottom: 20}) + .onClick(() => { + try { + promptAction.showActionMenu({ + title: this.title, + showInSubWindow: this.showInSubWindow, + isModal: this.isModal, + buttons: [ + { + text: 'item1', + color: '#666666' + }, + { + text: 'item2', + color: '#666666' + }, + ] + }, (err, data) => { + if (err) { + console.info('showActionMenu err: ' + err); + return; + } + console.info('showActionMenu success callback, click button: ' + data.index); + }) + } catch (error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code + console.error(`showActionMenu args error code is ${code}, message is ${message}`); + }; + }) + + Text("Show ActionMenu03 with 3 buttons") + .fontSize(18) + .margin({top: 24}) + Button('Show ActionMenu03') + .fontSize(20) + .margin({bottom: 20}) + .onClick(() => { + try { + promptAction.showActionMenu({ + title: this.title, + showInSubWindow: this.showInSubWindow, + isModal: this.isModal, + buttons: [ + { + text: 'item1', + color: '#666666' + }, + { + text: 'item2', + color: '#666666' + }, + { + text: 'item3', + color: '#666666' + }, + ] + }, (err, data) => { + if (err) { + console.info('showActionMenu err: ' + err); + return; + } + console.info('showActionMenu success callback, click button: ' + data.index); + }) + } catch (error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code + console.error(`showActionMenu args error code is ${code}, message is ${message}`); + }; + }) + + Text("Show ActionMenu04 with 4 buttons") + .fontSize(18) + .margin({top: 24}) + Button('Show ActionMenu04') + .fontSize(20) + .margin({bottom: 20}) + .onClick(() => { + try { + promptAction.showActionMenu({ + title: this.title, + showInSubWindow: this.showInSubWindow, + isModal: this.isModal, + buttons: [ + { + text: 'item1', + color: '#666666' + }, + { + text: 'item2', + color: '#666666' + }, + { + text: 'item3', + color: '#666666' + }, + { + text: 'item4', + color: '#666666' + }, + ] + }, (err, data) => { + if (err) { + console.info('showActionMenu err: ' + err); + return; + } + console.info('showActionMenu success callback, click button: ' + data.index); + }) + } catch (error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code + console.error(`showActionMenu args error code is ${code}, message is ${message}`); + }; + }) + + Text("Show ActionMenu05 with 5 buttons") + .fontSize(18) + .margin({top: 24}) + Button('Show ActionMenu05') + .fontSize(20) + .margin({bottom: 20}) + .onClick(() => { + try { + promptAction.showActionMenu({ + title: this.title, + showInSubWindow: this.showInSubWindow, + isModal: this.isModal, + buttons: [ + { + text: 'item1', + color: '#666666' + }, + { + text: 'item2', + color: '#666666' + }, + { + text: 'item3', + color: '#666666' + }, + { + text: 'item4', + color: '#666666' + }, + { + text: 'item5', + color: '#666666' + }, + ] + }, (err, data) => { + if (err) { + console.info('showActionMenu err: ' + err); + return; + } + console.info('showActionMenu success callback, click button: ' + data.index); + }) + } catch (error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code + console.error(`showActionMenu args error code is ${code}, message is ${message}`); + }; + }) + + Text("Show ActionMenu06 with 6 buttons") + .fontSize(18) + .margin({top: 24}) + Button('Show ActionMenu06') + .fontSize(20) + .margin({bottom: 20}) + .onClick(() => { + try { + promptAction.showActionMenu({ + title: this.title, + showInSubWindow: this.showInSubWindow, + isModal: this.isModal, + buttons: [ + { + text: 'item1', + color: '#666666' + }, + { + text: 'item2', + color: '#666666' + }, + { + text: 'item3', + color: '#666666' + }, + { + text: 'item4', + color: '#666666' + }, + { + text: 'item5', + color: '#666666' + }, + { + text: 'item6', + color: '#666666' + }, + ] + }, (err, data) => { + if (err) { + console.info('showActionMenu err: ' + err); + return; + } + console.info('showActionMenu success callback, click button: ' + data.index); + }) + } catch (error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code + console.error(`showActionMenu args error code is ${code}, message is ${message}`); + }; + }) + + }.width('100%') + }.height('100%') + } +} + diff --git a/function/arkui/inspector_test/entry/src/main/ets/pages/promptAction/promptAction04.ets b/function/arkui/inspector_test/entry/src/main/ets/pages/promptAction/promptAction04.ets new file mode 100644 index 0000000000000000000000000000000000000000..c2076a123c0394d14ec3f3c47c609b38ea922827 --- /dev/null +++ b/function/arkui/inspector_test/entry/src/main/ets/pages/promptAction/promptAction04.ets @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2025 Shenzhen Kaihong Digital Industry Development 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 { promptAction } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; + +let customDialogId: number = 0 +@Builder +function customStyleDialogBuilder() { + Column() { + Text('Custom dialog message01').fontSize(10) + Row() { + Button("确认").onClick(() => { + promptAction.closeCustomDialog(customDialogId) + }) + Blank().width(50) + Button("取消").onClick(() => { + promptAction.closeCustomDialog(customDialogId) + }) + } + Text('Custom dialog message02').fontSize(10) + } +} + +@Entry +@Component +struct customDialogExample { + private customDialogComponentId: number = 0 + @State message: string = 'Hello World' + + @Builder + customStyleDialogComponent() { + customStyleDialogBuilder() + } + + @Builder + customDialogComponent() { + Row() { + Column() { + Text('弹窗').fontSize(30) + Row({ space: 50 }) { + Button("确认").onClick(() => { + try { + promptAction.closeCustomDialog(this.customDialogComponentId) + } catch (error) { + let message = (error as BusinessError).message; + let code = (error as BusinessError).code; + console.error(`closeCustomDialog error code is ${code}, message is ${message}`); + } + }) + Button("取消").onClick(() => { + try { + promptAction.closeCustomDialog(this.customDialogComponentId) + } catch (error) { + let message = (error as BusinessError).message; + let code = (error as BusinessError).code; + console.error(`closeCustomDialog error code is ${code}, message is ${message}`); + } + }) + } + }.height(200).padding(5).justifyContent(FlexAlign.SpaceBetween) + } + } + + build() { + Scroll() { + Column() { + Text("promptAction.openCustomDialog()") + .fontSize(18) + .margin({top: 24, bottom: 24}) + + Button('CustomDialog01') + .fontSize(30) + .onClick(() => { + promptAction.openCustomDialog({ + builder: () => { + this.customDialogComponent() + }, + onWillDismiss: (dismissDialogAction: DismissDialogAction) => { + console.info("reason" + JSON.stringify(dismissDialogAction.reason)) + console.log("dialog onWillDismiss") + if (dismissDialogAction.reason == DismissReason.PRESS_BACK) { + dismissDialogAction.dismiss() + } + if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) { + dismissDialogAction.dismiss() + } + } + }).then((dialogId: number) => { + this.customDialogComponentId = dialogId + }) + .catch((error: BusinessError) => { + console.error(`openCustomDialog error code is ${error.code}, message is ${error.message}`) + }) + }) + .margin({top: 10, bottom: 10}) + + Button('CustomDialog02') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + promptAction.openCustomDialog({ + builder: () => { + this.customStyleDialogComponent() + }, + keyboardAvoidMode: KeyboardAvoidMode.NONE, + showInSubWindow: false, + offset: { dx: 5, dy: 5 }, + backgroundColor: 0xd9ffffff, + cornerRadius: 20, + width: '80%', + height: 200, + borderWidth: 1, + borderStyle: BorderStyle.Dashed, + borderColor: Color.Blue, + shadow: ({ + radius: 20, + color: Color.Grey, + offsetX: 50, + offsetY: 0 + }), + }).then((dialogId: number) => { + customDialogId = dialogId + }) + }) + .margin({top: 10, bottom: 10}) + + }.width('100%') + }.height('100%') + } +} + diff --git a/function/arkui/inspector_test/entry/src/main/resources/base/profile/main_pages.json b/function/arkui/inspector_test/entry/src/main/resources/base/profile/main_pages.json index 164b8d65576d2256dba908c4e182e81aa5dfb397..cad8eda3b80ca7f2ef8eb988c1909786ccfd9ad8 100644 --- a/function/arkui/inspector_test/entry/src/main/resources/base/profile/main_pages.json +++ b/function/arkui/inspector_test/entry/src/main/resources/base/profile/main_pages.json @@ -34,6 +34,12 @@ "pages/AlertDialog/alertDialog02", "pages/AlertDialog/alertDialog03", "pages/AlertDialog/alertDialog04", - "pages/CalendarPickerDialog/calendarPickerDialog" + "pages/CalendarPickerDialog/calendarPickerDialog", + "pages/TextPickerDialog/textPickerDialog01", + "pages/promptAction/promptAction01", + "pages/promptAction/promptAction02", + "pages/promptAction/promptAction03", + "pages/promptAction/promptAction04", + "pages/bindMenu/bindMenu01" ] }