鴻蒙OS ComponentProvider

2022-09-20 10:28 更新

ComponentProvider

java.lang.Object

|---ohos.agp.components.ComponentProvider

  1. public class ComponentProvider
  2. extends Object
  3. implements Sequenceable

為跨進程顯示提供遠程組件。

該類提供了一組用于修改遠程組件內(nèi)容的基本操作。 它通常用于開發(fā)顯示在通知欄中的通知以及桌面或主屏幕上的小部件。

嵌套類摘要

修飾符和類型 描述
static class ComponentProvider.Action 描述可以對遠程組件執(zhí)行的操作。
static class ComponentProvider.ComponentProviderException 對遠程組件操作期間發(fā)生的錯誤引發(fā)異常。
從接口 ohos.utils.Sequenceable 繼承的嵌套類/接口
Sequenceable.ProducerT

字段摘要

修飾符和類型 字段 描述
static int APPLY_TYPE_ACTIONS_ONLY 在 ComponentProvider 對象更新后應(yīng)用所有操作。
static int APPLY_TYPE_LAYOUT_AND_ACTIONS 在創(chuàng)建 ComponentProvider 對象后擴展布局并應(yīng)用所有操作。

構(gòu)造函數(shù)摘要

構(gòu)造函數(shù) 描述
ComponentProvider() 用于創(chuàng)建 ComponentProvider 的默認構(gòu)造函數(shù)。
ComponentProvider(int layoutId, Context context) 用于根據(jù)應(yīng)用程序的布局 ID 和上下文創(chuàng)建 ComponentProvider 實例的構(gòu)造函數(shù)。

方法總結(jié)

修飾符和類型 方法 描述
void applyAction(ComponentContainer root) 應(yīng)用當(dāng)前進程中的所有操作。
CollectionComponentProvider.Action getActions() 獲取所有動作。
ComponentContainer getAllComponents() 獲取 ComponentContainer 中的所有組件。
int getApplyType() 獲取操作類型。
String getDefaultBundleName() 獲取默認捆綁包名稱。
int getLayoutId() 獲取布局ID。
void inflateLayout(Context context) 根據(jù)布局定義擴展布局。
boolean isValidComponentId(int componentId) 根據(jù)提供的組件 ID 檢查組件是否有效。
boolean marshalling(Parcel out) 編組 ComponentProvider 對象,然后將其寫入 Parcelobject。
void mergeAction(ComponentProvider.Action action) 將 ComponentProvider.Action 對象合并到一個 ComponentProvider 對象中。
void mergeActions(CollectionComponentProvider.Action actions) 將所有 Action 對象合并并存儲到一個 ComponentProvider 對象中。
void resetActions() 清除當(dāng)前 ComponentProvider 對象中的所有操作。
ComponentProvider.Action setAccessibilityDescription(int componentId, String description) 設(shè)置指定組件的可訪問性模式的描述..
boolean setApplyType(int applyType) 設(shè)置操作類型。
ComponentProvider.Action setBackgroundPixelMap(int componentId, PixelMap pixelMap) 設(shè)置組件的背景圖像。
ComponentProvider.Action setBoolean(int componentId, String methodName, boolean value) 調(diào)用組件的指定接口。
ComponentProvider.Action setClipToContourEnabled(int componentId, boolean enable) 設(shè)置組件的輪廓是否可以用于內(nèi)容裁剪。
ComponentProvider.Action setComponentContainerLayoutConfig(int componentId, ComponentContainer.LayoutConfig params) 設(shè)置組件的邊距布局參數(shù)。
void setDefaultBundleName(String bundleName) 設(shè)置獲取資源的默認捆綁包名稱。
ComponentProvider.Action setDouble(int componentId, String methodName, double value) 調(diào)用組件的指定接口。
ComponentProvider.Action setFloat(int componentId, String methodName, float value) 調(diào)用組件的指定接口。
ComponentProvider.Action setImageContent(int componentId, int resId) 設(shè)置要在指定圖像組件上顯示的內(nèi)容。
ComponentProvider.Action setImagePixelMap(int componentId, PixelMap pixelMap) 設(shè)置組件的圖像內(nèi)容。
ComponentProvider.Action setInt(int componentId, String methodName, int value) 調(diào)用組件的指定接口。
ComponentProvider.Action setIntentAgent(int componentId, IntentAgent intent) 設(shè)置遠程組件的 IntentAgent 對象。
ComponentProvider.Action setLong(int componentId, String methodName, long value) 調(diào)用組件的指定接口。
ComponentProvider.Action setPadding(int componentId, int top, int bottom, int left, int right) 設(shè)置組件的填充。
ComponentProvider.Action setPixelMap(int componentId, String methodName, PixelMap value) 調(diào)用組件的指定接口。
ComponentProvider.Action setProgressBar(int componentId, int max, int progress, boolean indeterminate) 設(shè)置 ProgressBar 的進度。
ComponentProvider.Action setString(int componentId, String methodName, String value) 調(diào)用組件的指定接口。
ComponentProvider.Action setText(int componentId, String text) 設(shè)置組件的文本內(nèi)容。
ComponentProvider.Action setTextAlignment(int componentId, int textAlignment) 設(shè)置組件的文本對齊模式。
ComponentProvider.Action setTextColor(int componentId, Color color) 設(shè)置組件的文本顏色。
ComponentProvider.Action setTextSize(int componentId, int size) 設(shè)置組件的文本大小。
ComponentProvider.Action setTextSize(int componentId, int size, Text.TextSizeType textSizeType) 設(shè)置組件的文本大小。
ComponentProvider.Action setVisibility(int componentId, int visibility) 設(shè)置組件的可見性。
boolean unmarshalling(Parcel in) 使用從 Parcel 對象讀取的內(nèi)容解組(或初始化) 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 對象更新后應(yīng)用所有操作。

