Register now for Android Dev Summit 2019!

SliceUtils

open class SliceUtils
kotlin.Any
   ↳ androidx.slice.SliceUtils

Utilities for dealing with slices.

Summary

Nested classes

open

Holds options for how to handle SliceItems that cannot be serialized.

abstract

A listener used to receive events on slices parsed with parseSlice(Context, InputStream, String, SliceActionListener).

open

Exception thrown during parseSlice(Context, InputStream, String, SliceActionListener).

Public methods

open static Slice
parseSlice(@NonNull context: Context, @NonNull input: InputStream, @NonNull encoding: String, @NonNull listener: SliceUtils.SliceActionListener)

Parse a slice that has been previously serialized.

open static Unit
serializeSlice(@NonNull s: Slice, @NonNull context: Context, @NonNull output: OutputStream, @NonNull options: SliceUtils.SerializeOptions)

Serialize a slice to an OutputStream.

open static Slice
stripSlice(@NonNull s: Slice, mode: Int, isScrollable: Boolean)

Attempt to remove any extra content from the slice.

Public methods

parseSlice

@NonNull open static fun parseSlice(@NonNull context: Context, @NonNull input: InputStream, @NonNull encoding: String, @NonNull 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 SliceConvert#unwrap(Slice).

Parameters
input Context: The input stream to read from.
encoding Context: The encoding to read as.
listener Context: Listener used to handle actions when reconstructing the slice.
Exceptions
SliceParseException if the InputStream cannot be parsed.

serializeSlice

open static fun serializeSlice(@NonNull s: Slice, @NonNull context: Context, @NonNull output: OutputStream, @NonNull 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 Slice: Context used to load any resources in the slice.
output Slice: The output of the serialization.
options Slice: Options defining how to handle non-serializable items.
Exceptions
IllegalArgumentException if the slice cannot be serialized using the given options.

stripSlice

@NonNull open static fun stripSlice(@NonNull 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 Slice: The mode that will be used with SliceView#setMode to display the slice.
isScrollable Slice: The value that will be used with SliceView#setScrollable to display the slice.
Return
Slice: returns A new smaller slice if stripping can be done, or the original slice if no content can be removed.