• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import i18n from '@ohos.i18n'
16import IntlUtil from '../model/IntlUtil'
17import TitleBar from '../view/TitleBar'
18import ResourceUtil from '../model/ResourceUtil'
19
20@Entry
21@Component
22struct Examples {
23  private is24Hours: boolean = i18n.is24HourClock()
24  @State date: string = ''
25  @State time: string = ''
26  @State language: string = ''
27  @State numberFormat: Array<string> = []
28  @State pluralFormat: string = ''
29  @State mDirection: string = ''
30
31  aboutToAppear() {
32    this.getLanguage()
33    this.getTimeDisplay()
34    this.numberFormat = IntlUtil.getNumberFormatString()
35    this.getPluralFormat()
36  }
37
38  async getPluralFormat() {
39    this.pluralFormat = await ResourceUtil.getPluralString($r('app.plural.eat_apple').id, 5)
40    this.mDirection = await ResourceUtil.getString($r('app.string.screen_direction').id)
41    this.mDirection += await ResourceUtil.getDirection()
42  }
43
44  getTimeDisplay() {
45    let timeInfo = IntlUtil.getDateString()
46    this.date = timeInfo[0]
47    this.time = timeInfo[1]
48  }
49
50  getLanguage() {
51    let systemLanguage = i18n.getSystemLanguage()
52    this.language = i18n.getDisplayLanguage(systemLanguage, systemLanguage)
53  }
54
55  @Builder TextView(text) {
56    Text(text)
57      .fontSize(22)
58      .fontColor(Color.Gray)
59      .width('95%')
60      .margin({ top: 20 })
61  }
62
63  build() {
64    Column() {
65      TitleBar({ hasBackPress: true, title: $r('app.string.format_example') })
66      this.TextView(this.language)
67      Column() {
68        this.TextView(this.date)
69        this.TextView(this.time)
70        ForEach(this.numberFormat, (item, index) => {
71          this.TextView(item)
72        }, item => item)
73        this.TextView(this.pluralFormat)
74        this.TextView(this.mDirection)
75      }
76      .width('95%')
77      .padding(10)
78      .backgroundColor(Color.White)
79      .margin({ top: 10 })
80      .border({ color: Color.White, width: 1, radius: 15 })
81    }
82    .width('100%')
83    .height('100%')
84    .backgroundColor('#F5F5F5')
85  }
86}