這允許在另一個應(yīng)用程序中更新組件。

APPLY_TYPE_LAYOUT_AND_ACTIONS

public static final int APPLY_TYPE_LAYOUT_AND_ACTIONS

在創(chuàng)建 ComponentProvider 對象后擴展布局并應(yīng)用所有操作。

這允許創(chuàng)建的組件顯示在另一個應(yīng)用程序中。

構(gòu)造函數(shù)詳細信息

ComponentProvider

public ComponentProvider()

用于創(chuàng)建 ComponentProvider 的默認構(gòu)造函數(shù)。

ComponentProvider

public ComponentProvider(int layoutId, Context context)

用于根據(jù)應(yīng)用程序的布局 ID 和上下文創(chuàng)建 ComponentProvider 實例的構(gòu)造函數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
layoutId 表示布局ID。
context 指示應(yīng)用程序的上下文。

方法詳情

setApplyType

public boolean setApplyType(int applyType)

設(shè)置操作類型。

操作類型可以是 APPLY_TYPE_LAYOUT_AND_ACTIONS 或 APPLY_TYPE_ACTIONS_ONLY。 APPLY_TYPE_LAYOUT_AND_ACTIONS 類型意味著膨脹布局并應(yīng)用所有動作,而 APPLY_TYPE_ACTIONS_ONLY 類型意味著只應(yīng)用所有動作。

參數(shù):

參數(shù)名稱 參數(shù)描述
applyType 表示操作類型,只能是APPLY_TYPE_LAYOUT_AND_ACTIONS或APPLY_TYPE_ACTIONS_ONLY。 這兩個以外的值將導(dǎo)致調(diào)用當(dāng)前方法失敗。

返回:

如果操作類型設(shè)置成功,則返回true; 否則返回 false。

getApplyType

public int getApplyType()

獲取操作類型。

返回:

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

setDefaultBundleName

public void setDefaultBundleName(String bundleName)

設(shè)置獲取資源的默認捆綁包名稱。

參數(shù):

參數(shù)名稱 參數(shù)描述
bundleName 指示要設(shè)置的捆綁包名稱。 在將 ohos 資源轉(zhuǎn)換為其他系統(tǒng)可以識別的資源之前,您需要通過 bundle 名稱來定位 ohos 資源。 如果bundle名稱不正確,將無法定位到ohos資源,轉(zhuǎn)換失敗。

getDefaultBundleName

public String getDefaultBundleName()

獲取默認捆綁包名稱。

