Windows Phone Development Tomer Shamam Senior Architect Sela Group
Windows Phone Microsoft Corporation. Agenda: Windows Phone General Concept Metro Software Architecture Silverlight Capabilities Application Model Activation and Navigation Application Lifecycle User Interface Application Bar and System Tray, Panorama, Pivot Integration Services Launchers and Choosers, Tiles and Push Notifications, Location and Services Software Architecture App Model Cloud and Integration Services Hardware Foundation UI Model
General Concept Software Architecture App Model Cloud and Integration Services Hardware Foundation UI Model
Windows Phone Microsoft Corporation. New Concept 4 DESIGN: END USER COMES FIRST PLATFORM: RICHER, DEEPER, EASIER APPS HARDWARE: FASTER TO MARKET, LESS HEAVY LIFTING
Windows Phone Microsoft Corporation. Life Maximizers
Windows Phone Microsoft Corporation. Metro UI 6
Windows Phone Microsoft Corporation. Hardware Foundation (in 7.0) Capacitive touch 4 or more contact points Sensors A-GPS, Accelerometer, Compass, Light, Proximity, Gyro (optional) Camera 5 mega pixels or more Multimedia Common detailed specs, Codec acceleration Memory 256MB RAM or more, 8GB Flash or more GPU DirectX 9 acceleration CPU Qualcomm MSM8x55 800Mhz or higher Hardware buttons | Back, Start, Search
Windows Phone Microsoft Corporation. Two Flavors of Applications 8
Windows Phone Microsoft Corporation. Windows Phone Developer Tools 9 Windows Phone device Windows Phone Emulator Phone Emulator SamplesDocumentation GuidesCommunity Packaging and Verification Tools Tools
Windows Phone Microsoft Corporation. Deployment Process 10 Develop & Debug Submit & Validate Certify & Sign Windows Phone Application Deployment Service Marketplace
Software Architecture App Model Cloud and Integration Services Hardware Foundation UI Model
Windows Phone Microsoft Corporation. Silverlight Capabilities Inputs Keyboard, Mouse, Touch, Ink XAML UI Core Common Controls, Text, Images, Data Binding, Page Navigation, Vector Graphics, Animation, Transformation, Styles and Templates Media Capture and Playback, VC1, WMA, MP3 Data LINQ to Objects, LINQ to XML, Isolated Storage, XML Base Class Library Generics, Collections, Cryptography, Threading Communication REST, RSS/ATOM, SOAP 12
Windows Phone Microsoft Corporation. Multitouch OOB Controls support touch Translate touch events to mouse events ScrollViewer has built-in support for pan and flick Manipulation for all UIElements Scale Translate Raw Touch, compatible with SL4 Touch Events (tap, double tap) 13
Windows Phone Microsoft Corporation. Keyboard Silverlight TextBox integrates with the SIP (on screen keyboard) Password has a delay SIP supports input scoping Key InputScopes: Text, Url, Number, Time, TelephoneNumber, NameOrAddress 14
Windows Phone Microsoft Corporation. Media 15 Media support H/W decode MediaStreamSource PlayReady DRM MediaElement Limitations One MediaElement only XNA sound effect API Supports polyphonic, looping wav data
Windows Phone Microsoft Corporation. Isolated Storage Compatible APIs with Silverlight on desktop No quota limits Not shared No write access to Media Library, use XNA for that Use for your application settings 16
Software Architecture demo
Application Model Software Architecture App Model Cloud and Integration Services Hardware Foundation UI Model
Windows Phone Microsoft Corporation. Fast Application Resume Immediate Resume of recently used applications Apps stay in memory after deactivation New “ task switcher ” Long-press back button While dormant Apps are not getting CPU cycles Resources are detached 19
Windows Phone Microsoft Corporation. Activation and Navigation Activation Events Handled by the Application instance Launching, Activated, Deactivated and Closing Navigation Events Handled by each PhoneApplicationPage class OnNavigatedTo, OnNavigatedFrom, OnBackKeyPressed, OnChooserReturn, OnOrientationChanged Controlled by Hardware using Back and Home keys Software using Navigation Service 20
Windows Phone Microsoft Corporation. Application Lifecycle runningdeactivateddormantactivated Phone resources detached Threads & timers suspended Fast App Resume Save State! State preserved! IsAppInstancePreserved == true Restore state! IsAppInstancePreserved == false Resuming... Tombstone the oldest app Tombstoned
Windows Phone Microsoft Corporation. Deactivation Resource Management MediaPlayer.Pause MediaElement.Pause SoundEffectInstance.Pause VibrateController.Stop PhotoCamera.Dispose Save page/global state XNA AudioPaused SensorsNotifications suppressed NetworkingCancelled SocketsDisconnected MediaElementDisconnected CameraDisposed
Windows Phone Microsoft Corporation. Activation Resource Management MediaElement.Source/Position/Play Socket.ConnectAsync new PhotoCamera/VideoCamera Restore app state if tombstoned XNA AudioResumed SensorsNotifications resumed NetworkingCompleted with Cancellation Sockets- MediaElement- Camera-
Application Model demo
Multitasking Software Architecture App Model Cloud and Integration Services Hardware Foundation UI Model
Windows Phone Microsoft Corporation. Multi-tasking design principles 26 Network Conscience Battery Friendly Hardened Services Delightful and Responsive UX Never Regret App Install Integrated Feel UX Health
Windows Phone Microsoft Corporation. Multi-tasking Choices Background Transfer Service Background Audio Background Agents Periodic Resource Intensive Alarms and Reminders 27
Windows Phone Microsoft Corporation. Background Audio Playback App provides URL or stream to Zune Audio continues to play even if app is closed App is notified of file or buffer near completion Phone Integration Music & Video Hub Universal Volume Control (UVC), launch app, controls, contextual info Contextual launch – Start menu, UVC, Music & Video Hub App Integration App can retrieve playback status, progress, & metadata Playback notification registration 28
Windows Phone Microsoft Corporation. Background Audio App Types URL PlayList Provide URL to play Pause, resume, stop, skip-forward, skip-backward Stream Source Provide audio buffers Custom decryption, decompression Requires app to run some code in background 29
Background Audio demo
Windows Phone Microsoft Corporation. Background Agents Background Agent Allows an application to execute code in the background Two types of background processing scenarios: tasks: Periodic and Resource Intensive Application may have only one background agent Initialized in foreground, run in background Persisted across reboots Scheduled Tasks Periodic task runs regularly for a small amount of time Resource Intensive task runs occasionally and is allowed to use substantial device resources User control through CPL System maximum of 18 periodic agents Agent runs for up to 14 days (can be renewed) 31
Windows Phone Microsoft Corporation. Agent Types 32 Periodic Occurrence Every 30 min, non battery saver Duration ~15 seconds Memory Constraints <= 5 MB Memory Resource Intensive Occurrence External power or battery > 90%, screen lock, no-call, no-cell Duration 10 minutes Memory Constraints <= 5 MB Memory All of this requirements can change before RTM, but should not change too much
Windows Phone Microsoft Corporation. Background Agent Functionality 33 Allowed Tiles Toast Location Network R/W ISO store Sockets Most framework APIs Restricted Display UI XNA libraries Microphone and Camera Sensors Play audio
Background Agent demo
Windows Phone Microsoft Corporation. Background Transfer Service Start transfer in foreground, complete in background, even if app is closed Queue persists across reboots Queue size limit = 5 Queue APIs (Add, Remove, Query status) Single service for many apps, FIFO Download ~20 MB ( > over Wi-Fi) Upload Size ~4 MB (limit to come) Transfers to Isolated Storage 35
Windows Phone Microsoft Corporation. Code Sample: Background Transfer 36 using Microsoft.Phone.BackgroundTransfer; void DownloadWithBTS(Uri sourceUri, Uri destinationPath) { btr = new BackgroundTransferRequest(sourceUri, destinationUri); btr.TransferStatusChanged += BtsStatusChanged; btr.TransferProgressChanged += BtsProgressChanged; BackgroundTransferService.Add(btr); } void BtsProgressChanged(object sender, BackgroundTransferEventArgs e) { DrawProgressBar(e.Request.BytesReceived); }
Windows Phone Microsoft Corporation. Notifications Time-based, on-phone notifications Supports Alerts & Reminders Persist across reboots Adheres to user settings Consistent with phone UX 37
Windows Phone Microsoft Corporation. Alarms vs Reminders? Alarms Modal Snooze and Dismiss Sound customization No app invocation No stacking Reminders Rich information Integrates with other reminders Snooze and Dismiss Launch app Follows the phones global settings 38
Windows Phone Microsoft Corporation. Code Sample: Alarms 39 Alarms using Microsoft.Phone.Scheduler; private void AddAlarm(object sender, RoutedEventArgs e) { Alarm alarm = new Alarm("Long Day"); alarm.BeginTime = DateTime.Now.AddSeconds(15); alarm.Content = "It's been a long day. Go to bed."; alarm.Title = "Alarm"; ScheduledActionService.Add(alarm); }
Windows Phone Microsoft Corporation. Code Sample: Reminders 40 using Microsoft.Phone.Scheduler; private void AddReminder(object sender, RoutedEventArgs e) { Reminder reminder = new Reminder("CompanyMeeting"); reminder.BeginTime = DateTime.Now.AddSeconds(15); reminder.Content = "Soccer Fields by The Commons"; reminder.Title = "Microsoft Annual Company Product Fair 2009"; reminder.RecurrenceType = RecurrenceInterval.Yearly; reminder.NavigationUri = new Uri("/Reminder.xaml", UriKind.Relative); ScheduledActionService.Add(reminder); } Reminders
UI Model Software Architecture App Model Cloud and Integration Services Hardware Foundation UI Model
Windows Phone Microsoft Corporation. Application Bar and System Tray System Tray No integration, but does affect Layout Show:Hide using SystemTray.IsVisible Application Bar Up to 4 Buttons Menu Items (Recommended 6) Toggle Visibility .ApplicationBar.IsVisible 42
Windows Phone Microsoft Corporation. Panorama 43 Part of the native Windows Phone look and feel Panorama is a long horizontal canvas PanoramaItem serves as a container that hosts other content and controls
Windows Phone Microsoft Corporation. Pivot 44 Provides a quick way to manage views or pages Pivot is a container of pivot items PivotItem contain individual page content such as controls, grids, or links
Windows Phone Microsoft Corporation. Many more… Standard Controls Buttons, Image, Layout, ListBox, TextBox, Slider, Other… Bing Maps Bing Map Control, Integration with Bing Maps Services Deep Zoom Included in core run-time, Optimized to take advantage of GPU, Consumes same content as SL on desktop, Supported for Online content Web Browser Displays network and local content, Supports pan, double tap and pinch to zoom, Supports transforms & projections, Application can interact with javascript 45
UI Model demo
Integration Services Software Architecture App Model Cloud and Integration Services Hardware Foundation UI Model
Windows Phone Microsoft Corporation. Launchers & Choosers Enable applications to provide a set of common phone tasks to their users Launchers let you fire and forget SMS, , Web Browser, Dialer, Search, etc. Choosers let you fire and pick the results back Picture, Camera, Contact, etc. 48
Launchers & Choosers demo
Windows Phone Microsoft Corporation. Push Notifications 50
Windows Phone Microsoft Corporation. Types of Push Notifications Tile notifications Update tile count, title and background image Update back tile title, content and image Toast/Deep Toast notifications Display a on-top-like message Take users directly to an application experience Uses standard SL navigation (OnNavigatedTo) Raw notifications Can be used in application logic 51
Windows Phone Microsoft Corporation. Push Notifications (Core) Enhancements Reliability New TDET mechanism for broader network compatibility Lowered polling interval for non- persistent connection friendly networks Efficiency TLS resume for sessions within 8 hours Hints for improved radio dormancy Concurrent tile downloads for less radio uptime Performance Faster state machine for faster client service Smarter queue logic for less redundancy 52
Windows Phone Microsoft Corporation. Live Tile Local Tile APIs Full control of ALL properties Multiple tiles per app Create,Update/Delete/Query Launches direct to Uri 53
Windows Phone Microsoft Corporation. Back of tile updates Full control of all properties when your app is in the foreground or background Content, Title, Background Flips from front to back at random interval Smart logic to make flips asynchronous Live Tiles – Local Tile API Continued… Title Content Title Background Content string is bigger
Windows Phone Microsoft Corporation. Location and Services The service obtains location data from multiple sources such as GPS, Wi-Fi, and cellular Applications can access location information Allows you to create location- aware applications 55
Windows Phone Microsoft Corporation. Accelerometer Measures force applied on each axis over time Determine in which direction the user is moving the device Expressed as a 3-dimensional vector 56 +Y -Y +X -X +Z -Z
Windows Phone Microsoft Corporation. Measures rotational velocity on 3 axis Significant drift Indicates rotation even when device is stationary Availability: Optional on Mango phones Not present in pre-Mango WP7 phones 57 Gyroscope
Windows Phone Microsoft Corporation. Code Sample: Gyroscope 58
Windows Phone Microsoft Corporation. Gives 3D heading of Earth’s magnetic and Geographic North Subject to external electromagnetic influences Requires user calibration over time Great inaccuracies in orientation, up to 20 degrees Significant lag Availability: Optional on “Mango” phones Included in some pre-Mango WP7 phones 59 Compass (aka Magnetometer)
Windows Phone Microsoft Corporation. Accelerometer required on all devices Gyro and Compass sensors are optional Application should leverage sensors based on device capabilities 60 Sensor Hardware Availability
Windows Phone Microsoft Corporation. Virtual sensor, combines gyro + compass + accelerometer Motion Sensor vs. gyro or compass or accelerometer More accurate Faster response times Comparatively low drift Can disambiguate motion types 61 Motion Sensor Always prefer Motion Sensor when available
Windows Phone Microsoft Corporation. Degraded modes have lower quality approximations When Motion.IsSupported is false, apps should use accelerometer or other input and control mechanisms 62 Motion Sensor Adapts to Devices AccelerometerCompassGyroMotion Yes Full Yes NoDegraded YesNoYesUnsupported YesNo Unsupported
Windows Phone Microsoft Corporation. Sensor Calibration Calibration Event is fired when calibration is needed Both Compass and Motion sensors need user calibration Apps should handle it Provide UI asking user to move device through a full range of orientations Not handling will cause inaccurate readings 63
Windows Phone Microsoft Corporation. Networking Sockets TCP UDP unicast, Multicast ( on Wi-Fi) Connection Manager Control Overrides and sets preferences (e.g. Wi-Fi or Cellular only) HTTP Full header access WebClient returns in originating thread 64
Windows Phone Microsoft Corporation. Sockets Classes in Mango AreaSilverlight 4.0Windows Phone TCP SocketsSocket class (Async)Socket UDP SocketsUdpAnySourceMulticastClient UdpSingleSourceMulticastClient Socket AddressingSocketAddress IPAddress IPEndPoint SocketAddress IPAddress IPEndPoint Name Resolution DnsEndPoint NameResolution APIs
Windows Phone Microsoft Corporation. Code Sample: TCP Socket 66 _endPoint = new DnsEndPoint(“ ", 5000); _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.UserToken = _socket; args.RemoteEndPoint = _endPoint; args.Completed += new EventHandler (OnSocketConnectCompleted); _socket.ConnectAsync(args);
Windows Phone Microsoft Corporation. Code Sample: UDP Socket 67 Client = new UdpAnySourceMulticastClient(address, port); Client.BeginJoinGroup( result => { Client.EndJoinGroup(result); Dispatcher.BeginInvoke( delegate { OnAfterOpen(); Receive(); }); }, null);
Windows Phone Microsoft Corporation. Silverlight and XNA Shared Graphics XNA inside Silverlight App Integration at Page Level XNA takes over rendering Integration at Element level Silverlight elements in XNA pipeline via UIElementRenderer Shared input 68
Windows Phone Microsoft Corporation. Local database SQL Compact Edition Object Model for CRUD LINQ to SQL to query, filter, sort Application scope Uses IsolatedStorage DatabaseSchemaUpdater APIs for upgrades 69
Local database demo
Windows Phone Microsoft Corporation. Register Your Device 71 Test on a physical device Register your device Install, run, and debug unsigned applications Use Zune to register your device
Questions? 72