Upload
jonah-lang
View
221
Download
1
Tags:
Embed Size (px)
Citation preview
Charles Petzoldwww.charlespetzold.com
Silverlight for Windows Phone
Agenda
• Windows Phone 7• Silverlight for Windows Phone• Your first phone application• Deploying to a device• Page orientation• Screen layout• Device information
• Meet or exceed a common hardware specification– Minimum 1 GHz ARM v7 CPU and DirectX9 GPU– Minimum 256 MB RAM and 8 GB flash storage– 480 x 800 screen (480 x 320 coming later)– Capacitive 4-point multi-touch screen– Minimum 5-megapixel camera– Location (Assisted-GPS), accelerometer,
compass, light sensor, and proximity sensor– Connectivity support via cellular networks and
WiFi • Available from Samsung, HTC, and other
OEMs
Windows Phones
• Operating system for Windows phones– Clean break from the past (Windows Mobile)– Released in U.S. on November 8, 2010
• "Metro" user interface– Crisp and sexy (icon grids are boring)– Start screen populated with tiles– Hubs that aggregate content (Pictures, Games,
etc.)• Built-in browser based on IE7 and IE8• Apps written in Silverlight or XNA
Windows Phone 7
• UI Design and Interaction Guide for WP7– http://go.microsoft.com/fwlink/?LinkID=183218
• WP7 Application Certification Requirements– http://go.microsoft.com/?linkid=9730558
Documents You Must Have
• Primary development platform for WP7 phones
• Based on Silverlight 3, but with some features of 4
• Adds many phone-specific features– Page orientation (portrait or landscape)– Richer touch APIs (Manipulation events)– Sensor and location APIs– Device APIs (e.g., camera)– Launchers and choosers and more
• Based on .NET Compact Framework 3.7
Silverlight for Windows Phone
• Windows Phone Developer Tools– Visual Studio 2010 Express for Windows Phone– Expression Blend for Windows Phone– Windows Phone Emulator– XNA Game Studio– http://www.microsoft.com/downloads/en/
details.aspx?FamilyID=04704acf-a63a-4f97-952c-8b51b34b00ce
• Silverlight for Windows Phone Toolkit– http://silverlight.codeplex.com/releases/view/
55034
Phone Developer Tools
• Runs phone apps in a VM• Supports multi-touch on PCs with multi-
touch screens and OSes that support multi-touch
• For best performance, enable hardware-assisted virtualization in your BIOS– http://www.microsoft.com/windows/virtual-pc/support/configure-bios.aspx
• For GPU emulation, run dxdiag.exe and make sure DDI version >= 10 and WDDM version >= 1.1– http://www.andybeaulieu.com/Default.aspx?
EntryID=196&tabid=67
Windows Phone Emulator
demoYour First Windows Phone Application
• Visual Studio supports deploying to the emulator or to a device (phone)
• To deploy to a device, you must:– Register and obtain a developer account
• http://create.msdn.com/en-us/home/membership
– Unlock the device with the Developer Registration Tool• http://msdn.microsoft.com/en-us/library/
ff769508(v=vs.92).aspx
– Download and install the Zune client• http://www.zune.net/en-US/products/software
• Debugger works with code running on a device!
Deploying to a Device
• Start the Zune client before deploying to device
• Media APIs not available while client is running
Zune Client
• First shipped in October 2010 tools update• Enables apps running on phones connected
to PCs to access media APIs
WPConnect
demoTesting on a Device
• Display can rotate when orientation changes
• PhoneApplicationPage.SupportedOrientations controls behavior when orientation changes– Portrait – Display does not rotate– Landscape – Display does not rotate– PortraitOrLandscape – Display rotates
automatically• PhoneApplicationPage.OrientationChanged
events fire when orientation changes– If SupportedOrientations =
"PortraitOrLandscape"
Page Orientation
Preventing the Page from Rotating// In MainPage.xamlSupportedOrientations="Portrait"
Rotating the Page
// In MainPage.xamlSupportedOrientations="PortraitOrLandscape"
Customizing the Rotated Page
// In the page constructorthis.OrientationChanged += new EventHandler<OrientationChangedEventArgs>(OnOrientationChanged);
private void OnOrientationChanged(object sender, OrientationChangedEventArgs e){ if ((e.Orientation & PageOrientation.Landscape) != 0) { // TODO: Adjust the page for landscape mode } else // Portrait { // TODO: Adjust the page for portrait mode }}
demoPage Orientation
Screen Layout
• Screen layout includes optional system tray and application bar
System tray32 pixels high in portrait mode72 pixels high in landscape mode
Application bar72 pixels high in portrait mode72 pixels high in landscape mode
Hiding the System Tray
// In MainPage.xaml<phone:PhoneApplicationPage x:Class="PhoneDemo.MainPage" ... FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="Portrait" Orientation="Portrait" shell:SystemTray.IsVisible="False">
Hide the system tray
Getting the Absolute Screen Sizedouble width = Application.Current.Host.Content.ActualWidth;double height = Application.Current.Host.Content.ActualHeight;
Getting the Usable Screen Sizedouble width = this.ActualWidth;double height = this.ActualHeight;
• DeviceExtendedProperties class provides information about host device
• Retrieve dictionary-type values with GetValue
Getting Device Information
DeviceExtendedProperties
Value Description Type
DeviceManufacturer Device manufacturer (e.g. SAMSUNG) string
DeviceName Device name (e.g., SGH-i917) string
DeviceUniqueId Device ID (e.g., 29-49-7B-05-D3-FA…) byte[]
DeviceFirmwareVersion
Firmware version (e.g., 2013.10.10.1) string
DeviceHardwareVersion
Hardware version (e.g., 3.1.0.7) string
DeviceTotalMemory Total memory (bytes) long
ApplicationCurrent-MemoryUsage
Memory currently allocated (bytes) long
ApplicationPeak-MemoryUsage
Peak memory allocated (bytes) long
Getting Model Information
string manufacturer = DeviceExtendedProperties.GetValue ("DeviceManufacturer").ToString();string name = DeviceExtendedProperties.GetValue ("DeviceName").ToString();string id = BitConverter.ToString((byte[]) DeviceExtendedProperties.GetValue("DeviceUniqueId"));
Getting Memory Information
string total = ((long)DeviceExtendedProperties.GetValue ("DeviceTotalMemory")).ToString("N0") + " bytes";string current = ((long)DeviceExtendedProperties.GetValue ("ApplicationCurrentMemoryUsage")).ToString("N0") + " bytes";string peak = ((long)DeviceExtendedProperties.GetValue ("ApplicationPeakMemoryUsage")).ToString("N0") + " bytes";
Charles Petzoldwww.charlespetzold.com
Questions?