Showing posts with label barcodes. Show all posts
Showing posts with label barcodes. Show all posts

Thursday, June 16, 2011

Update - Barcode check-in

After using my barcode check-in app at the GVCC races on Thursday nights, I noticed that it was still missing a couple of major features.  While the main barcode scanning workflow worked correctly I still had problems with:

  • Assigning a barcode to a new racer - this was annoying because in the beginning of the season I had to hand out quite a few barcodes to new racers.  Unfortunately, I didn't have a good way to track them, so I ended up writing them down on a piece of paper.  Of course this meant that I didn't want to send in the barcodes until I also sent in the updates to the new barcodes.
  • Manually entering a barcode - There really was no way to manually enter a barcode.  I saw that this could become a problem, since many racers have their barcode sticker on their helmet or bike where it's exposed to the elements.  As the season goes on, members may have scratches on the barcode that would prevent it from being read.
I was able to make additions to the app to resolve these issues.  First, I decided to add some buttons to the main view of the app, but I wanted to make sure that I didn't have to take the user away from the main workflow.  This lead me to using a dialog.

A dialog is a panel that is displayed over the top of your current view.  You can add just about anything to it, including text, images, radio buttons, etc.  For the "assign a new barcode" case, I added a dialog with 3 textboxes and a button at the bottom that allowed me to collect first name, last name, and barcode, and then submit the answers to a separate file.  The "manually enter barcode" case was even easier, since it just required a single textbox where I could type in a barcode, and then the button would save it to the same file that the other barcodes were being scanned into.

There were 2 "tricky" parts to creating a dialog.  The first was trying to figure out when in the lifecycle to actually create the dialog.  Apparently, the recommendation is to create it in the onCreateDialog(id) event, and this is what I used.  This event is fired during a call to showDialog(id), where you pass in an integer that identifies which dialog you want to show.  From there, I just used a simple switch statement to differentiate between the 2 types of dialogs, used a layoutInflater to set up the layout from an xml file, and finally call the create() method on the AlertDialog.Builder object.  The create() method actually creates and shows the dialog on the screen.

The second trick that I ran into is realizing that all of the objects that are on the dialog are really on a separate view.  That means that if you want to access the fields on the view, you can't just do something like "this.myTextBox", you need to use "memberDialog.myTextBox".  Obviously that meant that I ended up storing the actual dialog object in a member variable, which I'm not too happy with, but it seemed to work ok.

Other features that I'd like to include in this app are:
  • Look up member barcode by name
  • Look up member eligibility - paperwork turned in, paid - from gvcc racing database
  • Check in marshals - so they can be flagged for not showing up!
I think that I've got the most important cases covered though.  I'd like to publish this to the Android Market so that other gvcc members can access it quickly if there's a need to do a check-in and I'm not there, so that will probably be my next action with this app.

Thursday, April 14, 2011

Barcode check-in app - Beta Testing


Woohoo! *pumps fist*

Yes, thank you, I will use my barcode app. Oh wait, that means it actually has to be done and (mostly) functional. Better get on that!

What need to function for this app to be useful?
  • Scan barcodes and write them to a file - done
  • View barcodes (for verification) - done
  • Email barcodes to Todd - done
I took some time to re-work the menus on this app to use xml files and a MenuInflator instead of building each MenuItem programmatically. I also finally figured out how to use intents to move between Activities within my project (Intent intent = new Intent(this, ViewScans.class);). I still have a problem with going back to a previous Activity if I just came from there, but that's just an annoyance, because it puts another instance of that Activity on the top of the stack. I'm sure there's a better way to deal with this, even if it just means that I re-work the menu options.

After getting everything working, I started thinking about other functionality that I could include in this app - yes, the dreaded "feature creep"! Here's what I came up with:
  • Better way to store settings - email address to send to, default subject line, default storage folder
  • View list of barcode files in a folder
  • Edit barcodes within a file
  • Add a nice icon
Here are some "pie in the sky" features that would be cool, but probably won't happen:
  • Pull the name of the rider associated with a barcode from the GVCC database
  • Option to validate that there are no duplicate barcodes within a file
  • Automatically name files by creation date
Beta testing will commence tonight!

Wednesday, April 6, 2011

Nice and Smooth - Sending email

After having a horrible time with permissions last night, I moved on to figuring out how to send an email with an attachment. It turns out that this is the easiest thing that I've done on Android so far! I just had to create an Intent to ACTION_SEND, add some parameters that are pretty standard, and start her up.

Here's the code:
     Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ "youremail@gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Checkins today");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Here you go.");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+Environment.getExternalStorageDirectory()+"/barcodes/checkins.txt"));
emailIntent.setType("text/csv");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
It's looking more and more like this thing will be ready for prime-time before the B5s race next week. Todd might be pleasantly surprised if he gets the check-ins before the race starts.

Tuesday, April 5, 2011

Pulling my hair out - Permissions

Don't you hate it when you burn through an hour of work with something that you know should have taken 5 minutes?

I got the barcode intent switches working without any problems the other night, but for some reason I couldn't write a file to the SD card. I only played with it for 5 minutes, and had the correct code written, but it just wasn't working so I moved onto other things (the menus). I decided to sit down and get the file storage working correctly tonight.

First, I did add a line to the AndroidManifest.xml to add permissions for android.permission.WRITE_EXTERNAL_STORAGE. What I didn't realize is that there are multiple places in the Eclipse Manifest tool to specify permissions. There's a drop down under the "Application" tab, and then there's the "Permissions" tab (the obvious place to look). My initial thought was to go to the "Permissions" tab, and add a "Permission" element. Makes sense, right?

Nope, you need to add a "uses-permission" element. Unfortunately, I apparently can't read detail-oriented documentation anymore, so this small difference was lost on me. The worst part about it is that because I wasn't really paying attention to "permission" vs "uses-permission" while I was reading through the websites I looked at, I don't even know what "permission" is used for! All I know is that if you actually want to let your application use some of the phone's resources, you need a "uses-permission" element.

The good news: progress is being made on the app, and I just need to work out some stuff with the menu and some basic cleanup/error handling in the file creation code before it's ready for prime-time. Oh yeah, and the email part too, but as long as I can collect all of the barcodes into a file, that's all I need for now.

Sunday, April 3, 2011

Progress: Barcode check-in app

I made some progress on my barcode scanner app for GVCC last night. After screwing around for 2 hours trying to compile zxing in Eclipse, I gave up and used the "cheap" way and just used the barcode scanner through Intents. What a difference! Used/modified the example code snippet that zxing posted on their website, and within 10 minutes I was scanning barcodes and displaying the results on the screen.

Now I just have to finish up by writing those scanned codes into a file and allowing the user to email the file to a configured email address once all of the scans are completed. I tried messing with the file system, but I don't think I have the permissions set right, or maybe I'm just not saving the file to the correct location. Shouldn't be too hard to figure out, but I just need to get in there and figure out why it's not working.

Saturday, April 2, 2011

App idea: Simple gvcc check-in

This is probably the app that I will start with. Should just be a simple app that uses the camera to scan barcodes and saves them to a file. After everyone has checked in, just press a button to email the file to Todd.

I like this idea for a first attempt at Android development, since it utilizes an external component, helps me be come familiar with using intents to switch between activities, and has most of the basic components of an app (permissions, menus, etc).