树叶云鸿蒙OS教程:鸿蒙OS ComponentProvider

ComponentProvider

java.lang.Object

|—ohos.agp.components.ComponentProvider

public class ComponentProvider
extends Object
implements Sequenceable

为跨进程显示提供远程组件。

该类提供了一组用于修改远程组件内容的基本操作。 它通常用于开发显示在通知栏中的通知以及桌面或主屏幕上的小部件。

嵌套类摘要

修饰符和类型描述
static classComponentProvider.Action描述可以对远程组件执行的操作。
static classComponentProvider.ComponentProviderException对远程组件操作期间发生的错误引发异常。
从接口 ohos.utils.Sequenceable 继承的嵌套类/接口
Sequenceable.ProducerT

字段摘要

修饰符和类型字段描述
static intAPPLY_TYPE_ACTIONS_ONLY在 ComponentProvider 对象更新后应用所有操作。
static intAPPLY_TYPE_LAYOUT_AND_ACTIONS在创建 ComponentProvider 对象后扩展布局并应用所有操作。

构造函数摘要

构造函数描述
ComponentProvider()用于创建 ComponentProvider 的默认构造函数。
ComponentProvider(int layoutId, Context context)用于根据应用程序的布局 ID 和上下文创建 ComponentProvider 实例的构造函数。

方法总结

修饰符和类型方法描述
voidapplyAction(ComponentContainer root)应用当前进程中的所有操作。
CollectionComponentProvider.ActiongetActions()获取所有动作。
ComponentContainergetAllComponents()获取 ComponentContainer 中的所有组件。
intgetApplyType()获取操作类型。
StringgetDefaultBundleName()获取默认捆绑包名称。
intgetLayoutId()获取布局ID。
voidinflateLayout(Context context)根据布局定义扩展布局。
booleanisValidComponentId(int componentId)根据提供的组件 ID 检查组件是否有效。
booleanmarshalling(Parcel out)编组 ComponentProvider 对象,然后将其写入 Parcelobject。
voidmergeAction(ComponentProvider.Action action)将 ComponentProvider.Action 对象合并到一个 ComponentProvider 对象中。
voidmergeActions(CollectionComponentProvider.Action actions)将所有 Action 对象合并并存储到一个 ComponentProvider 对象中。
voidresetActions()清除当前 ComponentProvider 对象中的所有操作。
ComponentProvider.ActionsetAccessibilityDescription(int componentId, String description)设置指定组件的可访问性模式的描述..
booleansetApplyType(int applyType)设置操作类型。
ComponentProvider.ActionsetBackgroundPixelMap(int componentId, PixelMap pixelMap)设置组件的背景图像。
ComponentProvider.ActionsetBoolean(int componentId, String methodName, boolean value)调用组件的指定接口。
ComponentProvider.ActionsetClipToContourEnabled(int componentId, boolean enable)设置组件的轮廓是否可以用于内容裁剪。
ComponentProvider.ActionsetComponentContainerLayoutConfig(int componentId, ComponentContainer.LayoutConfig params)设置组件的边距布局参数。
voidsetDefaultBundleName(String bundleName)设置获取资源的默认捆绑包名称。
ComponentProvider.ActionsetDouble(int componentId, String methodName, double value)调用组件的指定接口。
ComponentProvider.ActionsetFloat(int componentId, String methodName, float value)调用组件的指定接口。
ComponentProvider.ActionsetImageContent(int componentId, int resId)设置要在指定图像组件上显示的内容。
ComponentProvider.ActionsetImagePixelMap(int componentId, PixelMap pixelMap)设置组件的图像内容。
ComponentProvider.ActionsetInt(int componentId, String methodName, int value)调用组件的指定接口。
ComponentProvider.ActionsetIntentAgent(int componentId, IntentAgent intent)设置远程组件的 IntentAgent 对象。
ComponentProvider.ActionsetLong(int componentId, String methodName, long value)调用组件的指定接口。
ComponentProvider.ActionsetPadding(int componentId, int top, int bottom, int left, int right)设置组件的填充。
ComponentProvider.ActionsetPixelMap(int componentId, String methodName, PixelMap value)调用组件的指定接口。
ComponentProvider.ActionsetProgressBar(int componentId, int max, int progress, boolean indeterminate)设置 ProgressBar 的进度。
ComponentProvider.ActionsetString(int componentId, String methodName, String value)调用组件的指定接口。
ComponentProvider.ActionsetText(int componentId, String text)设置组件的文本内容。
ComponentProvider.ActionsetTextAlignment(int componentId, int textAlignment)设置组件的文本对齐模式。
ComponentProvider.ActionsetTextColor(int componentId, Color color)设置组件的文本颜色。
ComponentProvider.ActionsetTextSize(int componentId, int size)设置组件的文本大小。
ComponentProvider.ActionsetTextSize(int componentId, int size, Text.TextSizeType textSizeType)设置组件的文本大小。
ComponentProvider.ActionsetVisibility(int componentId, int visibility)设置组件的可见性。
booleanunmarshalling(Parcel in)使用从 Parcel 对象读取的内容解组(或初始化) ComponentProvider 对象。
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口 ohos.utils.Sequenceable 继承的方法
hasFileDescriptor

