• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Rsm from '@ohos.resourceManager';
17import {LogUtil} from './LogUtil'
18
19const TAG = "Note_GlobalResourceManager"
20
21export class GlobalResourceManager {
22  public async getStringByResource(res: any): Promise<string> {
23    let json = JSON.parse(JSON.stringify(res));
24    let id = json.id;
25    LogUtil.info(TAG, "ResourceID = " + id)
26    return await this.getStringById(id);
27  }
28
29  public getStringById(id: number): Promise<string>{
30    let promise = new Promise<string>(resolve => {
31      let resourceMgr = Rsm.getResourceManager("com.example.note");
32      resourceMgr.then((result) => {
33        result.getString(id)
34          .then((resource) => {
35            resolve(resource);
36            LogUtil.info(TAG, 'getStringById resolve(resource) : ' + resolve(resource));
37            LogUtil.info(TAG, 'getStringById resource : ' + resource);
38            LogUtil.info(TAG, 'getStringById resource2 : ' + JSON.stringify(resource));
39          })
40          .catch((err) => {
41            LogUtil.info(TAG, 'getStringById err : ' + JSON.stringify(err));
42          });
43      });
44    });
45    LogUtil.info(TAG, 'getStringById promise: ' + JSON.stringify(promise));
46    return promise;
47  }
48}
49
50let mGlobalResourceManager = new GlobalResourceManager();
51
52export default mGlobalResourceManager as GlobalResourceManager;
53