Etendre ses applications aux smartwatches et TVs android

Preview:

Citation preview

Étendre ses Applications aux smartwatches et TVs Android™Xavier Hallade - @ph0b - +XavierHalladeApplication Engineer, Intel Corporation

Android

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

Android TV

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.

Devices

NVIDIA* Shield

Razer* Forge TV

Smart TVs: Sony*, Philips*, Sharp*, TCL*…

Google* Nexus Player

Demo

Demo

Demo

Adapter son application pour Android TV

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.

1. Leanback Intent

<activity android:name=".TvMainActivity" ><intent-filter>

<action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" />

</intent-filter></activity>

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

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)

4. Adapting the UI

Démarrer de android:Theme.NoTitleBarou 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 estpossible 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" />

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”

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 AlarmManagerthat will run it periodically, starting with shorty after boot.

The Leanback support library – BrowseFragment

BackgroundManager.getInstance()

.setDrawable()

setTitle()

setBadgeDrawable()

setAdapter( ObjectAdapter )

Presented items have to be Rows.

setBrandColor()

setSearchAffordanceColor()

setOnSearchClickedListener()

setOnItemViewSelectedListener()

setOnItemViewClickedListener()

setHeadersState()

Supporter plusieurs contrôleurs

• int KeyEvent.getDeviceId()

• String KeyEvent.getDevice().getDescriptor()API Level 16+

• Nearby Connection API Google Play Services 7.0+

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.

TV Input Framework – Live Channels

<serviceandroid: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 {…@Overridepublic Session onCreateSession(String inputId) {

return new MyTvInputServiceSession(MyTvInputService.this); //ServiceSession implementation is on next slide }

}

TV Input Framework – Live Channels

public class MyTvInputServiceSession extends TvInputService.Session {Surface mSurface;

@Overridepublic boolean onSetSurface(Surface surface) {

mSurface = surface;return true;

}

@Overridepublic 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;

}

@Overridepublic void onSetCaptionEnabled(boolean enabled) { }…

}

Distribuer son application Android TV

Ajuster son Manifest

Game ?<application … android:isGame="true" …>

Support des Gamepads ?

<uses-feature android:name="android.hardware.gamepad" android:required="false" />

“features” indisponibles:

android.hardware.location.gps, android.hardware.camera.*, android.hardware.telephony, android.hardware.sensor.*,

android.hardware.nfc, android.hardware.touchscreen, android.hardware.microphone, android.hardware.location

Android TV only ?

<uses-feature android:name="android.software.leanback" android:required="true" />

Soumission

Android TV - résumé

• Le support d’Android TV n’est pas nécessairement compliqué à ajouter.

• Pas besoin de maintenir un APK séparé.

Resources additionnelles:

• Udacity Course: http://bit.ly/1GJ7OyW

• Leanback Support Library Sample: https://github.com/googlesamples/androidtv-Leanback

• TV Input Framework Sample: https://github.com/googlesamples/androidtv-sample-inputs

• ATV Unity Codelab: http://bit.ly/1LNJ6My

• ATV Leanback Codelab: http://bit.ly/1No3rue

• Pie Noon sample: https://github.com/google/pienoon

• Feedback Form: http://bit.ly/20qYaaw

Questions?

Android Wear

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

NOTIFICATIONS

Notifications

Marchent automatiquement.

Les améliorer pour Wear = Les améliorer pour Android

Styles, icônes, priorité, type..

Groupes

Actions

Éléments spécifiques à Wear:

Pages/Remote Input

Tout reste contrôlé et reçu par l’application d’origine.

NotificationCompat.Builder notificationBuilder =new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_event).setLargeIcon(BitmapFactory.decodeResource(

getResources(), R.drawable.notif_background)).setContentTitle(eventTitle).setContentText(eventLocation).setContentIntent(viewPendingIntent).addAction(R.drawable.ic_map,

getString(R.string.map), mapPendingIntent)…

NotificationCompat.Builder

Notifications - actions

NotificationCompat.Builder.addAction()

Notifications - groupes

NotificationCompat.Builder.setGroup(String groupKey)

Réponses complèxes depuis une notification

Texte libre / Emojis

Réponses prédéfinies

android.app.RemoteInput

Notifications – spécique à Android Wear

Notification.WearableExtender.addPage(Notification)

Pagination

Notifications – spécique à Android Wear

Action directe au touch sur la notification

Notification.WearableExtender.setContentxxx()

Notifications – spécique à Android Wear

Notification.WearableExtender.setBackground()

+ setHintShowBackgroundOnly()(+ for QR codes: setHintAvoidBackgroundClipping())

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

Créer et distribuer une application native ou une watchface

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')

}

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

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.

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

Utiliser des éléments prédéfinis

DelayedConfirmationView

ConfirmationActivity

WearableListView

CardFragment

GridViewPager+DotsPageIndicator

DismissOverlayView

Intéractions vocalesCall 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”

S’adapter aux différents hardware

Écran circulaire w/ chin

LCDARMv7 OS512MB ram

Écran carréAMOLED

ARMv7 OS512MB ram

Onboard speaker

Écran circulaireAMOLED

ARMv7 OS512MB ram

Écran carréLCD

TransflectifARMv7 OS

Onboard GPS512MB ram

Écran circulaireLCD Transflectif

x86 OS1GB ram

Écran circulaire w/ chin

LCDx86 OS

1GB ram

Pas de tailles d’écran standard: 320x290px, 360x360px, 360x325px, 360x326px, 400x400px…

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.

Ambient modeUsually LCD technology(transflective or not)

Ambient modeLOW_BIT displayUsually AMOLED technology

Interactive Mode

Différents types d’écrans

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>

Watchfaces interactives

Peut gérer le Tap sur toute la surfaceLes autres gestes sont réservés au système.

setWatchFaceStyle(new WatchFaceStyle.Builder(mService).setAcceptsTapEvents(true)// other style customizations.build());

@Overridepublic 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;//…

}}

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:

Questions?xavier.hallade@intel.com - @ph0b - +XavierHallade

Recommended