字段详细信息

APPLY_TYPE_ACTIONS_ONLY

public static final int APPLY_TYPE_ACTIONS_ONLY

在 ComponentProvider 对象更新后应用所有操作。

这允许在另一个应用程序中更新组件。

APPLY_TYPE_LAYOUT_AND_ACTIONS

public static final int APPLY_TYPE_LAYOUT_AND_ACTIONS

在创建 ComponentProvider 对象后扩展布局并应用所有操作。

这允许创建的组件显示在另一个应用程序中。

构造函数详细信息

ComponentProvider

public ComponentProvider()

用于创建 ComponentProvider 的默认构造函数。

ComponentProvider

public ComponentProvider(int layoutId, Context context)

用于根据应用程序的布局 ID 和上下文创建 ComponentProvider 实例的构造函数。

参数:

参数名称参数描述
layoutId表示布局ID。
context指示应用程序的上下文。

方法详情

setApplyType

public boolean setApplyType(int applyType)

设置操作类型。

操作类型可以是 APPLY_TYPE_LAYOUT_AND_ACTIONS 或 APPLY_TYPE_ACTIONS_ONLY。 APPLY_TYPE_LAYOUT_AND_ACTIONS 类型意味着膨胀布局并应用所有动作,而 APPLY_TYPE_ACTIONS_ONLY 类型意味着只应用所有动作。

参数:

参数名称参数描述
applyType表示操作类型,只能是APPLY_TYPE_LAYOUT_AND_ACTIONS或APPLY_TYPE_ACTIONS_ONLY。 这两个以外的值将导致调用当前方法失败。

返回:

如果操作类型设置成功,则返回true; 否则返回 false。

getApplyType

public int getApplyType()

获取操作类型。

返回:

返回操作类型,可以是 APPLY_TYPE_LAYOUT_AND_ACTIONS 或 APPLY_TYPE_ACTIONS_ONLY。

setDefaultBundleName

public void setDefaultBundleName(String bundleName)

设置获取资源的默认捆绑包名称。

参数:

参数名称参数描述
bundleName指示要设置的捆绑包名称。 在将 ohos 资源转换为其他系统可以识别的资源之前,您需要通过 bundle 名称来定位 ohos 资源。 如果bundle名称不正确,将无法定位到ohos资源,转换失败。

getDefaultBundleName

public String getDefaultBundleName()

获取默认捆绑包名称。

返回:

返回默认捆绑包名称。

isValidComponentId

public boolean isValidComponentId(int componentId)

根据提供的组件 ID 检查组件是否有效。

此方法查找与提供的组件 ID 对应的 ComponentProvider。

参数:

参数名称参数描述
componentId表示组件ID。

返回:

如果找到具有给定 ID 的组件,则返回 true; 否则返回 false。

marshalling

public boolean marshalling(Parcel out)

编组 ComponentProvider 对象,然后将其写入 Parcelobject。

指定者:

接口 Sequenceable 中的编组

参数:

参数名称参数描述
out指示将被编组的 ComponentProvider 对象写入的对象。

返回:

如果封送成功,则返回 true; 否则返回 false。

unmarshalling

public boolean unmarshalling(Parcel in)

使用从 Parcel 对象读取的内容解组(或初始化) ComponentProvider 对象。

指定者:

在接口 Sequenceable 中解组

参数:

参数名称参数描述
in指示要解组的 ComponentProvider 对象。

返回:

如果解组(或初始化) ComponentProvider 对象成功,则返回 true,否则返回 false。

inflateLayout

public void inflateLayout(Context context)

