lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

belongs to Maven artifact androidx.slice:slice-view:1.0.0-alpha3

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)

Constants

int LOADING_ALL

This constant is deprecated. TO BE REMOVED: use SliceMetadata.LOADED_NONE

int LOADING_COMPLETE

This constant is deprecated. TO BE REMOVED: use SliceMetadata.LOADED_ALL

int LOADING_PARTIAL

This constant is deprecated. TO BE REMOVED: use SliceMetadata.LOADED_PARTIAL

Public methods

static int getLoadingState(Slice slice)

This method is deprecated. TO BE REMOVED: use SliceMetadata.getLoadingState()

static List<SliceItem> getSliceActions(Slice slice)

This method is deprecated. TO BE REMOVED; use SliceMetadata.getSliceActions()

static List<String> getSliceKeywords(Slice slice)

This method is deprecated. TO BE REMOVED; use SliceMetadata.getSliceKeywords()

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, String encoding, SliceUtils.SerializeOptions options)

This method is deprecated. TO BE REMOVED

static void serializeSlice(Slice s, Context context, OutputStream output, SliceUtils.SerializeOptions options)

Serialize a slice to an OutputStream.

Inherited methods

Constants

LOADING_ALL

public static final int LOADING_ALL

This constant is deprecated.
TO BE REMOVED: use SliceMetadata.LOADED_NONE

Indicates this slice is empty and waiting for content to be loaded.

Constant Value: 0 (0x00000000)

LOADING_COMPLETE

public static final int LOADING_COMPLETE

This constant is deprecated.
TO BE REMOVED: use SliceMetadata.LOADED_ALL

Indicates this slice has fully loaded and is not waiting for other content.

Constant Value: 2 (0x00000002)

LOADING_PARTIAL

public static final int LOADING_PARTIAL

This constant is deprecated.
TO BE REMOVED: use SliceMetadata.LOADED_PARTIAL

Indicates this slice has some content but is waiting for other content to be loaded.

Constant Value: 1 (0x00000001)

Public methods

getLoadingState

public static int getLoadingState (Slice slice)

This method is deprecated.
TO BE REMOVED: use SliceMetadata.getLoadingState()

Parameters
slice Slice

Returns
int the current loading state of the provided Slice.

getSliceActions

public static List<SliceItem> getSliceActions (Slice slice)

This method is deprecated.
TO BE REMOVED; use SliceMetadata.getSliceActions()

Parameters
slice Slice

Returns
List<SliceItem> the group of actions associated with the provided slice, if they exist.

getSliceKeywords

public static List<String> getSliceKeywords (Slice slice)

This method is deprecated.
TO BE REMOVED; use SliceMetadata.getSliceKeywords()

Parameters
slice Slice

Returns
List<String> the list of keywords associated with the provided slice, null if no keywords were specified or an empty list if the slice was specified to have no keywords.

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, 
                String encoding, 
                SliceUtils.SerializeOptions options)

This method is deprecated.
TO BE REMOVED

Serialize a slice to an OutputStream.

The 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.

encoding String: The encoding to use for serialization.

options SliceUtils.SerializeOptions: Options defining how to handle non-serializable items.

Throws
IllegalArgumentException if the slice cannot be serialized using the given options.
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.