13bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu/*
23bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu * Copyright (C) 2017 The Android Open Source Project
33bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu *
43bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu * Licensed under the Apache License, Version 2.0 (the "License");
53bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu * you may not use this file except in compliance with the License.
63bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu * You may obtain a copy of the License at
73bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu *
83bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu *      http://www.apache.org/licenses/LICENSE-2.0
93bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu *
103bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu * Unless required by applicable law or agreed to in writing, software
113bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu * distributed under the License is distributed on an "AS IS" BASIS,
123bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu * See the License for the specific language governing permissions and
143bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu * limitations under the License.
153bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu */
163bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu
173bcad88cbf4488e747d84893c35f2351b8f84afeDake Gupackage android.support.v17.leanback.widget;
183bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu
193bcad88cbf4488e747d84893c35f2351b8f84afeDake Guimport android.graphics.Bitmap;
203bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu
213bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu/**
223bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu * Class to be implemented by app to provide seeking data and thumbnails to UI.
233bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu */
243bcad88cbf4488e747d84893c35f2351b8f84afeDake Gupublic class PlaybackSeekDataProvider {
253bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu
263bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu    /**
273bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * Client to receive result for {@link PlaybackSeekDataProvider#getThumbnail(int,
283bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * ResultCallback)}.
293bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     */
303bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu    public static class ResultCallback {
313bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu
323bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu        /**
333bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu         * Client of thumbnail bitmap being loaded. PlaybackSeekDataProvider must invoke this method
343bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu         * in UI thread such as in {@link android.os.AsyncTask#onPostExecute(Object)}.
353bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu         *
363bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu         * @param bitmap Result of bitmap.
373bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu         * @param index Index of {@link #getSeekPositions()}.
383bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu         */
393bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu        public void onThumbnailLoaded(Bitmap bitmap, int index) {
403bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu        }
413bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu    }
423bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu
433bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu    /**
443bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * Get a list of sorted seek positions. The positions should not change after user starts
453bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * seeking.
463bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     *
473bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * @return A list of sorted seek positions.
483bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     */
493bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu    public long[] getSeekPositions() {
503bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu        return null;
513bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu    }
523bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu
533bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu    /**
543bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * Called to get thumbnail bitmap. This method is called on UI thread. When provider finds
553bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * cache bitmap, it may invoke {@link ResultCallback#onThumbnailLoaded(Bitmap, int)}
563bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * immediately. Provider may start background thread and invoke
573bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * {@link ResultCallback#onThumbnailLoaded(Bitmap, int)} later in UI thread. The method might
583bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * be called multiple times for the same position, PlaybackSeekDataProvider must guarantee
593bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * to replace pending {@link ResultCallback} with the new one. When seeking right,
603bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * getThumbnail() will be called with increasing index; when seeking left, getThumbnail() will
613bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * be called with decreasing index. The increment of index can be used by subclass to determine
623bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * prefetch direction.
633bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     *
643bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * @param index Index of position in {@link #getSeekPositions()}.
653bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * @param callback The callback to receive the result on UI thread. It may be called within
663bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     *                 getThumbnail() if hit cache directly.
673bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     */
683bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu    public void getThumbnail(int index, ResultCallback callback) {
693bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu    }
703bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu
713bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu    /**
723bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     * Called when seek stops, Provider should cancel pending requests for the thumbnails.
733bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu     */
743bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu    public void reset() {
753bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu    }
763bcad88cbf4488e747d84893c35f2351b8f84afeDake Gu}
77