1/*
2 * Copyright (c) 2021-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 */
15
16import wifi from '@ohos.wifi';
17import Log from '../../../../../../../common/src/main/ets/default/Log';
18import iconTitleBase from '../../../../../../../common/src/main/ets/template/iconTitleBase';
19
20const TAG = 'Control-airPlaneComponent';
21
22@Component
23export default
24struct airplaneComponent {
25
26  private IconInfo: any[] = [
27    $r('app.media.airplane_d'),
28    $r('app.media.airplane'),
29  ];
30  @State flyModelTitle: Resource = $r("app.string.airplane_mode");
31  @StorageLink('flyModelStatus') flyModelStatus: boolean = false;
32  private mWifiOriginalStatus: boolean = false;
33
34
35/*  when flyModelStatus == true, so airplane is opening,
36 *  use variable mWifiOriginalStatus to record WLAN current status
37 *  use system interface to WLAN current status: WifiInfo.isWifiActive()
38 *  when flyModelStatus == false ,so airplane is closed
39 *      get variable mWifiOriginalStatus
40 *           if variable mWifiOriginalStatus == true, set WLAN status enableWifi(),conversely disableWifi().
41 */
42  mClickEvent() {
43    this.flyModelStatus =!this.flyModelStatus;
44    Log.showDebug(TAG, `flyModelStatus:${this.flyModelStatus}`);
45    if (this.flyModelStatus == true) {
46      this.mWifiOriginalStatus = wifi.isWifiActive();
47      Log.showInfo(TAG, `airplane status is opening, WLAN Original Status :${this.mWifiOriginalStatus}`);
48      wifi.disableWifi();
49    }else{
50      if(this.mWifiOriginalStatus == true) {
51        wifi.enableWifi();
52        Log.showInfo(TAG, `airplane status closed, WLAN Original Status:${this.mWifiOriginalStatus},get system interface, set WLAN status enableWifi`);
53      } else {
54        wifi.disableWifi();
55        Log.showInfo(TAG, `airplane status closed, WLAN Original Status:${this.mWifiOriginalStatus},,get system interface, set WLAN status disableWifi`);
56      };
57    };
58  }
59
60  aboutToAppear(){
61    Log.showInfo(TAG, 'aboutToAppear');
62  }
63
64  aboutToDisappear (){
65    Log.showInfo(TAG, 'aboutToDisappear ');
66  }
67
68  build() {
69    Column() {
70      iconTitleBase({
71        iconOff: this.IconInfo[0],
72        iconOn: this.IconInfo[1],
73        mTitle: $flyModelTitle,
74        changeSwitch: $flyModelStatus,
75        mClickEvent: () => this.mClickEvent()
76      })
77    }.width('100%')
78    .height('100%')
79  }
80}