1 /*
2  * Copyright (C) 2017 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 androidx.leanback.widget;
18 
19 import android.graphics.Bitmap;
20 
21 /**
22  * Class to be implemented by app to provide seeking data and thumbnails to UI.
23  */
24 public class PlaybackSeekDataProvider {
25 
26     /**
27      * Client to receive result for {@link PlaybackSeekDataProvider#getThumbnail(int,
28      * ResultCallback)}.
29      */
30     public static class ResultCallback {
31 
32         /**
33          * Client of thumbnail bitmap being loaded. PlaybackSeekDataProvider must invoke this method
34          * in UI thread such as in {@link android.os.AsyncTask#onPostExecute(Object)}.
35          *
36          * @param bitmap Result of bitmap.
37          * @param index Index of {@link #getSeekPositions()}.
38          */
onThumbnailLoaded(Bitmap bitmap, int index)39         public void onThumbnailLoaded(Bitmap bitmap, int index) {
40         }
41     }
42 
43     /**
44      * Get a list of sorted seek positions. The positions should not change after user starts
45      * seeking.
46      *
47      * @return A list of sorted seek positions.
48      */
getSeekPositions()49     public long[] getSeekPositions() {
50         return null;
51     }
52 
53     /**
54      * Called to get thumbnail bitmap. This method is called on UI thread. When provider finds
55      * cache bitmap, it may invoke {@link ResultCallback#onThumbnailLoaded(Bitmap, int)}
56      * immediately. Provider may start background thread and invoke
57      * {@link ResultCallback#onThumbnailLoaded(Bitmap, int)} later in UI thread. The method might
58      * be called multiple times for the same position, PlaybackSeekDataProvider must guarantee
59      * to replace pending {@link ResultCallback} with the new one. When seeking right,
60      * getThumbnail() will be called with increasing index; when seeking left, getThumbnail() will
61      * be called with decreasing index. The increment of index can be used by subclass to determine
62      * prefetch direction.
63      *
64      * @param index Index of position in {@link #getSeekPositions()}.
65      * @param callback The callback to receive the result on UI thread. It may be called within
66      *                 getThumbnail() if hit cache directly.
67      */
getThumbnail(int index, ResultCallback callback)68     public void getThumbnail(int index, ResultCallback callback) {
69     }
70 
71     /**
72      * Called when seek stops, Provider should cancel pending requests for the thumbnails.
73      */
reset()74     public void reset() {
75     }
76 }
77