1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.tv.twopanelsettings.slices.compat.widget; 18 19 /** 20 * Class containing configurable settings for SliceView that may impact interaction and contents of 21 * the slice that are displayed. 22 */ 23 // @RestrictTo(RestrictTo.Scope.LIBRARY) 24 // @Deprecated // Supported for TV 25 public class SliceViewPolicy { 26 /** 27 * Mode indicating this slice should be presented in small format, only top-level information and 28 * actions from the slice are shown. 29 */ 30 public static final int MODE_SMALL = 1; 31 32 /** 33 * Mode indicating this slice should be presented in large format, as much or all of the slice 34 * contents are shown. 35 */ 36 public static final int MODE_LARGE = 2; 37 38 /** Mode indicating this slice should be presented as a tappable icon. */ 39 public static final int MODE_SHORTCUT = 3; 40 41 /** Implement this to find out about different view configuration changes. */ 42 public interface PolicyChangeListener { 43 /** Notified when scrolling policy changes. */ onScrollingChanged(boolean newScrolling)44 void onScrollingChanged(boolean newScrolling); 45 46 /** Notified when available height changes. */ onMaxHeightChanged(int newNewHeight)47 void onMaxHeightChanged(int newNewHeight); 48 49 /** Notified when max small height changes. */ onMaxSmallChanged(int newMaxSmallHeight)50 void onMaxSmallChanged(int newMaxSmallHeight); 51 52 /** Notified when mode changes. */ onModeChanged(int newMode)53 void onModeChanged(int newMode); 54 } 55 56 private int mMaxHeight = 0; 57 private int mMaxSmallHeight = 0; 58 private boolean mScrollable = true; 59 private int mMode = MODE_LARGE; 60 private PolicyChangeListener mListener; 61 62 /** 63 * @param listener the listener to notify for policy changes. 64 */ setListener(PolicyChangeListener listener)65 public void setListener(PolicyChangeListener listener) { 66 mListener = listener; 67 } 68 69 /** 70 * @return the maximum height ths slice has to be displayed in. 71 */ getMaxHeight()72 public int getMaxHeight() { 73 return mMaxHeight; 74 } 75 76 /** 77 * @return the maximum height a small slice should be presented in. 78 */ getMaxSmallHeight()79 public int getMaxSmallHeight() { 80 return mMaxSmallHeight; 81 } 82 83 /** 84 * @return whether the slice is allowed to scroll or not. 85 */ isScrollable()86 public boolean isScrollable() { 87 return mScrollable; 88 } 89 90 /** 91 * @return the mode the slice is displayed in. 92 */ getMode()93 public int getMode() { 94 return mMode; 95 } 96 97 /** Sets what the max height the slice can be presented in. */ setMaxHeight(int max)98 public void setMaxHeight(int max) { 99 if (max != mMaxHeight) { 100 mMaxHeight = max; 101 if (mListener != null) { 102 mListener.onMaxHeightChanged(max); 103 } 104 } 105 } 106 107 /** Overrides the normal maximum height for a slice displayed in {@link #MODE_SMALL}. */ setMaxSmallHeight(int maxSmallHeight)108 public void setMaxSmallHeight(int maxSmallHeight) { 109 if (mMaxSmallHeight != maxSmallHeight) { 110 mMaxSmallHeight = maxSmallHeight; 111 if (mListener != null) { 112 mListener.onMaxSmallChanged(maxSmallHeight); 113 } 114 } 115 } 116 117 /** Sets whether the slice should be presented as scrollable or not. */ setScrollable(boolean scrollable)118 public void setScrollable(boolean scrollable) { 119 if (scrollable != mScrollable) { 120 mScrollable = scrollable; 121 if (mListener != null) { 122 mListener.onScrollingChanged(scrollable); 123 } 124 } 125 } 126 127 /** Set the mode of the slice being presented. */ setMode(int mode)128 public void setMode(int mode) { 129 if (mMode != mode) { 130 mMode = mode; 131 if (mListener != null) { 132 mListener.onModeChanged(mode); 133 } 134 } 135 } 136 } 137