Monday, December 20, 2010

Handling onClick in ListView with embedded WebViews

Oh boy, dear readers, I have something relatively good to show off!  It's a bit of a hack, but it's something we fought with for a very, very long time that hasn't had a solution posted.

Firstly, like a lot of other people, we decided we wanted to override our ListViewAdapter to make a custom layout.  This in itself is not difficult, and there are many, many good tutorials out there on the internet.  We followed this one and the supplementary article linked within.  For anyone looking to start doing so, check it out. It's really the best way to start getting the best out of the provided layouts.

For our purposes and using what we had available, we needed to use an ASP file to generate the thumbnail for our textbook listing.  We found out upon trying to load it directly to an ImageView that it is actually returning an entire HTML block.  When attempting to strip the image URL from that block, we found out that it was simply the same URL we'd just visited.  Without much recourse, and no way to get at the data ourselves (3rd party systems, hurray!) we resolved to use a WebView and cut our losses.

When you use a focusable/clickable object inside a custom ListView layout, you immediately run into a problem: they steal all input from the ListView's native onClick events.  This is overidden easily by setting the focusable="true" attribute to focusable="false".  Same goes for clickable="true".  This works for everything except a WebView.  Because WebViews are more complicated and listen for a lot more types of events and more inherent functionality, a simple attribute change won't do anything.  It essentially leaves your entire ListView item dead in the water.

The solution?  Handle the click event in the WebView.

This is a hack, as I've said.  This does not restore the functionality to the parent ListView item.  As of this posting, I haven't figured that much out.  This will, however, handle the click when it happens to the WebView.  You could replace your entire ListView item with a single, formatted WebView and this would work swimmingly, but for our purposes, that's more trouble than it's worth.

Onto the code!


Wednesday, December 15, 2010

Extra This-and-That

Been working on little things for the app over the last couple of days.  Mostly filler stuff to make it more robust, nothing especially difficult.  Here's a run-down of what I've done and any additional info on it:


  • Added Store Info tab with photos of each campus, the phone number and address.  Need to do screen resolution handling, but that's the same for the whole app, so not worth a separate bulletpoint.
    • Making the phone number and address clickable was extremely easy.  In the XML for each TextView, just add android:autoLink="phone" for phone numbers and  android:autoLink="map" for addresses.  The former puts the number into the Dialer and allows you to just press send, the other gives you the option of opening the address in Maps or the Navigator.  Handy!
  • Added a Send Feedback function with user-entered name, e-mail address and comments.  It generates the subject on its own based on a Spinner for type of feedback and the supplied name and e-mail address.  The comments have an appended line for whether or not the user clicked a CheckBox requesting a response.
    • If you try to use Intent.EXTRA_EMAIL with new String("jldomagala@aacc.edu"), the To portion of the generated e-mail will be suspiciously blank.  For some reason it accepts this without compiler errors, but unless you style it new String[]{"jldomagala@aacc.edu"}, you won't get what you're looking for, or expect.
    • Not programmatical, but apparently my work e-mail address filters out anything with curse words in it.  Guess putting in a comment asking 'why does this shitty app not work right?' was a bit too much for it, haha!
  • Found a bug in the Hours of Operation calendar with displaying the dates in the proper cells.
    • Each month is padded by empty, greyed-out cells that ensure that all the dates fall on the proper day of the week.  My test month (December 2010) was displaying properly by pure luck due to the improper calculations.
      • Beginning of the month padding went from for
        (int i = 0; i < (Calendar.SATURDAY - date.get(Calendar.DAY_OF_WEEK)); i++)
         to
        for (int i = 0; i < (date.get(Calendar.DAY_OF_WEEK) - 1); i++)
      • End of the month padding went from
        for (int i = 0; i < (Calendar.SATURDAY - date.get(Calendar.DAY_OF_WEEK)); i++)
         to 
        for (int i = date.get(Calendar.DAY_OF_WEEK); i < Calendar.SATURDAY; i++)
So, all in all a relatively productive day.  More nuances and bug-fixing tomorrow.

Monday, December 13, 2010

Demo Day Recap

Ah, things are finally calming down, readers!  With our first major milestone reached, now it's on to polishing and bug-tracking on the app.

My partner suggested I mention that mere hours before DD started, I not only made all the signage for the table, I also edited together a quick demo video in case something happened on the phone or we lost service and added in my hours of operation functionality, did three quick bug-fixes and got everything set up by 12.  While I think this showcases how horribly irresposible I am and that I don't do things 'the right way,' he maintains that it shows I work well under crunch and am highly resourceful.  I'll leave that up for you to decide.

I don't feel I can rightfully brag about the video.  I find it to be very crude, but it did its job when we did occasionally lose service, or the table was too crowded to allow anyone else looking at the single Droid2 that we had to play with.  It also showed off the Event functionality that I had commented out just prior, as the duplicate checking wasn't working yet and I didn't want 100+ 'Demonstration Day' events added to my calendar.  Smart thinking on my part, haha!

We did at some point lose our camera, so I do need to see what there is to be done about that.  I realized this after a particularly good set of comments, so we'll have to figure out just when it bailed on us.  No matter how full a charge you have, if your camera is running, recording raw footage for 2+ hours, it will die.  I did pull it off the tripod as soon as I noticed and charged it between demo's after that, so we do have some other good footage, just a shame.  Learning experience and all that.

I was pleasantly surprised that though our app was really primitive visually, people loved it.  No one really said it needed to be cleaned up or that it was hard to read or navigate.  That means, of course, that as long as we keep to our basic principles, we should be fine.  A definite, definite plus.

The boss' boss' boss showed up again, which was really great.  She seemed really impressed with how much we had done, I got to give her a quick demonstration and she hung around watching me interact with all the students.  Apparently everyone is very surprised at how well I interact with people.  Not all programmers are terrible introverts!  Promise!

All in all, we did really well.  My partner congratulated me and went as far as sending me a quick email afterward to say he was happy to have worked on the project and to let him know if I need any more help.  We gave out probably somewhere around 12 pizza's worth of slices to people who were filling out surveys and giving us soundbytes.

Lastly, here's the demo video we used.  No complaints, it was done in about half an hour, haha!


Tuesday, December 7, 2010

Starting Over

Hello hello again dear readers!  I do owe you quite an update, but unfortunately I haven't had to time or energy to do so adequately.  Suffice to say, I will sometime near the end of this week, as promotion for my Android app is beginning sometime between tomorrow and Wednesday.  That will feature all of our new functionality in video format, so you'll get another nice run-through of what's been going on since my last in-depth feature summary.

To tide you over until then, I'm going to drop off a base Away3D file that I recently wrote for my internship to help one of their Flash designers get into the swing of things.  It's a basic start-up file that handles some input and is ready to have objects added to it for display.  It's heavily commented and (hopefully!) logically arranged, so it's good for any beginner that wants to wade through it.  Enjoy!