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