Sequenceablepublic class ComponentProvider extends Object implements Sequenceable
This class provides a set of basic operations for modifying the content of remote components. It is commonly used for developing notifications displayed in the notification bar as well as widgets on the desktop or home screen.
| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
ComponentProvider.Action |
Describes actions that can be performed on remote components.
|
static class |
ComponentProvider.ComponentProviderException |
Throws an exception for an error that occurs during a remote component operation.
|
Sequenceable.Producer<T>| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
APPLY_TYPE_ACTIONS_ONLY |
Applies all of the actions after a
ComponentProvider object is updated. |
static int |
APPLY_TYPE_LAYOUT_AND_ACTIONS |
Inflates the layout and applies all of the actions after a
ComponentProvider object is created. |
| 构造器 | 说明 |
|---|---|
ComponentProvider() |
Default constructor used to create a
ComponentProvider. |
ComponentProvider(int layoutId,
Context context) |
A constructor used to create a
ComponentProvider instance based on the layout ID and Context
of the application. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
applyAction(ComponentContainer root) |
Applies all of the actions in the current process.
|
Collection<ComponentProvider.Action> |
getActions() |
Obtains all actions.
|
ComponentContainer |
getAllComponents() |
Obtains all components in a
ComponentContainer. |
int |
getApplyType() |
Obtains the operation type.
|
String |
getDefaultBundleName() |
Obtains the default bundle name.
|
int |
getLayoutId() |
Obtains the layout ID.
|
void |
inflateLayout(Context context) |
Inflates the layout based on layout definition.
|
boolean |
isValidComponentId(int componentId) |
Checks whether a component is valid based on the provided component ID.
|
boolean |
marshalling(Parcel out) |
Marshals a
ComponentProvider object and then writes it into a Parcelobject. |
void |
mergeAction(ComponentProvider.Action action) |
Merges
ComponentProvider.Action objects into a ComponentProvider object. |
void |
mergeActions(Collection<ComponentProvider.Action> actions) |
Merges and stores all
Action objects into a ComponentProvider object. |
void |
resetActions() |
Clears all actions in the current
ComponentProvider object. |
ComponentProvider.Action |
setAccessibilityDescription(int componentId,
String description) |
Sets the description of the accessibility mode for a specified component..
|
boolean |
setApplyType(int applyType) |
Sets the operation type.
|
ComponentProvider.Action |
setBackgroundPixelMap(int componentId,
PixelMap pixelMap) |
Sets the background image of a component.
|
ComponentProvider.Action |
setBoolean(int componentId,
String methodName,
boolean value) |
Invokes a specified interface of a component.
|
ComponentProvider.Action |
setClipToContourEnabled(int componentId,
boolean enable) |
Sets whether the contour of a component can be used for content clipping.
|
ComponentProvider.Action |
setComponentContainerLayoutConfig(int componentId,
ComponentContainer.LayoutConfig params) |
Sets the margin layout parameters of a component.
|
void |
setDefaultBundleName(String bundleName) |
Sets the default bundle name for obtaining resources.
|
ComponentProvider.Action |
setDouble(int componentId,
String methodName,
double value) |
Invokes a specified interface of a component.
|
ComponentProvider.Action |
setFloat(int componentId,
String methodName,
float value) |
Invokes a specified interface of a component.
|
ComponentProvider.Action |
setImageContent(int componentId,
int resId) |
Sets the content to be displayed on a specified image component.
|
ComponentProvider.Action |
setImagePixelMap(int componentId,
PixelMap pixelMap) |
Sets the image content for a component.
|
ComponentProvider.Action |
setInt(int componentId,
String methodName,
int value) |
Invokes a specified interface of a component.
|
ComponentProvider.Action |
setIntentAgent(int componentId,
IntentAgent intent) |
Sets the
IntentAgent object for a remote component. |
ComponentProvider.Action |
setLong(int componentId,
String methodName,
long value) |
Invokes a specified interface of a component.
|
ComponentProvider.Action |
setPadding(int componentId,
int top,
int bottom,
int left,
int right) |
Sets the padding for a component.
|
ComponentProvider.Action |
setPixelMap(int componentId,
String methodName,
PixelMap value) |
Invokes a specified interface of a component.
|
ComponentProvider.Action |
setProgressBar(int componentId,
int max,
int progress,
boolean indeterminate) |
Sets the progress of
ProgressBar. |
ComponentProvider.Action |
setString(int componentId,
String methodName,
String value) |
Invokes a specified interface of a component.
|
ComponentProvider.Action |
setText(int componentId,
String text) |
Sets the text content for a component.
|
ComponentProvider.Action |
setTextAlignment(int componentId,
int textAlignment) |
Sets the text alignment mode for a component.
|
ComponentProvider.Action |
setTextColor(int componentId,
Color color) |
Sets the text color for a component.
|
ComponentProvider.Action |
setTextSize(int componentId,
int size) |
Sets the text size for a component.
|
ComponentProvider.Action |
setTextSize(int componentId,
int size,
Text.TextSizeType textSizeType) |
Sets the text size of the component.
|
ComponentProvider.Action |
setVisibility(int componentId,
int visibility) |
Sets the visibility of a component.
|
boolean |
unmarshalling(Parcel in) |
Unmarshals (or initializes) a
ComponentProvider object using content read from a Parcel object. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithasFileDescriptorpublic static final int APPLY_TYPE_ACTIONS_ONLY
ComponentProvider object is updated.
This allows the components to be updated in another application.
public static final int APPLY_TYPE_LAYOUT_AND_ACTIONS
ComponentProvider object is created.
This allows the created components to be displayed in another application.
public ComponentProvider()
ComponentProvider.public boolean setApplyType(int applyType)
The operation type can be APPLY_TYPE_LAYOUT_AND_ACTIONS or APPLY_TYPE_ACTIONS_ONLY. The
APPLY_TYPE_LAYOUT_AND_ACTIONS type means to inflate the layout and apply all of the actions, whereas
the APPLY_TYPE_ACTIONS_ONLY type means to apply all of the actions only.
applyType - Indicates the operation type, which can only be APPLY_TYPE_LAYOUT_AND_ACTIONS or
APPLY_TYPE_ACTIONS_ONLY. A value other than these two will cause failure to invoke
the current method.true if the operation type is set successfully; returns false otherwise.public int getApplyType()
APPLY_TYPE_LAYOUT_AND_ACTIONS or
APPLY_TYPE_ACTIONS_ONLY.setApplyType(int)public void setDefaultBundleName(String bundleName)
bundleName - Indicates the bundle name to set.
Before converting ohos resources into ones that can be identified by other systems,
you need the bundle name to locate the ohos resources.
If the bundle name is incorrect, ohos resources cannot be located,
and the conversion will fail.public String getDefaultBundleName()
setDefaultBundleName(String)public boolean isValidComponentId(int componentId)
This method finds the ComponentProvider corresponding to the provided component ID.
componentId - Indicates the component ID.true if a component with the given ID is found; returns false otherwise.public boolean marshalling(Parcel out)
ComponentProvider object and then writes it into a Parcelobject.marshalling 在接口中 Sequenceableout - Indicates the object into which the marshaled ComponentProvider object will be written.true if marshaling is successful; returns false otherwise.public boolean unmarshalling(Parcel in)
ComponentProvider object using content read from a Parcel object.unmarshalling 在接口中 Sequenceablein - Indicates the ComponentProvider object to unmarshal.true if Unmarshals (or initializes) a ComponentProvider object success,
returns false otherwise.marshalling(Parcel)public void inflateLayout(Context context)
If the layout in ComponentProvider needs to be displayed, inflate the layout based on the
Context of the application.
context - Indicates the Context of the current application.public ComponentContainer getAllComponents()
ComponentContainer.ComponentContainer object containing all components.public void applyAction(ComponentContainer root)
root - Indicates all components of the ComponentProvider object.public Collection<ComponentProvider.Action> getActions()
ComponentProvider.Action objects.public int getLayoutId()
public void mergeActions(Collection<ComponentProvider.Action> actions)
Action objects into a ComponentProvider object.actions - Indicates the list of Action objects.public ComponentProvider.Action setTextSize(int componentId, int size)
This method is equivalent to Text#setTextSize(int). However, it requires that you manually
invoke applyAction(ohos.agp.components.ComponentContainer).
componentId - Indicates the component ID.size - Indicates the text size.Action object.public ComponentProvider.Action setTextSize(int componentId, int size, Text.TextSizeType textSizeType)
This method is equivalent to Text#setTextSize(int, ohos.agp.components.Text.TextSizeType).
You need to call applyAction(ohos.agp.components.ComponentContainer) for the method to take effect.
componentId - Indicates the component ID.size - Indicates the text size.textSizeType - Indicates the unit of the text size, as enumerated in
Text.TextSizeType.Action object.public ComponentProvider.Action setTextColor(int componentId, Color color)
This method is equivalent to Text#setTextColor(Color). However, it requires that you manually
invoke applyAction(ohos.agp.components.ComponentContainer).
public ComponentProvider.Action setTextAlignment(int componentId, int textAlignment)
This method is equivalent to Text#setTextAlignment(int). However, it requires that you manually
invoke applyAction(ohos.agp.components.ComponentContainer).
componentId - Indicates the component ID.textAlignment - Indicates the text alignment mode to set to.Action object.TextAlignmentpublic ComponentProvider.Action setComponentContainerLayoutConfig(int componentId, ComponentContainer.LayoutConfig params)
This method is equivalent to Component#setLayoutConfig(ComponentContainer.LayoutConfig). However,
it requires that you manually invoke applyAction(ohos.agp.components.ComponentContainer).
componentId - Indicates the component ID.params - Indicates the layout parameters to set.Action object.public ComponentProvider.Action setVisibility(int componentId, int visibility)
This method is equivalent to Component#setVisibility(int). However,
it requires that you manually invoke applyAction(ohos.agp.components.ComponentContainer).
componentId - Indicates the component ID.visibility - Indicates the component's visibility.Action object.Component.VISIBLE,
Component.INVISIBLE,
Component.HIDEpublic ComponentProvider.Action setProgressBar(int componentId, int max, int progress, boolean indeterminate)
ProgressBar.
This method is equivalent to ProgressBar#setMaxValue(int), ProgressBar#setProgressValue(int),
and ProgressBar#setIndeterminate(boolean). However, it requires that you manually invoke
applyAction(ohos.agp.components.ComponentContainer).
componentId - Indicates the component ID.max - Indicates the maximum value of the progress bar.progress - Indicates the current progress.indeterminate - Indicates whether the progress is indeterminate. true means that the progress is
indeterminate; false means otherwise.Action object.public ComponentProvider.Action setPadding(int componentId, int top, int bottom, int left, int right)
This method is equivalent to Component#setPadding(int, int, int, int). However, it
requires that you manually invoke applyAction(ohos.agp.components.ComponentContainer).
componentId - Indicates the component ID.top - Indicates the number of pixels for top padding.bottom - Indicates the number of pixels for bottom padding.left - Indicates the number of pixels for left padding.right - Indicates the number of pixels for right padding.Action object.public ComponentProvider.Action setText(int componentId, String text)
This method is equivalent to Text#setText(String). However, it requires that you manually
invoke applyAction(ohos.agp.components.ComponentContainer).
componentId - Indicates the component ID.text - Indicates the text content to set for the component.Action object.public ComponentProvider.Action setAccessibilityDescription(int componentId, String description)
This method is equivalent to Component#setAccessibilityDescription(String),
except that you must call applyAction(ohos.agp.components.ComponentContainer).
componentId - Indicates the component ID.description - Indicates the description to set.Action object.setDefaultBundleName(String)public ComponentProvider.Action setClipToContourEnabled(int componentId, boolean enable)
This method is equivalent to ohos.agp.components.Component#setClipToContourEnabled(boolean),
except that you must call applyAction(ohos.agp.components.ComponentContainer).
componentId - Indicates the component ID.enable - Indicates whether clipping is supported.Action object.public void mergeAction(ComponentProvider.Action action)
ComponentProvider.Action objects into a ComponentProvider object.action - Indicates the merge action to perform.public void resetActions()
ComponentProvider object.public ComponentProvider.Action setInt(int componentId, String methodName, int value)
componentId - Indicates the component ID.methodName - Indicates the name of the interface to invoke.value - Indicates the parameter of the interface to invoke.Action object.public ComponentProvider.Action setString(int componentId, String methodName, String value)
componentId - Indicates the component ID.methodName - Indicates the name of the interface to invoke.value - Indicates the parameter of the interface to invoke.Action object.public ComponentProvider.Action setFloat(int componentId, String methodName, float value)
componentId - Indicates the component ID.methodName - Indicates the name of the interface to invoke.value - Indicates the parameter of the interface to invoke.Action object.public ComponentProvider.Action setDouble(int componentId, String methodName, double value)
componentId - Indicates the component ID.methodName - Indicates the name of the interface to invoke.value - Indicates the parameter of the interface to invoke.Action object.public ComponentProvider.Action setLong(int componentId, String methodName, long value)
componentId - Indicates the component ID.methodName - Indicates the name of the interface to invoke.value - Indicates the parameter of the interface to invoke.Action object.public ComponentProvider.Action setBoolean(int componentId, String methodName, boolean value)
componentId - Indicates the component ID.methodName - Indicates the name of the interface to invoke.value - Indicates the parameter of the interface to invoke.Action object.public ComponentProvider.Action setPixelMap(int componentId, String methodName, PixelMap value)
PixelMap
parameter.componentId - Indicates the component ID.methodName - Indicates the name of the interface to invoke.value - Indicates the parameter of the interface to invoke.Action object.public ComponentProvider.Action setImagePixelMap(int componentId, PixelMap pixelMap)
This method is equivalent to Image#setPixelMap(PixelMap). However, it requires that you
manually invoke applyAction(ohos.agp.components.ComponentContainer).
componentId - Indicates the component ID.pixelMap - Indicates the image content to set.Action object.public ComponentProvider.Action setImageContent(int componentId, int resId)
This method is equivalent toImage#setPixelMap(int).
You need to call applyAction(ohos.agp.components.ComponentContainer) for the method to take effect.
componentId - Indicates the ID of the image component.resId - Indicates the resource ID of the content to be displayed on the image component.
The content can be an image in the PNG, SVG, or another applicable format.Action object.public ComponentProvider.Action setBackgroundPixelMap(int componentId, PixelMap pixelMap)
This method is equivalent to Component#setBackground(Element). However, it
requires that you manually invoke applyAction(ohos.agp.components.ComponentContainer).
componentId - Indicates the component ID.pixelMap - Indicates the background image to set.Action object.public ComponentProvider.Action setIntentAgent(int componentId, IntentAgent intent)
IntentAgent object for a remote component.componentId - Indicates the remote component ID.intent - Indicates intent to use.Action object.