Archives for April 2008
Android talk at Tampa JUG
Tuesday I gave a talk at the Tampa JUG and for the most part it went well. The projector in the JUG space didn’t like my Hardy (Ubuntu) partition, nor my Windows partition. Nor the Xandros on my eee pc. After some playing with settings and rebooting, I got the projector to be recognized as a secondary screen for XP. Matters weren’t helped by the fact that I live in Ubuntu and even my thumbdrive is formatted as ext3. Oh well...but I was able to show the demo and some of the code. Here’s some of the random stuff I didn’t get to show or I think needs a little bit more explanation.
General structure of a Android app
/build.xml
/AndroidManifest.xml <---Registration of Activities, Intents, and IntentFilters/Receivers
/IDE specific build files
/src
/res
/res/drawable <---Images
/res/layout <---XML Layouts of Activities
/res/values <---Strings/Arrays for Spinners and such
/bin
/bin/classes
/bin/classes.dex
/bin/<Your Application>.apk <---Application file that is loaded to phone
Background Images
The background is set in the outermost layer tag with android:background.
<AbsoluteLayout android:id="@+id/widget0" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/trafficviewer" >
The @drawable refers to the above drawable directory and also notice that the filename leaves off the extension.
TrafficViewer
TrafficViewer is a small Android application that allows a user to input a mile radius and a zip code or city and state to find accidents in that area. The input from the user is sent to the Yahoo! Traffic APIs and it returns geocoded lat/long points indicating accidents.


