• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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 Context from './application/Context';
17import { RawFileDescriptor } from './global/rawFileDescriptor';
18
19/**
20 * Provides resource related APIs.
21 *
22 * @since 6
23 * @syscap SystemCapability.Global.ResourceManager
24 */
25declare namespace resourceManager {
26/**
27 * Enumerates screen directions.
28 *
29 * @since 6
30 */
31export enum Direction {
32    /**
33     * Indicates the vertical direction.
34     *
35     * @since 6
36     */
37    DIRECTION_VERTICAL = 0,
38
39    /**
40     * Indicates the horizontal direction.
41     *
42     * @since 6
43     */
44    DIRECTION_HORIZONTAL = 1
45}
46
47/**
48 * Enumerates device types.
49 *
50 * @since 6
51 */
52export enum DeviceType {
53    /**
54     * Indicates a phone.
55     *
56     * @since 6
57     */
58    DEVICE_TYPE_PHONE = 0x00,
59
60    /**
61     * Indicates a tablet.
62     *
63     * @since 6
64     */
65    DEVICE_TYPE_TABLET = 0x01,
66
67    /**
68     * Indicates a car.
69     *
70     * @since 6
71     */
72    DEVICE_TYPE_CAR = 0x02,
73
74    /**
75     * Indicates a PC.
76     *
77     * @since 6
78     */
79    DEVICE_TYPE_PC = 0x03,
80
81    /**
82     * Indicates a smart TV.
83     *
84     * @since 6
85     */
86    DEVICE_TYPE_TV = 0x04,
87
88    /**
89     * Indicates a wearable device.
90     *
91     * @since 6
92     */
93    DEVICE_TYPE_WEARABLE = 0x06
94}
95
96/**
97 * Enumerates screen density types.
98 *
99 * @since 6
100 */
101export enum ScreenDensity {
102    /**
103     * Indicates small screen density.
104     *
105     * @since 6
106     */
107    SCREEN_SDPI = 120,
108
109    /**
110     * Indicates medium screen density.
111     *
112     * @since 6
113     */
114    SCREEN_MDPI = 160,
115
116    /**
117     * Indicates large screen density.
118     *
119     * @since 6
120     */
121    SCREEN_LDPI = 240,
122
123    /**
124     * Indicates extra-large screen density.
125     *
126     * @since 6
127     */
128    SCREEN_XLDPI = 320,
129
130    /**
131     * Indicates extra-extra-large screen density.
132     *
133     * @since 6
134     */
135    SCREEN_XXLDPI = 480,
136
137    /**
138     * Indicates extra-extra-extra-large screen density.
139     *
140     * @since 6
141     */
142    SCREEN_XXXLDPI = 640
143}
144
145/**
146 * Provides the device configuration.
147 *
148 * @since 6
149 */
150export class Configuration {
151    /**
152     * Indicates the screen direction of the current device.
153     *
154     * @since 6
155     */
156    direction: Direction
157
158    /**
159     * Indicates the current system language, for example, zh-Hans-CN.
160     *
161     * @since 6
162     */
163    locale: string
164}
165
166/**
167 * Provides the device capability.
168 *
169 * @since 6
170 */
171export class DeviceCapability {
172    /**
173     * Indicates the screen density of the current device.
174     *
175     * @since 6
176     */
177    screenDensity: ScreenDensity
178
179    /**
180     * Indicates the type of the current device.
181     *
182     * @since 6
183     */
184    deviceType: DeviceType
185}
186
187/**
188 * The ResourceManager callback.
189 * @since 6
190 */
191export interface AsyncCallback<T> {
192    (err: Error, data: T): void;
193}
194
195/**
196 * Obtains the ResourceManager object of the current application.
197 *
198 * @param callback Indicates the callback containing the ResourceManager object.
199 * @since 6
200 * @FAModelOnly
201 */
202export function getResourceManager(callback: AsyncCallback<ResourceManager>): void;
203
204/**
205 * Obtains the ResourceManager object of the specified application.
206 *
207 * @param bundleName Indicates the bundle name of the specified application.
208 * @param callback Indicates the callback containing the ResourceManager object.
209 * @since 6
210 * @FAModelOnly
211 */
212export function getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManager>): void;
213
214/**
215 * Obtains the ResourceManager object of the current application.
216 *
217 * @return Returns that the ResourceManager object is returned in Promise mode.
218 * @since 6
219 * @FAModelOnly
220 */
221export function getResourceManager(): Promise<ResourceManager>;
222
223/**
224 * Obtains the ResourceManager object of the specified application.
225 *
226 * @param bundleName Indicates the bundle name of the specified application.
227 * @return Returns that the ResourceManager object is returned in Promise mode.
228 * @since 6
229 * @FAModelOnly
230 */
231export function getResourceManager(bundleName: string): Promise<ResourceManager>;
232
233/**
234 * Provides the capability of accessing application resources.
235 *
236 * @since 6
237 */
238export interface ResourceManager {
239    /**
240     * Obtains the character string corresponding to a specified resource ID in callback mode.
241     *
242     * @param resId Indicates the resource ID.
243     * @param callback Indicates the asynchronous callback used to return the obtained character string.
244     * @since 6
245     */
246    getString(resId: number, callback: AsyncCallback<string>): void;
247
248    /**
249     * Obtains string resources associated with a specified resource ID in Promise mode.
250     *
251     * @param resId Indicates the resource ID.
252     * @return Returns the character string corresponding to the resource ID.
253     * @since 6
254     */
255    getString(resId: number): Promise<string>;
256
257    /**
258     * Obtains the array of character strings corresponding to a specified resource ID in callback mode.
259     *
260     * @param resId Indicates the resource ID.
261     * @param callback Indicates the asynchronous callback used to return the obtained array of character strings.
262     * @since 6
263     */
264    getStringArray(resId: number, callback: AsyncCallback<Array<string>>): void;
265
266    /**
267     * Obtains the array of character strings corresponding to a specified resource ID in Promise mode.
268     *
269     * @param resId Indicates the resource ID.
270     * @return Returns the array of character strings corresponding to the specified resource ID.
271     * @since 6
272     */
273   getStringArray(resId: number): Promise<Array<string>>;
274
275    /**
276     * Obtains the content of the media file corresponding to a specified resource ID in callback mode.
277     *
278     * @param resId Indicates the resource ID.
279     * @param callback Indicates the asynchronous callback used to return the obtained media file content.
280     * @since 6
281     */
282    getMedia(resId: number, callback: AsyncCallback<Uint8Array>): void;
283
284    /**
285     * Obtains the content of the media file corresponding to a specified resource ID in Promise mode.
286     *
287     * @param resId Indicates the resource ID.
288     * @return Returns the content of the media file corresponding to the specified resource ID.
289     * @since 6
290     */
291    getMedia(resId: number): Promise<Uint8Array>;
292
293    /**
294     * Obtains the Base64 code of the image resource corresponding to the specified resource ID in callback mode.
295     *
296     * @param resId Indicates the resource ID.
297     * @param callback Indicates the asynchronous callback used to return the obtained Base64 code of the image
298     *                 resource.
299     * @since 6
300     */
301   getMediaBase64(resId: number, callback: AsyncCallback<string>): void;
302
303    /**
304     * Obtains the Base64 code of the image resource corresponding to the specified resource ID in Promise mode.
305     *
306     * @param resId Indicates the resource ID.
307     * @return Returns the Base64 code of the image resource corresponding to the specified resource ID.
308     * @since 6
309     */
310    getMediaBase64(resId: number): Promise<string>;
311
312    /**
313     * Obtains the device capability in callback mode.
314     *
315     * @param callback Indicates the asynchronous callback used to return the obtained device capability.
316     * @since 6
317     */
318    getDeviceCapability(callback: AsyncCallback<DeviceCapability>): void;
319
320    /**
321     * Obtains the device capability in Promise mode.
322     *
323     * @return Returns the device capability.
324     * @since 6
325     */
326    getDeviceCapability(): Promise<DeviceCapability>;
327
328    /**
329     * Obtains the device configuration in callback mode.
330     *
331     * @param callback Indicates the asynchronous callback used to return the obtained device
332     *                 configuration.
333     * @since 6
334     */
335    getConfiguration(callback: AsyncCallback<Configuration>): void;
336
337    /**
338     * Obtains the device configuration in Promise mode.
339     *
340     * @return Returns the device configuration.
341     * @since 6
342     */
343    getConfiguration(): Promise<Configuration>;
344
345    /**
346     * Obtains the singular-plural character string represented by the ID string corresponding to the
347     * specified number in callback mode.
348     *
349     * @param resId Indicates the resource ID.
350     * @param num Indicates the number.
351     * @param callback Indicates the asynchronous callback used to return the singular-plural character
352     *                 string represented by the ID string corresponding to the specified number.
353     * @since 6
354     */
355    getPluralString(resId: number, num: number, callback: AsyncCallback<string>): void;
356
357    /**
358     * Obtains the singular-plural character string represented by the ID string corresponding to
359     * the specified number in Promise mode.
360     *
361     * @param resId Indicates the resource ID.
362     * @param num Indicates the number.
363     * @return Returns the singular-plural character string represented by the ID string
364     *         corresponding to the specified number.
365     * @since 6
366     */
367    getPluralString(resId: number, num: number): Promise<string>;
368
369    /**
370     * Obtains the raw file resource corresponding to the specified resource path in callback mode.
371     *
372     * @param path Indicates the resource relative path.
373     * @param callback Indicates the asynchronous callback used to return the raw file resource.
374     * @since 8
375     */
376    getRawFile(path: string, callback: AsyncCallback<Uint8Array>): void;
377
378    /**
379     * Obtains the raw file resource corresponding to the specified resource path in Promise mode.
380     *
381     * @param path Indicates the resource relative path.
382     * @return Returns the raw file resource corresponding to the specified resource path.
383     * @since 8
384     */
385    getRawFile(path: string): Promise<Uint8Array>;
386
387    /**
388     * Obtains the raw file resource descriptor corresponding to the specified resource path in callback mode.
389     *
390     * @param path Indicates the resource relative path.
391     * @param callback Indicates the asynchronous callback used to return the raw file resource descriptor.
392     * @since 8
393     */
394    getRawFileDescriptor(path: string, callback: AsyncCallback<RawFileDescriptor>): void;
395
396     /**
397      * Obtains the raw file resource descriptor corresponding to the specified resource path in Promise mode.
398      *
399      * @param path Indicates the resource relative path.
400      * @return Returns the raw file resource descriptor corresponding to the specified resource path.
401      * @since 8
402      */
403    getRawFileDescriptor(path: string): Promise<RawFileDescriptor>;
404
405    /**
406     * Obtains close raw file resource descriptor corresponding to the specified resource path in callback mode.
407     *
408     * @param path Indicates the resource relative path.
409     * @param callback Indicates the asynchronous callback used to return result close raw file resource descriptor.
410     * @since 8
411     */
412    closeRawFileDescriptor(path: string, callback: AsyncCallback<void>): void;
413
414    /**
415     * Obtains close raw file resource descriptor corresponding to the specified resource path in Promise mode.
416     *
417     * @param path Indicates the resource relative path.
418     * @return Returns result close raw file resource descriptor corresponding to the specified resource path.
419     * @since 8
420     */
421     closeRawFileDescriptor(path: string): Promise<void>;
422
423    /**
424     * Obtains release resourceManager.
425     *
426     * @since 7
427     */
428    release();
429}
430}
431export default resourceManager;