3. Windows Phone 7
Introduction
A bit of history…
Begining of major
WM Update :
« Photom »
2000 2005 2009 2010
First version Windows Windows Windows
of Pocket PC Mobile 5 Phone 6.5 Phone 7
Usage of the name
Windows Mobile Windows
Zune HD
Mobile 6
2003 2007 2009
3
5. Windows Phone 7
Introduction
The break point
Windows Phone 7 has :
No Retro-compatibility with Windows
Mobile
Based on Windows CE 6
New Interface based-on Metro UI
Hardware requirements
Good-bye Stylus !
5
7. Windows Phone 7
Introduction
Windows Common
Consistent Quality
Phone Hardware
Platform Focus
Hardware Elements
Consistent set of
hardware capabilities
defined by Microsoft
One resolution at launch
Second resolution added later
Same touch input
Consistent processor / GPU
Same available RAM
Optional keyboard
7
8. Windows Phone 7
Introduction : Original hardware requirements
Touch
4 points of contacts
Sensors
A-GPS, Accelerometer, Luminosity, …
APN
5 Megapixels minimum, flash
Multimedia
Codecs, Smooth Streaming
Memory
256 Mo RAM minimum, 8Go of flash memory minimum
GPU
DirectX
CPU
1GHz or more
Buttons | Back, Start, Search
8
9. Windows Phone 7
Introduction : Developement technologies
User interfaces in XAML High performance game framework
Easy & quick to create rich visuel Rapid creation of multi-screen 2D & 3D
applications games
Metro-UI themed controls Rich content pipeline
500 000 developers spanning Windows Mature, robust, widely adopted
& Web spanning Xbox 360, Windows & Zune.
11
10. Windows Phone 7
Introduction
Applications
Your App UI and logic
Frameworks
Silverlight XNA HTML/JavaScript
CLR
App Model UI Model Cloud Integration
Xbox LIVE
App management Shell frame Bing
Licensing Session manager Location
Chamber isolation Direct3D Push notifications
Software updates Compositor Windows Live ID
Kernel
Hardware BSP
Security
Networking A-GPS AccelerometerCompass Light Proximity
Storage Media Wi-Fi Radio Graphics
Hardware Foundation
12
11. Windows Phone 7
Introduction : App Model Concepts
Application
Uniquely identifiable,
licensable and serviceable
software product packaged
as a XAP
Application Deployment
Steps include Ingestion,
Certification and Signing Windows Phone
Marketplace
Application license
Crypto-verifiable object
issued to grant rights to Windows Phone
an application Marketplace
13
12. Windows Phone 7
Introduction : Deployement and distribution process
Develop Submit Certify
& Debug & Validate & Sign
Windows Phone
Application Deployment Marketplace
Service
14
13. Windows Phone 7
Introduction : Developement tools
w/ Windows
Phone SDK
OR
Third party IDE
You can also use Visual studio 2010 Express Edition for Windows Phone
SDK Available at : http://developer.windowsphone.com/
15
14. Windows Phone 7
Basics : Controls
Some of the controls :
Pivot
Panorama
Bing maps
DatePickers
Time Pickers
…. And more in the SL toolkit
17
16. Windows Phone 7
Some of the Tasks
AddressChooserTask
BingMapsDirectionsTask
BingMapsTask
ConnectionSettingsTask
GameInviteTask
PhoneCallTask
SmsComposeTasks
WebBrowserTask
SaveContactTask
SaveRingtoneTask
ShareLinkTask
ShareStatusTask 19
17. Windows Phone 7
Tasks : AddressChooserTask
AddressChooserTask addressChooserTask;
addressChooserTask = new AddressChooserTask();
addressChooserTask.Completed += new EventHandler<AddressResult>(addressChooserTask_Completed);
try
{
addressChooserTask.Show();
}
catch (System.InvalidOperationException ex)
{
MessageBox.Show("An error occurred.");
}
void addressChooserTask_Completed(object sender, AddressResult e)
{
if (e.TaskResult == TaskResult.OK)
{
MessageBox.Show("The address for " + e.DisplayName + " is " + e.Address);
}
}
20
18. Windows Phone 7
Tasks : BingMapsDirectionsTask
BingMapsDirectionsTask bingMapsDirectionsTask = new BingMapsDirectionsTask();
// You can specify a label and a geocoordinate for the end point.
// GeoCoordinate spaceNeedleLocation = new GeoCoordinate(47.6204,-122.3493);
// LabeledMapLocation spaceNeedleLML = new LabeledMapLocation("Space Needle", spaceNeedleLocation);
// If you set the geocoordinate parameter to null, the label parameter is used as a search term.
LabeledMapLocation spaceNeedleLML = new LabeledMapLocation("Space Needle", null);
bingMapsDirectionsTask.End = spaceNeedleLML;
// If bingMapsDirectionsTask.Start is not set, the user's current location is used as the start point.
bingMapsDirectionsTask.Show();
21
19. Windows Phone 7
Tasks : BingMapsTask
BingMapsTask bingMapsTask = new BingMapsTask();
//Omit the Center property to use the user's current location.
//bingMapsTask.Center = new GeoCoordinate(47.6204, -122.3493);
bingMapsTask.SearchTerm = "coffee";
bingMapsTask.ZoomLevel = 2;
bingMapsTask.Show();
22
20. Windows Phone 7
Tasks : ConnectionSettingsTask
ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.WiFi;
connectionSettingsTask.Show();
23
21. Windows Phone 7
Tasks : GameInviteTask
GameInviteTask gameInviteTask;
gameInviteTask = new GameInviteTask();
gameInviteTask.Completed += new EventHandler<TaskEventArgs>(gameInviteTask_Completed);
try {
gameInviteTask.SessionId = "<my session id>";
gameInviteTask.Show();
}
catch (System.InvalidOperationException ex)
{
MessageBox.Show("An error occurred.");
}
void gameInviteTask_Completed(object sender, TaskEventArgs e)
{
switch(e.TaskResult)
{
//Game logic for when the invite was sent successfully
case TaskResult.OK:
MessageBox.Show("Game invitation sent.");
break; /
//Game logic for when the invite is cancelled by the user
case TaskResult.Cancel:
MessageBox.Show("Game invitation cancelled.");
break;
// Game logic for when the invite could not be sent
case TaskResult.None:
MessageBox.Show("Game invitation could not be sent.");
break;
}
}
24
23. Windows Phone 7 Company Gets or sets the name of the company associated with the contact.
FirstName Gets or sets the given name of the contact.
Gets or sets the city of the home address associated with the
HomeAddressCity
contact.
Gets or sets the country or region of the home address associated
Tasks : SaveContactTask HomeAddressCountry
with the contact.
Gets or sets the state of the home address associated with the
HomeAddressState
contact.
Gets or sets the street name and number of the home address
HomeAddressStreet
associated with the contact.
Gets or sets the postal code of the home address associated with
HomeAddressZipCode
the contact.
HomePhone Gets or sets the home phone number associated with the contact.
JobTitle Gets or sets the job title associated with the contact.
LastName Gets or sets the surname of the contact.
MiddleName Gets or sets the middle name of the contact.
MobilePhone Gets or sets the mobile phone number associated with the contact.
Nickname Gets or sets the nickname of the contact.
Notes Gets or sets a note associated with the contact.
Gets or sets an additional email address associated with the
OtherEmail
contact.
PersonalEmail Gets or sets the personal email address associated with the contact.
Suffix Gets or sets the suffix of the name of the contact.
Title Gets or sets the title of the name of the contact.
Website Gets or sets the website associated with the contact.
Gets or sets the city of the work address associated with the
WorkAddressCity
contact.
Gets or sets the country or region of the work address associated
WorkAddressCountry
with the contact.
Gets or sets the state of the work address associated with the
WorkAddressState
contact.
Gets or sets the street name and number of the work address
WorkAddressStreet
associated with the contact.
Gets or sets the postal code of the work address associated with
WorkAddressZipCode
the contact.
WorkEmail Gets or sets the work email address associated with the contact.
WorkPhone Gets or sets the work phone number associated with the contact.
26
24. Windows Phone 7
Tasks : SaveRingtoneTask
try {
saveRingtoneChooser.Source = new Uri("appdata:/ReneLaTaupe.mp3");
//saveRingtoneChooser.Source = new Uri("isostore:/ReneLaTaupe.mp3");
saveRingtoneChooser.DisplayName = "My custom ringtone"; saveRingtoneChooser.Show();
}
catch (System.InvalidOperationException ex)
{
MessageBox.Show("An error occurred.");
}
27
25. Windows Phone 7
Tasks : ShareLinkTask
ShareLinkTask shareLinkTask = new ShareLinkTask();
shareLinkTask.Title = "Code Samples";
shareLinkTask.LinkUri = new Uri("http://soumow.dollon.net", UriKind.Absolute);
shareLinkTask.Message = "Have you seen the latest demo ?";
shareLinkTask.Show();
28
27. Windows Phone 7
Live Tiles
Live Tiles allow content on a
tile to be updated and
changed remotely to signifly
a change in the backend
application
30
28. Windows Phone 7
Creating a tile
ShellTile.Create(new Uri("/MainPage.xaml", UriKind.Relative),
new StandardTileData(){
BackgroundImage = new Uri("isostore:/Shared/ShellContent/image.png",
UriKind.Absolute),
Title = "Sample"});
Tiles are recto and verso
There are also some additional properties that you can use in addition to the basic ones:
BackContent - used to display a string onthe back of the tile. The tile itself will automatically rotate betwen the
base and secondary content.
BackTitle - the title to be displayed on the back of the tile.
Count - the count displayed in the corner of the tile. Only displayed on the front side of the tile.
BackBackgroundImage - the background image displayed on the back of the tile.
31
29. Windows Phone 7
Update/Deleting tiles
Tiles can expire or need updating
Enumerate the tiles associated with the application, accessible
through the ShellTile.ActiveTiles IEnumerable:
foreach (ShellTile tile in ShellTile.ActiveTiles){
Debug.WriteLine(tile.NavigationUri.ToString());
}
For each shell tile, we can either Update it (and pass a new
instance of StandardTileData with updated content) or Delete it.
32
30. Windows Phone 7
Push Notifications
3 Types of Push
Notifications
Toast Notifications
Tile Notifications
Raw Notifications
33
31. Windows Phone 7
Push Notifications : Toast Notifications
Title. A boldface string that displays immediately after the application icon. This is defined as
the Text1 property in the XML schema.
Content. A non-boldface string that displays immediately after the Title. This is defined as the
Text2 property in the XML schema.
Parameter. A parameter value that is not displayed but passed to your application if the user
taps on the toast. This parameter can indicate what page the application should launch to. It
can also contain name-value pairs to pass to the application. This is defined as the Param
property in the XML schema.
34
38. Windows Phone 7
What are background agents?
Background Agents are a seperate project from the
application you are creating.
They are instantiated when the application isn’t in an
active state. When the application is in an active state,
they don’t run.
Maximum of 18 simultaneous agents.
Background Agents are desactivated 14 days if they are
never used.
41
39. Windows Phone 7
What can/can’t you do with Background Agents
Allowed Not Allowed
Tiles Interact with UI
Toast XNA Libraries
Location Services Microphone & Camera
Connectivity Sensors
Access to Play audio without using
IsolatedStorage the appropriate APIs for
Sockets background sound
Most APIs
42
40. Windows Phone 7
Background Agents
Background Transfer Service
Background Audio
Background Agents
Periodic
On Idle
Alarms and Reminders
43
41. Windows Phone 7
Background Agents
Background Agents in Mango take the form of a separate assembly, which gets linked
in your WMAppManifest.xml
44
42. Windows Phone 7
Background Agents
Background Transfer Service
45
43. Windows Phone 7
Background Agents : Background Transfer Service
Start in foreground, complete in background, even if
app is closed
Queue (of 5) persists across reboots
Single service for many apps, FIFO
Download ~20 MB ( > over Wi-Fi)
Upload Size ~4 MB (limit to come)
Transfers to Isolated Storage 46
46. Windows Phone 7
Background Agents : ScheduledTask Agent
It is possible to have in Windows Phone 7 to execute code
as a planned tack.
There are two types of scheduled tasks therefore one class
that from ScheduledTask for each of these types :
PeriodicTask and ResourceIntensiveTask
49
47. Windows Phone 7
Background Agents : ScheduledTask Agent
Limitations:
Memory 5 Mo
Expiration : 2 Weeks
Restrained acces to APIs
User can desactivate them
PeriodicTask :
Every 30 minutes (+/-) for 15 seconds
Can be dismissed if two many background agents are active
ResourceIntensiveTask
Runs for 10 minutes
Only runs if the phone is plugged in
If the phone is connected to Wifi or PC
If the phone is 90% Charged
If absolutely no application is running on the phone
50
48. Windows Phone 7
Background Agents : ScheduledTask Agent
Microsoft.Phone.Scheduler.PeriodicTask
PeriodicTask periodicTask = new PeriodicTask("TaskUniqueNameInApp");
periodicTask.Description = "My Periodic Task Description";
periodicTask.ExpirationTime = DateTime.Now.AddDays(10);
ScheduledActionService.Add(periodicTask);
Microsoft.Phone.Scheduler.ResourceIntensiveTask
ResourceIntensiveTask intensiveTask new ResourceIntensiveTask("TaskUniqueNameInApp");
intensiveTask.Description = "My Intensive Task Description";
intensiveTask.ExpirationTime = DateTime.Now.AddDays(10);
ScheduledActionService.Add(intensiveTask)
51
49. Windows Phone 7
Background Agents : ScheduledTask Agent
Then create a class that inherits of ScheduledTaskAgent and override OnInvoke and OnCancel
public class TaskScheduler : ScheduledTaskAgent
{
protected override void OnInvoke(ScheduledTask task)
{
if (task is PeriodicTask)
{ }
else //is ResourceIntensiveTask
{ }
NotifyComplete();
}
}
52
52. Windows Phone 7
Sockets
Windows Phone provides the programming interface needed to create and use TCP and UDP sockets. You can select
which type of socket to use based on your application’s needs.
55
53. Windows Phone 7
Sockets
using System.Net.Sockets;
public string Connect(string hostName, int portNumber) {
DnsEndPoint hostEntry = new DnsEndPoint(hostName, portNumber);
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
socketEventArg.RemoteEndPoint = hostEntry;
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>( delegate(object s, SocketAsyncEventArgs e)
{
result = e.SocketError.ToString();
_clientDone.Set(); });
_clientDone.Reset();
_socket.ConnectAsync(socketEventArg);
_clientDone.WaitOne(TIMEOUT_MILLISECONDS);
});
return result;
}
56
55. Windows Phone 7
Contacts/Calendar
In Windows Phone, you can now access the user information asynchrously, and even better you can query them with
Linq !!!
using Microsoft.Phone.UserData;
Get contacts:
private void ButtonContacts_Click(object sender, RoutedEventArgs e) {
Contacts cons = new Contacts();
//Identify the method that runs after the asynchronous search completes.
cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(Contacts_SearchCompleted);
//Start the asynchronous search.
cons.SearchAsync(String.Empty, FilterKind.None, "Contacts Test #1");
}
void Contacts_SearchCompleted(object sender, ContactsSearchEventArgs e) {
//Do something with the results.
MessageBox.Show(e.Results.Count().ToString());
}
58
56. Windows Phone 7
Contacts/Calendar
using Microsoft.Phone.UserData;
Get appoinments using Linq:
void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
{
try
{
AppointmentResultsDataLINQ.DataContext = from Appointment appt in e.Results
where appt.IsAllDayEvent == false
select appt;
}
catch (System.Exception)
{
//No results
}
}
59
58. Windows Phone 7
Media
You can use the following features to consume media in a Windows Phone application:
Use the MediaPlayerLauncher class for Windows Phone to embed audio or video using the device media player. Cf.
Launchers and Choosers chapter
Use the Silverlight MediaElement API to embed audio or video using a more customizable interface.
MediaElement for Windows Phone has a few differences than MediaElement for the desktop.
Add sound effects using XNA Game Studio.
Use the MediaStreamSource class for adaptive streaming solutions.
Use Microsoft.Phone.BackgroundAudio to create a media application that will continue playing audio when another
application is in the foreground. Cf. background agents chapter
61
59. Windows Phone 7
Media : MediaElement
<MediaElement Name="mediaElement1" Source="http://mschannel9.vo.msecnd.net/o9/mix/09/wmv/key01.wmv" AutoPlay="True"/>
mediaElement1.Play();
mediaElement1.Pause();
mediaElement1.Stop();
62
61. Windows Phone 7
Media : Integration with the music hub
Your Music + Videos Hub application must conform to the Application Certification
Requirements for Windows Phone to integrate with the Music + Videos Hub.
Tiles that are displayed in the Music + Videos Hub must conform to additional iconography rules:
You must include your application title or logo on each Tile.
The now playing Tile must be 358 pixels x 358 pixels. The file size must be 75 KB or less.
Other tiles must be 173 pixels x 173 pixels in size.
The Title property of the MediaHistoryItem class must be set to text that represents the content, such as a
station name or video title.
To help avoid confusion for users, Hub Tiles should not contain album art unless the album plays when the Hub
Tile is pressed.
If your application plays a stream, the Hub Tile graphic should describe the stream that is being played.
This is not a certification requirement, it is a good practice.
64
62. Windows Phone 7
Media : Integration with the music hub
Updating the 'now playing' Tile of the 'history' List
MediaHistoryItem mediaHistoryItem = new MediaHistoryItem();
//<hubTileImageStream> must be a valid ImageStream.
mediaHistoryItem.ImageStream = <hubTileImageStream>;
mediaHistoryItem.Source = "";
mediaHistoryItem.Title = "NowPlaying";
mediaHistoryItem.PlayerContext.Add("keyString", "Song Name");
MediaHistory.Instance.NowPlaying = mediaHistoryItem;
65
64. Windows Phone 7
Application Lifecycle Pre-Mango
Windows Phone supports programmatic access to the camera on a device, offering a rich
set of APIs for developers to create their applications.
Some features include:
Creating a camera application with a viewfinder and capturing still photos
Providing real-time access to raw frames from the camera
Adjusting the resolution of the captured photo
Implementing functionality such as focus and flash
Detecting and querying the device camera capabilities such as flash
Accessing the camera hardware shutter button for capturing photos and triggering auto-focus
67
66. Windows Phone 7
Camera API
To use a camera in your Windows Phone application, you must add the
camera capability (ID_CAP_ISV_CAMERA) to the application manifest file.
<Capability Name="ID_CAP_ISV_CAMERA"/>
<Capability Name="ID_HW_FRONTCAMERA"/>
69