O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Construindo Universal Apps para Windows e Windows Phone

928 visualizações

Publicada em

Palestra apresentada no evento The Developers Conference em Porto Alegre em outubro/2014

Publicada em: Tecnologia
  • Seja o primeiro a comentar

Construindo Universal Apps para Windows e Windows Phone

  1. 1. • • • •
  2. 2.          
  3. 3.     
  4. 4.  
  5. 5. Um Código-fonte Um Projeto Um Binário Múltiplas Platformas!
  6. 6. Perspectiva do Usuário: “Compro a app apenas uma vez, e posso usá-la em todos os meus dispositivos Windows. Configurações e compras “in-app” migram entre meus dispositivos" reuso “A app tem tema e funcionalidades similares nos dois dispositivos" reuso “Mas a experiência e recursos são adaptados ao dispositivo” com adaptações
  7. 7. Definição da Store: Use o mesmo Package Full Name (PFN) ao fazer o upload nas duas Stores (Windows Phone e Windows) • O “badge universal” aparecerá nas listagens das Stores • Compre a app em uma store, e o mesmo PFN contará como comprado na outra • Compre um item durável em uma store, e o mesmo contará como comprado na outra • Dados poderão migrar entre apps em múltiplos dispositivos desde que as mesmas compartilhem o PFN
  8. 8.   
  9. 9.         
  10. 10. Solution 'App1' App1_Phone81 References App1_Shared App1_Windows81 References App1_Shared App1_Shared Class1.cs Page1.xaml App.xaml Asset1.png Shared Projects compartilhando código Solution 'App1' App1_Phone81 References App1_PCL App.xaml App1_Windows81 References App1_PCL App.xaml App1_PCL Class1.cs Page1.xaml Asset1.png .NET PCLs compartilhando binários Solution 'App1' App1_Phone81 MyData.cs App1_Windows81 MyData.cs MyWebservice MyData.cs Linked files compartilhando código
  11. 11. Solution 'App1' App1_Phone81 Class1.cs Page1.xaml App.xaml Asset1.png App1_Windows81 Class1.cs Page1.xaml App.xaml Asset1.png Solution 'App1' App1_Phone81 MyData.cs App1_Windows81 MyData.cs MyWebservice MyData.cs Linked files compartilhando código Solution 'App1' App1_Phone81 References App1_Shared App1_Windows81 References App1_Shared App1_Shared Class1.cs Page1.xaml App.xaml Asset1.png Shared Projects compartilhando código Solution 'App1' App1_Phone81 References App1_PCL App.xaml App1_Windows81 References App1_PCL App.xaml App1_PCL Class1.cs Page1.xaml Asset1.png .NET PCLs compartilhando binários
  12. 12. Solution 'App1' App1_Phone81 Class1.cs Page1.xaml App.xaml Asset1.png App1_Windows81 Class1.cs Page1.xaml App.xaml Asset1.png Solution 'App1' App1_Phone81 MyData.cs App1_Windows81 MyData.cs MyWebservice MyData.cs Linked files compartilhando código Solution 'App1' App1_Phone81 References App1_Shared App1_Windows81 References App1_Shared App1_Shared Class1.cs Page1.xaml App.xaml Asset1.png Shared Projects compartilhando código Solution 'App1' App1_Phone81 References App1_PCL App.xaml App1_Windows81 References App1_PCL App.xaml App1_PCL Class1.cs Page1.xaml Asset1.png .NET PCLs compartilhando binários
  13. 13. Solution 'App1' App1_Phone81 Class1.cs Page1.xaml App.xaml Asset1.png App1_Windows81 Class1.cs Page1.xaml App.xaml Asset1.png Solution 'App1' App1_Phone81 MyData.cs App1_Windows81 MyData.cs MyWebservice MyData.cs Linked files compartilhando código Solution 'App1' App1_Phone81 References App1_Shared App1_Windows81 References App1_Shared App1_Shared Class1.cs Page1.xaml App.xaml Asset1.png Shared Projects compartilhando código Solution 'App1' App1_Phone81 References App1_PCL App.xaml App1_Windows81 References App1_PCL App.xaml App1_PCL Class1.cs Page1.xaml Asset1.png .NET PCLs compartilhando binários
  14. 14. Solution 'App1' App1_Phone81 Class1.cs Page1.xaml App.xaml Asset1.png App1_Windows81 Class1.cs Page1.xaml App.xaml Asset1.png Solution 'App1' App1_Phone81 MyData.cs App1_Windows81 MyData.cs MyWebservice MyData.cs Linked files compartilhando código Solution 'App1' App1_Phone81 References App1_Shared App1_Windows81 References App1_Shared App1_Shared Class1.cs Page1.xaml App.xaml Asset1.png Shared Projects compartilhando código Solution 'App1' App1_Phone81 References App1_PCL App.xaml App1_Windows81 References App1_PCL App.xaml App1_PCL Class1.cs Page1.xaml Asset1.png .NET PCLs compartilhando binários
  15. 15. Solution 'App1' App1_Phone81 References App1_Shared App1_Windows81 References App1_Shared App1_Shared/PCL Class1.cs private void OnSuspending(object sender, SuspendingEventArgs e) { // TODO: Save application state and stop any background activity ApplicationData.Current.RoamingSettings.Values["IsBurnt"] = model.IsBurnt; ApplicationData.Current.RoamingSettings.Values["Velocity"] = model.Velocity; } // TODO: Load state from previously suspended application model.IsBurnt = (bool?)ApplicationData.Current.RoamingSettings.Values["IsBurnt"] ?? false; model.Velocity = (double?)ApplicationData.Current.RoamingSettings.Values["Velocity"] ?? 1.0;
  16. 16. Dentro do meu código comum, preciso “ajustá-lo” com uma chamada específica de um dispositivo. Como fazer isto?
  17. 17. Solution 'App1' App1_Phone81 References App1_Shared App1_Windows81 References App1_Shared App1_Shared Class1.cs #if block fácil e rápido Solution 'App1' App1_Phone81 References App1_PCL PhoneImpl.cs App1_Windows81 References App1_PCL WinImpl.cs App1_PCL Class1.cs IAbstraction.cs Inversion of Control (IOC) pattern que também funciona com PCL Solution 'App1' App1_Phone81 References App1_Shared ViewModel.cs App1_Windows81 References App1_Shared ViewModel.cs App1_Shared Class1.cs ViewModel.cs Partial classes mais organizado
  18. 18. Solution 'App1' App1_Phone81 References App1_Shared ViewModel.cs App1_Windows81 References App1_Shared ViewModel.cs App1_Shared Class1.cs ViewModel.cs Partial classes mais organizado Solution 'App1' App1_Phone81 References App1_PCL PhoneImpl.cs App1_Windows81 References App1_PCL WinImpl.cs App1_PCL Class1.cs IAbstraction.cs Inversion of Control (IOC) pattern que também funciona com PCL Solution 'App1' App1_Phone81 References App1_Shared App1_Windows81 References App1_Shared App1_Shared Class1.cs #if block fácil e rápido #if WINDOWS_PHONE_APP StatusBar.GetForCurrentView().HideAsync(); Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareBackPressed; #endif #if WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP StatusBar::GetForCurrentView()->HideAsync(); #endif
  19. 19. // I can provide my own implementation of the missing APIs !!! namespace Windows.UI.ViewManagement { Solution 'App1' public class StatusBar { App1_Phone81 References App1_Shared ViewModel.cs App1_Windows81 References App1_Shared ViewModel.cs App1_Shared Class1.cs ViewModel.cs Partial classes mais organizado Solution 'App1' App1_Phone81 References App1_PCL PhoneImpl.cs App1_Windows81 References App1_PCL WinImpl.cs App1_PCL Class1.cs IAbstraction.cs Inversion of Control (IOC) pattern que também funciona com PCL Solution 'App1' App1_Phone81 References App1_Shared App1_Windows81 References App1_Shared App1_Shared Class1.cs #if block fácil e rápido #if WINDOWS_PHONE_APP StatusBar.GetForCurrentView().HideAsync(); #endif static StatusBar dummy = new StatusBar(); public static StatusBar GetForCurrentView() { return dummy; } public async Task HideAsync() {} } }
  20. 20. Solution 'App1' App1_Phone81 References App1_Shared ViewModel.cs App1_Windows81 References App1_Shared ViewModel.cs App1_Shared Class1.cs ViewModel.cs Partial classes mais organizado // PhoneViewModel.cs public partial class ViewModel { Solution 'App1' App1_Phone81 References App1_PCL PhoneImpl.cs App1_Windows81 References App1_PCL WinImpl.cs App1_PCL Class1.cs IAbstraction.cs Inversion of Control (IOC) pattern que também funciona com PCL Solution 'App1' App1_Phone81 References App1_Shared App1_Windows81 References App1_Shared App1_Shared Class1.cs #if block fácil e rápido // WindowsViewModel.cs public partial class ViewModel { async Task HideStatusBarAsync() { } } async Task HideStatusBarAsync() { await StatusBar.GetForCurrentView() .HideAsync(); } } // SharedClass1.cs await viewModel.HideStatusBarAsync();
  21. 21. // PhonePhoneImpl.cs public class PhonePAL : IPlatformAbstractionLayer { async Task HideStatusBarAsync() { Solution 'App1' await StatusBar.GetForCurrentView() App1_Phone81 .HideAsync(); References App1_Shared ViewModel.cs App1_Windows81 } } // WindowsWinImpl.cs References public class WindowsPAL: IPlatformAbstractionLayer App1_Shared { ViewModel.cs async Task HideStatusBarAsync() { } App1_Shared Class1.cs ViewModel.cs } // Shared public interface IPlatformAbstractionLayer { Task HideStatusBarAsync(); Partial classes mais organizado Solution 'App1' App1_Phone81 References App1_PCL PhoneImpl.cs App1_Windows81 References App1_PCL WinImpl.cs App1_PCL Class1.cs IAbstraction.cs Inversion of Control (IOC) pattern que também funciona com PCL Solution 'App1' App1_Phone81 References App1_Shared App1_Windows81 References App1_Shared App1_Shared Class1.cs #if block } fácil e rápido await pal.HideStatusBarAsync();
  22. 22. Solution 'App1' App1_Phone81 References App1_Shared App1_Windows81 References App1_Shared App1_Shared Class1.cs #if block fácil e rápido Solution 'App1' App1_Phone81 References App1_PCL PhoneImpl.cs App1_Windows81 References App1_PCL WinImpl.cs App1_PCL Class1.cs IAbstraction.cs Inversion of Control (IOC) pattern que também funciona com PCL Solution 'App1' App1_Phone81 References App1_Shared ViewModel.cs App1_Windows81 References App1_Shared ViewModel.cs App1_Shared Class1.cs ViewModel.cs Partial classes mais organizado
  23. 23.      
  24. 24.         
  25. 25. <Page.BottomAppBar> <CommandBar> <AppBarButton Icon="Accept" Label="Accept" /> <AppBarButton Icon="Cancel" Label="Cancel" /> <CommandBar.SecondaryCommands> <AppBarButton x:Uid="AboutAppBarButton" Icon="Help" /> <AppBarButton x:Uid="HomeAppBarButton" Icon="Home" /> </CommandBar.SecondaryCommands> </CommandBar> </Page.BottomAppBar>
  26. 26.                

×