windows phone live apps: tile, notifiche, lock screen e servizi in background

44
WPReborn 2013 Dan Ardelean @danardelean [email protected] Live App: tile, notifiche, lock screen e servizi in background @dnlombardia #wpreborn

Upload: dan-ardelean

Post on 09-May-2015

356 views

Category:

Technology


0 download

DESCRIPTION

Introduzione alle nuove funzionlità di Windows Phone 8

TRANSCRIPT

Page 1: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

WPReborn 2013

Dan [email protected]@live.com

Live App: tile, notifiche, lock screen e servizi in background

@dnlombardia#wpreborn

Page 2: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

1. Live Tiles 2. Lock screen notifications3. Lock screen background4. Background Agents5. Background Transfers

Agenda

Page 3: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

1. Live Tiles

Page 4: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Windows Phone 7.5Tile NotificationsPrimary, secondary, front and back

Toast Notifications

Page 5: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Live Tiles• Collegamenti alla nostra applicazione• Si possono creare Tile secondarie• Per Windows Phone 7.8 e 8 abbiamo:

1. 3 dimensioni2. 3 template

Page 6: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Templates1. Flip

2. Iconic

3. Cycle

Page 7: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Flip Tile Template (TemplateFlip, FlipTileData)

medium: 336x336

small: 99x99

wide: 691x336

Page 8: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Cycle Tile (TemplateCycle, CycleTileData)

medium: 336x336

small: 99x99

wide center crops to medium

wide: 691x336

Page 9: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Iconic Tile Template (TemplateIconic, IconicTileData)

medium: 202x202small: 110x110

white with transparency only

crop tight on horizontal

Page 10: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Aggiornare le Live Tiles

• Possono essere aggiornate usando notifiche PUSH

• Direttamente dalla applicazione (WP7.5 Mango)• In modo schedulato (WP8)

Page 11: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

API Front Count Front Title Front Image Back Content

Back Title Back Image

Multi Tile

Push Yes Yes Yes Yes Yes Yes Yes

ShellTile Yes Yes Partial Yes Yes Partial Yes

ShellTileSchedule

No No Yes No No No Yes

API Front Count Front Title Front Image Back Content

Back Title Back Image

Multi Tile

Push Yes Yes Yes Yes Yes Yes Yes

ShellTile Yes Yes Partial Yes Yes Partial Yes

ShellTileSchedule

Yes Yes Yes Yes Yes Yes Yes

API Front Count Front Title Front Image Back Content

Back Title Back Image

Multi Tile

Push Yes Yes Yes Yes Yes Yes Yes

ShellTile Yes Yes Yes Yes Yes Yes Yes

ShellTileSchedule

Yes Yes Yes Yes Yes Yes Yes

API Front Count Front Title Front Image Back Content Back Title Back Image

Multi Tile XML

Push Yes Yes Yes Yes Yes Yes Yes Yes

ShellTile Yes Yes Yes Yes Yes Yes Yes Yes

ShellTileSchedule

Yes Yes Yes Yes Yes Yes Yes Yes

API per aggiornare le Live Tiles

Focus su coerenzaShellTileSchedule aggiorna tutte le proprietàShellTile accetta web URIs per immaginiBONUS: Tutte le classi ShellTileData accettano stringhe XML

Page 12: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Aggiornamento Live Tiles da XAML

Page 13: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Aggiornamento usando Tile Schedule

• Ricorrenza: Onetime, EveryHour, EveryDay, EveryWeek o EveryMonth

• Dimensioni immagini <150KB (era 80KB per WP 7.5)

• Tempo di download non deve superare 45 secondi

• Se va in eccezione troppe volte il SO cancella la schedulazione

Page 14: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Live TilesDemo

Page 15: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Live Tiles WP 7.8 e 8.0 per progetti 7.11. Reflection http://ow.ly/hanGP

WMAppManifest.xml<AppExtra xmlns="" AppPlatformVersion="8.0">

<Extra Name="Tiles"/> </AppExtra>

private static Version TargetedVersion = new Version(7, 10, 8858);public static bool IsTargetedVersion {get{return Environment.OSVersion.Version >= TargetedVersion;}}

Page 16: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background
Page 17: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Live Tiles WP 7.8 e 8.0 per progetti 7.12. Codeplex MangoPollohttp://mangopollo.codeplex.com/

Page 18: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

MangoPolloDemo

Page 19: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

2. Lock screen notifications

Page 20: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Lock screen1. L’utente può selezionare le

applicazioni abilitate ad interagire con la Lock Screen

2. Un massimo di 5 applicazioni abbilitate per notifiche di tipo icon

3. Bisogna:1. Fornire l’icona per le notifiche2. Registrare le varie Extension

Page 21: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Come aggiornare Icon Count e Text1. Lock Screen Icon Count e Text sono i valori della tile primaria

• Le tile secondary non sono usate

2. Le informazioni vengono visualizzate solo se I campi sono valorizzati

• Count solo se la Tile principale ha Count

3. La Tile primaria non deve necessariamente essere presente sulla Start Screen

4. Aggiornamento usando:• Local Shell Tiles API• Push Notifications

Page 22: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Lock screen notificationsDemo

