13. Device Communication
private void sendMessage( final String path, final String text ) {
new Thread( new Runnable() {
@Override
public void run() {
//Get all nodes connected to the phone
NodeApi.GetConnectedNodesResult nodes =
Wearable.NodeApi.getConnectedNodes( mApiClient ).await();
//Try sending a message to each node via the Wearable Message API
for( Node node : nodes.getNodes() ) {
Wearable.MessageApi.sendMessage(
mApiClient,
node.getId(),
path,
text.getBytes() ).await();
}
}
} ).start();
}
15. Additional Resources for Wear
Android Developers Documentation:
https://developer.android.com/wear/index.html
Designing for Wearables
https://www.youtube.com/watch?v=ea_KCJ2qy6s
Building for Android Wear: Depth and Flexibility
http://android-developers.blogspot.com/2015/02/building-
for-android-wear-depth-and.html
16. Related Tutorials
Building a Native Wear Application
http://bit.ly/1B8yfL8
Wear Notifications
http://bit.ly/1FgomIu
Using Native Android Sensors
http://bit.ly/1Azfe0U
Wear Message API
http://bit.ly/1D0v56V
19. Designing for the Livingroom
10 Foot View
Immersive Experiences
Voice Interaction
Audio Feedback
Provide Recommendations
20. Media Apps
Leanback Support Library
−
Browse Fragment
Horizontal and Vertical Navigation
Fastlane Navigation
Similar to ListFragment
−
DetailFragment
Detailed information and action chooser
Recommendations
−
SearchFragment
Content Activity
24. DetailFragment
Use an AsyncTask to load DetailFragment:
@Override
protected DetailsOverviewRow doInBackground( Movie... movies ) {
//Create the initial details 'row'
DetailsOverviewRow row = new DetailsOverviewRow( mSelectedMovie );
//Set main image for details
Bitmap poster = getPosterForMovie( mSelectedMovie );
row.setImageBitmap( getActivity(), poster );
//Add buttons to detail view
row.addAction( new Action( ACTION_WATCH, getResources().getString(
R.string.watch ), getResources().getString( R.string.watch_subtext) ) );
return row;
}
25. DetailFragment
@Override
protected void onPostExecute( DetailsOverviewRow detailRow ) {
ClassPresenterSelector classPresenter = new ClassPresenterSelector();
/*
Get the presenter for the detail information:
1. Uses the binder pattern to associate movie dana to the detail view
2. Sets background color and styles
3. Adds ActionClickedListeners to Action buttons
*/
classPresenter.addClassPresenter( DetailsOverviewRow.class,
getDetailsOverviewRowPresenter() );
//Create the recommendations row
classPresenter.addClassPresenter( ListRow.class, new ListRowPresenter() );
//Put everything together
ArrayObjectAdapter adapter = new ArrayObjectAdapter( classPresenter );
adapter.add( detailRow );
loadRelatedMedia( adapter );
setAdapter( adapter );
}
27. DetailFragment - Recommendations
private void loadRelatedMedia( ArrayObjectAdapter adapter ) {
List<Movie> movies = getMovies();
List<Movie> related = new ArrayList<>();
//Save a list of 'related' movies. In this case, all from the same category
for( Movie movie : movies ) {
if( movie.getCategory().equals( mSelectedMovie.getCategory() ) ) {
related.add( movie );
}
}
//Create a new row adapter for related movies using the same movie cards in BrowseFragment
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter( new CardPresenter() );
for( Movie movie : related ) {
listRowAdapter.add( movie );
}
//Create a new header and associate the related row with the
//detail view adapter
HeaderItem header = new HeaderItem( 0, "Related", null );
adapter.add( new ListRow( header, listRowAdapter ) );
}
31. Additional Resources for TV
Android Developers Documentation:
http://developer.android.com/training/tv/index.html
Android Design Documentation:
http://developer.android.com/design/tv/index.html
32. Related Tutorials
Creating a Media App for Android TV:
http://bit.ly/1D9gwAL
Getting Started with the Gamepad Controller
for Android TV:
http://bit.ly/1MMjPDn
33. Sample Code Projects for Android TV
Android TV Media Player
https://github.com/PaulTR/AndroidDemoProjects/
tree/master/AndroidTVMediaPlayer
Game Using Game Controller
https://github.com/PaulTR/AndroidDemoProjects/
tree/master/AndroidTVAsteroidBelt
34. Android Auto
Design
−
Glanceable and Simple
−
Context Aware
−
Provided UIs
Implementation
−
CarExtender Notifications
−
Media Browser Interface – Folders and playable
items, MediaSession callbacks
Out Soon
40. Auto Media App
@Override
public void onLoadChildren(String parentId, Result<List<MediaBrowser.MediaItem>>
result) {
//This method is called by the system to populate items in the media browser
List<MediaBrowser.MediaItem> items = getMediaItemsById( parentId );
if( items != null )
result.sendResult( items );
}
private List<MediaBrowser.MediaItem> getMediaItemsById( String id ) {
List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>();
if( BROWSEABLE_ROOT.equalsIgnoreCase( id ) ) {
//Add folders here
mediaItems.add( generateBrowseableMediaItemByGenre ( BROWSEABLE_ROCK ) );
} else
//Get media items for the selected folder
return getPlayableMediaItemsByGenre( id );
return mediaItems;
}
41. Auto Media App
private MediaBrowser.MediaItem generateBrowseableMediaItemByGenre( String genre ) {
MediaDescription.Builder mediaDescriptionBuilder = new MediaDescription.Builder();
mediaDescriptionBuilder.setMediaId( genre );
mediaDescriptionBuilder.setTitle( genre );
mediaDescriptionBuilder.setIconBitmap( folderBitmap );
return new MediaBrowser.MediaItem( mediaDescriptionBuilder.build(),
MediaBrowser.MediaItem.FLAG_BROWSABLE );
}
private MediaBrowser.MediaItem generatePlayableMediaItem( Song song ) {
MediaDescription.Builder mediaDescriptionBuilder = new MediaDescription.Builder();
mediaDescriptionBuilder.setMediaId( song.getuId() );
mediaDescriptionBuilder.setTitle( song.getTitle() );
mediaDescriptionBuilder.setSubtitle( song.getArtist() );
mediaDescriptionBuilder.setIconUri( song.getImage() ) );
return new MediaBrowser.MediaItem(
mediaDescriptionBuilder.build(),
MediaBrowser.MediaItem.FLAG_PLAYABLE );
}
42. Additonal Resources for Auto
Developer Overview:
https://developer.android.com/auto/overview.html
Managing Audio Playback:
https://developer.android.com/training/managing-
audio/index.html
Notifications:
http://developer.android.com/guide/topics/ui/notifiers/
notifications.html
43. Related Tutorials
Using the Android Auto Media Browser:
http://bit.ly/17KsqWj
Sending Messages to Android Auto:
http://bit.ly/1JB9ZoT
44. Sample Code Projects for Auto
Media Browser:
https://github.com/PaulTR/AndroidDemoProjects/tree/
master/AndroidAutoMedia
Auto Messenger:
https://github.com/PaulTR/AndroidDemoProjects/tree/
master/AndroidAutoMessenger