Tag Archives: android

Dev links #2

  1. XmlHttpRequests via Javascript
  2. HTTP requests using PHP
  3. Base64 encoding/decoding in Javascript
  4. Getting installation date of an app (Android)

I’m attempting to resuscitate my TweetPuller chrome extension to use v. 1.1. of Twitter’s api. So far, I’ve created a PHP script to retrieve the needed access token and calling out to that in order to prevent exposure of my consumer key and/or secret on the client. So far so good. 

Oh and merry Christmas! 🙂

Advertisements

Application Structure

I’m currently adding some new features to my app. Here’s my summary of changes since my last post:

  1. Added  Navigation Drawer go the first “page” of the application which allowed me to add links to things like an About fragment, Copyright fragment, Signup and Login Fragments, etc. I really like the Navigation Drawer UI pattern and will probably roll it out to the rest of the pages once I’m done testing thoroughly. My Navigation Drawer’s a little bare now so once I’ve worked out any lingering kinks, I’ll add some icons to the left of the drawer menu items.
  2. Used Parse to manage the users of my application. Currently, the app supports user signups, user login and allows the user to use the floating context menu to save their favorite restaurants to a Parse database.

I’m trying to avoid the shiny toy syndrome so I think I will stop at this latest iteration, focus on “hardening” the application and continue testing. Check the pics about and I’ll share one cool thing I learned from tonight’s coding binge. So, I created a custom adapter to handle my Restaurant objects. to give me greater control over what was returned when selecting items from my ListView and to present a prettier display. This is what that code snippet looks like:


ArrayList[Restaurant] rr = restaurantDAO.getRestaurantsByCounty(county);
RestaurantAdapter adapter = new RestaurantAdapter(this,R.layout.itemlisting, rr);
ListView listView = (ListView) findViewById(R.id.restaurantsListView);
listView.setAdapter(adapter);

When I was handling onItemClick events on the ListView called listView, I was grabbing a String representation of my Restaurant and was doing some string manipulation on the values returned from what was essentially myRestaurantObject.toString().  While I was adding the floating context menu to listView, I realized that I didn’t need to convert my Restaurant object to a string in order to get the restaurant ID from a series of string operations! I know this seems obvious in hindsight but when I was learning how to handle onItemClick events on ListView objects, I blindly followed a recommendation to do this:

String rString = parent.getItemAtPosition(position).toString()

When I needed to do was:

Restaurant temp = (Restaurant) parent.getItemAtPosition(position);

So, long story short, if you’ve created a custom Adapter, don’t let your hard work go to waste! I saved myself an unneeded database call once I realized I could grab my Restaurant object from the ListView instead of parsing the toString() value for the restaurant ID and then querying the database.

Screenshot_2013-11-01-21-49-00 Screenshot_2013-11-01-22-40-16 Screenshot_2013-11-01-21-49-19 Screenshot_2013-11-01-22-40-00 Screenshot_2013-11-01-21-49-33

Lastly, I may have gone a little overboard on organizing my files into packages. I’m not sure what the proper way to group things so I just went with what would make my life easier. So far, here’s the layout of my Java files. That’s a lot of code for a simple app but my chief concern is readability so wherever private inner fragments were used, I pulled those out into separate classes and tried to keep the names consistent. My goal is to be able to forget about this app for a month and pick up where I left off with minimal difficulty. I’m open to any conventions or better ways of organizing. With that, I bid you a good night! 🙂

Screenshot from 2013-11-01 22:24:57

Stackoverflow

I posted my first StackOverflow question today and it was (with the benefit of hindsight) a dumb question; I wish my first ever question wasn’t but hey at least, I popped my SO cherry. 🙂 Here’s to many more questions (and hopefully more answers). I’m running on little sleep and I blame my tired state for overlooking the obvious. My question dealt with the proper arguments for an Intent and as my previous posts have shown, I clearly know how to deal with Intents but this one time … Ah well, all’s well that ends well.

#memotoself: new Intent(CurrentClass.this,IntendedClass.class) 🙂

