SliceUtils
@RequiresApi(value = 19)
class SliceUtils
Utilities for dealing with slices.
Summary
Nested types |
|---|
|
Holds options for how to handle SliceItems that cannot be serialized. |
interface SliceUtils.SliceActionListenerA listener used to receive events on slices parsed with |
|
Exception thrown during |
Public functions |
|
|---|---|
java-static Slice |
parseSlice(Parse a slice that has been previously serialized. |
java-static Unit |
serializeSlice(Serialize a slice to an OutputStream. |
java-static Slice |
stripSlice(s: Slice, mode: Int, isScrollable: Boolean)Attempt to remove any extra content from the slice. |
Public functions
parseSlice
java-static fun parseSlice(
context: Context,
input: InputStream,
encoding: String,
listener: SliceUtils.SliceActionListener
): Slice
Parse a slice that has been previously serialized.
Parses a slice that was serialized with serializeSlice.
Note: Slices returned by this cannot be passed to unwrap.
| Parameters | |
|---|---|
input: InputStream |
The input stream to read from. |
encoding: String |
The encoding to read as. |
listener: SliceUtils.SliceActionListener |
Listener used to handle actions when reconstructing the slice. |
| Throws | |
|---|---|
androidx.slice.SliceUtils.SliceParseException |
if the InputStream cannot be parsed. |
java.io.IOException |
serializeSlice
java-static fun serializeSlice(
s: Slice,
context: Context,
output: OutputStream,
options: SliceUtils.SerializeOptions
): Unit
Serialize a slice to an OutputStream.
The serialized slice can later be read into slice form again with parseSlice. Some slice types cannot be serialized, their handling is controlled by SerializeOptions.
| Parameters | |
|---|---|
s: Slice |
The slice to serialize. |
context: Context |
Context used to load any resources in the slice. |
output: OutputStream |
The output of the serialization. |
options: SliceUtils.SerializeOptions |
Options defining how to handle non-serializable items. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the slice cannot be serialized using the given options. |
stripSlice
java-static fun stripSlice(s: Slice, mode: Int, isScrollable: Boolean): Slice
Attempt to remove any extra content from the slice.
This is meant to be used alongside serializeSlice to reduce the size of a slice by only including data for the slice to be displayed in a specific mode.
| Parameters | |
|---|---|
s: Slice |
The slice to strip. |
mode: Int |
The mode that will be used with setMode to display the slice. |
isScrollable: Boolean |
The value that will be used with |
| Returns | |
|---|---|
Slice |
returns A new smaller slice if stripping can be done, or the original slice if no content can be removed. |