Friday, June 20, 2008

After the last GPS related application, GPS Compass, I’ve been wanting to do another GPS focused application. This time I figured we’d get in the driver’s seat with our friend: SPEED.

Gentlemen, start your engines…

image

Mobile Speedometer

The application is built off of  Windows Mobile 6 SDK included a GPS Application in the samples folder, C:\Program Files\Windows Mobile 6 SDK\Samples\PocketPC\CS\GPS.

This uses the GPS Intermediate Driver. If you are writing a location aware application for Windows Mobile this is definitely the way to go. ;)

The main UI is located at the top of the screen. We have a simple speedometer graphic in the background to add some flair to the application. On top of this we overlay the current speed based off of information returned from the GPS device. We can also use Fake GPS to simulate a GPS device.

Below this we have a readout of various GPS statistics that are updated continuously.

One thing to note is Speed may be return in knots which you will likely want to convert to either miles or kilometers.

 

 

 

 

We just need to create a method something like UpdateData below.

   1: void UpdateData(object sender, System.EventArgs args)
   2: {
   3:     if (gps.Opened)
   4:     {
   5:         if (position != null)
   6:         {
   7:             if (position.SpeedValid)
   8:             {
   9:                 labelSpeed.Text = (position.Speed/1.15077945).ToString("0.00");
  10:             }
  11:          }
  12:      }
  13: }

Possibilities:

I think a more realistic UI would be a great improvement. And the ability to switch from miles to kilometers would be good too. If the odometer would track miles traveled that would be an awesome enhancement.

Download executable: mobileSpeedometer.cab

Download Source Code: mobileSpeedometer.zip

Feedback:

Want more? What else would you like to see?


Friday, June 20, 2008 00:53:00 (Eastern Standard Time, UTC-05:00)  #    Comments [2]  |  Trackback
Thursday, June 19, 2008

How'd we make it this far without a weather application? I must admit its hard to buy anything these days that doesn’t have a weather feature built in. But does everyone understand the basic of writing such an application? That’s what we will explore today.

 

image

Mobile Weather

UI is a little plain. I really think a weather application needs to have a top notch exciting UI, but we’ll keep it simple this time. We have an input section at the top that takes the user’s ZIP Code, and we have an output section at the bottom.

In the output section we have some basic factoids like current conditions and temperature. We also have a forecast for the next day showing date, description, with high and low temperature. And finally we have a graphic to add a little something to an otherwise drab application.

How did we mine this information. Basically I connected to a public weather RSS feed that takes zip code as an URL parameter, using an HttpWebRespone object. I then parsed out the data I need using regular expressions.

There are other ways of doing this type of thing, but I thought this would allow us to use a lot of neat Window Mobile technologies we haven’t explorer before.

Our friend the HttpWebResponse:

   1: private void RefreshData()
   2: {
   3:     string lcUrl = "http://weather.yahooapis.com/forecastrss?p=" + textBoxZipCode.Text.TrimEnd();
   4:  
   5:     // *** Establish the request 
   6:     HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(lcUrl);
   7:  
   8:     // *** Set properties
   9:     loHttp.Timeout = 10000;     // 10 secs
  10:  
  11:     // *** Retrieve request info headers
  12:     HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();
  13:  
  14:     Encoding enc = Encoding.GetEncoding(1252);  // Windows default Code Page
  15:  
  16:     StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(), enc);
  17:  
  18:     string lcHtml = loResponseStream.ReadToEnd();
  19:  
  20:     RefreshScreen(lcHtml);
  21:  
  22:     loWebResponse.Close();
  23:     loResponseStream.Close();
  24: }

 

Last but not least the Regex object:

   1: string conditionsEx = @"<yweather:condition  text=""(?<desc>[^@]+)""  code=""(?<code>[^@]+)""  temp=""(?<temp>[^@]+)""  date=""(?<junk>[^@]+)"" ";
   2:  
   3: Regex regEx = new Regex(conditionsEx);
   4:  
   5: Match m = regEx.Match(input);
   6:  
   7: if(m.Success)
   8: {
   9:     desc = m.Groups["desc"].Value;
  10:     temp = m.Groups["temp"].Value;
  11: }

