SliceUtils
public
class
SliceUtils
extends Object
java.lang.Object | |
↳ | androidx.slice.SliceUtils |
Utilities for dealing with slices.
Summary
Nested classes | |
---|---|
class |
SliceUtils.SerializeOptions
Holds options for how to handle SliceItems that cannot be serialized. |
interface |
SliceUtils.SliceActionListener
A listener used to receive events on slices parsed with
|
class |
SliceUtils.SliceParseException
Exception thrown during
|
Public methods | |
---|---|
static
Slice
|
parseSlice(Context context, InputStream input, String encoding, SliceUtils.SliceActionListener listener)
Parse a slice that has been previously serialized. |
static
void
|
serializeSlice(Slice s, Context context, OutputStream output, SliceUtils.SerializeOptions options)
Serialize a slice to an OutputStream. |
static
Slice
|
stripSlice(Slice s, int mode, boolean isScrollable)
Attempt to remove any extra content from the slice. |
Inherited methods | |
---|---|
Public methods
parseSlice
public static Slice parseSlice (Context context, InputStream input, String encoding, SliceUtils.SliceActionListener listener)
Parse a slice that has been previously serialized.
Parses a slice that was serialized with serializeSlice(Slice, Context, OutputStream, SliceUtils.SerializeOptions)
.
Note: Slices returned by this cannot be passed to SliceConvert.unwrap(Slice)
.
Parameters | |
---|---|
context |
Context |
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. |
Returns | |
---|---|
Slice |
Throws | |
---|---|
SliceUtils.SliceParseException |
if the InputStream cannot be parsed. |
IOException |
serializeSlice
public static void serializeSlice (Slice s, Context context, OutputStream output, SliceUtils.SerializeOptions options)
Serialize a slice to an OutputStream.
The serialized slice can later be read into slice form again with parseSlice(Context, InputStream, String, SliceUtils.SliceActionListener)
.
Some slice types cannot be serialized, their handling is controlled by
SliceUtils.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 | |
---|---|
IllegalArgumentException |
if the slice cannot be serialized using the given options. |
stripSlice
public static Slice stripSlice (Slice s, int mode, boolean isScrollable)
Attempt to remove any extra content from the slice.
This is meant to be used alongside serializeSlice(Slice, Context, OutputStream, SliceUtils.SerializeOptions)
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 SliceView.setMode(int) to
display the slice. |
isScrollable |
boolean : The value that will be used with SliceView.setScrollable(boolean) to
display the slice. |
Returns | |
---|---|
Slice |
returns A new smaller slice if stripping can be done, or the original slice if no content can be removed. |
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-09-30 UTC.