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 } from '../redux/actions/Action'; 1742365ec6Sopenharmony_ciimport { CameraBasicFunction } from '../function/CameraBasicFunction'; 1842365ec6Sopenharmony_ciimport { CaptureFunction } from '../function/CaptureFunction'; 1942365ec6Sopenharmony_ciimport { Log } from '../utils/Log'; 2042365ec6Sopenharmony_ciimport { FunctionId } from './FunctionId'; 2142365ec6Sopenharmony_ciimport type { EventBus } from '../worker/eventbus/EventBus'; 2242365ec6Sopenharmony_ciimport { EventBusManager } from '../worker/eventbus/EventBusManager'; 2342365ec6Sopenharmony_ciimport { ModeAssembler } from './ModeAssembler'; 2442365ec6Sopenharmony_ciimport { RecordFunction } from '../function/RecordFunction'; 2542365ec6Sopenharmony_ciimport { WorkerManager } from '../worker/WorkerManager'; 2642365ec6Sopenharmony_ciimport { ZoomFunction } from '../function/ZoomFunction'; 2742365ec6Sopenharmony_ciimport type { IModeMap } from './IModeMap'; 2842365ec6Sopenharmony_ci 2942365ec6Sopenharmony_ciconst TAG = '[FeatureManager]:'; 3042365ec6Sopenharmony_ci 3142365ec6Sopenharmony_ciexport class FeatureManager { 3242365ec6Sopenharmony_ci appEventBus: EventBus = EventBusManager.getInstance().getEventBus(); 3342365ec6Sopenharmony_ci private mModeAssembler: ModeAssembler; 3442365ec6Sopenharmony_ci private mPreMode: string = 'PHOTO'; 3542365ec6Sopenharmony_ci public mCurrentMode: string = this.mPreMode; 3642365ec6Sopenharmony_ci private mFunctionsMap = new Map(); 3742365ec6Sopenharmony_ci 3842365ec6Sopenharmony_ci constructor(mode: string, modeMap: IModeMap) { 3942365ec6Sopenharmony_ci Log.info(`${TAG} constructor`); 4042365ec6Sopenharmony_ci this.initFunctionsMap(); 4142365ec6Sopenharmony_ci this.mModeAssembler = new ModeAssembler(this.mFunctionsMap, modeMap); 4242365ec6Sopenharmony_ci this.mPreMode = mode; 4342365ec6Sopenharmony_ci this.mCurrentMode = mode; 4442365ec6Sopenharmony_ci this.mFunctionsMap.get(FunctionId.CAMERA_BASIC_FUNCTION).load(); 4542365ec6Sopenharmony_ci this.mModeAssembler.assembler(null, this.mPreMode); 4642365ec6Sopenharmony_ci // 接收到modeChange的消息,调用changeMode做处理 4742365ec6Sopenharmony_ci this.appEventBus.on(Action.ACTION_CHANGE_MODE, this.changeMode.bind(this)); 4842365ec6Sopenharmony_ci } 4942365ec6Sopenharmony_ci 5042365ec6Sopenharmony_ci public changeMode(data: any): void { 5142365ec6Sopenharmony_ci // 外部条件触发mode切换,传入下一个mode名称 5242365ec6Sopenharmony_ci Log.info(`${TAG} changeMode start data: ${JSON.stringify(data)}`); 5342365ec6Sopenharmony_ci this.mModeAssembler.assembler(this.mPreMode, data.mode); 5442365ec6Sopenharmony_ci this.mPreMode = data.mode; 5542365ec6Sopenharmony_ci } 5642365ec6Sopenharmony_ci 5742365ec6Sopenharmony_ci private initFunctionsMap(): void { 5842365ec6Sopenharmony_ci Log.info(`${TAG} initFunctionsMap invoke E.`); 5942365ec6Sopenharmony_ci this.mFunctionsMap.set(FunctionId.CAMERA_BASIC_FUNCTION, CameraBasicFunction.getInstance()); 6042365ec6Sopenharmony_ci this.mFunctionsMap.set(FunctionId.CAPTURE_FUNCTION, new CaptureFunction()); 6142365ec6Sopenharmony_ci this.mFunctionsMap.set(FunctionId.RECORDING_FUNCTION, new RecordFunction()); 6242365ec6Sopenharmony_ci this.mFunctionsMap.set(FunctionId.ZOOM_FUNCTION, new ZoomFunction()); 6342365ec6Sopenharmony_ci Log.info(`${TAG} initFunctionsMap invoke X.`); 6442365ec6Sopenharmony_ci } 6542365ec6Sopenharmony_ci}