Friday, June 13, 2008

Today we are going to look at another classic goal in Mobile development, data collection. You might need it for a line of business application, for example a field service application where workers need to inspection equipment and fill out a questionnaire. Or you might need it in a mobile poll taker application. You could even use it in a trivia game. There are few applications actually that couldn’t take advantage of a question and answer system like the Mobile Quiz.

 

image

imageMobile Quiz

There is so much potential with this application. I hope you can see the concept and see the potential here. There are a world of possibilities here. Hopefully this application will help you get ever so slightly closer to realizing some of them.

The UI is a straight-forward and clean design, which was easy to make but should appeal to users. Everything is meant to be intuitive and self explanatory. Users should simple be able to look at the screen and get it.

The first screen is an quiz introduction form. All we have here is some eye candy, the name of the quiz, and some basic menu options: Start, About, and Exit.

After this the user is presented with the questions screen. This is the main meat of the application.

Questions are pulled from an XML file which could be retrieved from a remote server.

 

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <quiz name ="Family Guy Quiz">
   3:   <question>
   4:     <text>In what state do the Griffins live?</text>
   5:     <correct>2</correct>
   6:     <answer>Connecticuit</answer>
   7:     <answer>Rhode Island</answer>
   8:     <answer>Massachusetts</answer>
   9:     <answer>Deleware</answer>
  10:     <answer>South Carolina</answer>
  11:   </question>
  12:   <question>
  13:     <text>What television actor is the mayor of the town?</text>
  14:     <correct>1</correct>
  15:     <answer>Adam West</answer>
  16:     <answer>David Hasselhoff</answer>
  17:     <answer>Leonard Nimoy</answer>
  18:     <answer>William Shatner</answer>
  19:     <answer>Harrison Ford</answer>
  20:   </question>
  21:   <question>
  22:     <text>What is Cleveland's last name?</text>
  23:     <correct>1</correct>
  24:     <answer>Brown</answer>
  25:     <answer>Smith</answer>
  26:     <answer>Craft</answer>
  27:     <answer>Cub</answer>
  28:     <answer>Jones</answer>
  29:   </question>
  30:   <question>
  31:     <text>What is the name of Stewie's stuffed bear?</text>
  32:     <correct>3</correct>
  33:     <answer>Barry</answer>
  34:     <answer>Chris</answer>
  35:     <answer>Rubert</answer>
  36:     <answer>Edward</answer>
  37:     <answer>Paddy</answer>
  38:   </question>
  39:   <question>
  40:     <text>What is Quagmire's profession?</text>
  41:     <correct>4</correct>
  42:     <answer>Developer</answer>
  43:     <answer>Police Office</answer>
  44:     <answer>Barber</answer>
  45:     <answer>Pilot</answer>
  46:     <answer>Teacher</answer>
  47:   </question>
  48: </quiz>

 

It’s a snap to open the XML file and read in all of our data.

   1: DataSet dataSet = new DataSet();
   2: // read quiz data file
   3: dataSet.ReadXml(@"\Program Files\MobileQuiz\quiz.xml");

One thing that I decided was important was to avoid showing modal MessageBox dialogs often. Sick Instead I choose to use a label, place it at the top, set it’s background color to Info, and use it accordingly. This works out great and I think is a much better user experience. Data entry on a mobile device is a huge pain, and if you can take a dialog out of the equation that’s a good thing.

Download executable: mobileQuiz.cab

Download Source Code: mobileQuiz.zip

Feedback

There’s a lot here for a little effort, a couple hours, and there is a huge potential for this type of application. This would be a great project for someone to expand on and create something really special from. Consider it if you are looking for your first mobile project.


Friday, June 13, 2008 02:49:00 (Eastern Standard Time, UTC-05:00)  #    Comments [0]  |  Trackback
Thursday, June 12, 2008

image

You know sometime someone tells you about something, and you can tell there is a whole lot more to it than they are telling you about. Well, signature capture for Windows Mobile is one of those things. It’s really not bad today and you can do it in one sitting easily now. But there was a time, when if your life depending on it you might be able to get it right. At least we have managed code now. A few of us attempted to do this feat in embedded Visual Basic years ago and I’m surprised it didn’t cost us our sanity. Oh the humanity…

You could do it you just had to copy each color pixel by pixel and save it into a bitmap, and that was a challenge too. And GetPixel() had to be the slowest function call ever. It took at least a second. No way, you were going to give someone a full screen to put there signature.

That was then, this is now…

image

Mobile Signature

Office 2007 might have 2007 features in it. And it works for Office 2007, well to a point. But with Windows Mobile applications less is more. Don’t get me wrong I really do think Mobile Signature would make a great feature in a more complete application. But as far as the feature of taking a signature on a mobile device this is a great approach.

