• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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 display from '@ohos.display';
17import type common from '@ohos.app.ability.common';
18import type Want from '@ohos.app.ability.Want';
19import type window from '@ohos.window';
20import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
21import { Log } from './Log';
22
23export class GlobalContext {
24  private static TAG: string = '[GlobalContext]:';
25  private static instance: GlobalContext;
26  private _objects = new Map<string, Object>();
27  private mDisplay: display.Display | undefined = undefined;
28  private mCutoutInfo: display.CutoutInfo | undefined = undefined;
29  private cameraAbilityContext;
30  private cameraAbilityStageContext: common.AbilityStageContext;
31  private cameraAbilityWant: Want;
32  private cameraNewWant: Want;
33  private windowStage: window.WindowStage;
34  private cameraWinClass: window.Window;
35  private cameraSettingContext: common.UIAbilityContext;
36  private cameraWindowStageEvent: window.WindowStageEventType;
37  private xComponentController;
38  private cameraFormParam;
39  private isPicker: boolean = false;
40  private cameraUIExtensionContentSession: UIExtensionContentSession;
41  private pickerUri: string;
42
43  private constructor() {
44  }
45
46  public static get(): GlobalContext {
47    if (!Boolean(GlobalContext.instance).valueOf()) {
48      GlobalContext.instance = new GlobalContext();
49    }
50    return GlobalContext.instance;
51  }
52
53  getObject(value: string): Object {
54    return this._objects.get(value);
55  }
56
57  getT<T>(value: string): T {
58    return this._objects.get(value) as T;
59  }
60
61  setObject(key: string, objectClass: Object): void {
62    this._objects.set(key, objectClass);
63  }
64
65  apply(value: string): void {
66    const func = this._objects.get(value);
67    if (func) {
68      (func as Function)();
69    }
70  }
71
72  // 显示实例,在 phone设备上用 display获得的长宽与 State变量中 windowSize一致。
73  public getDisplayInfo(): display.Display {
74    if (!this.mDisplay) {
75      this.mDisplay = display.getDefaultDisplaySync();
76    }
77    return this.mDisplay;
78  }
79
80  public async getCutoutInfo(): Promise<display.CutoutInfo> {
81    if (!this.mCutoutInfo) {
82      this.mCutoutInfo = await this.getDisplayInfo().getCutoutInfo();
83    }
84    return this.mCutoutInfo;
85  }
86
87  public getCameraAbilityContext() {
88    return this.cameraAbilityContext;
89  }
90
91  public setCameraAbilityContext(context): void {
92    this.cameraAbilityContext = context;
93  }
94
95  public getCameraAbilityWant(): Want {
96    return this.cameraAbilityWant;
97  }
98
99  public setCameraAbilityWant(want: Want): void {
100    this.cameraAbilityWant = want;
101  }
102
103  public getCameraNewWant(): Want {
104    return this.cameraNewWant;
105  }
106
107  public setCameraNewWant(want: Want): void {
108    this.cameraNewWant = want;
109  }
110
111  public getWindowStage(): window.WindowStage {
112    return this.windowStage;
113  }
114
115  public setWindowStage(stage: window.WindowStage): void {
116    this.windowStage = stage;
117  }
118
119  public getCameraAbilityStageContext(): common.AbilityStageContext {
120    return this.cameraAbilityStageContext;
121  }
122
123  public setCameraAbilityStageContext(context: common.AbilityStageContext): void {
124    this.cameraAbilityStageContext = context;
125  }
126
127  public getCameraWinClass(): window.Window {
128    return this.cameraWinClass;
129  }
130
131  public setCameraWinClass(win: window.Window): void {
132    this.cameraWinClass = win;
133  }
134
135  public getCameraSettingContext(): common.UIAbilityContext {
136    return this.cameraSettingContext;
137  }
138
139  public setCameraSettingContext(context: common.UIAbilityContext): void {
140    this.cameraSettingContext = context;
141  }
142
143  public getCameraWindowStageEvent(): window.WindowStageEventType {
144    return this.cameraWindowStageEvent;
145  }
146
147  public setCameraWindowStageEvent(event: window.WindowStageEventType): void {
148    this.cameraWindowStageEvent = event;
149  }
150
151  public getXComponentController() {
152    return this.xComponentController;
153  }
154
155  public setXComponentController(controller): void {
156    this.xComponentController = controller;
157  }
158
159  public getCameraFormParam() {
160    return this.cameraFormParam;
161  }
162
163  public setCameraFormParam(cameraParam): void {
164    this.cameraFormParam = cameraParam;
165  }
166
167  public setIsPicker(isPicker: boolean): void {
168    this.isPicker = isPicker;
169  }
170
171  public getIsPicker(isPicker: boolean): void {
172    this.isPicker = isPicker;
173  }
174
175  public setSession(session: UIExtensionContentSession): void {
176    Log.info('setSession' + session)
177    this.cameraUIExtensionContentSession = session;
178  }
179
180  public getSession(): UIExtensionContentSession {
181    return this.cameraUIExtensionContentSession;
182  }
183
184  public setPickerUri(pickerUri: string): void {
185    if (pickerUri) {
186      this.pickerUri = pickerUri;
187    } else {
188      this.pickerUri = '';
189    }
190  }
191
192  public getPickerUri(): string {
193    return this.pickerUri;
194  }
195}