Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Construindo Universal apps para Windows e Windows Phone

710 views

Published on

Conheça o modelo de desenvolvimento "Universal App" para Windows e Windows Phone, que permite a utilização do mesmo código para as duas plataformas. Veja até onde pode ir o reaproveitamento de código e as diferentes alternativas disponíveis para este tipo de desenvolvimento.

Published in: Software
  • Be the first to comment

Construindo Universal apps para Windows e Windows Phone

  1. 1.          
  2. 2.     
  3. 3.  
  4. 4. Um Código-fonte Um Projeto Um Binário Múltiplas Platformas!
  5. 5. “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 Perspectiva do Usuário:
  6. 6. 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
  7. 7.   
  8. 8.         
  9. 9. Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png References App1_Shared References App1_Shared App1_Shared App.xaml Shared Projects compartilhando código Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png References App1_PCL References App1_PCL App1_PCL App.xaml App.xaml .NET PCLs compartilhando binários Solution 'App1' App1_Phone81 App1_Windows81 MyData.cs MyData.cs MyWebservice MyData.cs Linked files compartilhando código
  10. 10. Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png Class1.cs Page1.xaml Asset1.png App.xaml App.xaml Solution 'App1' App1_Phone81 App1_Windows81 MyData.cs MyData.cs MyWebservice MyData.cs Linked files compartilhando código Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png References App1_Shared References App1_Shared App1_Shared App.xaml Shared Projects compartilhando código Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png References App1_PCL References App1_PCL App1_PCL App.xaml App.xaml .NET PCLs compartilhando binários
  11. 11. Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png Class1.cs Page1.xaml Asset1.png App.xaml App.xaml Solution 'App1' App1_Phone81 App1_Windows81 MyData.cs MyData.cs MyWebservice MyData.cs Linked files compartilhando código Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png References App1_Shared References App1_Shared App1_Shared App.xaml Shared Projects compartilhando código Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png References App1_PCL References App1_PCL App1_PCL App.xaml App.xaml .NET PCLs compartilhando binários
  12. 12. Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png Class1.cs Page1.xaml Asset1.png App.xaml App.xaml Solution 'App1' App1_Phone81 App1_Windows81 MyData.cs MyData.cs MyWebservice MyData.cs Linked files compartilhando código Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png References App1_Shared References App1_Shared App1_Shared App.xaml Shared Projects compartilhando código Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png References App1_PCL References App1_PCL App1_PCL App.xaml App.xaml .NET PCLs compartilhando binários
  13. 13. Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png Class1.cs Page1.xaml Asset1.png App.xaml App.xaml Solution 'App1' App1_Phone81 App1_Windows81 MyData.cs MyData.cs MyWebservice MyData.cs Linked files compartilhando código Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png References App1_Shared References App1_Shared App1_Shared App.xaml Shared Projects compartilhando código Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs Page1.xaml Asset1.png References App1_PCL References App1_PCL App1_PCL App.xaml App.xaml .NET PCLs compartilhando binários
  14. 14. Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References App1_Shared References App1_Shared App1_Shared/PCL 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;
  15. 15. Dentro do meu código comum, preciso “ajustá-lo” com uma chamada específica de um dispositivo. Como fazer isto?
  16. 16. Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References App1_Shared References App1_Shared App1_Shared #if block fácil e rápido Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References App1_PCL References App1_PCL App1_PCL IAbstraction.cs PhoneImpl.cs WinImpl.cs Inversion of Control (IOC) pattern que também funciona com PCL Partial classes mais organizado Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References References App1_Shared ViewModel.cs ViewModel.cs ViewModel.cs App1_Shared App1_Shared
  17. 17. Partial classes mais organizado Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References References App1_Shared ViewModel.cs ViewModel.cs ViewModel.cs App1_Shared App1_Shared Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References App1_PCL References App1_PCL App1_PCL IAbstraction.cs PhoneImpl.cs WinImpl.cs Inversion of Control (IOC) pattern que também funciona com PCL Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References App1_Shared References App1_Shared App1_Shared #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
  18. 18. Partial classes mais organizado Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References References App1_Shared ViewModel.cs ViewModel.cs ViewModel.cs App1_Shared App1_Shared Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References App1_PCL References App1_PCL App1_PCL IAbstraction.cs PhoneImpl.cs WinImpl.cs Inversion of Control (IOC) pattern que também funciona com PCL Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References App1_Shared References App1_Shared App1_Shared #if block fácil e rápido #if WINDOWS_PHONE_APP StatusBar.GetForCurrentView().HideAsync(); #endif // I can provide my own implementation of the missing APIs !!! namespace Windows.UI.ViewManagement { public class StatusBar { static StatusBar dummy = new StatusBar(); public static StatusBar GetForCurrentView() { return dummy; } public async Task HideAsync() {} } }
  19. 19. Partial classes mais organizado Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References References App1_Shared ViewModel.cs ViewModel.cs ViewModel.cs App1_Shared App1_Shared Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References App1_PCL References App1_PCL App1_PCL IAbstraction.cs PhoneImpl.cs WinImpl.cs Inversion of Control (IOC) pattern que também funciona com PCL Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References App1_Shared References App1_Shared App1_Shared #if block fácil e rápido // WindowsViewModel.cs public partial class ViewModel { async Task HideStatusBarAsync() { } } // PhoneViewModel.cs public partial class ViewModel { async Task HideStatusBarAsync() { await StatusBar.GetForCurrentView() .HideAsync(); } } // SharedClass1.cs await viewModel.HideStatusBarAsync();
  20. 20. Partial classes mais organizado Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References References App1_Shared ViewModel.cs ViewModel.cs ViewModel.cs App1_Shared App1_Shared Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References App1_PCL References App1_PCL App1_PCL IAbstraction.cs PhoneImpl.cs WinImpl.cs Inversion of Control (IOC) pattern que também funciona com PCL Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References App1_Shared References App1_Shared App1_Shared #if block fácil e rápido // Shared public interface IPlatformAbstractionLayer { Task HideStatusBarAsync(); } await pal.HideStatusBarAsync(); // WindowsWinImpl.cs public class WindowsPAL: IPlatformAbstractionLayer { async Task HideStatusBarAsync() { } } // PhonePhoneImpl.cs public class PhonePAL : IPlatformAbstractionLayer { async Task HideStatusBarAsync() { await StatusBar.GetForCurrentView() .HideAsync(); } }
  21. 21. Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References App1_Shared References App1_Shared App1_Shared #if block fácil e rápido Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References App1_PCL References App1_PCL App1_PCL IAbstraction.cs PhoneImpl.cs WinImpl.cs Inversion of Control (IOC) pattern que também funciona com PCL Partial classes mais organizado Solution 'App1' App1_Phone81 App1_Windows81 Class1.cs References References App1_Shared ViewModel.cs ViewModel.cs ViewModel.cs App1_Shared App1_Shared
  22. 22.      
  23. 23.         
  24. 24. <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>
  25. 25.                

×