android for all the things
TRANSCRIPT
![Page 1: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/1.jpg)
Android For All The Things
Paul Ruiz
![Page 2: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/2.jpg)
New Android Form Factors
• Android Wear• Android TV• Android Auto
![Page 3: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/3.jpg)
Android Wear
Android for wearable computing (smart watches)
Design for Accessibility Notifications Hardware Sensors Device Communication
![Page 4: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/4.jpg)
Design for Accessibility
Glanceable Information Voice Actions No to Low Interactions
![Page 5: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/5.jpg)
Notifications
Cards● Action Buttons● Quick Reply● Media Controls
![Page 6: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/6.jpg)
Notifications
![Page 7: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/7.jpg)
NotificationsAction Button Notifications://Create action pending intentIntent intent = new Intent( Intent.ACTION_VIEW );intent.setData( Uri.parse( "http://ptrprograms.blogspot.com" ) );PendingIntent pendingIntent = PendingIntent.getActivity( getActivity(), 0, intent, 0 );
//Create notification builder with NotificationCompatNotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( getActivity() )
.setSmallIcon( R.drawable.ic_launcher )
.setLargeIcon( BitmapFactory.decodeResource( getResources(), R.drawable.icon ) )
.setContentText( getString( R.string.content_text ) )
.setContentTitle( getString( R.string.content_title ) )
.addAction( R.drawable.ic_launcher, "Launch Blog", pendingIntent );
//Create WearableNotification with the previous builder as a baseNotification notification = new WearableNotifications.Builder( notificationBuilder ) .setHintHideIcon( true )
.build();
mNotificationManager.notify( notificationId, notification );
![Page 8: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/8.jpg)
NotificationsQuick Reply Notifications://Create notification builder with NotificationCompatNotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( getActivity() )
.setSmallIcon( R.drawable.ic_launcher )
.setLargeIcon( BitmapFactory.decodeResource( getResources(), R.drawable.icon ) )
.setContentText( getString( R.string.content_text ) )
.setContentTitle( getString( R.string.content_title ) )
//Create RemoteInput list of quick reply optionsRemoteInput remoteInput = new RemoteInput.Builder( "extra_replies" )
.setLabel( ''Transportation'' )
.setChoices( getResources().getStringArray( R.array.getting_around ) )
.build();
Notification notification =new WearableNotifications.Builder( notificationBuilder )
.setHintHideIcon( true )
.addRemoteInputForContentIntent( remoteInput )
.build();
mNotificationManager.notify( notificationId, notification );
![Page 9: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/9.jpg)
Hardware Sensors Gyroscope Compass Barometer Optical Heart Rate Monitor Accelerometer
![Page 10: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/10.jpg)
Hardware SensorsRegister the SensorListener from android.sensor package:
public void start( SensorManager manager ) { this.mSensorManager = manager;
//Check if device has a heart rate sensor mHeartRateSensor = mSensorManager .getDefaultSensor( Sensor.TYPE_HEART_RATE );
//If heart rate sensor exists, associate it with the SensorListener if ( mHeartRateSensor != null ) { mSensorManager.registerListener( this, mHeartRateSensor, SensorManager.SENSOR_DELAY_FASTEST ); }}
![Page 11: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/11.jpg)
Hardware SensorsImplement SensorEventListener:
@Overridepublic void onSensorChanged( SensorEvent event ) { if ( event.sensor.getType() == Sensor.TYPE_HEART_RATE ) { if ( (int) event.values[0] > 0 ) { handleHeartRate( (int) event.values[0] ); } }}
![Page 12: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/12.jpg)
Device Communication
Direct Bluetooth Wear APIs
− Message and DataLayer APIs – Play Services
![Page 13: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/13.jpg)
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(); }
![Page 14: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/14.jpg)
Device Communication
Implement MessageApi.MessageListener or Extend WearableListenerService
@Override public void onMessageReceived( MessageEvent messageEvent ) { if( messageEvent.getPath().equalsIgnoreCase( ''/PathFilter'' ) ) { handleMessageEvent( messageEvent.getData() ); } else { super.onMessageReceived( messageEvent ); } }
![Page 15: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/15.jpg)
Additional Resources for WearAndroid Developers Documentation:
https://developer.android.com/wear/index.htmlDesigning for Wearables
https://www.youtube.com/watch?v=ea_KCJ2qy6sBuilding for Android Wear: Depth and Flexibility
http://android-developers.blogspot.com/2015/02/building-for-android-wear-depth-and.html
![Page 16: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/16.jpg)
Related TutorialsBuilding 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
![Page 17: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/17.jpg)
Sample Code Projects for WearAndroid Wear Seizure Detector
https://github.com/PaulTR/WearHackathon
Wear MessageAPI
https://github.com/PaulTR/AndroidDemoProjects/tree/ master/WearMessageApi
Native App – Stay Awake
https://github.com/PaulTR/AndroidDemoProjects/ tree/master/StayAwake
![Page 18: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/18.jpg)
Android TV
Designing for the Livingroom Media Apps Games
![Page 19: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/19.jpg)
Designing for the Livingroom
10 Foot View Immersive Experiences Voice Interaction Audio Feedback Provide Recommendations
![Page 20: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/20.jpg)
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
![Page 21: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/21.jpg)
BrowseFragment
![Page 22: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/22.jpg)
BrowseFragment Rows private void loadRows() {
ArrayObjectAdapter rowsAdapter = new ArrayObjectAdapter( new ListRowPresenter() ); CardPresenter cardPresenter = new CardPresenter();
for( String category : getCategories() ) { ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter( cardPresenter ); for( Movie movie : mMovies ) {
//Group movies by their category if( category.equalsIgnoreCase( movie.getCategory() ) ) listRowAdapter.add( movie ); }
//Add headers for BrowseFragment Categories if( listRowAdapter.size() > 0 ) { HeaderItem header = new HeaderItem( rowsAdapter.size() - 1, category, null ); rowsAdapter.add( new ListRow( header, listRowAdapter ) ); } }
setAdapter( rowsAdapter );
}
![Page 23: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/23.jpg)
DetailFragment
![Page 24: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/24.jpg)
DetailFragmentUse an AsyncTask to load DetailFragment:
@Overrideprotected 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;}
![Page 25: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/25.jpg)
DetailFragment@Overrideprotected 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 );}
![Page 26: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/26.jpg)
DetailFragment - Recommendations
![Page 27: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/27.jpg)
DetailFragment - Recommendationsprivate 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 ) );}
![Page 28: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/28.jpg)
Games Design– Landscape
– Companion Apps
Game Controller
![Page 29: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/29.jpg)
Game Controller
![Page 30: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/30.jpg)
Game ControllerImplement InputDeviceListener
public boolean handleMotionEvent(MotionEvent motionEvent) { Int deviceId = motionEvent.getDeviceId(); float leftJoystickX = motionEvent.getAxisValue( MotionEvent.AXIS_X );
float leftJoystickY = motionEvent.getAxisValue( MotionEvent.AXIS_Y ); float rightJoystickX = motionEvent.getAxisValue( MotionEvent.AXIS_Z ); float rightJoystickY = motionEvent.getAxisValue( MotionEvent.AXIS_RZ ); return true; }
public boolean handleKeyEvent(KeyEvent keyEvent) {Int deviceId = keyEvent.getDeviceId();
return keyEvent.getKeyCode() == KeyEvent.KEYCODE_BUTTON_X;/* Possible KeyEvents: KEYCODE_BUTTON_A, KEYCODE_BUTTON_B, KEYCODE_BUTTON_X, KEYCODE_BUTTON_YKEYCODE_BUTTON_R1, KEYCODE_BUTTON_R2,KEYCODE_BUTTON_L1, KEYCODE_BUTTON_L2, etc */
}
![Page 31: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/31.jpg)
Additional Resources for TVAndroid Developers Documentation:
http://developer.android.com/training/tv/index.html
Android Design Documentation: http://developer.android.com/design/tv/index.html
![Page 32: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/32.jpg)
Related TutorialsCreating a Media App for Android TV:
http://bit.ly/1D9gwAL
Getting Started with the Gamepad Controller for Android TV: http://bit.ly/1MMjPDn
![Page 33: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/33.jpg)
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
![Page 34: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/34.jpg)
Android Auto Design
− Glanceable and Simple− Context Aware− Provided UIs
Implementation− CarExtender Notifications− Media Browser Interface – Folders and playable
items, MediaSession callbacks
Out Soon
![Page 35: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/35.jpg)
Message Cards
![Page 36: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/36.jpg)
Auto Messaging App//Create UnreadConversation ObjectNotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( ''Convo'' ); unreadConversationBuilder.setReadPendingIntent( getMessageReadPendingIntent() ); unreadConversationBuilder.setReplyAction( getMessageReplyPendingIntent(), getVoiceReplyRemoteInput() );
unreadConversationBuilder.addMessage( "Message Text" );
return unreadConversationBuilder.build()
![Page 37: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/37.jpg)
Auto Messaging App//Create Notification with Unread ConversationNotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( getApplicationContext() ) .setSmallIcon( R.drawable.ic_launcher ) .setLargeIcon( BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher ) ) .setContentText( "content text" ) .setWhen( Calendar.getInstance().get( Calendar.SECOND ) ) .setContentTitle( "content title" );
notificationBuilder.extend( new NotificationCompat.CarExtender() .setUnreadConversation( getUnreadConversation() ) );NotificationManagerCompat.from( this ).notify( 1, notificationBuilder.build() );
![Page 38: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/38.jpg)
Auto Media App
![Page 39: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/39.jpg)
Auto Media App
![Page 40: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/40.jpg)
Auto Media App@Overridepublic 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;}
![Page 41: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/41.jpg)
Auto Media Appprivate 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 );}
![Page 42: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/42.jpg)
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
![Page 43: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/43.jpg)
Related TutorialsUsing the Android Auto Media Browser: http://bit.ly/17KsqWj
Sending Messages to Android Auto: http://bit.ly/1JB9ZoT
![Page 44: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/44.jpg)
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
![Page 45: Android For All The Things](https://reader030.vdocuments.net/reader030/viewer/2022032616/55a6357b1a28ab71488b489b/html5/thumbnails/45.jpg)
Me
Android Development Blog:
http://ptrprograms.blogspot.com/
GitHub:
https://github.com/PaulTR
Google Plus:
+PaulTrebilcoxRuiz