Also note that Mobile Signature could be easily adapted into a drawing application, and so on, especially for kids.

Let’s talk about UI first. Notice how much space is dedicated to taking the user’s signature. This is important; I’ve seen almost the reverse before and that just isn’t very usable. I took a little extra time and care to make sure all control had a black border around them,expect the black color square. It has a gray border.

One thing to note is a wanted the user to be able to tell what color they would be writing in without having to draw on the screen. This is accomplished by having the borders around the active color flash on and off. This is a great visual effect that was easy to implement with a timer. We track the currently active color in a form level variable, and on the timer tick event, which happens every 500 ms, we toggle the visibility of the border around the active color. Works great! Check it out!

The menu is another area that is simple but you can learn from it. Save is very important to us, so it is prominent and has it own hardware button that can cause it to occur. On the menu we have an option for clearing the screen, showing the about form, and exiting the application. But we also have a menu option to change the size of the line we are drawing with. It can be set from any of the following: 1 pixel, 3 pixels, 5 pixels.

The core of the application is the code that actually draws the lines on the screen. Here it is:

   1: private void pictureBox_MouseMove(object sender, MouseEventArgs e)
   2: {
   3:     if (pen.Color != signatureColor)
   4:         pen = new Pen(signatureColor);
   5:  
   6:     if (pen.Width != width)
   7:         pen.Width = width;
   8:  
   9:     x1 = x2;
  10:     y1 = y2;
  11:     x2 = e.X;
  12:     y2 = e.Y;
  13:  
  14:     if (x1 == -1 && y1 == -1)
  15:         return;
  16:  
  17:     pictureBoxSignature.CreateGraphics().DrawLine(pen, x1, y1, x2, y2);
  18: }

 

One area of code that is worth checking out is the code to save the bitmap of the signature. It’s pretty advanced and powerful.

   1: // P/Invoke declaration
   2: [DllImport("coredll.dll")]
   3: public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
   4:  
   5: const int SRCCOPY = 0x00CC0020;
   6:  
   7: private void Save(string filename, Graphics gx, Rectangle rect)
   8: {
   9:     Bitmap bmp = new Bitmap(rect.Width, rect.Height);
  10:     // Create compatible graphics
  11:     Graphics gxComp = Graphics.FromImage(bmp);
  12:     // Blit the image data
  13:     BitBlt(gxComp.GetHdc(), 0, 0, rect.Width, rect.Height, gx.GetHdc(), rect.Left, rect.Top, SRCCOPY);
  14:     bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Bmp);
  15:     // Cleanup
  16:     bmp.Dispose();
  17:     gxComp.Dispose();
  18: }

Everything else is pretty straight forward, but check it out and see what you think!

Download executable: mobileSignature.cab

Download Source Code: mobileSignature.zip

Feedback

So, how do you guys feel about line of business applications? Do you want more days that focus on line of business application topics? or less? Let me know! :D Tomorrow will be here before you know it.


Thursday, June 12, 2008 02:48:00 (Eastern Standard Time, UTC-05:00)  #    Comments [2]  |  Trackback
Wednesday, June 11, 2008

I mentioned to the group that I would post the Prize Picker application we wrote together on my blog as part of my 30 Days of .NET series. I think this was an awesome idea, and it looked like everyone really enjoyed themselves. Hopefully, a few of them will see this post and share their thoughts as well. It was very nice to have a hands on type presentation that everyone got to participate in together. And since only one person was “driving” we didn’t have to stop and fix a disconnected monitor. Ok, we did one time, but just one time. Open-mouthed 

Big thanks to everyone that came out and participated! Page Brooks, Donny Craft, Benton Little, , Jamey McElveen , Shawn Morris, and Thad Smith. It was a lot of fun!

 

PrizePicker

Prize Picker

There is probably someone out there who doesn’t think this is the best looking application ever. Well, you’re right! It’s not, but we didn’t really focus on that any until we had a fully functional application. At that point it was time to pick prizes for the lucky hopefuls that became winners at the event.

The only big item we didn’t implement, was an item that came up right at the end, we wanted to show the last winner in the area down at the bottom of the screen in big blog letters. And we wanted to rotate through remaining hopefuls and then finally pick a winner moving them to the winners table.

The application is a firm believer of the KISS principle. We did the entire application in about an hour and a half. And that is including some refactorings, and changes we made along the way. I’m pretty happy with the application, and will love it once we have the “Jackpot” style UI element added.

We added validation as we needed it, and decided to keep the applications logic in the UI, as hard as it was for us to do, to in this case to follow our KISS guidelines.

