Random babblings about creating, using and generally considering software.
Friday, December 17, 2010
CPVanity for Windows Phone
So here's a WP7 port of it as a small homage. It's up on the marketplace too.
Wednesday, December 15, 2010
Handy Windows Phone 7 resources
- GalaSoft's MVVM Light - for MVVM support (Commands, ViewModel, Mediator etc.). It nice and lightweight and present a good framework on the phone platform
- The Silverlight for Windows Phone Toolkit - for some additional controls like the WrapPanel. Plus transitions and other miscellaneous good stuff not included in the SDK
- The PhoneHyperlinkButton - It handles executing different Launchers and Choosers based on the protocol of the link. For instance it starts the WebBrowserTask for non-relative urls, or the PhoneCallTask for "tel:" etc. Really saves a lot of plumbing and makes it quite easy to invoke those thingys.
- The TiltEffect - attaches to all the Buttons you create and makes them have the tilting behavior when they are pressed. Gives your app the same feel as the built in ones.
- A good set of Metro UI icons
- The Silverlight MD5 implementation - it's not built in and sometimes you just need it.
- The code on this page for preserving and restoring UI state on pages - definitely helps dealing with page lifecycle and UI transient state.
- This CustomIndeterminateProgressBar - it moves the animating off of the UI thread and onto the compositor thread so it looks much smoother.
- A nice visual summary of the pre-defined phone styles.
Wednesday, December 8, 2010
A helper class to get the current location on a Windows Phone just once
There are some instance where you may not a running notification of the current potion but just want the current position (for instance you may want to initialize the position on a map but not track changes to position).
So this is a small helper class that starts up the coordinate watcher asynchronously, returns the first coordinate found and then shuts it down. One could use TryStart like so:
using (var watcher = new
GeoCoordinateWatcher(GeoPositionAccuracy.Default))
{
var location = watcher.TryStart
(false, TimeSpan.FromMilliseconds(1000));
}
but since that will block your UI thread (assuming you call it from the UI) you'd need to wrap it in some asynchronous stuff anyways.So I use this class:
public class ImmediateLocation : IDisposable
{
private GeoCoordinateWatcher _watcher;
private Action<GeoCoordinate> _action;
public ImmediateLocation(Action<GeoCoordinate> a)
{
Debug.Assert(a != null);
_action = a;
}
public void GetLocation()
{
if (_watcher == null)
{
_watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
_watcher.MovementThreshold = 1000;
_watcher.PositionChanged += new
EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>
(_watcher_PositionChanged);
_watcher.StatusChanged += new
EventHandler<GeoPositionStatusChangedEventArgs>
(_watcher_StatusChanged);
_watcher.Start(false);
if (_watcher.Status == GeoPositionStatus.Disabled
|| _watcher.Permission == GeoPositionPermission.Denied)
Dispose();
}
}
void _watcher_StatusChanged(object sender,
GeoPositionStatusChangedEventArgs e)
{
if (e.Status == GeoPositionStatus.Disabled
|| _watcher.Permission == GeoPositionPermission.Denied)
Dispose();
}
void _watcher_PositionChanged(object sender,
GeoPositionChangedEventArgs<GeoCoordinate> e)
{
_action(e.Position.Location);
Dispose();
}
public void Dispose()
{
if (_watcher != null)
{
_watcher.Stop();
_watcher.PositionChanged -= new
EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>
(_watcher_PositionChanged);
_watcher.StatusChanged -= new
EventHandler<GeoPositionStatusChangedEventArgs>
(_watcher_StatusChanged);
_watcher.Dispose();
}
_watcher = null;
_action = null;
}
}Then you can just do this:
void InitLocation()
{
var immediate = new ImmediateLocation(x => location = x);
immediate.GetLocation();
}
GeoCoordinate location;It acts like a one time use, fire and forget location setter that cleans itself up when done. It does have Dispose if you want to mange the lifetime more closely.CodeProject
Thursday, December 2, 2010
Got a WP7 app published
It's published now on the app hub. So that's pretty cool.
CodeProject
Thursday, November 25, 2010
Lesson's learned from my first WP7 App submission
I developed the app completely using the Dark theme on my phone and the emulator. Lo and behold switch it to Light and some parts of it were unreadable, especially the ApplicationBar. My first submission was rejected because of this. Other parts just didn't all that good on the Light theme. We'll see how swing #2 goes...
Lesson 2: Don't set the ApplicationBar colors unless you really want those colors on both themes.
You can't DataBind them and they will be switched automatically per Theme by WP7, but not if you have set the colors by hand in your XAML.
Lesson 3: Don't use color icons on the ApplicationBar
Again, they may look great on the dark theme but switch to the Light theme and they will be drawn as black outlines at best, black blobs at worst. Use White on Transparent icons. They look fine on both themes. There are some good ones online. Don't include the outer circle (the app bar adds it) and set the image itself to 24x24.
CodeProject
Wednesday, October 13, 2010
I'm actually getting excited for Windows Phone 7
I've always been a nerd for mobile devices. I buy new phones more often than is wise; mostly just to see the latest technology. For years I had Windows Mobile based phones and even convinced myself that I liked them. The HTC Touch (WM 6) almost bordered on not sucking, but deep down I knew that Windows Mobile was slow, clunky and had the worst of the two worlds of PDA and Phone. I even had a WM SmartPhone once but don't get me started (I never did buy a SmartWatch though).
Finally, a year or so ago, after the umpteenth hard-rest to get my Window Mobile device to actually work as a phone again, I gave up and bought a BlackBerry. It's worked but I've never really liked it.
But now Windows Phone 7 has launched. And I gotta say it looks cool. No more Windows 95 trying to be a mobile OS. And it looks interestingly enough different from iOS and Android to have me curious. Plus I have a reasonable chance of being able to jump start some app development without having to learn the Eclipse/Java/Android stack and there's no way in hell I'll have the time to figure out to develop on a Mac with Objective C.
I've got the SDK and have already whipped up a quick app. Now all I need is a new phone.
The temptation is killing me. It's probably a foregone conclusion at this point.