• 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 */
15
16import { Action, UiStateMode } from '../redux/actions/Action'
17import { Log } from '../utils/Log'
18import { BaseFunction } from './BaseFunction'
19
20export class CaptureFunction extends BaseFunction {
21  private TAG = '[CaptureFunction]:'
22
23  private async capture(): Promise<void> {
24    Log.info(`${this.TAG} capture E`)
25    globalThis.startCaptureTime = new Date().getTime()
26    this.disableUiWithMode(UiStateMode.EXCLUDE_PREVIEW)
27    await this.mCameraService.takePicture()
28    Log.info(`${this.TAG} capture X`)
29  }
30
31  private onCapturePhotoOutput(){
32    Log.info(`${this.TAG} onCapturePhotoOutput E`)
33    this.enableUiWithMode(UiStateMode.EXCLUDE_PREVIEW)
34    Log.info(`${this.TAG} onCapturePhotoOutput X`)
35  }
36
37  load(): void{
38    Log.info(`${this.TAG} load E`)
39    this.mEventBus.on(Action.ACTION_CAPTURE, this.capture.bind(this))
40    this.mEventBus.on(Action.ACTION_CAPTURE_PHOTO_OUTPUT, this.onCapturePhotoOutput.bind(this))
41    Log.info(`${this.TAG} load X`)
42  }
43
44  unload(): void {
45    Log.info(`${this.TAG} unload E`)
46    this.mEventBus.off(Action.ACTION_CAPTURE, this.capture.bind(this))
47    this.mEventBus.off(Action.ACTION_CAPTURE_PHOTO_OUTPUT, this.onCapturePhotoOutput.bind(this))
48    Log.info(`${this.TAG} unload X`)
49
50  }
51}