My first Native Android App (Update #2)

I’m very close to calling this app, version 1.0. 🙂 Since the last update, I’ve tweaked a few things about the Android application. For starters, I stepped back to think about the potential users of my app and streamlined the ‘home’ screen into 2 core functions:

A. Browse restaurant inspection results by county.

  • This defaults to Clarke county but you can select a different county to view
  • After hitting the button, the user will be presented with simple listing of all the restaurants in that county.
  • I added SectionIndexer to this listing to help the user navigate faster. This blog post was very helpful in understanding this feature and getting it to work.

Screenshot_2013-10-28-18-35-54Screenshot_2013-10-28-18-36-01Screenshot_2013-10-29-00-13-58device-2013-10-29-004634

B. Find a specific restaurant’s scores by searching.

  • This is an AutoCompleteTextView which hopefully guides the user in their search
  • The user has to enter a search term with at least 2 characters. I tried searching “a” and it wasn’t pretty. 🙂
  • After hitting the button, the user will be presented with a map with the locations represented by markers and  a ListView of the found restaurants. It also implements the SectionIndexer.
  • A concern I had with this page was the fact that initially, I was calling out to Google Maps API in the same thread as my user interface and Google recommends against doing this. For queries like “uga” or “mc” which return a large number of restaurants, it took the resultant activity a while to load to I investigated AsyncTask. I’m happy to say I got it working and I owe a ton of thanks to Stackoverflow.com without which I would not have come this far in my app. 😀

Screenshot_2013-10-28-18-36-13Screenshot_2013-10-28-18-58-35device-2013-10-29-004856

After performing either A or B, the user can select a restaurant to view health inspection details and the user will see any of the following screens:

Screenshot_2013-10-28-19-00-27Screenshot_2013-10-28-19-00-37Screenshot_2013-10-28-19-03-12Screenshot_2013-10-29-00-29-50

Sidebar: I scraped the health inspection data from the Public Health Athens website and I used the wonderful Jsoup library to do it. I’m hoping to clean up my code and publish it on Github for others to check out and maybe use.  <digression>I’m currently using git (Bitbucket) for version control and I love Bitbucket because of their unlimited free private repos! Github does offer 5 free private repos to students but I use version control on my school projects and as you can imagine, I have way more than 5 private repos on Bitbucket.</digression>

Because of the way I scraped/collected the data, my application (should) only display the recent health inspection data, etc. It doesn’t retain any historical information but that is out of my hands due to the limited information available on the website. A case could be made for instances where the site shows 2 different scores but scraping depends on regularity and I found several instances where the site didn’t stick to expected format. I digress;  I’ll deal with that issue later.

From what I was able to glean from the site, here’s how the colors work:

  1. if you have a score of 90 or higher without any critical violations, you are in the green. You could have a few non-critical violations here.
  2. Any critical violations lands you in the red zone even with a score above 90.
  3. If you are above 80 and only have non-critical violations, you get a yellow check mark.

If any violations are present, there’ll be a button for you to click through to see the corresponding violations associated with that restaurant. For instance:

Screenshot_2013-10-29-00-31-27 Screenshot_2013-10-29-00-31-02

So there you have it: my first native Android app in the works. I’m feeling pretty good about my app’s progress and I’m currently seeking a few beta testers. If you live in the Athens, GA area and have an Android phone with version 2.3 or higher, feel free to send me a note about wanting to be a beta tester. My gmail handle is janeullah so shoot me an email if interested. The impetus for getting this app off the ground was the fact that I’m working on another Android app with 3 of my classmates for a class (Human Computer Interaction (HCI) with Dr. Chris Plaue).

Helpful Tools

  1. Stackoverflow is every CS student’s not-so-secret weapon. I’m not ashamed to say this was my first port of call whenever I had problems. Thanks to Stackoverflow, I resolved every issue I had. From how to create the proper calls to the SQLite database, getting the SQLiteDatabase to be copied to the right location using the right conventions, properly setting up my Async Task, to creating custom ListView adapters, et cetera. So, even if the first question doesn’t have an answer, try a different search term and really try to understand the answers that were provided. From now on, I’ll do my part by documenting solutions to issues I’ve faced either here or on Stackoverflow.
  2. On Android, the data’s stored in a SQLiteDatabase which I created by using the mysql2sqlite.sh script to convert my MySQL database to SQLite. For version 2, I’ll probably make the home screen a little nicer (less bare) and include a “restaurants around me” type of activity.
  3. After converting the MySQL database to a SQLiteDatabase file, I had to edit the SQLiteDatabase directly and I did this with the help of a Firefox addon called SQLite Manager.

Screenshot from 2013-10-29 00:53:30

Health Inspection Scores

I’m working on an Android app that displays the health inspections scores for restaurants in the Athens, GA area. Currently, this information is located here: Public Health Athens and I am doing this to scratch my itch. It’s pretty basic but I’m just celebrating the small victories i.e. learning to use the sqlite database on Android, really getting into Android programming, troubleshooting, etc. My layouts could use a lot of work. Learning to design the Android layout feels like voodoo to me so I’m open to any ideas for really learning/understanding how to translate my app sketches to Android layout files. Without further ado, here are some screenshots:

Screenshot_2013-10-24-00-32-31Screenshot_2013-10-24-00-21-38Screenshot_2013-10-24-00-22-07