Construindo Universal Apps para Windows e Windows Phone

45
Construindo Universal Apps para Windows e Windows Phone @marlonluz Evangelista de Tecnologia Microsoft

description

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

Transcript of Construindo Universal Apps para Windows e Windows Phone

  • 1.

2. 3. 4. 5. Um Cdigo-fonteUm ProjetoUm BinrioMltiplas Platformas! 6. Perspectiva do Usurio:Compro a app apenas uma vez, eposso us-la em todos os meusdispositivos Windows. Configuraes ecompras in-app migram entre meusdispositivos" reusoA app tem tema e funcionalidadessimilares nos dois dispositivos" reusoMas a experincia e recursos soadaptados ao dispositivo comadaptaes 7. Definio da Store:Use o mesmo Package Full Name (PFN)ao fazer o upload nas duas Stores (Windows Phone eWindows) O badge universal aparecer nas listagens das Stores Compre a app em uma store, e o mesmo PFN contarcomo comprado na outra Compre um item durvel em uma store, e o mesmocontar como comprado na outra Dados podero migrar entre apps em mltiplosdispositivos desde que as mesmas compartilhem o PFN 8. 9. 10. Solution 'App1'App1_Phone81ReferencesApp1_SharedApp1_Windows81ReferencesApp1_SharedApp1_SharedClass1.csPage1.xamlApp.xamlAsset1.pngShared Projectscompartilhando cdigoSolution 'App1'App1_Phone81ReferencesApp1_PCLApp.xamlApp1_Windows81ReferencesApp1_PCLApp.xamlApp1_PCLClass1.csPage1.xamlAsset1.png.NET PCLscompartilhando binriosSolution 'App1'App1_Phone81MyData.csApp1_Windows81MyData.csMyWebserviceMyData.csLinked filescompartilhando cdigo 11. Solution 'App1'App1_Phone81Class1.csPage1.xamlApp.xamlAsset1.pngApp1_Windows81Class1.csPage1.xamlApp.xamlAsset1.pngSolution 'App1'App1_Phone81MyData.csApp1_Windows81MyData.csMyWebserviceMyData.csLinked filescompartilhando cdigoSolution 'App1'App1_Phone81ReferencesApp1_SharedApp1_Windows81ReferencesApp1_SharedApp1_SharedClass1.csPage1.xamlApp.xamlAsset1.pngShared Projectscompartilhando cdigoSolution 'App1'App1_Phone81ReferencesApp1_PCLApp.xamlApp1_Windows81ReferencesApp1_PCLApp.xamlApp1_PCLClass1.csPage1.xamlAsset1.png.NET PCLscompartilhando binrios 12. Solution 'App1'App1_Phone81Class1.csPage1.xamlApp.xamlAsset1.pngApp1_Windows81Class1.csPage1.xamlApp.xamlAsset1.pngSolution 'App1'App1_Phone81MyData.csApp1_Windows81MyData.csMyWebserviceMyData.csLinked filescompartilhando cdigoSolution 'App1'App1_Phone81ReferencesApp1_SharedApp1_Windows81ReferencesApp1_SharedApp1_SharedClass1.csPage1.xamlApp.xamlAsset1.pngShared Projectscompartilhando cdigoSolution 'App1'App1_Phone81ReferencesApp1_PCLApp.xamlApp1_Windows81ReferencesApp1_PCLApp.xamlApp1_PCLClass1.csPage1.xamlAsset1.png.NET PCLscompartilhando binrios 13. Solution 'App1'App1_Phone81Class1.csPage1.xamlApp.xamlAsset1.pngApp1_Windows81Class1.csPage1.xamlApp.xamlAsset1.pngSolution 'App1'App1_Phone81MyData.csApp1_Windows81MyData.csMyWebserviceMyData.csLinked filescompartilhando cdigoSolution 'App1'App1_Phone81ReferencesApp1_SharedApp1_Windows81ReferencesApp1_SharedApp1_SharedClass1.csPage1.xamlApp.xamlAsset1.pngShared Projectscompartilhando cdigoSolution 'App1'App1_Phone81ReferencesApp1_PCLApp.xamlApp1_Windows81ReferencesApp1_PCLApp.xamlApp1_PCLClass1.csPage1.xamlAsset1.png.NET PCLscompartilhando binrios 14. Solution 'App1'App1_Phone81Class1.csPage1.xamlApp.xamlAsset1.pngApp1_Windows81Class1.csPage1.xamlApp.xamlAsset1.pngSolution 'App1'App1_Phone81MyData.csApp1_Windows81MyData.csMyWebserviceMyData.csLinked filescompartilhando cdigoSolution 'App1'App1_Phone81ReferencesApp1_SharedApp1_Windows81ReferencesApp1_SharedApp1_SharedClass1.csPage1.xamlApp.xamlAsset1.pngShared Projectscompartilhando cdigoSolution 'App1'App1_Phone81ReferencesApp1_PCLApp.xamlApp1_Windows81ReferencesApp1_PCLApp.xamlApp1_PCLClass1.csPage1.xamlAsset1.png.NET PCLscompartilhando binrios 15. Solution 'App1'App1_Phone81ReferencesApp1_SharedApp1_Windows81ReferencesApp1_SharedApp1_Shared/PCLClass1.csprivate void OnSuspending(object sender, SuspendingEventArgs e){// TODO: Save application state and stop any background activityApplicationData.Current.RoamingSettings.Values["IsBurnt"] = model.IsBurnt;ApplicationData.Current.RoamingSettings.Values["Velocity"] = model.Velocity;}// TODO: Load state from previously suspended applicationmodel.IsBurnt = (bool?)ApplicationData.Current.RoamingSettings.Values["IsBurnt"]?? false;model.Velocity = (double?)ApplicationData.Current.RoamingSettings.Values["Velocity"]?? 1.0; 16. Dentro do meu cdigo comum, precisoajust-lo com uma chamada especficade um dispositivo.Como fazer isto? 17. Solution 'App1'App1_Phone81ReferencesApp1_SharedApp1_Windows81ReferencesApp1_SharedApp1_SharedClass1.cs#if blockfcil e rpidoSolution 'App1'App1_Phone81ReferencesApp1_PCLPhoneImpl.csApp1_Windows81ReferencesApp1_PCLWinImpl.csApp1_PCLClass1.csIAbstraction.csInversion of Control (IOC)pattern que tambm funciona com PCLSolution 'App1'App1_Phone81ReferencesApp1_SharedViewModel.csApp1_Windows81ReferencesApp1_SharedViewModel.csApp1_SharedClass1.csViewModel.csPartial classesmais organizado 18. Solution 'App1'App1_Phone81ReferencesApp1_SharedViewModel.csApp1_Windows81ReferencesApp1_SharedViewModel.csApp1_SharedClass1.csViewModel.csPartial classesmais organizadoSolution 'App1'App1_Phone81ReferencesApp1_PCLPhoneImpl.csApp1_Windows81ReferencesApp1_PCLWinImpl.csApp1_PCLClass1.csIAbstraction.csInversion of Control (IOC)pattern que tambm funciona com PCLSolution 'App1'App1_Phone81ReferencesApp1_SharedApp1_Windows81ReferencesApp1_SharedApp1_SharedClass1.cs#if blockfcil e rpido#if WINDOWS_PHONE_APPStatusBar.GetForCurrentView().HideAsync();Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareBackPressed;#endif#if WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APPStatusBar::GetForCurrentView()->HideAsync();#endif 19. // I can provide my own implementation of the missing APIs !!!namespace Windows.UI.ViewManagement{Solution 'App1'public class StatusBar{App1_Phone81ReferencesApp1_SharedViewModel.csApp1_Windows81ReferencesApp1_SharedViewModel.csApp1_SharedClass1.csViewModel.csPartial classesmais organizadoSolution 'App1'App1_Phone81ReferencesApp1_PCLPhoneImpl.csApp1_Windows81ReferencesApp1_PCLWinImpl.csApp1_PCLClass1.csIAbstraction.csInversion of Control (IOC)pattern que tambm funciona com PCLSolution 'App1'App1_Phone81ReferencesApp1_SharedApp1_Windows81ReferencesApp1_SharedApp1_SharedClass1.cs#if blockfcil e rpido#if WINDOWS_PHONE_APPStatusBar.GetForCurrentView().HideAsync();#endifstatic StatusBar dummy = new StatusBar();public static StatusBar GetForCurrentView() { return dummy; }public async Task HideAsync() {}}} 20. Solution 'App1'App1_Phone81ReferencesApp1_SharedViewModel.csApp1_Windows81ReferencesApp1_SharedViewModel.csApp1_SharedClass1.csViewModel.csPartial classesmais organizado// PhoneViewModel.cspublic partial class ViewModel{Solution 'App1'App1_Phone81ReferencesApp1_PCLPhoneImpl.csApp1_Windows81ReferencesApp1_PCLWinImpl.csApp1_PCLClass1.csIAbstraction.csInversion of Control (IOC)pattern que tambm funciona com PCLSolution 'App1'App1_Phone81ReferencesApp1_SharedApp1_Windows81ReferencesApp1_SharedApp1_SharedClass1.cs#if blockfcil e rpido// WindowsViewModel.cspublic partial class ViewModel{async Task HideStatusBarAsync() { }}async Task HideStatusBarAsync(){await StatusBar.GetForCurrentView().HideAsync();}}// SharedClass1.csawait viewModel.HideStatusBarAsync(); 21. // PhonePhoneImpl.cspublic class PhonePAL : IPlatformAbstractionLayer{async Task HideStatusBarAsync(){Solution 'App1'await StatusBar.GetForCurrentView()App1_Phone81.HideAsync();ReferencesApp1_SharedViewModel.csApp1_Windows81}}// WindowsWinImpl.csReferencespublic class WindowsPAL: IPlatformAbstractionLayerApp1_Shared{ViewModel.csasync Task HideStatusBarAsync() { }App1_SharedClass1.csViewModel.cs}// Sharedpublic interface IPlatformAbstractionLayer{Task HideStatusBarAsync();Partial classesmais organizadoSolution 'App1'App1_Phone81ReferencesApp1_PCLPhoneImpl.csApp1_Windows81ReferencesApp1_PCLWinImpl.csApp1_PCLClass1.csIAbstraction.csInversion of Control (IOC)pattern que tambm funciona com PCLSolution 'App1'App1_Phone81ReferencesApp1_SharedApp1_Windows81ReferencesApp1_SharedApp1_SharedClass1.cs#if block}fcil e rpidoawait pal.HideStatusBarAsync(); 22. Solution 'App1'App1_Phone81ReferencesApp1_SharedApp1_Windows81ReferencesApp1_SharedApp1_SharedClass1.cs#if blockfcil e rpidoSolution 'App1'App1_Phone81ReferencesApp1_PCLPhoneImpl.csApp1_Windows81ReferencesApp1_PCLWinImpl.csApp1_PCLClass1.csIAbstraction.csInversion of Control (IOC)pattern que tambm funciona com PCLSolution 'App1'App1_Phone81ReferencesApp1_SharedViewModel.csApp1_Windows81ReferencesApp1_SharedViewModel.csApp1_SharedClass1.csViewModel.csPartial classesmais organizado 23. 24. 25. 26.