142365ec6Sopenharmony_ci/*
242365ec6Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
342365ec6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
442365ec6Sopenharmony_ci * you may not use this file except in compliance with the License.
542365ec6Sopenharmony_ci * You may obtain a copy of the License at
642365ec6Sopenharmony_ci *
742365ec6Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
842365ec6Sopenharmony_ci *
942365ec6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1042365ec6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1142365ec6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1242365ec6Sopenharmony_ci * See the License for the specific language governing permissions and
1342365ec6Sopenharmony_ci * limitations under the License.
1442365ec6Sopenharmony_ci */
1542365ec6Sopenharmony_ci
1642365ec6Sopenharmony_ciimport { Action, UiStateMode } from '../redux/actions/Action';
1742365ec6Sopenharmony_ciimport { GlobalContext } from '../utils/GlobalContext';
1842365ec6Sopenharmony_ciimport { Log } from '../utils/Log';
1942365ec6Sopenharmony_ciimport { BaseFunction } from './BaseFunction';
2042365ec6Sopenharmony_ci
2142365ec6Sopenharmony_ciconst TAG: string = '[CaptureFunction]:';
2242365ec6Sopenharmony_ci
2342365ec6Sopenharmony_ciexport class CaptureFunction extends BaseFunction {
2442365ec6Sopenharmony_ci  load(): void {
2542365ec6Sopenharmony_ci    Log.info(`${TAG} load E`);
2642365ec6Sopenharmony_ci    this.mEventBus.on(Action.ACTION_CAPTURE, this.capture.bind(this));
2742365ec6Sopenharmony_ci    this.mEventBus.on(Action.ACTION_CAPTURE_PHOTO_OUTPUT, this.onCapturePhotoOutput.bind(this));
2842365ec6Sopenharmony_ci    Log.info(`${TAG} load X`);
2942365ec6Sopenharmony_ci  }
3042365ec6Sopenharmony_ci
3142365ec6Sopenharmony_ci  unload(): void {
3242365ec6Sopenharmony_ci    Log.info(`${TAG} unload E`);
3342365ec6Sopenharmony_ci    this.mEventBus.off(Action.ACTION_CAPTURE, this.capture.bind(this));
3442365ec6Sopenharmony_ci    this.mEventBus.off(Action.ACTION_CAPTURE_PHOTO_OUTPUT, this.onCapturePhotoOutput.bind(this));
3542365ec6Sopenharmony_ci    Log.info(`${TAG} unload X`);
3642365ec6Sopenharmony_ci  }
3742365ec6Sopenharmony_ci
3842365ec6Sopenharmony_ci  private async capture(): Promise<void> {
3942365ec6Sopenharmony_ci    Log.info(`${TAG} capture E`);
4042365ec6Sopenharmony_ci    GlobalContext.get().setObject('startCaptureTime', new Date().getTime())
4142365ec6Sopenharmony_ci    this.disableUiWithMode(UiStateMode.EXCLUDE_PREVIEW);
4242365ec6Sopenharmony_ci    await this.mCameraService.takePicture();
4342365ec6Sopenharmony_ci    Log.info(`${TAG} capture X`);
4442365ec6Sopenharmony_ci  }
4542365ec6Sopenharmony_ci
4642365ec6Sopenharmony_ci  private onCapturePhotoOutput(): void {
4742365ec6Sopenharmony_ci    Log.info(`${TAG} onCapturePhotoOutput E`);
4842365ec6Sopenharmony_ci    this.enableUiWithMode(UiStateMode.EXCLUDE_PREVIEW);
4942365ec6Sopenharmony_ci    Log.info(`${TAG} onCapturePhotoOutput X`);
5042365ec6Sopenharmony_ci  }
5142365ec6Sopenharmony_ci}