Possibilities:

The UI needs more polish, but it is useable. There is even more data in this RSS feed than I’m exposing so that is another way to expand on this project and make something awesome.

Download executable: mobileWeather.cab

Download Source Code: mobileWeather.zip

Feedback:

How could we make this application even better? Share your ideas with the community.


Thursday, June 19, 2008 01:59:00 (Eastern Standard Time, UTC-05:00)  #    Comments [0]  |  Trackback
Wednesday, June 18, 2008

Being a geek, I have a lot of geek friends. Being friends, we tend to eat lunch together. The only problem is sometimes we have a hard time deciding where to go to eat lunch. This invariably leads to the “Where do you wanna eat?”, “I dunno, where do you wanna eat go?”, “It doesn’t matter to me, you decide.” Well here is a simple solution to this daily dilemma:

 

image

Lunch-O-Matic

Our UI has just enough class to be exciting and interesting, yet simple enough not to cause us too much grief. Seek balance in all things. The concept: restaurant logos flash across the screen, eventually stopping on the chosen food establishment. The application is visual, which is appealing. The application is clear. The user can easily tell which restaurant is chosen by following the ginormous arrow. A light blue background give the app a little warm and the arrow adds character.

We have a folder called LunchLogos. Any png file found is the folder is added to an generic image list at the start of the program. When the user clicks Spin, the logos are randomly displayed on the screen for a random number of times before stopping on a chosen eatery.

If you don’t like a restaurant all you have to do is remove the logo from the folder. If you have a restaurant you like that isn’t in the list all you have to do is add the logo to the same folder, simple, simple.

Again for this application we used the RNGCryptoServiceProvider class to generate a statistically sound random number.

   1: private int GetRandomNumber(int minValue, int maxValue)
   2: {
   3:     // Use a 4-byte array to fill it with random bytes and convert it then
   4:     // to an integer value.
   5:     byte[] randomBytes = new byte[4];
   6:  
   7:     // Generate 4 random bytes.
   8:     RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
   9:     rng.GetBytes(randomBytes);
  10:  
  11:     // Convert 4 bytes into a 32-bit integer value.
  12:     int seed = (randomBytes[0] & 0x7f) << 24 |
  13:                 randomBytes[1] << 16 |
  14:                 randomBytes[2] << 8 |
  15:                 randomBytes[3];
  16:  
  17:     // Now, this is real randomization.
  18:     Random random = new Random(seed);
  19:  
  20:     return random.Next(minValue, maxValue);
  21: }

And we have created a simple randomize list function to mix things up a bit.

   1: public void RandomizeList(List<string> arrayList)
   2: {
   3:  
   4:     if (arrayList == null) { return; }
   5:     int count = arrayList.Count;
   6:     for (int i = 0; i < count; i++)
   7:     {
   8:         string tmp = arrayList[i];
   9:         arrayList.RemoveAt(i);
  10:         arrayList.Insert(GetRandomNumber(0, count), tmp);
  11:     }
  12: }

Last but not least, we use the Mod function to make sure we can loop around the list when picking images.

   1: private void Spin()
   2: {
   3:     int index1 = GetRandomNumber(0, logos.Count);
   4:     int index2 = (index1 + 1) % logos.Count;
   5:     int index3 = (index2 + 1) % logos.Count;
   6:  
   7:     pictureBoxTop.Image = logos[index1];
   8:     pictureBox.Image = logos[index2];
   9:     pictureBoxBottom.Image = logos[index3];
  10: }

Possibilities:

Well, I think it would be cool if there was a background sound to go along with the spin. I also think a UI for adding and deleting logos would be great. It would be nice to be able to assign weights to each restaurant, and to favor new choices over previously selected places.

Download executable: lunchomatic.cab

Download Source Code: lunchomatic.zip

Feedback:

How could we make this application even better? Share your ideas with the community.


Wednesday, June 18, 2008 00:11:00 (Eastern Standard Time, UTC-05:00)  #    Comments [0]  |  Trackback
Monday, June 16, 2008

