Tag: Windows Phone 7

Windows Phone 7 Application Certification Guide

To submit your app to Marketplace for distribution, you will need an App Hub Account. Open one at: http://create.msdn.com

Opening an account is also necessary to developer unlock your Windows Phone 7 hardware.

Tip: Make sure you use an international credit card if opening an account outside of the US.
Tip: If you will use this account for a company, do not use a personal Windows Live ID when creating the account. You don’t want to mix your personal account details with your company’s and after you create the account, you can’t change the Windows Live ID.

For a guide of the Windows Phone 7 registration process, see here.

For a guide of the Windows Phone 7 Marketplace application submission process, see here.

To help teams track their progress in meeting the Windows Phone 7 certification requirements, I’ve created the following guide. I have used this myself when reviewing partners applications prior to submitting to Marketplace. Please see the instructions on the first tab.

image

Instructions

image

Sample Page

Thanks,

Mike

This work is licensed under a Creative Commons license.

Windows Phone 7: Detecting Tap and Hold

There are a couple of ways to go about detecting Tap and Hold in Windows Phone 7. This method uses the XNA Touch Gesture recognizer (Microsoft.Xna.Framework.Input.Touch) in a Silverlight application.  The touch gesture recognizer can tell the difference between tap, double-tap,  and hold gestures. Additionally, using the XNA gesture recognizer you don’t need to worry about mistaking a pan/drag for a hold: if you move your finger too much, a tap or hold won’t be recognized. Other solutions involve inferring these events through the use of a timer.  A common application of this is to implement a context menu in your Windows Phone 7 application.

This method handles the ManipulationStarted event to detect the initial tap. In this event, you tell the gesture recognizer which gestures you want to monitor. In this case, tap, double-tap, and hold.  (This is also done in the constructor of the page, to initialize the recognizer.)

Next a 500 ms timer is started. The timer is used to detect when enough ‘hold time’ has elapsed. When the ‘hold time’ threshold is met, the gesture is detected, the gesture recognizer is reset, and the timer is stopped. This is where you would invoke the context menu. (Not implemented here.) A timer is only necessary here for the implementation of a context-menu. You could detect the gesture in the ManipulationCompleted event handler, which fires when the user releases their finger from the screen.

  1. public MainPage()
  2. {
  3.     InitializeComponent();
  4.     TouchPanel.EnabledGestures = GestureType.Tap | GestureType.Hold | GestureType.DoubleTap;
  5. }
  6.  
  7. System.Windows.Threading.DispatcherTimer dt;
  8. public void StartHoldTimer()
  9. {
  10.     dt = new System.Windows.Threading.DispatcherTimer();
  11.     dt.Interval = new TimeSpan(0, 0, 0, 0, 500);// 500 Milliseconds
  12.     dt.Tick += new EventHandler(dt_Tick);
  13.     dt.Start();
  14. }
  15.  
  16. int cnt = 0;
  17. void dt_Tick(object sender, EventArgs e)
  18. {
  19.     if (cnt == 3) // 500 ms * 4 == 2 seconds
  20.     {
  21.         cnt = 0;
  22.         GetGesture();
  23.         // disable all events
  24.         TouchPanel.EnabledGestures = GestureType.None;
  25.         // stop the hold timer
  26.         StopHoldTimer();
  27.     }
  28.     cnt++;
  29. }
  30.  
  31. void StopHoldTimer()
  32. {
  33.     dt.Stop();
  34.     cnt = 0;
  35. }
  36.  
  37. private void GetGesture()
  38. {
  39.     if (TouchPanel.IsGestureAvailable)
  40.     {
  41.         GestureSample gs = TouchPanel.ReadGesture();
  42.         if (gs.GestureType == GestureType.Hold)
  43.         {
  44.             string gestureString = string.Format("{0}: {1}", gs.GestureType, gs.Position);
  45.             // Tap and Hold detected, report position
  46.             Debug.WriteLine(gestureString);
  47.         }
  48.     }
  49. }
  50.  
  51. private void PhoneApplicationPage_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
  52. {
  53.     // specify what events the XNA gesture recognizer will look out for
  54.     TouchPanel.EnabledGestures = GestureType.Tap | GestureType.Hold | GestureType.DoubleTap;
  55.     // start the hold timer
  56.     StartHoldTimer();
  57. }
  58.  
  59. private void PhoneApplicationPage_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
  60. {
  61.     // disable all events
  62.     TouchPanel.EnabledGestures = GestureType.None;
  63.     // stop the hold timer
  64.     StopHoldTimer();
  65. }

Enjoy!

Mike

This work is licensed under a Creative Commons license.

Windows Phone 7 : Code Snippet: Enumerate Files in Isolated Storage

This sample code uses the IsolatedStorageFile class to create a few test directories and populates them with files.  Then it recursively enumerates the files and directories, displaying the output in the debug window.

  1. public void EnumerateIsolatedStorageFiles()
  2. {
  3.     try
  4.     {
  5.         // Get an isolated store for this applicaiton and put it into an
  6.         // IsolatedStorageFile object.
  7.  
  8.         using (IsolatedStorageFile isoStore =
  9.             IsolatedStorageFile.GetUserStoreForApplication())
  10.         {
  11.             // Create sub directories and create files
  12.             // in them to test enumeration
  13.             isoStore.CreateDirectory("A");
  14.             IsolatedStorageFileStream streamA =
  15.                 new IsolatedStorageFileStream(@"A\TestFileA.Txt", FileMode.Create, isoStore);
  16.  
  17.             isoStore.CreateDirectory("B");
  18.             IsolatedStorageFileStream streamB =
  19.                 new IsolatedStorageFileStream(@"B\TestFileB.Txt", FileMode.Create, isoStore);
  20.  
  21.             isoStore.CreateDirectory("C");
  22.             IsolatedStorageFileStream streamC =
  23.                 new IsolatedStorageFileStream(@"C\TestFileC.Txt", FileMode.Create, isoStore);
  24.  
  25.             isoStore.CreateDirectory(@"C\1");
  26.             IsolatedStorageFileStream streamC1 =
  27.                 new IsolatedStorageFileStream(@"C\1\TestFileC1.Txt", FileMode.Create, isoStore);
  28.  
  29.             isoStore.CreateDirectory(@"D\1\2\3\4\5");
  30.             IsolatedStorageFileStream streamD =
  31.                 new IsolatedStorageFileStream(@"D\1\2\3\4\5\TestFileD.Txt", FileMode.Create, isoStore);
  32.  
  33.             streamA.Close();
  34.             streamB.Close();
  35.             streamC.Close();
  36.             streamC1.Close();
  37.             streamD.Close();
  38.  
  39.             // There might be a small delay between when the above code
  40.             // executes and when the files are created in the store.
  41.             // Closing and opening the store in this example ensures that
  42.             // the common language runtime has finished creating the files.
  43.         } // using
  44.  
  45.         using (IsolatedStorageFile isoStore =
  46.             IsolatedStorageFile.GetUserStoreForApplication())
  47.         {
  48.             // List files in root
  49.             foreach (string file in isoStore.GetFileNames())
  50.             {
  51.                 Debug.WriteLine(file);
  52.             }
  53.             // Recursively enumerate sub-directories and list contents
  54.             GetFiles(isoStore, @"\");
  55.         } // using
  56.     }
  57.     catch (IsolatedStorageException e)
  58.     {
  59.         Debug.WriteLine(e.Message);
  60.     }
  61. }
  62.  
  63. // Recursively enumerate sub-directories
  64. void GetFiles(IsolatedStorageFile isoStore, string directory)
  65. {
  66.     string[] DirNames;
  67.     if (directory == @"\")
  68.         DirNames = isoStore.GetDirectoryNames();
  69.     else
  70.         DirNames = isoStore.GetDirectoryNames(directory + @"\*");
  71.  
  72.     foreach (string dir in DirNames)
  73.     {
  74.         string mDir =
  75.             directory == @"\" ? directory + dir : directory + @"\" + dir;
  76.         foreach (string file in isoStore.GetFileNames(mDir + @"\*.*"))
  77.         {
  78.             Debug.WriteLine(file);
  79.         }
  80.         GetFiles(isoStore, mDir);
  81.     }
  82. }

 

Enjoy!

Mike

This work is licensed under a Creative Commons license.