返回:

返回默認捆綁包名稱。

isValidComponentId

public boolean isValidComponentId(int componentId)

根據(jù)提供的組件 ID 檢查組件是否有效。

此方法查找與提供的組件 ID 對應(yīng)的 ComponentProvider。

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。

返回:

如果找到具有給定 ID 的組件,則返回 true; 否則返回 false。

marshalling

public boolean marshalling(Parcel out)

編組 ComponentProvider 對象,然后將其寫入 Parcelobject。

指定者:

接口 Sequenceable 中的編組

參數(shù):

參數(shù)名稱 參數(shù)描述
out 指示將被編組的 ComponentProvider 對象寫入的對象。

返回:

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

unmarshalling

public boolean unmarshalling(Parcel in)

使用從 Parcel 對象讀取的內(nèi)容解組(或初始化) ComponentProvider 對象。

指定者:

在接口 Sequenceable 中解組

參數(shù):

參數(shù)名稱 參數(shù)描述
in 指示要解組的 ComponentProvider 對象。

返回:

如果解組(或初始化) ComponentProvider 對象成功,則返回 true,否則返回 false。

inflateLayout

public void inflateLayout(Context context)

根據(jù)布局定義擴展布局。

如果需要顯示 ComponentProvider 中的布局,請根據(jù)應(yīng)用的 Context 對布局進行充氣。

參數(shù):

參數(shù)名稱 參數(shù)描述
context 指示當(dāng)前應(yīng)用程序的上下文。

getAllComponents

public ComponentContainer getAllComponents()

獲取 ComponentContainer 中的所有組件。

返回:

返回包含所有組件的 ComponentContainer 對象。

applyAction

public void applyAction(ComponentContainer root)

應(yīng)用當(dāng)前進程中的所有操作。

參數(shù):

參數(shù)名稱 參數(shù)描述
root 表示 ComponentProvider 對象的所有組件。

getActions

public CollectionComponentProvider.Action getActions()

獲取所有動作。

返回:

返回所有 ComponentProvider.Action 對象。

getLayoutId

public int getLayoutId()

獲取布局ID。

返回:

返回布局 ID。

mergeActions

public void mergeActions(CollectionComponentProvider.Action actions)

將所有 Action 對象合并并存儲到一個 ComponentProvider 對象中。

參數(shù):

參數(shù)名稱 參數(shù)描述
actions 表示 Action 對象的列表。

setTextSize

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

設(shè)置組件的文本大小。

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

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
size 指示文本大小。

返回:

返回動作對象。

setTextSize

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

設(shè)置組件的文本大小。

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

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
size 指示文本大小。
textSizeType 指示文本大小的單位,在 Text.TextSizeType 中枚舉。

返回:

返回一個動作對象。

setTextColor

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

設(shè)置組件的文本顏色。

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

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
color 指示要設(shè)置為的文本顏色。

返回:

返回 Action 對象。

setTextAlignment

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

設(shè)置組件的文本對齊模式。

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

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
textAlignment 指示要設(shè)置的文本對齊模式。

返回:

返回 Action 對象。

setComponentContainerLayoutConfig

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

設(shè)置組件的邊距布局參數(shù)。

該方法等價于 Component#setLayoutConfig(ComponentContainer.LayoutConfig)。 但是,它需要您手動調(diào)用 applyAction(ohos.agp.components.ComponentContainer)。

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
params 表示要設(shè)置的布局參數(shù)。

返回:

返回 Action 對象。

setVisibility

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

設(shè)置組件的可見性。

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

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
visibility 指示組件的可見性。

返回:

返回 Action 對象。

setProgressBar

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

設(shè)置 ProgressBar 的進度。

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

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
max 表示進度條的最大值。
progress 表示當(dāng)前進度。
indeterminate 指示進度是否不確定。 true 表示進度不確定; false 表示其他情況。

返回:

返回 Action 對象。

setPadding

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

設(shè)置組件的填充。

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

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
top 指示頂部填充的像素數(shù)。
bottom 指示底部填充的像素數(shù)。
left 指示左側(cè)填充的像素數(shù)。
right 指示右側(cè)填充的像素數(shù)。

返回:

