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 android.support.v17.leanback.widget; 18 19 /** 20 * Interface to be implemented by UI component to support seeking. PlaybackGlueHost may implement 21 * the interface to support seeking UI for the PlaybackGlue. There is only one single method 22 * {@link #setPlaybackSeekUiClient(Client)} in the interface. Client (PlaybackGlue) registers 23 * itself as a Client to receive events emitted by PlaybackSeekUi and provide data to the 24 * PlaybackSeekUi. 25 */ 26 public interface PlaybackSeekUi { 27 28 /** 29 * Client (e.g. PlaybackGlue) to register on PlaybackSeekUi so that it can interact 30 * with Seeking UI. For example client(PlaybackGlue) will pause media when PlaybackSeekUi emits 31 * {@link #onSeekStarted()} event. 32 */ 33 class Client { 34 35 /** 36 * Called by PlaybackSeekUi to query client if seek is allowed. 37 * @return True if allow PlaybackSeekUi to start seek, false otherwise. 38 */ isSeekEnabled()39 public boolean isSeekEnabled() { 40 return false; 41 } 42 43 /** 44 * Event for start seeking. Client will typically pause media and save the current position 45 * in the callback. 46 */ onSeekStarted()47 public void onSeekStarted() { 48 } 49 50 /** 51 * Called by PlaybackSeekUi asking for PlaybackSeekDataProvider. This method will be called 52 * after {@link #isSeekEnabled()} returns true. If client does not provide a 53 * {@link PlaybackSeekDataProvider}, client may directly seek media in 54 * {@link #onSeekPositionChanged(long)}. 55 * @return PlaybackSeekDataProvider or null if no PlaybackSeekDataProvider is available. 56 */ getPlaybackSeekDataProvider()57 public PlaybackSeekDataProvider getPlaybackSeekDataProvider() { 58 return null; 59 } 60 61 /** 62 * Called when user seeks to a different location. This callback is called multiple times 63 * between {@link #onSeekStarted()} and {@link #onSeekFinished(boolean)}. 64 * @param pos Position that user seeks to. 65 */ onSeekPositionChanged(long pos)66 public void onSeekPositionChanged(long pos) { 67 } 68 69 /** 70 * Called when cancelled or confirmed. When cancelled, client should restore playing from 71 * the position before {@link #onSeekStarted()}. When confirmed, client should seek to 72 * last updated {@link #onSeekPositionChanged(long)}. 73 * @param cancelled True if cancelled false if confirmed. 74 */ onSeekFinished(boolean cancelled)75 public void onSeekFinished(boolean cancelled) { 76 } 77 } 78 79 /** 80 * Interface to be implemented by UI widget to support PlaybackSeekUi. 81 */ setPlaybackSeekUiClient(Client client)82 void setPlaybackSeekUiClient(Client client); 83 84 } 85