根据布局定义扩展布局。

如果需要显示 ComponentProvider 中的布局,请根据应用的 Context 对布局进行充气。

参数:

参数名称参数描述
context指示当前应用程序的上下文。

getAllComponents

public ComponentContainer getAllComponents()

获取 ComponentContainer 中的所有组件。

返回:

返回包含所有组件的 ComponentContainer 对象。

applyAction

public void applyAction(ComponentContainer root)

应用当前进程中的所有操作。

参数:

参数名称参数描述
root表示 ComponentProvider 对象的所有组件。

getActions

public CollectionComponentProvider.Action getActions()

获取所有动作。

返回:

返回所有 ComponentProvider.Action 对象。

getLayoutId

public int getLayoutId()

获取布局ID。

返回:

返回布局 ID。

mergeActions

public void mergeActions(CollectionComponentProvider.Action actions)

将所有 Action 对象合并并存储到一个 ComponentProvider 对象中。

参数:

参数名称参数描述
actions表示 Action 对象的列表。

setTextSize

public ComponentProvider.Action setTextSize(int componentId, int size)

设置组件的文本大小。

此方法等效于 Text#setTextSize(int)。 但是,它需要您手动调用 applyAction(ohos.agp.components.ComponentContainer)。

参数:

参数名称参数描述
componentId表示组件ID。
size指示文本大小。

返回:

返回动作对象。

setTextSize

public ComponentProvider.Action setTextSize(int componentId, int size, Text.TextSizeType textSizeType)

设置组件的文本大小。

此方法等效于 Text#setTextSize(int, ohos.agp.components.Text.TextSizeType)。 您需要调用 applyAction(ohos.agp.components.ComponentContainer) 以使该方法生效。

参数:

参数名称参数描述
componentId表示组件ID。
size指示文本大小。
textSizeType指示文本大小的单位,在 Text.TextSizeType 中枚举。

返回:

返回一个动作对象。

setTextColor

public ComponentProvider.Action setTextColor(int componentId, Color color)

设置组件的文本颜色。

此方法等效于 Text#setTextColor(Color)。 但是,它需要您手动调用 applyAction(ohos.agp.components.ComponentContainer)。

参数:

参数名称参数描述
componentId表示组件ID。
color指示要设置为的文本颜色。

返回:

返回 Action 对象。

setTextAlignment

public ComponentProvider.Action setTextAlignment(int componentId, int textAlignment)

设置组件的文本对齐模式。

此方法等效于 Text#setTextAlignment(int)。 但是,它需要您手动调用 applyAction(ohos.agp.components.ComponentContainer)。

参数:

参数名称参数描述
componentId表示组件ID。
textAlignment指示要设置的文本对齐模式。

返回:

返回 Action 对象。

setComponentContainerLayoutConfig

public ComponentProvider.Action setComponentContainerLayoutConfig(int componentId, ComponentContainer.LayoutConfig params)

设置组件的边距布局参数。

该方法等价于 Component#setLayoutConfig(ComponentContainer.LayoutConfig)。 但是,它需要您手动调用 applyAction(ohos.agp.components.ComponentContainer)。

参数:

参数名称参数描述
componentId表示组件ID。
params表示要设置的布局参数。

返回:

返回 Action 对象。

setVisibility

public ComponentProvider.Action setVisibility(int componentId, int visibility)

设置组件的可见性。

此方法等效于 Component#setVisibility(int)。 但是,它需要您手动调用 applyAction(ohos.agp.components.ComponentContainer)。

参数:

参数名称参数描述
componentId表示组件ID。
visibility指示组件的可见性。

返回:

返回 Action 对象。

setProgressBar

public ComponentProvider.Action setProgressBar(int componentId, int max, int progress, boolean indeterminate)

设置 ProgressBar 的进度。

此方法等效于 ProgressBar#setMaxValue(int)、ProgressBar#setProgressValue(int) 和 ProgressBar#setIndeterminate(boolean)。 但是,它需要您手动调用 applyAction(ohos.agp.components.ComponentContainer)。

参数:

参数名称参数描述
componentId表示组件ID。
max表示进度条的最大值。
progress表示当前进度。
indeterminate指示进度是否不确定。 true 表示进度不确定; false 表示其他情况。

返回:

返回 Action 对象。

setPadding

public ComponentProvider.Action setPadding(int componentId, int top, int bottom, int left, int right)

设置组件的填充。