I’ve had a lot of requests for SMS related applications. So today we will create a SMS logger application. This application will allow users to scroll through a listing of all the SMS / text messages they have received while the application has been running.

 

image

SMS Logger

This is a great application for a beginner to create. It has a very simple UI, the main component is the WebBrowser. The way we can have nicely formatted text easily.

The key piece of code here is the MessageRecieved event off of the SmsIntercepter object.

   1: private StringBuilder documentText = new StringBuilder();
   2: void SmsInterceptor_MessageReceived(object sender, MessageInterceptorEventArgs e)
   3: {
   4:     if (enableInterceptor == false)
   5:         return;
   6:  
   7:     // Cast to SmsMessage to access message body
   8:     // Not expecting to receive any non-SMS messages but use "as" to
   9:     // cast to be extra safe
  10:     SmsMessage newMessage = e.Message as SmsMessage;
  11:     if (newMessage != null)
  12:     {
  13:         documentText.AppendFormat(@"<b>Body:</b> {0}<br/>", newMessage.Body);
  14:         documentText.AppendFormat(@"<b>Name:</b> {0}<br/>", newMessage.From.Name);
  15:         documentText.AppendFormat(@"<b>Address:</b> {0}<br/>", newMessage.From.Address);
  16:         documentText.AppendFormat(@"<b>Last Modified:</b> {0}<br/>", newMessage.LastModified);
  17:         documentText.AppendFormat(@"<b>Received:</b> {0}<br/>", newMessage.Received);
  18:         documentText.Append(@"<br/>");
  19:  
  20:         webBrowser.DocumentText = documentText.ToString();
  21:     }
  22: }

We have a few actions the user do: Start, Stop, Clear, About, and Exit.

Possibilities:

This application logs incoming SMS messages, but it doesn’t do several thing that were requested from our reader. It doesn’t log outgoing messages. It doesn’t save to a text file. And it doesn’t clear out data from Outlook Mobile when the users runs SMS Logger.

I also think there is room to improve the UI. I think some small 16x16 pixel graphic files could really add some life to the application. Maybe one icon for incoming messages, and one for outgoing messages.

So who’s up to it? Anyone want to take this application to the next level? Just let me know.

 

Download executable: smsLogger.cab

Download Source Code: smsLogger.zip

Feedback:

So what possibilities do you see for this type of application? for business? for entertainment?


Monday, June 16, 2008 22:30:00 (Eastern Standard Time, UTC-05:00)  #    Comments [1]  |  Trackback

Today, is day 15 of my 30 Days of .NET challenge. That marks the 50% point, and we have 15 applications for 15 days. Thanks for your support!

And we have made it through another week. If you missed the week one recap here it is: 30 Days of .NET [Windows Mobile Applications] - Week One.

What’s your favorite?

 

image image image image
Rotate Me Mobile Tipper What is My IP? Mobile Signature

Lots of variety, everything from network utilities, to graphics, to humor, to SMS text messaging. Great ideas, guys!

 

image image image image_thumb14
Mobile Quiz Pocket Death Calculator Mobile SMS Contact What will be next?

 

Feedback:

Got an idea? Got some feedback? Share it? Thanks!


Monday, June 16, 2008 02:48:00 (Eastern Standard Time, UTC-05:00)  #    Comments [7]  |  Trackback

Today’s application is about possibilities. It’s a new area we will explore in our future applications. It’s important to learn how to development applications, but it is also important to learn what kind of applications you can develop. Your goal is always to reach just a little further, and grow from the experience.

 

The important thing here isn’t what this application does with these ideas, but what you could do with these ideas.

 

People can use SMS to send and receive information through text messages, but with the power of Windows Mobile it is easy for application to send and receive commands and data. There is a big movement for software to expose its features and functions to other programs. But image a world, that probably isn’t too far, where your mobile device has it’s own API that you and others can use to access its data and functions.

Where could this be useful? Well many companies need the ability to send “Alerts” of some kind to their workers. It is easy to use the Windows Mobile SMS API to have a custom written application that check for specially “tagged” SMS messages.

 

image