We have used RNGCryptoServiceProvider class already in the Pocket PasswordGen application on day six. This class makes sure that our random numbers are statistically random and not pretend watered down random.

   1: Byte[] randomBytes = new byte[4];
   2:  
   3: RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
   4: rng.GetBytes(randomBytes);
   5:  
   6: // Convert 4 bytes into a 32-bit integer value.
   7: int seed = (randomBytes[0] & 0x7f) << 24 |
   8:             randomBytes[1] << 16 |
   9:             randomBytes[2] << 8 |
  10:             randomBytes[3];
  11:  
  12: int pick = seed % listViewHopefuls.Items.Count;

 

Download executable: prizePicker.cab

Download Source Code: prizePicker.zip

Feedback

The cool thing is we used this application to actually pick the winners for the prizes, and everything went great. So our intention is to keep using it from now. We are also going to post it on CodePlex soon and allow others to work on it as well.


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

Wow, today was a busy day. I gave a Windows Mobile Programming presentation today at a .NET user group I help run, PDANUG. I changed it up at the very last minute, and instead of doing the presentation I was planing on doing we wrote a Windows Mobile application together. It was great. I think everyone contributed, and got something out of it. In the end we had a very nice Prize Picker application that we will be able to use again and again in the future. And I have a new talk that I can present. Any takers?

 

image

What is My IP?

You may have seen sites like WhatIsMyIP.com, IPChicken.com, and my favorite IPCow.com. Most people prefer command prompt and good ole IPConfig. But sometimes when you are troubleshooting an issue with a friend of family member over the phone that’s not always the best idea. Usually in those kind of situations it is easier to send someone to a Web site and just have them read the value to you. I think some of the sites above will render appropriately on a mobile device, pretty sure IPCow.com does.

But what if you can’t connect to the Internet, and you need to see your Intranet IP address. In this case, and many others, one wants something a little more direct, and clear.

For this reason, “What is My IP?” exists. It couldn’t be simpler. Run the program, then see your IP address, or IP addresses in case you have multiple connections open. Which is very possible with today’s devices, with everything from Bluetooth, cellular connections, wireless connections, and more.

This application only does one thing, so it needs to do it very well. And it needs to be appealing in how it looks and how it does it.

Since the application has minimal features, it has a minimalist style to it. There is only one focus point of attention and that is the large network icon in the center of the screen. Everything else is clean and simple.

There’s only one method of note in this application: RefreshData()

   1: private void RefreshData()
   2: {
   3:     string deviceName = System.Net.Dns.GetHostName();
   4:  
   5:     textBoxDeviceName.Text = deviceName;
   6:  
   7:     IPAddress[] addresses = Dns.GetHostEntry(deviceName).AddressList;
   8:  
   9:     comboBoxDeviceIP.Items.Clear();
  10:     for (int i = 0; i < addresses.Length; i++)
  11:         comboBoxDeviceIP.Items.Add(addresses[i].ToString());
  12:  
  13:     if (comboBoxDeviceIP.Items.Count > 0)
  14:         comboBoxDeviceIP.SelectedIndex = 0;
  15: }

Download executable: whatIsMyIP.cab

Download Source Code: whatIsMyIP.zip

Feedback

Not bad 10 applications in 10 days. Won’t be long before we’re at 20 applications in 20 days, and then 30 applications in 30 days. Keep the feedback coming.


Wednesday, June 11, 2008 02:14:00 (Eastern Standard Time, UTC-05:00)  #    Comments [1]  |  Trackback
Tuesday, June 10, 2008

Tuesday, June 10th, 2008image
Chris Craft

Topic: Windows Mobile Programming

Tuesday, June 10th, 2008, is the next meeting of the Pee Dee Area .NET User Group.

Chris Craft will be presenting at Microsoft Mobility Roadshow alongside Brian Hitney, Glen Gordon, and Lou Vega in Charlotte - June 18, 2008 and Atlanta (Alpharetta) - June 24, 2008. These are full day Windows Mobile device application development events.  PDANUG will be hosting our own special "Welcome to the World of Windows Mobile" event to keep in theme these two MSDN events.
Focus will be Windows Mobile 6.x and using Visual Studio 2008 to developer mobile applications.
Topics to be covered:

  •       Intro to Windows Mobile
  •       Data Guidance (some discussion of line of business applications)
  •       Whole New Level
Speaker Bio
Chris Craft
Pee Dee Area .NET User Group
Florence, SC      
•    Microsoft Windows Mobile Device Application Development MVP
•    Cofounder and regular speaker of Pee Dee Area .NET User Group.
•    Frequent CodeProject.com article author.
•    Expert's Exchange Windows Mobile Programming Master.
Email: ccraft@pdanug.net
Web: http://pdanug.net/
Blog: http://cjcraft.com/blog/


