• 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 mediaquery from '@ohos.mediaquery'
16import parameter from '@ohos.systemparameter'
17import { TabletTitle, BrowserTabs, WebTab } from '../common/TitleBar'
18import { PhoneLayout } from '../common/PhoneLayout'
19import { Browser, LoadingStatus } from '../model/Browser'
20import Logger from '../model/Logger'
21
22const TAG = '[index]'
23
24@Entry
25@Component
26struct Index {
27  @State isPhone: boolean= false
28  @State browser: Browser= new Browser()
29  private isInit: Boolean= false
30  listener= mediaquery.matchMediaSync('(orientation:landscape)')
31
32  build() {
33    Column() {
34      if (!this.isPhone) {
35        TabletTitle({ browser: $browser })
36        Progress({ value: this.browser.progress, total: 100 })
37          .color('#0000ff')
38          .visibility(this.browser.hideProgress ? Visibility.None : Visibility.Visible)
39        BrowserTabs({ browser: $browser })
40        Divider().color('#c6c6c6').width('100%').flexShrink(0)
41        WebTab({ browser: $browser, isPhone: $isPhone })
42      } else {
43        PhoneLayout({ browser: $browser })
44      }
45    }
46  }
47
48  aboutToAppear() {
49    try {
50      let deviceType = parameter.getSync("const.build.characteristics")
51      if (deviceType === 'phone') {
52        this.isPhone = true
53      }
54    } catch (e) {
55      Logger.info(TAG, `getSync unexpected error: ${e}`)
56    }
57  }
58
59  orientationCallback(result) {
60    if (!this.isInit) {
61      if (result.matches) {
62        this.isPhone = false
63      } else {
64        this.isPhone = true
65      }
66      this.isInit = true
67    }
68    Logger.info(TAG, `orientationCallback end,isPhone=${this.isPhone}`)
69  }
70
71  onBackPress(): boolean{
72    Logger.info(TAG, `enter onBackPress`)
73    if (this.browser.webControllerArray[this.browser.tabArrayIndex].controller.accessBackward() ||
74    this.browser.loadingStatus === LoadingStatus.LOADING) {
75      this.browser.webControllerArray[this.browser.tabArrayIndex].controller.backward()
76      return true
77    }
78    return false
79  }
80
81  onDeviceChange() {
82    this.browser = new Browser()
83  }
84}