Courtesy: GitHub

Leanback Support Library Showcase App for Android TV

This sample app showcases different components that come with Leanback library.

The home screen in this sample app is a BrowseFragment consisting of a set of different cards. Each card represents a component in Leanback.

All the cards in this sample app work except the Settings. Settings for now crashes due to some internal issue, and we are working on resolving that in the next few days.

We will also add a new music example card soon. This will be a new PlaybackOverlayFragment that comes with a set of new features.

Introduction

Dependencies

If you use Android Studio as recommended, the following dependencies will automatically be installed by Gradle.

  • Android SDK v7 appcompat library
  • Android SDK v17 leanback support library
  • Android SDK v7 recyclerview library

Getting Started

  • Clone this repo:
git clone https://github.com/googlesamples/leanback-showcase.git
  • In the local.properties file add the location to your Android SDK (You need to install Android SDK 'N').
  • Open the project in Android Studio.
  • Compile and deploy to your Android TV emulator or device (such as a Nexus Player).

Screenshots

Screenshot

Need more information about getting started with Android TV? Check the official docs.

Support

If you need additional help, our community might be able to help.

Contributing

We love contributions! :smile: Please follow the steps in the CONTRIBUTING guide to get started. If you found a bug, please file it here.

License

Licensed under the Apache 2.0 license. See the LICENSE file for details.

compileSdkVersion 26

applicationId 'com.example.android.persistence'

minSdkVersion 21

targetSdkVersion 26

versionCode 1

versionName "1.0"

compile fileTree(include: ['*.jar'], dir: 'libs')

compile 'com.android.support:design:' + rootProject.supportLibVersion

compile 'com.android.support:cardview-v7:' + rootProject.supportLibVersion

compile 'com.android.support:recyclerview-v7:' + rootProject.supportLibVersion

compile 'android.arch.lifecycle:extensions:' + rootProject.archLifecycleVersion

compile 'android.arch.persistence.room:runtime:' + rootProject.archRoomVersion

testCompile 'junit:junit:4.12'

compile 'com.android.support:leanback-v17:' + rootProject.supportLibVersion

compile 'com.android.support:appcompat-v7:' + rootProject.supportLibVersion

compile 'com.android.support:preference-v7:'+ rootProject.supportLibVersion

compile 'com.android.support:preference-leanback-v17:' + rootProject.supportLibVersion

compile 'com.android.support:preference-v14:' + rootProject.supportLibVersion

compile "com.google.code.gson:gson:2.8.1"

compile "com.android.support:palette-v7:" + rootProject.supportLibVersion

compile 'com.google.android.exoplayer:exoplayer:r2.2.0'

compile 'com.github.bumptech.glide:glide:4.0.0-RC1'

compile 'com.android.support:support-tv-provider:' + rootProject.supportLibVersion

compile 'com.squareup.retrofit2:converter-gson:2.3.0'

compile 'com.squareup.retrofit2:retrofit:2.3.0'

package android.support.v17.leanback.supportleanbackshowcase

uses-permission

  • android.permission.INTERNET
  • android.permission.ACCESS_NETWORK_STATE
  • android.permission.RECORD_AUDIO
  • android.permission.READ_EXTERNAL_STORAGE
  • android.permission.WRITE_EXTERNAL_STORAGE
  • com.android.providers.tv.permission.READ_EPG_DATA
  • com.android.providers.tv.permission.WRITE_EPG_DATA

application .app.room.controller.app.SampleApplication

MainActivity

Called when the activity is first created.

PageAndListRowActivity

Activity showcasing the use of {@link android.support.v17.leanback.widget.PageRow} and {@link android.support.v17.leanback.widget.ListRow}.

WizardExampleActivity

An Activity displaying a wizard for renting a movie.

SettingsExampleActivity

DialogExampleActivity

TODO: Javadoc

DetailViewExampleActivity

Contains a {@link DetailsFragment} in order to display more details for a given card.

DetailViewExampleWithVideoBackgroundActivity

Contains a {@link DetailsFragment} with video background in order to display more details for a given card.

CardExampleActivity

TODO: Javadoc

GridExampleActivity

TODO: Javadoc

VideoGridExampleActivity

TODO: Javadoc

VideoExampleActivity

Activity that hosts VideoConsumptionExampleFragment.

VideoExampleWithExoPlayerActivity

Activity that hosts VideoConsumptionExampleWithExoPlayerFragment.

MusicExampleActivity

TODO: Javadoc

DynamicVideoRowsActivity

The main activity to demonstrate how to add/ remove video rows from app to android tv launcher * It will hold DynamicRowsFragment for all UI interaction

VideoPlaybackActivity

VideoPlaybackActivity for video playback that loads PlaybackFragment * This activity can be invoked in two scenarios,

  1. In DynamicRowFragment, when the video clips is clicked, this activity will be fired up to play the video
  2. When the channel is added to the home screen, click the video content will also start since this activity can receive the broadcast which is declared in AndroidManifest.xml * <data android:scheme="rowsnewapi" android:host="android.support.v17.leanback.supportleanbackshowcase" android:pathPrefix="/playvideo" />

This is the helper function to extract the videoId (an unique id which will not be changed along with the transaction)

This is a helper function which can extract key fields from VideoContent (a data structure designed specific for the video clip which can be added to home screen) to MediaMetaData (a data structure which is used by VideoConsumptionExampleFragment.java to play and extract video meta data) So we can have unified data transmission interface without type casting on the fragment side * @param videoContent The video content you want to convert to MediaMetaData. @return MediaMetaData The conversion result.

If this activity is started from the home screen (that is the only information we have is videoId) a videoContent will be constructed through it, and put as an extra to the intent So VideoConsumptionExampleFragment can find the video source to play

Populate play lists firstly

Iterate through all video clips to find the video content which is selected from home screen

If this activity is started from clicking the video content from DynamicRowFragment

Firstly convert VideoContent to MediaMetaData, then put MediaMetaData as an extra for this intent

ChannelPublishActivity

Activity that showcases different aspects of GuidedStepFragments.

LiveDataRowsActivity

Extend from LifecycleActivity so this activity can be used as the owner of lifecycle event

LiveDataDetailActivity

Extend from LifecycleActivity so this activity can be used as the owner of lifecycle event

SearchActivity

Extend from LifecycleActivity so this activity can be used as the owner of lifecycle event

MusicPlaybackService

Music service that handles all the interactions between the app and the media player. It receives media list from an app and starts playing the media items one after another. Apps can also directly interact with the service for specific operations such as playing or pausing or getting different info about the current media item.

Sets the media session's activity launched when clicking on NowPlayingCard. This returns to the media screen that is playing or paused; the launched activity corresponds to the currently shown media session in the NowPlayingCard on TV launcher.

@return The available set of actions for the media session. These actions should be provided for the MediaSession PlaybackState in order for {@link MediaSessionCompat.Callback#onMediaButtonEvent} to call relevant methods of onPause() or onPlay().

starts playback of the previously opened media file

pauses playback (call play() to resume)

skip to next item

skip to previous item

@return The current playback position in milliseconds.

@return The duration of the current media item in milliseconds

Seeks to the given new position in milliseconds of the current media item @param newPosition The new position of the current media item in milliseconds

Configures service as a foreground service.