diff --git a/PageAndData03/03_Complete/entry/src/main/ets/common/network/ConnectionUtils.ets b/PageAndData03/03_Complete/entry/src/main/ets/common/network/ConnectionUtils.ets index e2ca4d96d32673d24b9815bf7bb316c5e3639895..81979488638807c1b9068e5ac79bb45e4a76be66 100644 --- a/PageAndData03/03_Complete/entry/src/main/ets/common/network/ConnectionUtils.ets +++ b/PageAndData03/03_Complete/entry/src/main/ets/common/network/ConnectionUtils.ets @@ -15,7 +15,6 @@ import { connection } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; -import { promptAction } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'ConnectionUtils'; @@ -71,23 +70,23 @@ export class ConnectionUtils { /** *The method of listening to the network status. */ - registerNetworkAvailableStatus() { + registerNetworkAvailableStatus(context: UIContext) { this.netConnection.on('netAvailable', () => { - promptAction.showToast({ + context.getPromptAction().showToast({ message: $r('app.string.Network_Available'), duration: 2000 }); }); this.netConnection.on('netUnavailable', () => { - promptAction.showToast({ + context.getPromptAction().showToast({ message: $r('app.string.Network_Unavailable'), duration: 2000 }); }); this.netConnection.on('netLost', () => { - promptAction.showToast({ + context.getPromptAction().showToast({ message: $r('app.string.Network_Lost'), duration: 2000 }); diff --git a/PageAndData03/03_Complete/entry/src/main/ets/entryability/EntryAbility.ets b/PageAndData03/03_Complete/entry/src/main/ets/entryability/EntryAbility.ets index 4a69eff069010eb1fce2a8f550777f30832a0a87..c822fc33f0df9fe704e248b9f88b739c67d82b83 100644 --- a/PageAndData03/03_Complete/entry/src/main/ets/entryability/EntryAbility.ets +++ b/PageAndData03/03_Complete/entry/src/main/ets/entryability/EntryAbility.ets @@ -49,7 +49,8 @@ export default class entryAbility extends UIAbility { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; } - ConnectionUtils.registerNetworkAvailableStatus(); + let context: UIContext = windowStage.getMainWindowSync().getUIContext(); + ConnectionUtils.registerNetworkAvailableStatus(context); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); }); diff --git a/PageAndData03/03_Complete/entry/src/main/ets/pages/LoginPage.ets b/PageAndData03/03_Complete/entry/src/main/ets/pages/LoginPage.ets index e736b5a437164f41a5d0ca1a3979b89599cf93d4..c2325aaea036f65422fd71763f3fca954e2f6ed8 100644 --- a/PageAndData03/03_Complete/entry/src/main/ets/pages/LoginPage.ets +++ b/PageAndData03/03_Complete/entry/src/main/ets/pages/LoginPage.ets @@ -13,9 +13,7 @@ * limitations under the License. */ -import { promptAction } from '@kit.ArkUI'; import ConnectionUtils from '../common/network/ConnectionUtils'; -import { MainPage } from './MainPage'; @Extend(TextInput) function inputStyle() { @@ -65,7 +63,7 @@ struct LoginPage { login(result: boolean): void { if (this.account === '' || this.password === '') { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.input_empty_tips') }); } else { @@ -78,7 +76,7 @@ struct LoginPage { if (result) { this.pathStack.pushPathByName('MainPage', null); } else { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.Network_Lost') }); } diff --git a/PageAndData03/03_Complete/entry/src/main/ets/view/Home.ets b/PageAndData03/03_Complete/entry/src/main/ets/view/Home.ets index f5fbc66cde44aa27a7264296a0cf63baad822fb3..221ac1a99f79b6880b72644893f6112304688083 100644 --- a/PageAndData03/03_Complete/entry/src/main/ets/view/Home.ets +++ b/PageAndData03/03_Complete/entry/src/main/ets/view/Home.ets @@ -28,7 +28,7 @@ export default struct Home { @State httpGridItems: Array = []; @State pictureUri: string = ''; private swiperController: SwiperController = new SwiperController(); - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; private applicationContext = this.context.getApplicationContext(); private cacheDir = this.applicationContext.filesDir; diff --git a/PageAndData03/03_Complete/entry/src/main/ets/view/test.ets b/PageAndData03/03_Complete/entry/src/main/ets/view/test.ets index 74041dada999c834c52b23f6b5e7c301f0e51ae7..a120ae7fac6bb49face16b512937d75dff12d83b 100644 --- a/PageAndData03/03_Complete/entry/src/main/ets/view/test.ets +++ b/PageAndData03/03_Complete/entry/src/main/ets/view/test.ets @@ -25,7 +25,7 @@ export default struct Home { @State httpGridItems: Array = []; @State pictureUri: string = ''; private swiperController: SwiperController = new SwiperController(); - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; private applicationContext = this.context.getApplicationContext(); private cacheDir = this.applicationContext.filesDir; diff --git a/PageAndData04/04_Complete/entry/src/main/ets/common/network/ConnectionUtils.ets b/PageAndData04/04_Complete/entry/src/main/ets/common/network/ConnectionUtils.ets index e2ca4d96d32673d24b9815bf7bb316c5e3639895..81979488638807c1b9068e5ac79bb45e4a76be66 100644 --- a/PageAndData04/04_Complete/entry/src/main/ets/common/network/ConnectionUtils.ets +++ b/PageAndData04/04_Complete/entry/src/main/ets/common/network/ConnectionUtils.ets @@ -15,7 +15,6 @@ import { connection } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; -import { promptAction } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'ConnectionUtils'; @@ -71,23 +70,23 @@ export class ConnectionUtils { /** *The method of listening to the network status. */ - registerNetworkAvailableStatus() { + registerNetworkAvailableStatus(context: UIContext) { this.netConnection.on('netAvailable', () => { - promptAction.showToast({ + context.getPromptAction().showToast({ message: $r('app.string.Network_Available'), duration: 2000 }); }); this.netConnection.on('netUnavailable', () => { - promptAction.showToast({ + context.getPromptAction().showToast({ message: $r('app.string.Network_Unavailable'), duration: 2000 }); }); this.netConnection.on('netLost', () => { - promptAction.showToast({ + context.getPromptAction().showToast({ message: $r('app.string.Network_Lost'), duration: 2000 }); diff --git a/PageAndData04/04_Complete/entry/src/main/ets/entryability/EntryAbility.ets b/PageAndData04/04_Complete/entry/src/main/ets/entryability/EntryAbility.ets index d113d5a0dfb97deea90c6088c4162338d3c80bb6..b3294e902d02dcdcf5978459bcd2af0c7b21e345 100644 --- a/PageAndData04/04_Complete/entry/src/main/ets/entryability/EntryAbility.ets +++ b/PageAndData04/04_Complete/entry/src/main/ets/entryability/EntryAbility.ets @@ -53,7 +53,8 @@ export default class entryAbility extends UIAbility { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; } - ConnectionUtils.registerNetworkAvailableStatus(); + let context: UIContext = windowStage.getMainWindowSync().getUIContext(); + ConnectionUtils.registerNetworkAvailableStatus(context); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); }); diff --git a/PageAndData04/04_Complete/entry/src/main/ets/pages/GoalPage.ets b/PageAndData04/04_Complete/entry/src/main/ets/pages/GoalPage.ets index e09d53b6b457a61e8118b60afa0ed692234f11cd..de1dddcdb39969cc4f2ff2601408b38c05b66efa 100644 --- a/PageAndData04/04_Complete/entry/src/main/ets/pages/GoalPage.ets +++ b/PageAndData04/04_Complete/entry/src/main/ets/pages/GoalPage.ets @@ -333,7 +333,7 @@ export struct GoalPage { .width('40vp') .margin({ right: '16vp' }) .onClick(() => { - AlertDialog.show( + this.getUIContext().showAlertDialog( { message: $r('app.string.delete_question'), autoCancel: true, diff --git a/PageAndData04/04_Complete/entry/src/main/ets/pages/LoginPage.ets b/PageAndData04/04_Complete/entry/src/main/ets/pages/LoginPage.ets index 2f543a45f04be52bea8b081aef4804165ffe3441..62ff5c8cc506e837b415637aa52fdfd5d503e9b0 100644 --- a/PageAndData04/04_Complete/entry/src/main/ets/pages/LoginPage.ets +++ b/PageAndData04/04_Complete/entry/src/main/ets/pages/LoginPage.ets @@ -64,7 +64,7 @@ struct LoginPage { login(result: boolean): void { if (this.account === '' || this.password === '') { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.input_empty_tips') }); } else { @@ -77,7 +77,7 @@ struct LoginPage { if (result) { this.pathStack.pushPathByName('MainPage', null); } else { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.Network_Lost') }); } diff --git a/PageAndData04/04_Complete/entry/src/main/ets/view/Home.ets b/PageAndData04/04_Complete/entry/src/main/ets/view/Home.ets index 1f23a3928fbdc39be5b65160db2744e195ab343a..e0b9aeee2a976e1bd92b26dd35b918b3de2df054 100644 --- a/PageAndData04/04_Complete/entry/src/main/ets/view/Home.ets +++ b/PageAndData04/04_Complete/entry/src/main/ets/view/Home.ets @@ -30,7 +30,7 @@ export default struct Home { @State pictureUri: string = ''; @Link pathStack: NavPathStack; private swiperController: SwiperController = new SwiperController(); - context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; applicationContext = this.context.getApplicationContext(); cacheDir = this.applicationContext.filesDir; diff --git a/PageAndData04/04_StartingPoint/entry/src/main/ets/common/network/ConnectionUtils.ets b/PageAndData04/04_StartingPoint/entry/src/main/ets/common/network/ConnectionUtils.ets index e2ca4d96d32673d24b9815bf7bb316c5e3639895..81979488638807c1b9068e5ac79bb45e4a76be66 100644 --- a/PageAndData04/04_StartingPoint/entry/src/main/ets/common/network/ConnectionUtils.ets +++ b/PageAndData04/04_StartingPoint/entry/src/main/ets/common/network/ConnectionUtils.ets @@ -15,7 +15,6 @@ import { connection } from '@kit.NetworkKit'; import { BusinessError } from '@kit.BasicServicesKit'; -import { promptAction } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'ConnectionUtils'; @@ -71,23 +70,23 @@ export class ConnectionUtils { /** *The method of listening to the network status. */ - registerNetworkAvailableStatus() { + registerNetworkAvailableStatus(context: UIContext) { this.netConnection.on('netAvailable', () => { - promptAction.showToast({ + context.getPromptAction().showToast({ message: $r('app.string.Network_Available'), duration: 2000 }); }); this.netConnection.on('netUnavailable', () => { - promptAction.showToast({ + context.getPromptAction().showToast({ message: $r('app.string.Network_Unavailable'), duration: 2000 }); }); this.netConnection.on('netLost', () => { - promptAction.showToast({ + context.getPromptAction().showToast({ message: $r('app.string.Network_Lost'), duration: 2000 }); diff --git a/PageAndData04/04_StartingPoint/entry/src/main/ets/entryability/EntryAbility.ets b/PageAndData04/04_StartingPoint/entry/src/main/ets/entryability/EntryAbility.ets index 4a69eff069010eb1fce2a8f550777f30832a0a87..c822fc33f0df9fe704e248b9f88b739c67d82b83 100644 --- a/PageAndData04/04_StartingPoint/entry/src/main/ets/entryability/EntryAbility.ets +++ b/PageAndData04/04_StartingPoint/entry/src/main/ets/entryability/EntryAbility.ets @@ -49,7 +49,8 @@ export default class entryAbility extends UIAbility { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; } - ConnectionUtils.registerNetworkAvailableStatus(); + let context: UIContext = windowStage.getMainWindowSync().getUIContext(); + ConnectionUtils.registerNetworkAvailableStatus(context); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); }); diff --git a/PageAndData04/04_StartingPoint/entry/src/main/ets/pages/LoginPage.ets b/PageAndData04/04_StartingPoint/entry/src/main/ets/pages/LoginPage.ets index e736b5a437164f41a5d0ca1a3979b89599cf93d4..c2325aaea036f65422fd71763f3fca954e2f6ed8 100644 --- a/PageAndData04/04_StartingPoint/entry/src/main/ets/pages/LoginPage.ets +++ b/PageAndData04/04_StartingPoint/entry/src/main/ets/pages/LoginPage.ets @@ -13,9 +13,7 @@ * limitations under the License. */ -import { promptAction } from '@kit.ArkUI'; import ConnectionUtils from '../common/network/ConnectionUtils'; -import { MainPage } from './MainPage'; @Extend(TextInput) function inputStyle() { @@ -65,7 +63,7 @@ struct LoginPage { login(result: boolean): void { if (this.account === '' || this.password === '') { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.input_empty_tips') }); } else { @@ -78,7 +76,7 @@ struct LoginPage { if (result) { this.pathStack.pushPathByName('MainPage', null); } else { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.Network_Lost') }); } diff --git a/PageAndData04/04_StartingPoint/entry/src/main/ets/view/Home.ets b/PageAndData04/04_StartingPoint/entry/src/main/ets/view/Home.ets index f5fbc66cde44aa27a7264296a0cf63baad822fb3..221ac1a99f79b6880b72644893f6112304688083 100644 --- a/PageAndData04/04_StartingPoint/entry/src/main/ets/view/Home.ets +++ b/PageAndData04/04_StartingPoint/entry/src/main/ets/view/Home.ets @@ -28,7 +28,7 @@ export default struct Home { @State httpGridItems: Array = []; @State pictureUri: string = ''; private swiperController: SwiperController = new SwiperController(); - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; private applicationContext = this.context.getApplicationContext(); private cacheDir = this.applicationContext.filesDir; diff --git a/PageAndData04/04_StartingPoint/entry/src/main/ets/view/test.ets b/PageAndData04/04_StartingPoint/entry/src/main/ets/view/test.ets index 74041dada999c834c52b23f6b5e7c301f0e51ae7..a120ae7fac6bb49face16b512937d75dff12d83b 100644 --- a/PageAndData04/04_StartingPoint/entry/src/main/ets/view/test.ets +++ b/PageAndData04/04_StartingPoint/entry/src/main/ets/view/test.ets @@ -25,7 +25,7 @@ export default struct Home { @State httpGridItems: Array = []; @State pictureUri: string = ''; private swiperController: SwiperController = new SwiperController(); - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; private applicationContext = this.context.getApplicationContext(); private cacheDir = this.applicationContext.filesDir;