From f30b7036d665916949739e280bbf87a63c411b59 Mon Sep 17 00:00:00 2001 From: DevWiki Date: Mon, 26 Aug 2024 16:54:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=BE=E7=BD=AE=E8=AF=AD?= =?UTF-8?q?=E8=A8=80demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...moAbilityStage.ets => AppAbilityStage.ets} | 5 ++- app/src/main/ets/appability/AppAbility.ets | 2 + app/src/main/ets/pages/Index.ets | 3 +- .../main/ets/pages/system/SetLanguagePage.ets | 38 +++++++++++++++++++ app/src/main/module.json5 | 1 + .../main/resources/base/element/string.json | 4 ++ .../resources/base/profile/main_pages.json | 1 + .../main/resources/en_US/element/string.json | 4 ++ .../main/resources/zh_CN/element/string.json | 4 ++ 9 files changed, 60 insertions(+), 2 deletions(-) rename app/src/main/ets/{HMDemoAbilityStage.ets => AppAbilityStage.ets} (73%) create mode 100644 app/src/main/ets/pages/system/SetLanguagePage.ets diff --git a/app/src/main/ets/HMDemoAbilityStage.ets b/app/src/main/ets/AppAbilityStage.ets similarity index 73% rename from app/src/main/ets/HMDemoAbilityStage.ets rename to app/src/main/ets/AppAbilityStage.ets index 69d61ef..f1dae20 100644 --- a/app/src/main/ets/HMDemoAbilityStage.ets +++ b/app/src/main/ets/AppAbilityStage.ets @@ -1,8 +1,11 @@ import { AbilityConstant, AbilityStage, Configuration, Want } from '@kit.AbilityKit'; -class HMDemoAbilityStage extends AbilityStage { +const TAG = '[AbilityStage]'; + +export default class AppAbilityStage extends AbilityStage { onCreate(): void { + console.log(TAG, "onCreate") } // onAcceptWant(want: Want): string { diff --git a/app/src/main/ets/appability/AppAbility.ets b/app/src/main/ets/appability/AppAbility.ets index ebf3029..3222813 100644 --- a/app/src/main/ets/appability/AppAbility.ets +++ b/app/src/main/ets/appability/AppAbility.ets @@ -2,6 +2,8 @@ import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; +const TAG = '[AppAbility]' + export default class AppAbility extends UIAbility { constructor() { super(); diff --git a/app/src/main/ets/pages/Index.ets b/app/src/main/ets/pages/Index.ets index bfe497c..2ce7e30 100644 --- a/app/src/main/ets/pages/Index.ets +++ b/app/src/main/ets/pages/Index.ets @@ -61,7 +61,8 @@ struct Index { name: 'System', items: [ {name: "Scheme", page: 'pages/system/SchemePage'}, - {name: "MVVM", page: 'pages/mvvm/HomePage'} + {name: "MVVM", page: 'pages/mvvm/HomePage'}, + {name: "SetLanguage", page: 'pages/system/SetLanguagePage'} ] } ]; diff --git a/app/src/main/ets/pages/system/SetLanguagePage.ets b/app/src/main/ets/pages/system/SetLanguagePage.ets new file mode 100644 index 0000000..b1fa39c --- /dev/null +++ b/app/src/main/ets/pages/system/SetLanguagePage.ets @@ -0,0 +1,38 @@ +import { TitleBar } from '@devwiki/common_ui'; +import { i18n } from '@kit.LocalizationKit'; + +@Entry +@Component +struct SetLanguagePage { + + private readonly languageGroup = "languageGroup" + @State selectedIndex: number = 0; + + build() { + Column() { + TitleBar({ + title: $r('app.string.set_language_title') + }); + Row() { + Text('简体中文'); + Radio({group: this.languageGroup, value: '简体中文'}).checked(true).onChange(isChecked => { + if (isChecked) { + this.selectedIndex = 0; + } + }); + } + Row() { + Text('英文'); + Radio({group: this.languageGroup, value: '英文'}).checked(false).onChange(isChecked => { + if (isChecked) { + this.selectedIndex = 1; + } + }); + } + + Button('修改语言').onClick(() => { + i18n.System.setAppPreferredLanguage(this.selectedIndex == 0 ? 'zh-Hans' : 'en-US') + }) + }.width('100%').height('100%') + } +} \ No newline at end of file diff --git a/app/src/main/module.json5 b/app/src/main/module.json5 index 19880b4..8c0345a 100644 --- a/app/src/main/module.json5 +++ b/app/src/main/module.json5 @@ -4,6 +4,7 @@ "type": "entry", "description": "$string:module_desc", "mainElement": "AppAbility", + "srcEntry": "./ets/AppAbilityStage.ets", "deviceTypes": [ "phone", "tablet", diff --git a/app/src/main/resources/base/element/string.json b/app/src/main/resources/base/element/string.json index e1898e9..24874f9 100644 --- a/app/src/main/resources/base/element/string.json +++ b/app/src/main/resources/base/element/string.json @@ -11,6 +11,10 @@ { "name": "AppAbility_label", "value": "HM4Demo" + }, + { + "name": "set_language_title", + "value": "Set Language" } ] } \ No newline at end of file diff --git a/app/src/main/resources/base/profile/main_pages.json b/app/src/main/resources/base/profile/main_pages.json index 14e442c..dec409a 100644 --- a/app/src/main/resources/base/profile/main_pages.json +++ b/app/src/main/resources/base/profile/main_pages.json @@ -24,6 +24,7 @@ "pages/system/SchemePage", "pages/system/TimerPage", + "pages/system/SetLanguagePage", "pages/web/WebPage", "pages/web/WebDialogPage" diff --git a/app/src/main/resources/en_US/element/string.json b/app/src/main/resources/en_US/element/string.json index 826a1f1..b507587 100644 --- a/app/src/main/resources/en_US/element/string.json +++ b/app/src/main/resources/en_US/element/string.json @@ -11,6 +11,10 @@ { "name": "AppAbility_label", "value": "HMDemo" + }, + { + "name": "set_language_title", + "value": "Set Language" } ] } \ No newline at end of file diff --git a/app/src/main/resources/zh_CN/element/string.json b/app/src/main/resources/zh_CN/element/string.json index 826a1f1..1f661c2 100644 --- a/app/src/main/resources/zh_CN/element/string.json +++ b/app/src/main/resources/zh_CN/element/string.json @@ -11,6 +11,10 @@ { "name": "AppAbility_label", "value": "HMDemo" + }, + { + "name": "set_language_title", + "value": "设置语言" } ] } \ No newline at end of file