树叶云鸿蒙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

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

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