From 3daf997f591a84c1091c57d8ed7215b54cb776c0 Mon Sep 17 00:00:00 2001 From: zhuxiang Date: Wed, 1 Jun 2022 16:53:04 +0800 Subject: [PATCH] add resource manager js interface for resource object Signed-off-by: zhuxiang --- api/@ohos.resourceManager.d.ts | 125 +++++++++++++++++++++++++++++++++ api/global/resource.d.ts | 44 ++++++++++++ 2 files changed, 169 insertions(+) create mode 100755 api/global/resource.d.ts diff --git a/api/@ohos.resourceManager.d.ts b/api/@ohos.resourceManager.d.ts index 7f2a2105f9..cde1e62a77 100644 --- a/api/@ohos.resourceManager.d.ts +++ b/api/@ohos.resourceManager.d.ts @@ -14,6 +14,7 @@ */ import { RawFileDescriptor } from './global/rawFileDescriptor'; +import { Resource } from './global/resource'; /** * Provides resource related APIs. @@ -253,6 +254,24 @@ export interface ResourceManager { */ getString(resId: number): Promise; + /** + * Obtains the character string corresponding to a specified resource object in callback mode. + * + * @param resource Indicates the resource object. + * @param callback Indicates the asynchronous callback used to return the obtained character string. + * @since 9 + */ + getString(resource: Resource, callback: AsyncCallback): void; + + /** + * Obtains string resources associated with a specified resource object in Promise mode. + * + * @param resource Indicates the resource object. + * @return Returns the character string corresponding to the resource object. + * @since 9 + */ + getString(resource: Resource): Promise; + /** * Obtains the array of character strings corresponding to a specified resource ID in callback mode. * @@ -271,6 +290,24 @@ export interface ResourceManager { */ getStringArray(resId: number): Promise>; + /** + * Obtains the array of character strings corresponding to a specified resource object in callback mode. + * + * @param resource Indicates the resource object. + * @param callback Indicates the asynchronous callback used to return the obtained array of character strings. + * @since 9 + */ + getStringArray(resource: Resource, callback: AsyncCallback>): void; + + /** + * Obtains the array of character strings corresponding to a specified resource object in Promise mode. + * + * @param resource Indicates the resource object. + * @return Returns the array of character strings corresponding to the specified resource object. + * @since 9 + */ + getStringArray(resource: Resource): Promise>; + /** * Obtains the content of the media file corresponding to a specified resource ID in callback mode. * @@ -289,6 +326,24 @@ export interface ResourceManager { */ getMedia(resId: number): Promise; + /** + * Obtains the content of the media file corresponding to a specified resource object in callback mode. + * + * @param resource Indicates the resource object. + * @param callback Indicates the asynchronous callback used to return the obtained media file content. + * @since 9 + */ + getMedia(resource: Resource, callback: AsyncCallback): void; + + /** + * Obtains the content of the media file corresponding to a specified resource object in Promise mode. + * + * @param resource Indicates the resource object. + * @return Returns the content of the media file corresponding to the specified resource object. + * @since 9 + */ + getMedia(resource: Resource): Promise; + /** * Obtains the Base64 code of the image resource corresponding to the specified resource ID in callback mode. * @@ -308,6 +363,25 @@ export interface ResourceManager { */ getMediaBase64(resId: number): Promise; + /** + * Obtains the Base64 code of the image resource corresponding to the specified resource object in callback mode. + * + * @param resource Indicates the resource object. + * @param callback Indicates the asynchronous callback used to return the obtained Base64 code of the image + * resource. + * @since 9 + */ + getMediaBase64(resource: Resource, callback: AsyncCallback): void; + + /** + * Obtains the Base64 code of the image resource corresponding to the specified resource object in Promise mode. + * + * @param resource Indicates the resource object. + * @return Returns the Base64 code of the image resource corresponding to the specified resource object. + * @since 9 + */ + getMediaBase64(resource: Resource): Promise; + /** * Obtains the device capability in callback mode. * @@ -365,6 +439,30 @@ export interface ResourceManager { */ getPluralString(resId: number, num: number): Promise; + /** + * Obtains the singular-plural character string represented by the resource object string corresponding to the + * specified number in callback mode. + * + * @param resource Indicates the resource object. + * @param num Indicates the number. + * @param callback Indicates the asynchronous callback used to return the singular-plural character + * string represented by the resource object string corresponding to the specified number. + * @since 9 + */ + getPluralString(resource: Resource, num: number, callback: AsyncCallback): void; + + /** + * Obtains the singular-plural character string represented by the resource object string corresponding to + * the specified number in Promise mode. + * + * @param resource Indicates the resource object. + * @param num Indicates the number. + * @return Returns the singular-plural character string represented by the resource object string + * corresponding to the specified number. + * @since 9 + */ + getPluralString(resource: Resource, num: number): Promise; + /** * Obtains the raw file resource corresponding to the specified resource path in callback mode. * @@ -525,6 +623,15 @@ export interface ResourceManager { */ getStringSync(resId: number): string; + /** + * Obtains string resources associated with a specified resource object. + * + * @param resource Indicates the resource object. + * @return Returns the character string corresponding to the resource object. + * @since 9 + */ + getStringSync(resource: Resource): string; + /** * Obtains string resources associated with a specified resource name. * @@ -543,6 +650,15 @@ export interface ResourceManager { */ getBoolean(resId: number): boolean; + /** + * Obtains the boolean result with a specified resource object. + * + * @param resource Indicates the resource object. + * @return Returns the boolean resource corresponding to the resource object. + * @since 9 + */ + getBoolean(resource: Resource): boolean; + /** * Obtains the boolean result with a specified resource name. * @@ -561,6 +677,15 @@ export interface ResourceManager { */ getNumber(resId: number): number; + /** + * Obtains the number result with a specified resource object. + * + * @param resource Indicates the resource object. + * @return Returns the number resource corresponding to the resource object. + * @since 9 + */ + getNumber(resource: Resource): number; + /** * Obtains the number result with a specified resource name. * diff --git a/api/global/resource.d.ts b/api/global/resource.d.ts new file mode 100755 index 0000000000..269ec392bd --- /dev/null +++ b/api/global/resource.d.ts @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Contains resource descriptor information. + * @name Contains resource descriptor information + * @since 9 + * @syscap SystemCapability.Global.ResourceManager + * + */ + export interface Resource { + /** + * bundle name in hap + * + * @since 9 + */ + bundleName: string; + + /** + * module name in hap + * + * @since 9 + */ + moduleName: string; + + /** + * resource id in hap + * + * @since 9 + */ + id: number; +} -- Gitee