Monday, June 09, 2008

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:

image

image

 

 

 

 

 

 

 

 

 

image

image 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.


Sunday, June 08, 2008 9:36:07 PM (Eastern Standard Time, UTC-05:00)
Greetings,

I have been very interested in your idea of promoting on how to do programming in mobile environment. I tried learning how to make a basic today screen before but was unable to find good examples of it. I am hoping that you may do one or maybe more than one application on today screen.
Tariq Niazi
Monday, June 09, 2008 3:35:54 AM (Eastern Standard Time, UTC-05:00)
Can you write some demos about creating advanced setup. How to create cab and raun it from PC and install it on Wince via ActiveSyn?
I mean explination about additional files, shortcuts, how to add shortcut that my prog will start every time pda starts... This would be very helpful!


Thanks!

Janez

Janez
Saturday, June 14, 2008 11:14:28 AM (Eastern Standard Time, UTC-05:00)
Thanks Tariq,

It's pretty involved to make a Today Screen plug in for Compact Framework. I'm considering it because it is a popular request. But here a white paper from Microsoft on how to do it. It is possible:

Creating a Pocket PC Today Screen Plug-in with the .NET Compact Framework

Thanks again,
Chris Craft
Saturday, June 14, 2008 11:18:11 AM (Eastern Standard Time, UTC-05:00)
Thanks Janez,

I like the idea. I've added it to my list. I will try to write two articles at some point, one introduction, and one advance to cover your topics. All of my applications use Smart Device CAB projects in Visual Studio to create the Cab file for installation on to Windows Mobile devices.

The easies way to install is to take the cab file and put it on the Inernet, and browse to it on the Windows Mobile device and it will install itself. :D How cool is that?

I'll try to do a full article this month! Thanks for the great idea!
Comments are closed.

Theme design by Jelle Druyts

Pick a theme: