teaching machines

RepreWho – Homework 3 – weeksc

November 7, 2011 by . Filed under cs491 mobile, fall 2011, postmortems.

First things first, I realize I’m late turning this in, so apologies to everyone out there who’s been waiting with bated breath for me to submit this. Yeah…pretty sure that’s no one. Anyway, there is a reason it’s late and that reason is this – I had 2 bugs that I’ve been trying to get sorted out for the last few hours. Not much luck either. I’ll get to the bugs later on in the post.

RepreWho is an app aimed at getting people more involved in the government. Specifically, it provides a simple means through which to contact Representatives and Senators. The UI is very, very primitive. I had such great dreams of where the UI would go – I started working on some of the items – but no time. The user simply enters a zip code or selects a state. The zip code takes precedent over the state in the event that values are entered for both.

The entered value is then sent to http://services.sunlightlabs.com/ which provides a feature rich api for accessing public government information. The api is a RESTful web service that return a JSON string. I found this in the big list Jonathan posted. I actually wrote my own web service to do this ( I’ve been meaning to write this app for a few months now) but the one provided by sunlightlabs puts mine to shame.

The resultant JSON string is converted into a list of Representatives and Senators. The list simply displays the Legislators full name and political party. The one thing I found lacking in the sunlightlabs api was that it did not provide a link to an image for each of the legislators. So I took advantage of a second web service – the Google Image Search api. This api is another RESTful/JSON api that just spits back the results of a Google Image search. So all I’m really doing is doing a Google Image search on the first and last name of each legislator and using the first image. This works very good in most cases – though there are numerous instances where the government official is not the first image returned. I thought about adding some intelligence in to try to find the best of the returned images to use, but I decided not to. If the legislators want to have an image in my app then the better improve the SEO. Their fault, not mine. During the interim between the list showing and the Google Image being downloaded there is supposed to be a “loading” animation. And, though I set up the animation appropriately, I could not get it to start. It would only show the first frame. I didn’t have enough time to really go dig into why this is happening. My thought is that is has something to do with when I’m calling Animation.start() in my code. I think the start() methods needs to wait to be called until the View has loaded.

From the list view the user can select any of the legislators to get a full profile view. This last view provides links to get more information about the individual, and most importantly, quick links to contact them. Nearly every legislator has a phone number and web form available. Some have emails. But the app makes any available means of contact accessible with a few simple clicks.

   

 

So there’s nothing to interesting visually about the app. Really I think the only new thing I found was styles. Styles are pretty much to Android what CSS is to HTML. Instead of having upwards of 10 attributes applied to every single View element, you can abstract it away one level then have the style as the only (or one of the few) attributes. What’s better though is that the style can be used for many View elements. Super awesome.

Here’s a section of  my “res/values/styles.xml”

<style name=”RepsListHeader” parent=”@android:style/TextAppearance.Medium”>

<item name=”android:layout_width”>fill_parent</item>

<item name=”android:layout_height”>wrap_content</item>

<item name=”android:typeface”>serif</item>

<item name=”android:textSize”>24sp</item>

<item name=”android:gravity”>center_horizontal</item>

</style>

<style name=”WhiteLine”>

<item name=”android:layout_width”>fill_parent</item>

<item name=”android:layout_height”>1dp</item>

<item name=”android:background”>@android:color/white</item>

</style>

Geez – I can not figure out formatting in WordPress…infuriating. Anyway, as you can sort of see above, you just define <style> elements as you want. They can then be referenced in the following way:

<TextView

android:text=”Representatives”

style=”@style/RepsListHeader” />

<View

style=”@style/WhiteLine” />

 

I’m going to move on to the issues. I encountered. Using the api’s were pretty straightforward, so I didn’t have much issue there. There were/are 2 main issues I had.

1) Getting the list view to show up properly. The Search result list is actually two different list view stacked one on top of the other. Originally, I had Senators on the bottom, but I ran into issues when the number of Representatives exceeded the space allocated for it. I couldn’t figure out why that was happening since both ListViews had an android:layout_weight=1. With the same value, it made sense to me that they should share the space available evenly. That wasn’t the case though. This is what it looked like when both ListViews had equal weights:

       As you can see, the Senators list got crunched. The list was still being populated appropriately, it was just getting pushed out of the way. I tried a number of fixes…TableRows, nested LinearLayouts, Tabs, but I couldn’t anything to work very well. In the end what I did was mess with the layout_weights of the 2 lists. What I ended up with was the following:

<ListView

android:layout_width=”match_parent”
android:id=”@+id/senatorsList”
android:layout_height=”wrap_content”
android:layout_weight=”1″></ListView>
<ListView
android:layout_width=”match_parent”
android:id=”@+id/representativesList”
android:layout_height=”wrap_content”
android:layout_weight=”20″></ListView>

Yep, 1 /20 seems to just about do. I really don’t understand why though. I’m thinking stacking 2 lists was not the approach I should have taken.

 

The second, much bigger and more time consuming issue that I’m still dealing with is a bitmap issue. It’s a very common error in Android, but it seems to me that there isn’t really a defined way of fixing it. The exact error is – “java.lang.OutOfMemoryError: bitmap size exceeds VM budget” This occurs when a large number of Representatives are returned in the search. As a result, a larger number of images must be downloaded and displayed. The other potential issue is that one of the images I’m downloading from Google Images is way too big. Debugging this became very difficult for me though, because logcat stopped receiving log messages of any kind, and adb logcat seemed equally confused.

Anway, that’s pretty much everything for me. I’ll post any updates I make in the near future.