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 } from '../../common/src/main/ets/default/redux/actions/Action' 17import { CameraBasicFunction } from '../../common/src/main/ets/default/function/CameraBasicFunction' 18import { CaptureFunction } from '../../common/src/main/ets/default/function/CaptureFunction' 19import { Log } from '../../common/src/main/ets/default/utils/Log' 20import { Constants } from './Constants' 21import { EventBus } from '../../common/src/main/ets/default/worker/eventbus/EventBus' 22import EventBusManager from '../../common/src/main/ets/default/worker/eventbus/EventBusManager' 23import { ModeAssembler } from './ModeAssembler' 24import { RecordFunction } from '../../common/src/main/ets/default/function/RecordFunction' 25import { WorkerManager } from '../../common/src/main/ets/default/worker/WorkerManager' 26import { ZoomFunction } from '../../common/src/main/ets/default/function/ZoomFunction' 27 28export class FeatureManager { 29 private TAG: string = '[FeatureManager]:' 30 private mModeAssembler: ModeAssembler 31 private mPreMode: string = 'PHOTO' 32 public mCurrentMode: string = this.mPreMode 33 appEventBus: EventBus = EventBusManager.getInstance().getEventBus() 34 private mFunctionsMap = new Map() 35 36 constructor(mode: string) { 37 Log.info(`${this.TAG} constructor`) 38 this.initFunctionsMap() 39 this.mModeAssembler = new ModeAssembler(this.mFunctionsMap) 40 this.mPreMode = mode 41 this.mCurrentMode = mode 42 this.mFunctionsMap.get(Constants.CAMERA_BASIC_FUNCTION).load() 43 this.mModeAssembler.assembler(null, this.mPreMode) 44 // 接收到modeChange的消息,调用changeMode做处理 45 this.appEventBus.on(Action.ACTION_CHANGE_MODE, this.changeMode.bind(this)) 46 } 47 48 public changeMode(data: any): void { 49 // 外部条件触发mode切换,传入下一个mode名称 50 Log.info(`${this.TAG} changeMode start data: ${JSON.stringify(data)}`) 51 this.mModeAssembler.assembler(this.mPreMode, data.mode) 52 this.mPreMode = data.mode 53 } 54 55 private initFunctionsMap(): void { 56 Log.info(`${this.TAG} initFunctionsMap invoke E.`) 57 this.mFunctionsMap.set(Constants.CAMERA_BASIC_FUNCTION, CameraBasicFunction.getInstance()) 58 this.mFunctionsMap.set(Constants.CAPTURE_FUNCTION, new CaptureFunction()) 59 this.mFunctionsMap.set(Constants.RECORDING_FUNCTION, new RecordFunction()) 60 this.mFunctionsMap.set(Constants.ZOOM_FUNCTION, new ZoomFunction()) 61 Log.info(`${this.TAG} initFunctionsMap invoke X.`) 62 } 63}