The background image is a Creative Commons licensed(by-nc) by Thomas Hawk
Some of the files I didn’t get to show as much were the YTrafficFetcher, TrafficRecord, YTrafficHandler, and TrafficMap.
YTrafficFetcher, like it’s name states, is an interface to the webservices. It constructs the uri query strings, and acts as a buffer for the YTrafficHandler which parses the code and loads them into the POJO TrafficRecord.
URL url = new URL(this.query); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); YTrafficHandler handler = new YTrafficHandler(); xr.setContentHandler(handler); xr.parse(new InputSource(url.openStream())); r = handler.getTrafficRecords();
YTrafficHandler walks the XML and has convenience methods for marking the start and end elements and gets the enclosed characters.
TrafficMap, as a MapActivity, wraps the functionality of a MapView. From it, I created a basic map and overlay reading in the location and the title of the incident. The map auto-zooms to the last point in the list. Actually it sets the zoom to each point as it is parsing them. I’ll admit that this was lazy and a more elegant solution would have been to find an equidistant point between them but lack of time requires some compromises.
Here’s the pertinent code that draws the overlays on the map [mostly borrowed from tutorials on anddev and helloandroid]
// Create a Point that represents our GPS-Location Double lat = record.getLatitude() * 1E6; Double lng = record.getLongitude() * 1E6; Point point = new Point(lat.intValue(), lng.intValue()); TrafficMap.myMapController.centerMapTo(point, false); int[] myScreenCoords = new int[2]; // Converts lat/lng-Point to OUR coordinates on the screen. calculator.getPointXY(point, myScreenCoords); // Draw a circle for our location RectF oval = new RectF(myScreenCoords[0] - 7, myScreenCoords[1] + 7, myScreenCoords[0] + 7, myScreenCoords[1] - 7); // Setup a color for our location paint.setStyle(Style.FILL); paint.setARGB(255, 0, 0, 0); // reddish color // Draw our name canvas.drawText(record.getTitle(), myScreenCoords[0] +9, myScreenCoords[1], paint); // Change the paint to a ’Lookthrough’ Android-Green paint.setARGB(80, 156, 192, 36); paint.setStrokeWidth(1); // draw an oval around our location canvas.drawOval(oval, paint); // With a black stroke around the oval we drew before. paint.setARGB(255,0,0,0); paint.setStyle(Style.STROKE); canvas.drawCircle(myScreenCoords[0], myScreenCoords[1], 7, paint);
Slides
Source code (Yahoo Developer ID needed)
Quick news
Apple Releases Java 6 Officially
It’s only 1.6 Update 5 but nonetheless a move in the right direction. I’m already using Update 10 but it removes one of my major objections to moving to OS X.
MigLayout version 3.5 released
Most of my demos use MigLayout almost exclusively. It gives you the expressivity of GroupLayout while keeping the code readable and able to code by hand.
is coming up on May 1st. For those that don’t know, it’s an effort to redesign one’s site and launch the changes on May 1st and November 1st at 2PM GMT. I’m pushing mine out a bit early to make sure the kinks are out in advance of JavaOne but it’s good to come back and reevalute your sites and fix the problems your users face.
Android Talk at Tampa JUG
Slides and demo application code is coming...by Thursday.
Groovy Summer of code projects
Leslie (Hawthorne) and company from the Google Open Source team have posted the accepted proposals for the 2008 Google Summer of Code. The Codehaus received seven slots this year up from three last year.
The Groovy/Grails proposals are:
Performance Improvement for Groovy(numeric primitives)
Include plugin for Grails
Scientific Groovy Module
All of them look really promising and I’m really looking forward to the Performance Improvement proposal and how it will affect and interact with the Scientific Groovy Module.
Good luck and congratulations all!!!
New release of Groovy
G2One and the Groovy team have released Groovy 1.5.5. One of the improvements, which will hopefully quiet the "Groovy is slow" arguments, is a improvement of compilation speed. MrG is saying 3x faster while some initial reports from the field are noting that increase and higher.
For those of you using Ubuntu or another Debian, if you don’t want to wait for Debian unstable to be updated which sometimes takes a while, you can download the Debian package here.
Groovy as a first programming language
Chrigel Uniter recently posted about the above question on his blog. He doesn’t conclusively say yea or nay but does raise some interesting sub-questions, namely, Groovy vs. Java as a first language.
Groovy is better...
Low barrier to entry
The lack of much scaffolding code would make the barrier to entry lower for students. However, this could descend into the current situation with ECMAScript. The low barrier to entry opens the door for some that shouldn’t be there in the first place.
Syntactic sugar.
Many of the functions that students I used to teach [in other languages] would think were provided are provided. For example, they were sometimes frustrated with the lack of consistency between finding the length of a static array and a dynamic array. Though it adds the convenience of calling size() on an int array, il ne cache pas the core-Java way. A prof could teach both while preferring consistency. It lets them code and not worry as much about semantics.
Groovy renaissance.
I believe it will continue and we will see Groovy emerge as the preferred scripting language for Java applications and as a possible secondary scripting language for some Linux distros. Groovy is now in the Ubuntu repositories. I know Ubuntu != Linux, but it’s my most favorite distro. Currently Python by far is the frequently used scripting language in Linux. As more move to Java 6, update 10, I think we’ll see more Groovy.
Java is better....
Groovy teaches the easy way first.
It makes me thing of a valuable lesson learned at my alma mater Baltimore Polytechnic Institute (it’s a high school y’all). The teacher’s name escapes me but I remember doing exercises for two weeks computing derivatives the long way in Calculus I class and then being shown the easy way. We asked the prof why didn’t he just show us the easy way. He said something along the lines of "you would never appreciate the easy way if you didn’t know the hard way." And that’s the case somewhat with Groovy, much of its power comes from Java but unlike calculating derivatives, it isn’t limited to the features of Java and can be a superset.
It might cause havoc to introduce CS 101 students to a language with weird parenthesis rules and as much syntactic sugar. (e.g. you can run a script without a class, unlike Java, but in actually it’s being compiled to a class in the background)
It is the standard.
Albeit verbose, Java has a defined structure. In the short term, there is a lot more reference material in Java than in Groovy....and a larger userbase [YMMV on that argument, it depends on if you believe that a Java dev is Groovy dev who doesn’t know it yet].
I guess I don’t actually answer the question either.
Friday Randomness
Sun apparently has a student program for JavaOne:
http://developers.sun.com/events/studentprogram/index.jsp
Among the awesome benefits...see SMASHMOUTH live at the JavaOne AfterDark Bask. (sighs)...well... I did like "All Star" though, it was one of the jams my senior year in high school (’99). Seriously though, if you’re eligible, apply. Apply with some friends so you can split a room if you all get picked. Once you’re there, make sure to come see my two BOFs.
I added Radar charts support to the grails google chart plugin bringing it to version 0.4.6 and back to fully implementing their spec(at least AFAIK).
Google App Engine... bummer that it’s Python only but understandable why Java/JVM languages didn’t make the first go-round. Those reasons have been discussed all over the web so I won’t go into them. If you would like Groovy support to be added, go over to their issues page and star the items (here and here). You will need a Google account and please don’t add "+1"s to the comments, there are enough already. My 0.02, or 0.0150 given the freefall of the dollar, I think it’s already planned and Python is a test run of the infrastructure.
For those in the Bay area, Tampa Bay area that is, I’ll be giving a presentation at the Tampa JUG on Google Android on April 29th. They’ll be pizza and semi-cool demos. Come check it out.