Les cibles TV et Android Wear ont toutes deux leur spécificité, tant en terme d'interface que de logique de développement.
Vous verrez de quelle manière l'OS Android se différencie sur ces plateformes, et comment simplement étendre votre support de ces versions depuis des applications Android classiques.
3. Agenda
Android TV
Les spécificités du système
Adapter et distribuer son application pour Android TV
Android Wear
Les spécificités du système
Des notifications sous stéroïdes
Créer une application native ou une watchface
Q&A
5. Android TV
• C’est Android
• Mais aussi Chromecast (Google Cast)
• Applications (multimedia et +)
• Jeux (casual et +)
• AOSP compliant
• Leanback Launcher, Google Apps, Play Store…
• Hardware: equivalent aux tablettes/smartphones de milieu à haut de gamme.
11. Adapter son application pour Android TV
1. Ajouter/réutiliser une activity pour Android TV, pour recevoir l’intent “Leanback”
2. Intégrer des assets spécifiques
3. Supporter la navigation sans couche tactile
4. Adapter l’UI
5. Aller plus loin!
Il n’est pas necessaire de créer une application séparée.
Même si cela reste possible en gardant une seule entrée sur le Play Store.
13. 2. Banner
<activity or <application
…
android:banner="@drawable/ic_banner"
…
>
• Inclu le nom localisé de l’application
• Pas de transparence
• Taille:160x90dp -> 320x180px dans drawable-xhdpi
14. 3. Supporter la navigation sans couche tactile
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
Adjust D-PAD navigation:
android:focusable="true", <requestFocus /> / .requestFocus()
android:nextFocusDown="@+id/whatever1"
android:nextFocusUp="@id/whatever2"
For custom Views:
KeyEvent.KEYCODE_DPAD_(UP|DOWN|LEFT|RIGHT|CENTER)
15. 4. Adapting the UI
Démarrer de android:Theme.NoTitleBar
ou Theme.Leanback de la Leanback support library:
compile "com.android.support:leanback-v17:23.1.1"
Ajouter des marges pour l’overscan: (Les Leanback Views et Fragments les ont déjà)
android:layout_marginTop="27dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="48dp"
android:layout_marginBottom="27dp"
* minSdkVersion>=17 est censé être requis pour la Leanback support library, mais il est
possible de passer outre:
• Utiliser Theme.Leanback depuis uniquement des resources –v21+, restreindre l’utilisation
de la librairie aux parties executées uniquement sur TV
• Ajouter au manifest: <uses-sdk
tools:overrideLibrary="android.support.v17.leanback" />
16. Aller plus loin dans l’intégration
• Pousser des recommendations
• Utiliser les éléments de la Leanback support library
• Supporter plusieurs controleurs
• S’intégrer au système de recherche
• Diffuser du contenu par le “TV Input Framework”
17. Pousser des recommendations
Bundle extras = new Bundle();
extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI, backgroundUri);
Notification notification = new NotificationCompat.BigPictureStyle(
new NotificationCompat.Builder(mContext)
.setLargeIcon(bitmap)
.setColor(color)
.setContentTitle(title)
.setContentText(description)
.setLocalOnly(true)
.setOngoing(true)
.setCategory(Notification.CATEGORY_RECOMMENDATION)
.setSmallIcon(mSmallIcon)
.setContentIntent(mIntent)
.setExtras(extras))
.build();
It’s advised to update recommendations from a service you can trigger using an AlarmManager
that will run it periodically, starting with shorty after boot.
18. The Leanback support library – BrowseFragment
BackgroundManager.getInstance()
.setDrawable()
setTitle()
setBadgeDrawable()
setAdapter( ObjectAdapter )
Presented items have to be Rows.
setBrandColor()
setSearchAffordanceColor()
setOnSearchClickedListener()
setOnItemViewSelectedListener()
setOnItemViewClickedListener()
setHeadersState()
19. Supporter plusieurs contrôleurs
• int KeyEvent.getDeviceId()
• String KeyEvent.getDevice().getDescriptor()
API Level 16+
• Nearby Connection API
Google Play Services 7.0+
20. Système de Recherche
• Global Search
• Implémentez un Content Provider
• Declarez android.app.searchable
• https://developer.android.com/training/
tv/discovery/searchable.html
• Search Activity:
• Utilisez SpeechRecognizer
• Ou directement le Leanback SearchFragment.
21. TV Input Framework – Live Channels
<service
android:name=".MyTvInputService"
android:permission="android.permission.BIND_TV_INPUT" >
<intent-filter>
<action android:name="android.media.tv.TvInputService" />
</intent-filter>
<meta-data android:name="android.media.tv.input“ android:resource="@xml/my_tv_input" />
</service>
<?xml version="1.0" encoding="utf-8"?>
<tv-input xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="com.xh.tvinputservicetest.SettingsActivity"
android:setupActivity="com.xh.tvinputservicetest.SetupActivity" />
my_tv_input.xml
AndroidManifest.xml
public class MyTvInputService extends TvInputService {
…
@Override
public Session onCreateSession(String inputId) {
return new MyTvInputServiceSession(MyTvInputService.this); //ServiceSession implementation is on next slide
}
}
22. TV Input Framework – Live Channels
public class MyTvInputServiceSession extends TvInputService.Session {
Surface mSurface;
@Override
public boolean onSetSurface(Surface surface) {
mSurface = surface;
return true;
}
@Override
public boolean onTune(Uri channelUri) {
notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_BUFFERING);
//tune to channel and change draws to surface in a render thread, then fire notifyVideoAvailable()
return true;
}
@Override
public void onSetCaptionEnabled(boolean enabled) { }
…
}
28. Android Wear
• C’est Android
• Extension au smartphone et à ses applications
• Applications Android natives
• Navigation tactile simple et gestuelle
• PAS dans l’AOSP
• Hardware: equivalent aux smartphones d’entrée de gamme.
• Pas de décodage vidéo, webview, clavier système, ni connexion
directe à Internet
33. Réponses complèxes depuis une notification
Texte libre / Emojis
Réponses prédéfinies
android.app.RemoteInput
34. Notifications – spécique à Android Wear
Notification.WearableExtender.addPage(Notification)
Pagination
35. Notifications – spécique à Android Wear
Action directe au
touch sur la notification
Notification.WearableExtender.setContentxxx()
36. Notifications – spécique à Android Wear
Notification.WearableExtender.setBackground()
+ setHintShowBackgroundOnly()
(+ for QR codes: setHintAvoidBackgroundClipping())
37. Avant d’aller plus loin, pensez l’expérience utilisateur
Qu’est ce que mon application peut apporter à l’utilisateur, à travers Android
Wear?
Notifications
Informations supplémentaires (pages, images, QR code..)
Actions simples
Plus?
-> Action pour ouvrir l’application Android associée
-> Utilisation d’une application Android Wear native
39. Applications Natives à Android Wear
- Mode de distribution: APK dans l’APK
- Déployé peu après l’installation de l’application sur le téléphone
- Pour le développement: connection directe à l’Émulateur ou smartwatch
dependencies {
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:support-v4:23.1.1'
wearApp project(':wearable')
}
40. Communication Wear App /Android App
Pas d’accès Internet
Solution: Google Play Services
NodeApi, MessageApi, DataApi, ChannelApi
Restez raisonnables sur la quantité et la fréquence des communications.
android.gms.wearable
41. Penser ses vues pour Android Wear
• Viser une consultation d’environ 5 secondes.
• Permettre une intéraction efficace
• voix, emoji, swipe, tap plein écran
• pas de champs textes ou autre.
• S’adapter aux différents types et tailles d’écrans
Non.
42. Gérer le mode ambient
• Intéractif: montre en utilisation
• intéractions possibles
• mises à jour en permanence
• Ambient:
• Optionnel
• Une mise à jour par minute par défaut
• Max 20 seconds recommandé
• Possible de faire plus, mais à éviter pour conserver la batterie
44. Intéractions vocales
Call a car/taxi "OK Google, get me a taxi“ / "OK Google, call me a car"
Take a note "OK Google, take a note“ / "OK Google, note to self"
Set alarm "OK Google, set an alarm for 8 AM“ / "OK Google, wake me up at 6 tomorrow"
Set timer "Ok Google, set a timer for 10 minutes"
Start stopwatch "Ok Google, start stopwatch"
Start/Stop a bike ride "OK Google, start cycling“ / "OK Google, start my bike ride“ / ”OK Google, stop cycling"
Start/Stop a run "OK Google, track my run“ / "OK Google, start running“ / OK Google, stop running"
Start/Stop a workout "OK Google, start a workout“ / "OK Google, track my workout“ / "OK Google, stop workout"
Show heart rate "OK Google, what’s my heart rate?“ / "OK Google, what’s my bpm?"
Show step count "OK Google, how many steps have I taken?“ / "OK Google, what’s my step count?"
Start your APP “OK Google, start yourApp”
45. S’adapter aux différents hardware
Écran circulaire w/ chin
LCD
ARMv7 OS
512MB ram
Écran carré
AMOLED
ARMv7 OS
512MB ram
Onboard speaker
Écran circulaire
AMOLED
ARMv7 OS
512MB ram
Écran carré
LCD
Transflectif
ARMv7 OS
Onboard GPS
512MB ram
Écran circulaire
LCD Transflectif
x86 OS
1GB ram
Écran circulaire w/ chin
LCD
x86 OS
1GB ram
Pas de tailles d’écran standard: 320x290px, 360x360px, 360x325px, 360x326px, 400x400px…
46. Différents types de CPU
Tous les téléphones/tablettes Android basés sur des architectures Intel
peuvent historiquement faire tourner du code ARM… ce n’est pas le cas pour
les smartwatches.
Cela reste rarement un problème:
Les applications Android sont à la base en Java
S’il y a des parties natives (anecdotique pour des applications Wear),
il est normalement simple d’intégrer leur version x86.
47. Ambient mode
Usually LCD technology
(transflective or not)
Ambient mode
LOW_BIT display
Usually AMOLED technology
Interactive Mode
Différents types d’écrans
48. Watchfaces
• Identique aux applications natives
• Peut passer une vue pour paramétrer la watchface
• Gestion du mode ambient obligatoire
• Implémente un WatchFaceService
<manifest ...>
<uses-permission
android:name="com.google.android.permission.PROVIDE_BACKGROUND" />
<uses-permission
android:name="android.permission.WAKE_LOCK" />
...
<application …>
<service android:name=".AnalogWatchFaceService" android:label="@string/analog_name" android:allowEmbedded="true“
android:permission="android.permission.BIND_WALLPAPER" >
<meta-data android:name="android.service.wallpaper“ android:resource="@xml/watch_face" />
<meta-data android:name="com.google.android.wearable.watchface.preview" android:resource="@drawable/preview_analog" />
<meta-data android:name="com.google.android.wearable.watchface.preview_circular" android:resource="@drawable/preview_analog_circular" />
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
<category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
</intent-filter>
</service>
</application>
</manifest>
49. Watchfaces interactives
Peut gérer le Tap sur toute la surface
Les autres gestes sont réservés au système.
setWatchFaceStyle(new WatchFaceStyle.Builder(mService)
.setAcceptsTapEvents(true)
// other style customizations
.build());
@Override
public void onTapCommand(
@TapType int tapType, int x, int y, long eventTime) {
switch (tapType) {
case WatchFaceService.TAP_TYPE_TAP:
hideTapHighlight();
if (withinTapRegion(x, y)) {
// Implement the tap action
// (e.g. show detailed step count)
onWatchFaceTap();
}
break;
//…
}
}
50. Android Wear - résumé
Penser, tester et améliorer ses notifications pour Android Wear est relativement simple.
La plateforme permet d’aller beaucoup plus loin si votre application s’y prête.
La distribution est approuvée de la même manière que pour Android TV: