public class

SliceViewPolicy

extends java.lang.Object

 java.lang.Object

↳androidx.slice.widget.SliceViewPolicy

Gradle dependencies

compile group: 'androidx.slice', name: 'slice-view', version: '1.1.0-alpha02'

  • groupId: androidx.slice
  • artifactId: slice-view
  • version: 1.1.0-alpha02

Artifact androidx.slice:slice-view:1.1.0-alpha02 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.slice:slice-view com.android.support:slices-view

Overview

Class containing configurable settings for SliceView that may impact interaction and contents of the slice that are displayed.

Summary

Constructors
publicSliceViewPolicy()

Methods
public intgetMaxHeight()

public intgetMaxSmallHeight()

public intgetMode()

public booleanisScrollable()

public voidsetListener(SliceViewPolicy.PolicyChangeListener listener)

public voidsetMaxHeight(int max)

Sets what the max height the slice can be presented in.

public voidsetMaxSmallHeight(int maxSmallHeight)

Overrides the normal maximum height for a slice displayed in SliceView.MODE_SMALL.

public voidsetMode(int mode)

Set the mode of the slice being presented.

public voidsetScrollable(boolean scrollable)

Sets whether the slice should be presented as scrollable or not.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public SliceViewPolicy()

Methods

public void setListener(SliceViewPolicy.PolicyChangeListener listener)

Parameters:

listener: the listener to notify for policy changes.

public int getMaxHeight()

Returns:

the maximum height ths slice has to be displayed in.

public int getMaxSmallHeight()

Returns:

the maximum height a small slice should be presented in.

public boolean isScrollable()

Returns:

whether the slice is allowed to scroll or not.

public int getMode()

Returns:

the mode the slice is displayed in.

public void setMaxHeight(int max)

Sets what the max height the slice can be presented in.

public void setMaxSmallHeight(int maxSmallHeight)

Overrides the normal maximum height for a slice displayed in SliceView.MODE_SMALL.

public void setScrollable(boolean scrollable)

Sets whether the slice should be presented as scrollable or not.

public void setMode(int mode)

Set the mode of the slice being presented.

Source

/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.slice.widget;

import static androidx.slice.widget.SliceView.MODE_LARGE;

import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;

/**
 * Class containing configurable settings for SliceView that may impact interaction and contents
 * of the slice that are displayed.
 * @hide
 */
@RestrictTo(RestrictTo.Scope.LIBRARY)
@RequiresApi(19)
public class SliceViewPolicy {

    /**
     * Implement this to find out about different view configuration changes.
     */
    public interface PolicyChangeListener {
        /**
         * Notified when scrolling policy changes.
         */
        void onScrollingChanged(boolean newScrolling);
        /**
         * Notified when available height changes.
         */
        void onMaxHeightChanged(int newNewHeight);
        /**
         * Notified when max small height changes.
         */
        void onMaxSmallChanged(int newMaxSmallHeight);
        /**
         * Notified when mode changes.
         */
        void onModeChanged(@SliceView.SliceMode int newMode);
    }

    private int mMaxHeight = 0;
    private int mMaxSmallHeight = 0;
    private boolean mScrollable = true;
    private @SliceView.SliceMode int mMode = MODE_LARGE;
    private PolicyChangeListener mListener;

    /**
     * @param listener the listener to notify for policy changes.
     */
    public void setListener(PolicyChangeListener listener) {
        mListener = listener;
    }

    /**
     * @return the maximum height ths slice has to be displayed in.
     */
    public int getMaxHeight() {
        return mMaxHeight;
    }

    /**
     * @return the maximum height a small slice should be presented in.
     */
    public int getMaxSmallHeight() {
        return mMaxSmallHeight;
    }

    /**
     * @return whether the slice is allowed to scroll or not.
     */
    public boolean isScrollable() {
        return mScrollable;
    }

    /**
     * @return the mode the slice is displayed in.
     */
    public @SliceView.SliceMode int getMode() {
        return mMode;
    }

    /**
     * Sets what the max height the slice can be presented in.
     */
    public void setMaxHeight(int max) {
        if (max != mMaxHeight) {
            mMaxHeight = max;
            if (mListener != null) {
                mListener.onMaxHeightChanged(max);
            }
        }
    }

    /**
     * Overrides the normal maximum height for a slice displayed in {@link SliceView#MODE_SMALL}.
     */
    public void setMaxSmallHeight(int maxSmallHeight) {
        if (mMaxSmallHeight != maxSmallHeight) {
            mMaxSmallHeight = maxSmallHeight;
            if (mListener != null) {
                mListener.onMaxSmallChanged(maxSmallHeight);
            }
        }
    }

    /**
     * Sets whether the slice should be presented as scrollable or not.
     */
    public void setScrollable(boolean scrollable) {
        if (scrollable != mScrollable) {
            mScrollable = scrollable;
            if (mListener != null) {
                mListener.onScrollingChanged(scrollable);
            }
        }
    }

    /**
     * Set the mode of the slice being presented.
     */
    public void setMode(@SliceView.SliceMode int mode) {
        if (mMode != mode) {
            mMode = mode;
            if (mListener != null) {
                mListener.onModeChanged(mode);
            }
        }
    }
}