此方法等效于 Component#setPadding(int, int, int, int)。 但是,它需要您手动调用 applyAction(ohos.agp.components.ComponentContainer)。

参数:

参数名称参数描述
componentId表示组件ID。
top指示顶部填充的像素数。
bottom指示底部填充的像素数。
left指示左侧填充的像素数。
right指示右侧填充的像素数。

返回:

返回 Action 对象。

setText

public ComponentProvider.Action setText(int componentId, String text)

设置组件的文本内容。

此方法等效于 Text#setText(String)。 但是,它需要您手动调用 applyAction(ohos.agp.components.ComponentContainer)。

参数:

参数名称参数描述
componentId表示组件ID。
text指示要为组件设置的文本内容。

返回:

返回 Action 对象。

setAccessibilityDescription

public ComponentProvider.Action setAccessibilityDescription(int componentId, String description)

设置指定组件的可访问性模式的描述..

此方法等效于 Component#setAccessibilityDescription(String),不同之处在于您必须调用 applyAction(ohos.agp.components.ComponentContainer)。

参数:

参数名称参数描述
componentId表示组件ID。
description表示要设置的描述。

返回:

返回 Action 对象。

setClipToContourEnabled

public ComponentProvider.Action setClipToContourEnabled(int componentId, boolean enable)

设置组件的轮廓是否可以用于内容裁剪。

此方法等效于 ohos.agp.components.Component#setClipToContourEnabled(boolean),不同之处在于您必须调用 applyAction(ohos.agp.components.ComponentContainer)。

参数:

参数名称参数描述
componentId表示组件ID。
enable指示是否支持剪辑。

返回:

返回 Action 对象。

mergeAction

public void mergeAction(ComponentProvider.Action action)

将 ComponentProvider.Action 对象合并到一个 ComponentProvider 对象中。

参数:

参数名称参数描述
action指示要执行的合并操作。

resetActions

public void resetActions()

清除当前 ComponentProvider 对象中的所有操作。

setInt

public ComponentProvider.Action setInt(int componentId, String methodName, int value)

调用组件的指定接口。 该接口只接受一个 int 类型的参数。

参数:

参数名称参数描述
componentId表示组件ID。
methodName指示要调用的接口的名称。
value指示要调用的接口的参数。

返回:

返回 Action 对象。

setString

public ComponentProvider.Action setString(int componentId, String methodName, String value)

调用组件的指定接口。 该接口只接受一个字符串类型的参数。

参数:

参数名称参数描述
componentId表示组件ID。
methodName指示要调用的接口的名称。
value指示要调用的接口的参数。

返回:

返回 Action 对象。

setFloat

public ComponentProvider.Action setFloat(int componentId, String methodName, float value)

调用组件的指定接口。 该接口只接受一个浮点型参数。

参数:

参数名称参数描述
componentId表示组件ID。
methodName指示要调用的接口的名称。
value指示要调用的接口的参数。

返回:

返回 Action 对象。

setDouble

public ComponentProvider.Action setDouble(int componentId, String methodName, double value)

调用组件的指定接口。 该接口只接受一个双精度类型的参数。

参数:

参数名称参数描述
componentId表示组件ID。
methodName指示要调用的接口的名称。
value指示要调用的接口的参数。

返回:

返回 Action 对象。

setLong

public ComponentProvider.Action setLong(int componentId, String methodName, long value)

调用组件的指定接口。 该接口只接受一个 long 类型的参数。

参数:

参数名称参数描述
componentId表示组件ID。
methodName指示要调用的接口的名称。
value指示要调用的接口的参数。

返回:

返回 Action 对象。

setBoolean

public ComponentProvider.Action setBoolean(int componentId, String methodName, boolean value)

调用组件的指定接口。 该接口只接受一个布尔类型的参数。

参数:

参数名称参数描述
componentId表示组件ID。
methodName指示要调用的接口的名称。
value指示要调用的接口的参数。

返回:

返回 Action 对象。

setPixelMap

public ComponentProvider.Action setPixelMap(int componentId, String methodName, PixelMap value)

调用组件的指定接口。 该接口只接受一个 PixelMap 参数。

参数:

参数名称参数描述
componentId表示组件ID。
methodName指示要调用的接口的名称。
value指示要调用的接口的参数。

返回:

返回 Action 对象。

setImagePixelMap

public ComponentProvider.Action setImagePixelMap(int componentId, PixelMap pixelMap)

