Ranting and raving about anything I feel like complaining about.

Phoney Windows Phone 7 Project Now Available!

Url: http://phoney.codeplex.com/

Silverlight Logo

UPDATE: Phoney now has a NuGet package.  Search on NuGet to add Phoney to your project!

I started this project when I found I had a number of small classes that I'd built for my Windows Phone 7 application so I thought it was time to share. here is the information on the new library.  

It is currently in a very early Alpha stage, but I expect to have it at a release version by MIX 11 (Mid-April). Let me know what you think!

Project Description

This is a project that contains several classes and controls for use with Windows Phone 7 applications. There are plans for:

  • Standard Set of Converters
  • Several Controls
  • BitlyHelper
  • TwitterHelper
  • PhoneLogger
  • ObservableObject
  • FadingMessage class

Exposing all the Phone Resources (e.g. PhoneTextSizeLarge) as staticly typed accessors

Current Version is 0.1.

Only the following features are included:

  • BitlyHelper
  • PhoneLogger
  • FadingMessage
  • ObservableObject
  • Phone Resources

Examples:

BitlyHelper class

Simple class for shortening URI's using your own Bit.ly API Key/username:

BitlyHelper.SetCredentials("MYBITLYAPIKEY", "MYBITLYUSERNAME");
BitlyHelper.Shorten("http://phoney.codeplex.com", (result, error) =>
  {
    if (error != null)
    {
      MessageBox.Show(string.Concat("Error Shortening Url: ", 
                                    error.Message));
    }
    else
    { 
      MessageBox.Show(result, 3000);
    }
  });

FadingMessage class

This class is to create messages that show up as a popup that fades in and fades out. For simple messages:

FadingMessage.ShowTextMessage("Saved...");

You can control the look and contents of the message by supplying your own UI objects:

FadingMessage msg = new FadingMessage()
{
  MessageToShow = theMessage,
  VerticalAlignment = VerticalAlignment.Top,
  HorizontalAlignment = HorizontalAlignment.Right
};
msg.Show(3000); // 3 seconds

PhoneLogger class

This class is to save a simple log file in Isolated Storage and can retrieve the contents of the log on demand:

PhoneLogger.LogError("Test Logging Message");

var log = PhoneLogger.LogContents;

ObservableObject class

This is an abstract class that supports the INotifyPropertyChanged interface for ease of hand-building objects that need observation.

public class MyObject : ObservableObject
{
}

Phone Resources

All of the known phone resources have accessors to give you strongly-typed access to the phone-based resources. Static Classes include:

 

  • PhoneColors
  • PhoneBrushes
  • PhoneFontSizes
  • PhoneFontFamilies
  • PhoneTextStyles
  • PhoneThicknesses

 

var theContainer = new Border()
{
  Background = PhoneBrushes.PhoneContrastBackgroundBrush,
  BorderBrush = PhoneBrushes.PhoneBorderBrush,
  BorderThickness = PhoneThicknesses.PhoneBorderThickness,
  CornerRadius = new CornerRadius(5)
};

theContainer.Child = new TextBlock()
{
  Margin = PhoneThicknesses.PhoneMargin,
  TextWrapping = TextWrapping.Wrap,
  Style = PhoneTextStyles.PhoneTextNormalStyle,
  Foreground = PhoneBrushes.PhoneAccentBrush,
  Text = message
};

In addition a PhoneTheme class that gives you a simple way to test for which theme (light or dark) the phone is using:

if (PhoneTheme.IsDarkTheme)
{
  // Change something because it's dark
}
else
{
  // Change it because it's light
}

 

What do you think?

 
 

Comments

Gravatar Great work Shawn (as always) but i'd consider changing the name of the project :-).
First few times I saw the name I dismissed it and moved on. Only after seeing a review article did I eventually wander over adn glad I did.

Quick, simple and to the point, like an entire extension library for the phone dev tool set.

Other Point, NuGet will only be useful for full VS owners since it's not available for C# express (only Web Express)
Gravatar Sweet - I will definitely be using some - if not all of these!

Thanks Shawn
Gravatar I have one suggestion for the FadingMessage. If another message is shown it doesn't obliterate the previous but grows the box to accommodate it. Then when the time is up for the first message it is removed and the box shrinks to just show the second.
Gravatar Jason,

Feel free to grab the code and implement it and send me a patch. If I like the way it works, I'd be happy to include it.
Gravatar Simon,

Thanks for the encouragement. I know that NuGet doesn't work for the Visual Studio Express edition for WP7, but I am hoping to get MS to change that (it works with Express for Web BTW so its possible).

Also, I was guilted into it by Tim Heuer since it takes like 3 minutes to create it (after the 10 minutes of learning how)!
Gravatar Hi Sean,

I've been playing around with the FadingMessage and got it to stack messages. I've zipped up the solution and put on my SkyDrive http://cid-8b68e525e8197d5c.office.live.com/self.aspx/Public/PhoneyToolsWithStackingFadingMessage.zip

A few compromises I'm afraid. I had to use a StackPanel for the host which means the messages are shown at the top of the page (although I guess we could put it inside a grid to get to to center again).

I also had to implement instance rather than static versions of the ShowTextMessage methods (and called them ShowMessage).

If you want to take a look I have used your Test Long Message button to use the stacking method.

Obviously feel free to chop change or ignore anything I have done :) and thanks for the kick start on getting me what I needed,

Jason


Add a Comment

*
*
*