• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import androidx.annotation.IntDef;
20 import java.lang.annotation.Retention;
21 import java.lang.annotation.RetentionPolicy;
22 
23 /**
24  * Represents information associated with a logged event on {@link SliceView}.
25  *
26  * <p>Slice framework has been deprecated, it will not receive any updates moving forward. If you
27  * are looking for a framework that handles communication across apps, consider using {@link
28  * android.app.appsearch.AppSearchManager}.
29  */
30 // @Deprecated // Supported for TV
31 public class EventInfo {
32 
33   /** */
34   // @RestrictTo(RestrictTo.Scope.LIBRARY)
35   @IntDef({
36     ROW_TYPE_SHORTCUT,
37     ROW_TYPE_LIST,
38     ROW_TYPE_GRID,
39     ROW_TYPE_MESSAGING,
40     ROW_TYPE_TOGGLE,
41     ROW_TYPE_SLIDER,
42     ROW_TYPE_PROGRESS,
43     ROW_TYPE_SELECTION,
44     ROW_TYPE_DATE_PICK,
45     ROW_TYPE_TIME_PICK,
46   })
47   @Retention(RetentionPolicy.SOURCE)
48   public @interface SliceRowType {}
49 
50   /** Indicates the slice is represented as a shortcut. */
51   public static final int ROW_TYPE_SHORTCUT = -1;
52 
53   /** Indicates the row is represented in a list template. */
54   public static final int ROW_TYPE_LIST = 0;
55 
56   /** Indicates the row is represented in a grid template. */
57   public static final int ROW_TYPE_GRID = 1;
58 
59   /** Indicates the row is represented as a messaging template. */
60   public static final int ROW_TYPE_MESSAGING = 2;
61 
62   /** Indicates the row represents a toggleable item. */
63   public static final int ROW_TYPE_TOGGLE = 3;
64 
65   /** Indicates the row represents an range input slider. */
66   public static final int ROW_TYPE_SLIDER = 4;
67 
68   /** Indicates the row represents a progress indicator. */
69   public static final int ROW_TYPE_PROGRESS = 5;
70 
71   /** Indicates the row represents a selection (drop-down list). */
72   public static final int ROW_TYPE_SELECTION = 6;
73 
74   /** Indicates the row represents a date selection (date picker). */
75   // @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
76   public static final int ROW_TYPE_DATE_PICK = 7;
77 
78   /** Indicates the row represents a time selection (time picker). */
79   // @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
80   public static final int ROW_TYPE_TIME_PICK = 8;
81 
82   /** */
83   // @RestrictTo(RestrictTo.Scope.LIBRARY)
84   @IntDef({
85     ACTION_TYPE_TOGGLE,
86     ACTION_TYPE_BUTTON,
87     ACTION_TYPE_SLIDER,
88     ACTION_TYPE_CONTENT,
89     ACTION_TYPE_SEE_MORE,
90     ACTION_TYPE_SELECTION,
91     ACTION_TYPE_DATE_PICK,
92     ACTION_TYPE_TIME_PICK,
93   })
94   @Retention(RetentionPolicy.SOURCE)
95   public @interface SliceActionType {}
96 
97   /**
98    * Indicates the event was an interaction with a toggle. Check {@link EventInfo#state} to see the
99    * new state of the toggle.
100    */
101   public static final int ACTION_TYPE_TOGGLE = 0;
102 
103   /**
104    * Indicates the event was an interaction with a button. Check {@link EventInfo#actionPosition} to
105    * see where on the card the button is placed.
106    */
107   public static final int ACTION_TYPE_BUTTON = 1;
108 
109   /**
110    * Indicates the event was an interaction with a slider. Check {@link EventInfo#state} to see the
111    * new state of the slider.
112    */
113   public static final int ACTION_TYPE_SLIDER = 2;
114 
115   /** Indicates the event was a tap on the entire row. */
116   public static final int ACTION_TYPE_CONTENT = 3;
117 
118   /** Indicates the event was a tap on a see more button. */
119   public static final int ACTION_TYPE_SEE_MORE = 4;
120 
121   /** Indicates the event was a selection from a selection row. */
122   public static final int ACTION_TYPE_SELECTION = 5;
123 
124   /** Indicates the event was a selection from a date picker. */
125   // @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
126   public static final int ACTION_TYPE_DATE_PICK = 6;
127 
128   /** Indicates the event was a selection from a time picker. */
129   // @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
130   public static final int ACTION_TYPE_TIME_PICK = 7;
131 
132   /** */
133   // @RestrictTo(RestrictTo.Scope.LIBRARY)
134   @IntDef({POSITION_START, POSITION_END, POSITION_CELL})
135   @Retention(RetentionPolicy.SOURCE)
136   public @interface SliceButtonPosition {}
137 
138   /** Indicates the event was an interaction with a button positioned at the start of the row. */
139   public static final int POSITION_START = 0;
140 
141   /**
142    * Indicates the event was an interaction with a button positioned at the end of the row,
143    * potentially grouped with other buttons.
144    */
145   public static final int POSITION_END = 1;
146 
147   /** Indicates the event was an interaction with a button positioned in a grid cell. */
148   public static final int POSITION_CELL = 2;
149 
150   /** Indicates the state of a toggle is off. */
151   public static final int STATE_OFF = 0;
152 
153   /** Indicates the state of a toggle is on. */
154   public static final int STATE_ON = 1;
155 
156   /** The display mode of the slice being interacted with. */
157   public int sliceMode;
158 
159   /** The type of action that occurred. */
160   public @SliceActionType int actionType;
161 
162   /** The template type of the row that was interacted with in the slice. */
163   public @SliceRowType int rowTemplateType;
164 
165   /** Index of the row that was interacted with in the slice. */
166   public int rowIndex;
167 
168   /**
169    * If multiple buttons are presented in this {@link #actionPosition} on the row, then this is the
170    * index of that button that was interacted with. For total number of actions see {@link
171    * #actionCount}.
172    *
173    * <p>If the {@link #actionPosition} is {@link #POSITION_CELL} the button is a cell within a grid,
174    * and this index would represent the cell position.
175    *
176    * <p>If the {@link #actionPosition} is {@link #POSITION_END} there might be other buttons in the
177    * end position, and this index would represent the position.
178    */
179   public int actionIndex;
180 
181   /**
182    * Total number of actions available in this row of the slice.
183    *
184    * <p>If the {@link #actionPosition} is {@link #POSITION_CELL} the button is a cell within a grid
185    * row, and this is the number of cells in the row.
186    *
187    * <p>If the {@link #actionPosition} is {@link #POSITION_END} this is the number of buttons in the
188    * end position of this row.
189    */
190   public int actionCount;
191 
192   /**
193    * Position of the button on the template.
194    *
195    * <p>{@link #POSITION_START} {@link #POSITION_END} {@link #POSITION_CELL}
196    */
197   public @SliceButtonPosition int actionPosition;
198 
199   /**
200    * Represents the state after the event or -1 if not applicable for the event type.
201    *
202    * <p>For {@link #ACTION_TYPE_TOGGLE} events, the state will be either {@link #STATE_OFF} or
203    * {@link #STATE_ON}.
204    *
205    * <p>For {@link #ACTION_TYPE_SLIDER} events, the state will be a number representing the new
206    * position of the slider.
207    */
208   public int state;
209 
210   /**
211    * Constructs an event info object with the required information for an event.
212    *
213    * @param sliceMode The display mode of the slice interacted with.
214    * @param actionType The type of action this event represents.
215    * @param rowTemplateType The template type of the row interacted with.
216    * @param rowIndex The index of the row that was interacted with in the slice.
217    */
EventInfo( int sliceMode, @SliceActionType int actionType, @SliceRowType int rowTemplateType, int rowIndex)218   public EventInfo(
219       int sliceMode,
220       @SliceActionType int actionType,
221       @SliceRowType int rowTemplateType,
222       int rowIndex) {
223     this.sliceMode = sliceMode;
224     this.actionType = actionType;
225     this.rowTemplateType = rowTemplateType;
226     this.rowIndex = rowIndex;
227 
228     this.actionPosition = POSITION_START;
229     this.actionIndex = -1;
230     this.actionCount = -1;
231     this.state = -1;
232   }
233 
234   /**
235    * Sets positional information for the event.
236    *
237    * @param actionPosition The position of the button on the template.
238    * @param actionIndex The index of that button that was interacted with.
239    * @param actionCount The number of actions available in this group of buttons on the slice.
240    */
setPosition( @liceButtonPosition int actionPosition, int actionIndex, int actionCount)241   public void setPosition(
242       @SliceButtonPosition int actionPosition, int actionIndex, int actionCount) {
243     this.actionPosition = actionPosition;
244     this.actionIndex = actionIndex;
245     this.actionCount = actionCount;
246   }
247 
248   @Override
toString()249   public String toString() {
250     StringBuilder sb = new StringBuilder();
251     sb.append("mode=").append(sliceMode);
252     sb.append(", actionType=").append(actionToString(actionType));
253     sb.append(", rowTemplateType=").append(rowTypeToString(rowTemplateType));
254     sb.append(", rowIndex=").append(rowIndex);
255     sb.append(", actionPosition=").append(positionToString(actionPosition));
256     sb.append(", actionIndex=").append(actionIndex);
257     sb.append(", actionCount=").append(actionCount);
258     sb.append(", state=").append(state);
259     return sb.toString();
260   }
261 
262   /**
263    * @return String representation of the provided position.
264    */
positionToString(@liceButtonPosition int position)265   private static String positionToString(@SliceButtonPosition int position) {
266     switch (position) {
267       case POSITION_START:
268         return "START";
269       case POSITION_END:
270         return "END";
271       case POSITION_CELL:
272         return "CELL";
273       default:
274         return "unknown position: " + position;
275     }
276   }
277 
278   /**
279    * @return String representation of the provided action.
280    */
actionToString(@liceActionType int action)281   private static String actionToString(@SliceActionType int action) {
282     switch (action) {
283       case ACTION_TYPE_TOGGLE:
284         return "TOGGLE";
285       case ACTION_TYPE_BUTTON:
286         return "BUTTON";
287       case ACTION_TYPE_SLIDER:
288         return "SLIDER";
289       case ACTION_TYPE_CONTENT:
290         return "CONTENT";
291       case ACTION_TYPE_SEE_MORE:
292         return "SEE MORE";
293       case ACTION_TYPE_SELECTION:
294         return "SELECTION";
295       case ACTION_TYPE_DATE_PICK:
296         return "DATE_PICK";
297       case ACTION_TYPE_TIME_PICK:
298         return "TIME_PICK";
299       default:
300         return "unknown action: " + action;
301     }
302   }
303 
304   /**
305    * @return String representation of the provided row template type.
306    */
rowTypeToString(@liceRowType int type)307   private static String rowTypeToString(@SliceRowType int type) {
308     switch (type) {
309       case ROW_TYPE_LIST:
310         return "LIST";
311       case ROW_TYPE_GRID:
312         return "GRID";
313       case ROW_TYPE_MESSAGING:
314         return "MESSAGING";
315       case ROW_TYPE_SHORTCUT:
316         return "SHORTCUT";
317       case ROW_TYPE_TOGGLE:
318         return "TOGGLE";
319       case ROW_TYPE_SLIDER:
320         return "SLIDER";
321       case ROW_TYPE_PROGRESS:
322         return "PROGRESS";
323       case ROW_TYPE_SELECTION:
324         return "SELECTION";
325       case ROW_TYPE_DATE_PICK:
326         return "DATE_PICK";
327       case ROW_TYPE_TIME_PICK:
328         return "TIME_PICK";
329       default:
330         return "unknown row type: " + type;
331     }
332   }
333 }
334