martedì 13 novembre 2012

myTasks for Windows Phone

With myTasks you can manage your daily tasks in easy steps.


Change the priority with a double tap and customize the UI as you wish.
Complete and restore the tasks with one tap.
If need, set the due date and/or the reminders.
With the new version you can backup and restore your data via SkyDrive.

UI customizations:
  • Task color
  • Priority color
  • Task font size
  • Priority font size
  • Live Tiles

Check the Marketplace and buy myTasks for only 0.99$.

QRCode

sabato 10 novembre 2012

NowPlaying for Windows Phone

With NowPlaying you can listen your music and share the #NowPlaying hashtag in Twitter, Facebook and the other networks.


Gestures control:
  • Open your media library.
  • Play or pause the music.
  • Move to next or previous song.
  • Share your #NowPlaying status.



More features:
  • Live Tile customizable with the last song played.
  • Select your #NowPlaying style from the default formats or create your own with the simple editor: you have the full control.
  • Disable the Lockscreen from the application.

Check NowPlaying in the Marketplace and remember to swipe down to share!

QRCode

domenica 4 novembre 2012

Windows 8 - Images and DPI

Windows 8 is DPI aware then the applications auto-scale images according to DPI and screen resolution:
  • 100% when the scale is not applied.
  • 140% when the screen resolution is 1920x1080 and for all devices with minimum 174 DPI.
  • 180% when the screen resolution is 2560x1440 and for all devices with minimum 240 DPI.

The developer can use vectorial elements like SVG or XAML without problems.

Otherwise when the developer uses the images raw, bitmap, png or jpg, he needs to create a file for every case.

He can explicit the scale factor in the file extension:
\myLogo.scale-100.jpg
\myLogo.scale-140.jpg
\myLogo.scale-180.jpg

Or use the folder convention:
\scale-100\myLogo.jpg
\scale-140\myLogo.jpg
\scale-180\myLogo.jpg

When the application don't has static images, it's possible to create a logic to have the same result from code behind.
switch (DisplayProperties.ResolutionScale)
{
 case ResolutionScale.Scale100Percent:
  img.Source = new BitmapImage(new Uri("url?s=100"));
 break;
 case ResolutionScale.Scale140Percent:
  img.Source = new BitmapImage(new Uri("url?s=140"));
 break;
 case ResolutionScale.Scale180Percent:
  img.Source = new BitmapImage(new Uri("url?s=180"));
 break;

 default:
 // some exception
}

The class DisplayProperties has some event to help the developer:
  • ColorProfileChanged: when the color profile changes.
  • LogicalDpiChanged: when the the pixel per inches (PPI) changes.
  • OrientationChanged: when device orientation changes.
  • StereoEnabledChanged: when the property StereoEnabled changes (3D stereoscopic).


domenica 28 ottobre 2012

Windows Phone - Localization

When you publish a Windows Phone application in the Marketplace, you have more visibility if you support the region language.

An easy way to build a localized app is to use resources file (.resx).

First of all remember to set the default "neutral" language in the project properties! This is an important step because the "AppResources.resx" file is used from all not specified languages.

Add new file, and name it "AppResources.resx" for default language. For a new language, just add a new resource named with the CultureInfo ISO letters:
  • AppResources.it-IT.resx for italian language.
  • AppResources.cs-CZ.resx for czech language.
  • AppResources.fr-FR.resx for french language.
  • etc..
Remember to set all resource files to the public access modifier.



Now unload your project and edit the csproj file to add your supported language:
<SupportedCultures>it-IT;en-US;cs-CZ;fr-FR</SupportedCultures>

Create a class to get your resources.

public class LocalizedStrings
    {
        private static AppResources localizedResources = new AppResources();

        public AppResources Strings
        {
            get
            {
                return localizedResources;
            }
        }
    }

In your xaml you need to declare your class as resource:
<phone:PhoneApplicationPage.Resources>
     <local:LocalizedStrings x:Key="LocalizedStrings"/>
 </phone:PhoneApplicationPage.Resources>

Now you can use your localized string like this:
Text="{Binding Strings.Loading, Source={StaticResource LocalizedStrings}}"
Or from code behind:
txtLoading.Text = AppResources.Loading;

To test your app you can insert this code in application launching event:
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("it-IT");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT");

All CultureInfo codes here.

venerdì 19 ottobre 2012

Windows Phone - Get Album Art

When you use MediaPlayer class in Windows Phone, usually you want to get the album cover for the current song.
You can access the current track with the ActiveSong property. This property is exposed by the Queue of MediaPlayer. Then you can check out the album art.

This code is all you need:

if (MediaPlayer.Queue.ActiveSong.Album.HasArt)
{
 BitmapImage bmp = new BitmapImage();
 bmp.SetSource(MediaPlayer.Queue.ActiveSong.Album.GetAlbumArt());
 imgAlbum.Source = bmp;
}

sabato 6 ottobre 2012

Equality Comparer with Lambda

Today, it's normal to write code with LINQ and Lambda Expressions.
But when you need to use IEqualityComparer, it's not possibile to use a lambda predicate.
The Interface needs a class, then you have to create a new type that inherit from IEqualityComparer.

You can use this workaround:
 
public class EqualityComparer<T> : IEqualityComparer<T>
{
   private Func<T, T, bool> _fnEquals;
   private Func<T, int> _fnGetHashCode;
   public EqualityComparer(Func<T, T, bool> fnEquals, Func<T, int> fnGetHashCode)
   {
      _fnEquals = fnEquals;
      _fnGetHashCode = fnGetHashCode;
   }
   public bool Equals(T x, T y)
   {
      return _fnEquals(x, y);
   }
   public int GetHashCode(T obj)
   {
      return _fnGetHashCode(obj);
   }
}

The simple usage is:

 
Dictionary<int, string> d = new Dictionary<int, string>() { { 1, "a" }, { 2, "a" }, { 3, "b" } };

var d2 = d.Distinct(new EqualityComparer<KeyValuePair<int, string>>((kvp1, kvp2) => kvp1.Value == kvp2.Value, kvp => kvp.Value.GetHashCode()));

lunedì 24 settembre 2012

Windows Phone - Settings Page in 5 minutes

The best user experience for a settings page is: stay away from the save button.

People don't love to press the back button and lose all settings. Then it's better to save when the user does something.

Thanks to Jerry Nixon you can use this code and have a base framework for all your applications.

    public static bool EnableLocation
    {
        get { return Get("EnableLocation", false); }
        private set { Set("EnableLocation", value); }
    }

    public static event PropertyChangedEventHandler SettingChanged;

    private static T Get<T>(string key, T otherwise)
    {
        try
        {
            return (T)IsolatedStorageSettings.ApplicationSettings[key];
        }
        catch { return otherwise; }
    }

    private static void Set<T>(string key, T value)
    {
        IsolatedStorageSettings.ApplicationSettings[key] = value;
        if (SettingChanged != null)
            SettingChanged(null, new PropertyChangedEventArgs(key));
    }

The code is very easy:
  • the "Get" function return the default value if the key don't exists.
  • the "Set" function uses an event to immediatly reflect changes into your apps.
  • the functions use "Generics".

Enjoy!