Page 23: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

3. Lock screen background

Page 24: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Lock Screen Background per Windows Phone 8

Page 25: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Aggiungere Lock Screen Background Extension

WMAppManifest.xml

<Extension ExtensionName="LockScreen_Background" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F" TaskID="_default" />

Page 26: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Impostare l’immagine di sfondo

• Asset fornito con l’applicazione usare ms-appx:///

Uri imageUri = new Uri("ms-appx:///background1.png", UriKind.RelativeOrAbsolute); LockScreen.SetImageUri(imageUri);

• Per Local Folder usare ms-appdata:///local/

Uri imageUri = new Uri("ms-appdata:///local/background2.png", UriKind.RelativeOrAbsolute); LockScreen.SetImageUri(imageUri);

Page 27: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Lock ScreenDemo

Page 28: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

4. Background Agents

New updates

from Background

Agent

Page 29: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Background Agents• Una applicazione Windows Phone può creare

un “background agent”1. PeriodicTask, ResourceIntensiveTask o entrambi nello stesso tempo2. Solo un agent per applicazione

• Il agent può essere eseguito quando l’applicazione non é in esecuzione

• Il agent non equivale ad una applicazione che gira in background

Page 30: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Background agents

SI

• Tiles• Toast• Location• Network• R/W ISO store• Sockets

NO

• Display UI• XNA libraries• Microphone and camera• Sensors• Play audio(may only use background audio APIs)

Page 31: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

PeriodicTasks• Il PeriodicTask viene eseguito ogni tanto

– Di solito ogni 30 minuti ma dipende da quello che il telefono sta eseguendo ad un certo momento

• Usato per attività veloci e ripetitive– Eseguito per un massimo di 25 secondi– Utilizzo di memoria<= 6 MB– Viene cancellato dopo 2 crash consecutivi– Esiste un limite per il numero massimo di agent che sono attivi ad un certo

momento

• Da usare per location tracking, polling background services, tile updates

Page 32: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

ResourceIntensive TasksViene eseguito solo in certe condizioni:• Il telefono è in carica• La carica della batteria è >90%• Il telefono è collegato via WiFi• Il telefono non viene usato (Lock screen)

Viene eseguito per un Massimo di 10 minuti– Utilizzo di memoria<= 6 MB– Viene cancellato dopo 2 crash consecutivi

Page 33: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Come creare un Background Agent

Page 34: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Il codice di un Background Agent

namespace LocationLogTaskAgent{ public class ScheduledAgent : ScheduledTaskAgent { protected override void OnInvoke(ScheduledTask task) { //TODO: Add code to perform your task in background NotifyComplete(); } }}

Page 35: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Concurrent Data Access

public bool LoadLogFromIsolatedStorageFile(){ mut.WaitOne(); // Wait until it is safe to enter

try { // read the file here return true; } catch { LogText = ""; return false; } finally { mut.ReleaseMutex(); // Release the Mutex. }}

Page 36: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Schedulazione di un Background AgentPeriodicTask t;

t = ScheduledActionService.Find(taskName) as PeriodicTask;bool found = (t != null);if (!found)             { t = new PeriodicTask(taskName);}t.Description = description;t.ExpirationTime = DateTime.Now.AddDays(10);if (!found){ ScheduledActionService.Add(t);}             else{  ScheduledActionService.Remove(taskName);    ScheduledActionService.Add(t);}

Page 37: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Debugging Background Agents

#if DEBUG_AGENT ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromSeconds(60));#endif

Page 38: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Consigli Background AgentsRinnovate spesso• Meglio ogni volta ce l’applicazione viene lanciata

Non implementare funzionalità critica• L’utente può disabilitare il agent• Il agent potrebbe essere sospeso da SO per batteria scarica

Per funzionalità critiche considerate Push Notifications

Page 39: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Background AgentsDemo

Page 40: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Novità Windows Phone 8Il background agent non viene sospeso dopo 2 settimane se:

1. L’applicazione ha Tiles sulla Start Screen• e l’agent chiama ShellTile.Update da PeriodicTask

2. L’applicazione usa Lock Screen• Count o detailed status (anche senza Tile sulla Start Screen)

• Background image provider quando chiama SetImageUri

Page 41: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

5. Background Transfers

Page 42: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Background Transfers

• Background task per trasferimento files da Isolated storage• Funzionano anche quando l’applicazione non è in primo piano• Possibilità di monitorare lo stato• Collegamenti HTTP e HTTPS

– FTP non funziona per il momento

• Il sistema mantiene una coda degli trasferimenti attivi

Page 43: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

Background Transfers Policies• Dimensioni

» Upload : 5Mb» Download usando dati cellulare: 20Mb» Download usando WiFi: 100Mb

• Impostate le condizioni desiderate usando TransferPreferences

• Numero Massimo di Background transfers per applicazione: 25 » Erano 5 per Windows Phone OS 7.1

Page 44: Windows Phone Live Apps: tile, notifiche, lock screen e servizi in background

WPReborn 2013

Dan [email protected]@neologics.eu

___________________________________________________Live App: tile, notifiche, lock screen e servizi in background

@dnlombardia#wpreborn