返回 Action 對象。

setText

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

設(shè)置組件的文本內(nèi)容。

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

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
text 指示要為組件設(shè)置的文本內(nèi)容。

返回:

返回 Action 對象。

setAccessibilityDescription

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

設(shè)置指定組件的可訪問性模式的描述..

此方法等效于 Component#setAccessibilityDescription(String),不同之處在于您必須調(diào)用 applyAction(ohos.agp.components.ComponentContainer)。

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
description 表示要設(shè)置的描述。

返回:

返回 Action 對象。

setClipToContourEnabled

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

設(shè)置組件的輪廓是否可以用于內(nèi)容裁剪。

此方法等效于 ohos.agp.components.Component#setClipToContourEnabled(boolean),不同之處在于您必須調(diào)用 applyAction(ohos.agp.components.ComponentContainer)。

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
enable 指示是否支持剪輯。

返回:

返回 Action 對象。

mergeAction

public void mergeAction(ComponentProvider.Action action)

將 ComponentProvider.Action 對象合并到一個 ComponentProvider 對象中。

參數(shù):

參數(shù)名稱 參數(shù)描述
action 指示要執(zhí)行的合并操作。

resetActions

public void resetActions()

清除當(dāng)前 ComponentProvider 對象中的所有操作。

setInt

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

調(diào)用組件的指定接口。 該接口只接受一個 int 類型的參數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
methodName 指示要調(diào)用的接口的名稱。
value 指示要調(diào)用的接口的參數(shù)。

返回:

返回 Action 對象。

setString

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

調(diào)用組件的指定接口。 該接口只接受一個字符串類型的參數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
methodName 指示要調(diào)用的接口的名稱。
value 指示要調(diào)用的接口的參數(shù)。

返回:

返回 Action 對象。

setFloat

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

調(diào)用組件的指定接口。 該接口只接受一個浮點型參數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
methodName 指示要調(diào)用的接口的名稱。
value 指示要調(diào)用的接口的參數(shù)。

返回:

返回 Action 對象。

setDouble

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

調(diào)用組件的指定接口。 該接口只接受一個雙精度類型的參數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
methodName 指示要調(diào)用的接口的名稱。
value 指示要調(diào)用的接口的參數(shù)。

返回:

返回 Action 對象。

setLong

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

調(diào)用組件的指定接口。 該接口只接受一個 long 類型的參數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
methodName 指示要調(diào)用的接口的名稱。
value 指示要調(diào)用的接口的參數(shù)。

返回:

返回 Action 對象。

setBoolean

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

調(diào)用組件的指定接口。 該接口只接受一個布爾類型的參數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
methodName 指示要調(diào)用的接口的名稱。
value 指示要調(diào)用的接口的參數(shù)。

返回:

返回 Action 對象。

setPixelMap

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

調(diào)用組件的指定接口。 該接口只接受一個 PixelMap 參數(shù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
methodName 指示要調(diào)用的接口的名稱。
value 指示要調(diào)用的接口的參數(shù)。

返回:

返回 Action 對象。

setImagePixelMap

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

設(shè)置組件的圖像內(nèi)容。

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

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
pixelMap 表示要設(shè)置的圖像內(nèi)容。

返回:

返回 Action 對象。

setImageContent

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

設(shè)置要在指定圖像組件上顯示的內(nèi)容。

該方法等價于Image#setPixelMap(int)。 您需要調(diào)用 applyAction(ohos.agp.components.ComponentContainer) 以使該方法生效。

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示圖片組件的ID。
resId 表示要在圖像組件上顯示的內(nèi)容的資源ID。 內(nèi)容可以是 PNG、SVG 或其他適用格式的圖像。

返回:

返回一個 Action 對象。

setBackgroundPixelMap

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

設(shè)置組件的背景圖像。

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

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示組件ID。
pixelMap 指示要設(shè)置的背景圖像。

返回:

返回 Action 對象。

setIntentAgent

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

設(shè)置遠程組件的 IntentAgent 對象。

參數(shù):

參數(shù)名稱 參數(shù)描述
componentId 表示遠程組件ID。
intent 表示使用意圖。

返回:

返回 Action 對象。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號