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