Yesterday, I read the following suggestion for the 30 Days of .NET series.
| "How about a program to manually rotate from portrait to landscape, the millions of new HTC Diamond owners would love that " - Alex |
Lucky guy, the HTC Diamond is a gorgeous device. I mean really, really good looking device - if Scarlett Johansson were a phone good looking here.
Don't take my word for it. See for yourself:



On my HTC device there is an today plug-in named "HTC Home", that gives me an icon I can click on my today screen which will rotate my device's screen. See screen capture, I've converted everything else to grayscale.
This is a great little app, that does everything it claims it will do. Only thing is I hate it. I hate it because it doesn't do what I want it to do. It rotates through all four combinations of screen directions: top (0 degrees), left (90 degrees), bottom (180 degrees), and right (270 degrees). See that's the rub, never want to see my device upside down.
So basically, every time you click this icon the screen rotates 90 degrees, which means I have to go through what I consider two junk orientations, bleh.
I think we can do better.
This is probably going to be the easiest application we write. Thanks, Alex! ;D
I considered a few approaches to this application. I thought about following the same model as HTC and placing the application somewhere on the Today screen. Basically there are three ways to accomplish this. One we could write a today screen plug-in, but this isn't straight-forward in an managed application. There is a way to do it however: Creating a Pocket PC Today Screen Plug-in with the .NET Compact Framework.
Or we could create a task tray icon for our application. If you look right about the Contacts menu item in the bottom right of my screen, you can see three application task tray icons. Again, I felt this was more work than worth. But here how you could do it: Using the Microsoft .NET Compact Framework MessageWindow Class.
Finally, I though we could add an icon to the notification area at the top-right of the screen. If you'll look at my screenshot again you'll see where I have 6, count them 6, notification icons on my device. Everyone is doing this lately, and it starting to get out of hand lately. But if you like here's the information you'll need to accomplish this: Programmatically create and display Notifications.
So what was my solution? Well, I decided to leave well enough alone. This leaves the end user three choices, one assign the application to hardware button, to assign the application to a today screen plug-in that can launch other applications, and three to simply run the application manually. A lot of today screen plugs-ins have application launchers capabilities. Back to my screenshots, the today screen plug-in at the top of the screen allows for nine applications to be started from it. I've highlight the icon for Rotate Me, and made the rest the screen grayscale.
So how hard is it to check the screen orientation and change it? You tell me.
using Microsoft.WindowsCE.Forms;
if (SystemSettings.ScreenOrientation == ScreenOrientation.Angle0)
SystemSettings.ScreenOrientation = ScreenOrientation.Angle90;
else
SystemSettings.ScreenOrientation = ScreenOrientation.Angle0;
Here's a link to a blog post I did on How To: Assign an Application to a Windows Mobile Device's Hardware Button in case you need it.
Sometimes it is surprising just how much you can get for such little time and effort. That's the power of the .NET Compact Framework.
Well, that does it for today. Here are the binaries. Hope you enjoy them.
Download executable: rotateMe.cab
Download Source Code: rotateMe.zip
Feedback:
Thanks guys, it's been fun. Keep the ideas coming. Don't wait until the last minute. I hope these applications are helping you realize the raw rapid application development power of the .NET Compact Framework.