Here is the tentative schedule:
6:00 PM - 6:20 PM Socializing / Free Dinner
6:20 PM - 6:30 PM Introduction, Sponsor Time, and News.
6:30 PM - 8:00 PM Presentations


Tuesday, June 10, 2008 11:52:00 (Eastern Standard Time, UTC-05:00)  #    Comments [0]  |  Trackback

Microsoft has published a SKU Matrix for Windows Mobile 6.1, and there is also an older one for Windows Mobile 5.0.

imageWindows Mobile 6.1 makes it easier to stay connected and manage your busy life—from just about anywhere. Windows Mobile 6.1 is full of enhancements, made with your needs in mind. Think about this: When you text with a friend, the messages thread together, just like instant messaging—no more confusion about what you’re talking about. Connecting to a Wi-Fi network is now simpler—no more scrolling through multiple pages; a single click and you’re connected. And Windows Mobile 6.1 runs on a growing variety of phones, including touch screen devices with slide-out keyboards, sleek full-keyboard smartphones, and compact flip phones.


Tuesday, June 10, 2008 09:46:43 (Eastern Standard Time, UTC-05:00)  #    Comments [2]  |  Trackback

Today's application is meant to be a simple, yet useful, application for people to use out on the town. This is an application that a couple of my friends recommended as a good beginner's introduction application to programming for the .NET Compact Framework. One thing I really like about it is that there is nothing to get in the way of a new developer's understanding of what is going on in this application. Everything is direct and straight-forward.

If you have ever eaten out with a large group of friends and wanted to split the tip, then you probably know how much of a challenge this can be. It seems trivial at first glance, but there is a decent set of variable inputs, and another good size set of outputs. All of which are interrelated. But that is the past, now you have Mobile Tipper to take care of the hard work for you.

 

image

Mobile Tipper

There's not a whole lot going on with the UI. It is still clean and simple. I have colored the output fields in a light yellow color, and I have added an icon to the top right of the screen for decoration. Also, notice we are formatting our outputs, and allowing users to enter '%' and '$' characters in the inputs. This is a nice touch of polish that users appreciate. The icon in the top right is also the icon for the applications and the forms themselves. (I couldn't take it; I decided to give the application, a famous light blue color to give it a little life.)

 

There's a lot of fields, and this is technically a mobile data entry application. So we want to enable our users to enter data as easily as possible. That's why we are using editable comboboxes, and allowing users to enter '%' and '&' characters. The comboboxes are pre-populated with a likely set of inputs users will want to use.

imageOne thing I did also to help with data entry is I assign tab orders to all my input controls, and marked all my output controls TabStop properties as false so they would be skipped over.

I implemented a Tip class that handles all the math calculations, and so on. And I created NumericTextBoxes and NumericComboBoxes that only allow numeric data to be entered. Again try to make end users lives easier.

You might be wondering what my secret is to handling the character's '%' and '$', it is the trusty String.Replace() method. I replace both of those characters with String.Empty's. :D

     return Decimal.Parse(this.Text.Replace("$", string.Empty).Replace("%", string.Empty));

I came close to skinning this application with some kind of butler them skin. Basically a white and black theme with a little bowtie band somewhere across the top, or middle with a watermarked jacket front in the application form's background. But decided it probably wouldn't end up looking like it does in my head.

 

 

 

 

Download executable: mobileTipper.cab

Download Source Code: mobileTipper.zip

Feedback

Tomorrow will be our tenth application, and mark us at 1/3 complete. So far I have managed to design, create, publish, and explain a new and different .NET Compact Framework application everyday. My goal is to do it everyday this month. Your support really makes a difference so keep it coming!


Tuesday, June 10, 2008 00:18:51 (Eastern Standard Time, UTC-05:00)  #    Comments [0]  |  Trackback
Monday, June 09, 2008

Wow, time sure does fly when you're having fun. Since the beginning of the June, we have already knocked out over a half-a-dozen applications. It's hard for me to choose a favorite, as there is such variety, and many of you submitted great application ideas. If I had to pick a favorite, I think I would pick Mobile FX, since it is just fun.

What's your favorite?

 

image image image image
Minutes to Midnight Countdown Bluetooth Manager GPS Compass Mileage Tracker

Look at the variety: a countdown time, a Bluetooth control panel type application, a GPS application, and a work utility.

 

image image image image
Mobile Capture Pocket PasswordGen Mobile FX What will be next?

 

Again, we get around as far as application topics: screen shot utility, password generator, a sound FX app, and who know's what we'll do next...

Looking forward to this week's applications? Let's see where we'll go next.