设置组件的图像内容。

此方法等效于 Image#setPixelMap(PixelMap)。 但是,它需要您手动调用 applyAction(ohos.agp.components.ComponentContainer)。

参数:

参数名称参数描述
componentId表示组件ID。
pixelMap表示要设置的图像内容。

返回:

返回 Action 对象。

setImageContent

public ComponentProvider.Action setImageContent(int componentId, int resId)

设置要在指定图像组件上显示的内容。

该方法等价于Image#setPixelMap(int)。 您需要调用 applyAction(ohos.agp.components.ComponentContainer) 以使该方法生效。

参数:

参数名称参数描述
componentId表示图片组件的ID。
resId表示要在图像组件上显示的内容的资源ID。 内容可以是 PNG、SVG 或其他适用格式的图像。

返回:

返回一个 Action 对象。

setBackgroundPixelMap

public ComponentProvider.Action setBackgroundPixelMap(int componentId, PixelMap pixelMap)

设置组件的背景图像。

此方法等效于 Component#setBackground(Element)。 但是,它需要您手动调用 applyAction(ohos.agp.components.ComponentContainer)。

参数:

参数名称参数描述
componentId表示组件ID。
pixelMap指示要设置的背景图像。

返回:

返回 Action 对象。

setIntentAgent

public ComponentProvider.Action setIntentAgent(int componentId, IntentAgent intent)

设置远程组件的 IntentAgent 对象。

参数:

参数名称参数描述
componentId表示远程组件ID。
intent表示使用意图。

返回:

返回 Action 对象。

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/163261.html<

(0)
管理的头像管理
上一篇2025-03-19 01:55
下一篇 2025-03-19 01:56

相关推荐

  • 云服务器和云虚拟主机怎么选?云服务器和虚拟主机区别

    云服务器适合业务增长快、需弹性扩展的场景,而云虚拟主机适合预算有限、技术门槛低的小型静态网站或测试环境,二者核心区别在于资源独享性与运维复杂度,核心差异解析:从底层架构到使用体验很多人容易混淆这两者,觉得它们都是“买空间建站”,它们的底层逻辑完全不同,云服务器(ECS)就像是你租了一整栋别墅,水电网络独立,你想……

    2026-06-29
    0
  • 赣州智慧旅游招聘是真的吗?赣州旅游人才招聘信息

    中级岗位(3-5年经验)月薪范围通常在6000-10000元,这类岗位需要独立负责项目模块,如独立运营一个抖音账号,或维护一个景区小程序的功能迭代,具备成功案例的候选人议价能力较强,高级岗位(5年以上经验)月薪范围通常在10000-20000元,部分核心管理岗可达更高,这类人才需要具备战略规划能力,如制定整个景……

    2026-06-29
    0
  • 赣州智能物联网车位锁如何管理?智能车位锁管理系统多少钱

    赣州智能物联网车位锁管理的核心在于通过云端平台实现远程控锁、状态实时监控及自动计费,彻底解决传统车位“被占难管”与“找位难”的痛点,在赣州这样的城市,随着机动车保有量的持续增长,老旧小区、商业综合体以及私人固定车位的资源矛盾日益凸显,传统的机械地锁或简易遥控锁,不仅操作繁琐,更无法实现数据化管理,引入智能物联网……

    2026-06-29
    0
  • 赣州智能消防栓好用吗,智能消防栓多少钱一个

    赣州智能消防栓通过物联网技术实现实时监测与远程报警,能显著降低火灾响应时间并提升城市消防安全管理水平,是目前智慧城市建设中不可或缺的基础设施,赣州智能消防栓的核心价值与应用场景传统消防栓往往存在“看不见、摸不着、用不了”的痛点,在赣州这样地形复杂、老城区与新城区并存的区域,传统设施的管理难度极大,智能消防栓的出……

    2026-06-29
    0
  • 云服务器和物理机到底有啥区别?

    云服务器本质上是虚拟化资源池中的弹性实例,而传统物理服务器是独占的硬件实体,前者胜在弹性与运维便捷,后者强在物理隔离与性能稳定,具体选择取决于业务对成本、扩展性及安全合规的权衡,很多人初次接触服务器时,容易把“云服务器”和“传统物理服务器”混为一谈,觉得它们都是用来跑网站或存数据的盒子,这两者的底层逻辑完全不同……

    2026-06-29
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注