提交 6abfe206 编写于 作者: W wangkailong

formability同步

Signed-off-by: Nwangkailong <wangkailong6@huawei.com>
Change-Id: I45428191aa9e60dde1a8e85b0c4cc85f7837aae0
上级 56b88883
# @ohos.app.form.FormExtensionAbility (FormExtensionAbility)
FormExtensionAbility模块提供了卡片扩展相关接口
FormExtensionAbility为卡片扩展模块,提供卡片创建、销毁、刷新等生命周期回调
> **说明:**
>
......@@ -17,9 +17,9 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
**系统能力**:SystemCapability.Ability.Form
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------- | ------------------------------------------------------- | ---- | ---- | --------------------------------------------------- |
| context | [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) | 是 | 否 | FormExtensionAbility的上下文环境,继承自ExtensionContext。 |
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
| context | [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) | 是 | 否 | FormExtensionAbility的上下文环境,继承自[ExtensionContext](js-apis-inner-application-extensionContext.md)。 |
## onAddForm
......@@ -33,7 +33,7 @@ onAddForm(want: Want): formBindingData.FormBindingData
| 参数名 | 类型 | 必填 | 说明 |
| ------ | -------------------------------------- | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-want.md) | 是 | 当前ExtensionAbility相关的Want类型信息,包括卡片ID、卡片名称、卡片样式等。这些卡片信息必须作为持久数据进行管理,以便后续更新和删除卡片。 |
| want | [Want](js-apis-application-want.md) | 是 | 当前卡片相关的Want类型信息,包括卡片ID、卡片名称、卡片样式等。这些卡片信息必须作为持久数据进行管理,以便后续更新和删除卡片。 |
**返回值:**
......@@ -45,17 +45,19 @@ onAddForm(want: Want): formBindingData.FormBindingData
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onAddForm(want) {
console.log('FormExtensionAbility onAddForm, want:' + want.abilityName);
console.log('FormExtensionAbility onAddForm, want: ${want.abilityName}');
let dataObj1 = {
temperature:'11c',
'time':'11:00'
temperature: '11c',
'time': '11:00'
};
let obj1 = formBindingData.createFormBindingData(dataObj1);
return obj1;
}
}
};
```
## onCastToNormalForm
......@@ -75,18 +77,20 @@ onCastToNormalForm(formId: string): void
**示例:**
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onCastToNormalForm(formId) {
console.log('FormExtensionAbility onCastToNormalForm, formId:' + formId);
console.log('FormExtensionAbility onCastToNormalForm, formId: ${formId}');
}
}
};
```
## onUpdateForm
onUpdateForm(formId: string): void
卡片提供方接收更新卡片的通知接口。获取最新数据后调用[FormExtensionContext](js-apis-inner-application-formExtensionContext.md)的updateForm接口刷新卡片数据。
卡片提供方接收更新卡片的通知接口。获取最新数据后调用formProvider的[updateForm](js-apis-app-form-formProvider.md#updateform)接口刷新卡片数据。
**系统能力**:SystemCapability.Ability.Form
......@@ -99,17 +103,24 @@ onUpdateForm(formId: string): void
**示例:**
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onUpdateForm(formId) {
console.log('FormExtensionAbility onUpdateForm, formId:' + formId);
let obj2 = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'});
this.context.updateForm(formId, obj2).then((data)=>{
console.log('FormExtensionAbility context updateForm, data:' + data);
console.log('FormExtensionAbility onUpdateForm, formId: ${formId}');
let obj2 = formBindingData.createFormBindingData({
temperature: '22c',
time: '22:00'
});
formProvider.updateForm(formId, obj2).then((data) => {
console.log('FormExtensionAbility context updateForm, data: ${data}');
}).catch((error) => {
console.error('Operation updateForm failed. Cause: ' + error);});
}
}
console.error('Operation updateForm failed. Cause: ${error}');
});
}
};
```
## onChangeFormVisibility
......@@ -129,21 +140,28 @@ onChangeFormVisibility(newStatus: { [key: string]: number }): void
**示例:**
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onChangeFormVisibility(newStatus) {
console.log('FormExtensionAbility onChangeFormVisibility, newStatus:' + newStatus);
let obj2 = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'});
for (let key in newStatus) {
console.log('FormExtensionAbility onChangeFormVisibility, key:' + key + ', value=' + newStatus[key]);
this.context.updateForm(key, obj2).then((data)=>{
console.log('FormExtensionAbility context updateForm, data:' + data);
}).catch((error) => {
console.error('Operation updateForm failed. Cause: ' + error);});
console.log('FormExtensionAbility onChangeFormVisibility, newStatus: ${newStatus}');
let obj2 = formBindingData.createFormBindingData({
temperature: '22c',
time: '22:00'
});
for (let key in newStatus) {
console.log('FormExtensionAbility onChangeFormVisibility, key: ${key}, value= ${newStatus[key]}');
formProvider.updateForm(key, obj2).then((data) => {
console.log('FormExtensionAbility context updateForm, data: ${data}');
}).catch((error) => {
console.error('Operation updateForm failed. Cause: ${error}');
});
}
}
}
};
```
## onFormEvent
......@@ -164,11 +182,13 @@ onFormEvent(formId: string, message: string): void
**示例:**
```ts
export default class MyFormExtension extends FormExtensionAbility {
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) {
console.log('FormExtensionAbility onFormEvent, formId:' + formId + ', message:' + message);
console.log('FormExtensionAbility onFormEvent, formId: ${formId}, message: ${message}');
}
}
};
```
## onRemoveForm
......@@ -188,11 +208,13 @@ onRemoveForm(formId: string): void
**示例:**
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onRemoveForm(formId) {
console.log('FormExtensionAbility onRemoveForm, formId:' + formId);
console.log('FormExtensionAbility onRemoveForm, formId: ${formId}');
}
}
};
```
## onConfigurationUpdate
......@@ -212,11 +234,13 @@ onConfigurationUpdate(newConfig: Configuration): void;
**示例:**
```ts
class MyFormExtensionAbility extends FormExtensionAbility {
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onConfigurationUpdate(config) {
console.log('onConfigurationUpdate, config:' + JSON.stringify(config));
console.log('onConfigurationUpdate, config: ${JSON.stringify(config)}');
}
}
};
```
## onAcquireFormState
......@@ -231,18 +255,20 @@ onAcquireFormState?(want: Want): formInfo.FormState;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-want.md) | 是 | want表示获取卡片状态的描述。描述包括名称、能力名称、模块名称、卡片名和卡片维度。 |
| want | [Want](js-apis-application-want.md) | 是 | want表示获取卡片状态的描述。描述包括Bundle名称、能力名称、模块名称、卡片名和卡片维度。 |
**示例:**
```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formInfo from '@ohos.app.form.formInfo';
class MyFormExtensionAbility extends FormExtensionAbility {
export default class MyFormExtensionAbility extends FormExtensionAbility {
onAcquireFormState(want) {
console.log('FormExtensionAbility onAcquireFormState, want:' + want);
console.log('FormExtensionAbility onAcquireFormState, want: ${want}');
return formInfo.FormState.UNKNOWN;
}
}
};
```
## onShareForm
......@@ -270,14 +296,16 @@ onShareForm?(formId: string): { [key: string]: any }
**示例:**
```ts
class MyFormExtensionAbility extends FormExtensionAbility {
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onShareForm(formId) {
console.log('FormExtensionAbility onShareForm, formId:' + formId);
console.log('FormExtensionAbility onShareForm, formId: ${formId}');
let wantParams = {
'temperature':'20',
'time':'2022-8-8 09:59',
'temperature': '20',
'time': '2022-8-8 09:59',
};
return wantParams;
}
}
};
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部