Mobile SMS Remote

SMS Remote is an application that could run on two or more Windows Mobile device and allow each of the phones run to support “commands” on the phones. For example, a user could get the date and time of another device running SMS Remote. Or the user could run a command to get the other phone’s current GPS location information. The possibilities are limitless. Both devices are both servers and both clients in other words a very simple peer-to-peer network using SMS technology. How cool is that?

What if sometimes we don’t want others to be able to run commands on our device remotely? First of all we could always exit the application. The application must be running in other to execute remote commands. Be I have also added an “Allow Remote Commands” feature.

How can we send SMS remote commands? Use the SMS command ComboBox and choose a command, and enter the remote device’s phone number. Then just click “Send”.

How can we tell what commands have been remotely run on our device? There is a received commands listing at the bottom the screen. It shows the phone number of the device that send the command, the time the command arrive, and which command was requested.

This is a rough prototype of an idea that has HUGE potential. Some point in the next ten years this concept will take off and become something along the lines of Mobile 2.0.

The trick to this application is using the very cooly named Windows Mobile 6.0 SDK MessageInterceptor class. We can use it to have any SMS that begins with “30days:” fire an event in our application that we will then handle. This is very, very, very simple for something so powerful. Use it!

   1: MessageInterceptor _smsInterceptor = null;
   2: private void LoadSmsIntercepter()
   3: {
   4:     _smsInterceptor = new MessageInterceptor(InterceptionAction.NotifyAndDelete);
   5:  
   6:     _smsInterceptor.MessageCondition =
   7:         new MessageCondition(MessageProperty.Subject,
   8:         MessagePropertyComparisonType.StartsWith, "30days:", true);
   9:     _smsInterceptor.MessageReceived += SmsInterceptor_MessageReceived;
  10: }

The rest is simple. Was the SMS a “command” or a “result”? If command we need to run and return a result. If result we need to act on or display to device user.

Possibilities:

I implemented the get date and time function, but not the GPS function. This would be a very useful addition to the application that I would love to say a reader did. Or how about a way to add Internet Explorer Mobile favorites? Or how about something more Web 2.0 like what song is currently playing.

Download executable: mobileSMSRemote.cab

Download Source Code: mobileSMSRemote.zip

Feedback:

So what possibilities do you see for this type of application? for business? for entertainment?


Monday, June 16, 2008 01:58:00 (Eastern Standard Time, UTC-05:00)  #    Comments [2]  |  Trackback
Sunday, June 15, 2008

Today one of my readers, Paul Diston, made the following request.

Hi,
I have another idea you might be interested in. I would like to be able to type in a single SMS message and then hit the send button which would then send the same message to all my contacts that have a mobile number specified.


Thanks
Paul Diston

The thing that I really liked about Paul’s suggestion is that is cover two very important mobile development topics: one is working with contacts stored in Outlook Mobile, and the other is working with SMS messaging.

image

image Mobile SMS Contact

I changed it a little bit from Paul’s original request. I decided to incorporate a filter into the application. This way you can send SMS messages to your personal contacts, or your business contacts. You could even create a custom category. I didn’t include an option to select contacts that do not have a category assigned to them. This would be a great modification for a reader to implement. Simply add a ‘<none>’ item to the list, and if that item is selected add any contact that doesn’t have a category.

I added a ListView so that users could see the contacts they were about to text message. Another great enhancement, would be the ability to modify this listing. Just a remove option would be a great addition in functionality.

One feature I added as a polishing touch, was the live character count feature. This feature lets users know how much more text they can send. And we have found another opportunity for improvement here. I limit the text to 160 characters, but if someone entered in more text we could send X number of text messages until the complete message was delivered.

Next with have our SMS Message TextBox where we can type the message we will send. Nothing special here, but I didn’t set a MaxLength of 160 characters.

At the bottom I exposed the RequestDeliveryReport property of the SmsMessage class. What ever the user picks here will be assigned to that property.

One feature that I really love about Windows Mobile programming, that especially came in useful for this application was the Cellular Emulator.

GetContacts Code:

   1: private List<Contact> GetContacts(string category)