lightbulb_outline Please take our October 2018 developer survey. Start survey
added in version 1.0.0
belongs to Maven artifact androidx.slice:slice-view:1.0.0

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 SliceUtils.parseSlice(Context, InputStream, String, SliceActionListener)

class SliceUtils.SliceParseException

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

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

added in version 1.0.0
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

added in version 1.0.0
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

added in version 1.0.0
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.