Parse CSV files easily with JavaCSV

Though it is much more likely you’ll get your data via a json / xml feed, sometimes it becomes necessary in the course of development events to parse a CSV file.  If you find yourself in this situation, here’s a nice library that will make the process as painless as can be.

JavaCSV is a library born out of the .Net DataStreams framework.  It promises good performance, low resource usage, and near unparalleled scalability (I have yet to test them out on the last claim, but so far I’ve gotten good mileage from the library).  Usage is quite simple:  just grab the .jar from SourceForge, import it into your project as described in Adding an External .jar to your Project, and read your file via the CsvReader class.  Here’s a snippet where I’m reading a file from the /assets folder within an AsyncTask:

protected Integer doInBackground(Void...voids){
// load the .csv file from assets
try {

CsvReader fileReader = new CsvReader(getAssets().open("file.csv"), Charset.defaultCharset());
fileReader.readHeaders();
while(
fileReader.readRecord()){
String unitName = units.get("")

}
} catch (IOException e) {
// TODO Handle Failure to get file
}
return numUnits;
}

Got any libraries you’ve found really useful in your Android development?  Let us know in the comments or over at twitter @droidweb!

Android Toolbox: AndroidViews.net

androidToolbox

Android toolbox is a new section on Droidweb where we feature a helpful Android tool once a week.  If you’ve got a nomination for a tool of the week, either comment below or tweet your entry @droidweb.  We look forward to checking out some of your suggestions in the future!

Ever since the introduction of Android 4.0 (Ice Cream Sandwich), there has been much focus on UI polish.  The developer site introduced a section overviewing good Android design principles, complete with thoughtful insights on how to design for this new generation of Android.  The OS itself gained many visual tweaks aimed at providing a more consistent and aesthetically pleasing experience.  Matias Duarte and his teams effort didn’t go unnoticed; not only did ICS mark a turning point of good feedback regarding Android’s overall look and feel, but the OS as won a few UX awards throughout the industry.

What does this have to do with us as developers?  Simply put, an implicit expectation has been placed (and for good reason) on applications that they follow Google’s lead in UI design.  Applications are supposed to play nicely with Android’s new design cues and leverage them to create a branded, but distinctly Android experience.  To assist in this effort, many tools have been developed with the purpose of exposing developers to Android UI paradigms and educating them on how to use them.

androidToolsnetcapture

One such tool is AndroidViews.net.  This site, similar to the previously covered Androidpatterns.com, lists popular Android Design paradigms.  However, unlike some other design patterns sites, these entries are libraries which help the developer implement the UI pattern.  This means the source code (source code makes developers happy) is right at the developers fingertips.  Most pages link to their respective library’s Github page, where more details may be found.

slidingmenu

Definite props to this site for maintaining a clean, informative form factor which emulates the Android 4.0+ look and feel itself.  Hopefully you’ll find some helpful bits here and be able to incorporate them into your application.

Happy development!

ActionBarSherlock Compatibility Library upgraded to v. 3.5.0

Developers rejoice! One of my favorite Android libraries to date has recently been upgraded to becoming evenmore awesome than before. Jake Wharton’s ActionBarSherlock library has been updated!

ActionBarSherlock is an extension of the compatibility library designed to facilitate the use of the action bar design pattern across all versions of Android with a single API.  It allows the easy addition of the action bar Android UI paradigm to applications without having to worry about compatibility with older versions of Android.  I am a strong supporter of this paradigm and try to use it whenever possible!

 

From his Google Plus:

Major updates in this version:

  • Completely redone menu and action item support. This has been backported from the progress made on ABS 4.0 and provides a much more stable and logical layout of action items and management of the menu.
  • The compatibility library base has been updated to r6. I have also re-added the *Compat classes that were duplicated by this library and marked them as deprecated.

Download the new version from http://abs.io/. The samples on GitHub and the Android Market will be rolling out this evening as well.

Updating your projects making use of the old library is ridiculously easy.  Just download the new library and any desired .jar files, add the library as a project to your eclipse setup, and replace the references in your project to the old libraries with references to the new libraries.

Do you have any experiences using the ActionBarSherlock Library?  Would you like to see a guide for how to get up and running on ActionBarSherlock?  Drop us a comment below or tweet us @droidweb!

Create Icons for your Application using Android Asset Studio

Screen Shot 2011-10-18 at 1.22.30 PM

Let’s be honest.  Sometimes creating icons for you Android Application can be a bit tedious.  There are three different resolutions you have to shoot for (mdpi, ldpi, and hdpi), and several iterations you have to create (launcher icons, menu icons, notification icons, and, now that Icre Cream Sandwich is coming out, Action Bar icons).  I, for one, can never remember all the proper resolutoins and have to keep running back to the Android Developers Icon Design Reference to get it right.  Even then, I’m a bit artistically challenged, so I’m never happy with the final result.

Enter Android Asset Studio.  This simple tool lets you create most, if not all, or the icons in your application quickly and easily.  There are wizards for creating Launcher icons, Menu icons, Action Bar Icons, Tab Icons, Notification Icons, and device framed screenshots.

 

For each type of icon, there is a simple to use wizard that allows you to choose, the artwork you wish to display on your button (you can upload your own artwork, use predefined clip-art pictures, or just use text).  After choosing artwork, add in trim, color, and shading values, and viola!  You have a set of icons.  This is a nice tool that all you independent developers should check out!

Screen Shot 2011-10-18 at 1.36.56 PM

Android Builders Summit Presentations

Here’s an interesting powerpoint presentation series I’ve been watching lately that thoroughly covers Android from the bottom up. Ranging from 30 min presentations to 90 min sessions, these presentations are no short task, but the information within is invaluable for a real Android guy (read hardcore developers). Find embedded copies below:

Android Builders Summit – A Walk Through The Android Stack

Learn about the stack that powers Android devices from the linux kernel core on up

Android Builders Summit – Beyond the Phone

Here we see some alternative uses of Android in corporations outside of just for phones

Tutorial: Android Application Development – A 9,000 foot overview

70 minute introduction to Android devices

For more helpful tutorials by the same guys, check out the Marakana TechTV website.

Implement a SwipeView in Android

Android development is partially about having a set of tools in your UI toolbox that you bring out when appropriate in the design and implementation phases of the project.  I’m about to add an invaluable tool to your toolbox.  Meet the SwipeView.

What is a “SwipeView”?

A SwipeView is an Android UI view similar to the homescreens.  You have several similar panes of content that you access by swiping left and right.  As you swipe left and right, transitions between the views are animated so that the view in focus follows your finger.  See the handy illustration below (Click to enlarge):

 

When Should I use a “SwipeView”?

SwipeViews are useful if you’re going to have several screens with the same layout and function that you want the user to switch between.  If you’ve ever used the Epicurious app they make good use of a SwipeView-esque implementation when searching for recipes.  Think of SwipeViews as something like a Gallery implementation for Views instead of just images.

How Do I implement a “SwipeView”?

Here’s the fun part.  Now that you know you want a SwipeView in your Android application how do you implement it.  As you probably know its not a standard Android View.  As such we’re going to make use of a third party library.  Jason Fry has put together a nice library for the simple implementation of SwipeViews.  Head on over to his site and blog post for more details about how to implement your very own SwipeView.  Since each SwipeView implementation is going to be widely different, I’m just going to summarize the steps to implement his library below:

  • Add SwipeView element (<uk.co.jasonfry.android.tools.ui.SwipeView…) to the desired XML layout as you would any Android View.
  • Reference SwipeView in java code via findViewById() as usual
  • Populate SwipeView with number of views that you’d like to be able to swipe between
  • Implement method private class SwipeImageLoader implements OnPageChangedListener {public void onPageChanged(int oldPage, int newPage) {}}. Look at the library’s documentation and examples for more details on how to do this.  Essentially this method will handle dynamically allocating and populating views as your user swipes back and forth.

I would include an example of implementation here, but my implementation was quite unorthodox and borrowed ideas from how to implement ListViews and other portions of my Android experience. Needless to say its a bit more involved than what should be expected from an introduction to an UI pattern.  If you’d like help implementing your own SwipeView, feel free to drop a line in the comments below or give us a shoutout via twitter @droidweb.

Introduction to Android Application Development Part 2: Homescreen Layout Design

Now that we’ve got some planning underway, let’s get to work.  The first piece is the homescreen of the app.  Let’s take a look at that mock-up we drew earlier:

Before we do any work on making that app happen, let’s have a quick crash course in Android layout development.  Android layouts can be designed in either of two ways: it can be declared though XML, or it can be created programmatically through Java statements.  We will look at both of those later on, though more focus will be given to XML layouts.  This is because XML layouts are how you’re going to be designing most, if not all, of your layouts.  Java programmatic layout design is used as a secondary means of doing custom / dynamic layouts.

XML layouts are done hierarchically and are composed of views.  A view is a prepackaged module that you can use easily in your applications. (For a quick intro to Android layouts, check out this link: Google Developer’s Hello, Views Blog Entry.)

Let’s look back at our planned layout and break it down into its component views:

Remember how I said that the views are hierarchical?  Well, here’s the hierarchy of the homescreen:

  1. LinearLayout
  • ImageView
  • Button
  • Button
  • Button

This is a simple layout; more complicated layouts have more levels of hierarchy.

———————

Now that we understand the hierarchy, how do we put this into a project?  Let’s move to the next tutorial: setting up a project and putting some code in it.

Introduction to Android Application Development Part 1: Planning

Application Tutorial page 1

Many people ask me how to get started in Android application development. As a result, I’ve always wanted to write a tutorial for Android beginners to help them accomplish that.  Such an undertaking is easier said than done, but here it goes.

For this tutorial, I’m mixing media types.  I go over some of the important stuff through video; I recount most of the process through text such as this, and there will be pictures galore. If I missed anything, feel free to comment and I’ll add to this tutorial.  Let’s get started, shall we?

Okay – now that you’ve watched that video, let me flesh out some of the ideas presented therein.

  • Planning is important: That’s the first thing we’re going to do. I drew a rough mock-up of what the application is going to be / do in the second half of that video.  I’ll expand upon it and make it neater below through making some application mock-ups in an image editor.
  • In this tutorial I’m going to focus on the points of Android development, not developing this app per se.  Of course we will develop this app to completion, but I will be highlighting the components that you’ll likely see throughout creating your own development.

Mock-ups

This is the homescreen for our app.  In the coming tutorials, I will show you how to write this homescreen, some of the design thinking behind said homescreen, and more.  This is where you will learn basic Android UI.

This screen will be your wishlist screen.  The same template will be used for the My Library screen.  It will consist of a custom ListView which will be populated with data we pull from both databases and APIs.

Being the tease that I am, I’m going to hold my ideas for the search screen back for now.  Come up with a design for it yourself.  Feel free to send it in to me by emailing triplemwebdesigns@gmail.com.  If it’s good enough, I might choose it and design it in an upcoming tutorial.  Until next time: Happy developing!

Android 2.2 Annoucned at Google I/O: What it Means for You

At Google I/O today, Android 2.2 (FroYo) was announced. News about the software and its features have been leaking for a little while now, so the move came as no surprise. What was useful about this release, is that we now know what features are included in the newest iteration of the Android Operating System platform. Here’s the official video from Google explaining those features:

In case you didn’t watch the whole video, the main features of Android 2.2 are:

  • Speed
  • API’s and Services
  • Browser
  • Android Market

The first and third feature will greatly improve the user experience, while the second and fourth issue will improve the toolset available to Android developers.  So what does Android 2.2 mean for you?  It depends on who you are:

What does Android 2.2 mean for Developers?

With Android 2.2 come some welcome features we’ve been clamoring for a for a long time.  Firstly there’s the updated 2.2 API.  Some new features are going to be present in this API, most notably the ability to push notifications via Google servers.  Google describes the additional functionality as being able to implement “alerts, send to phone, and two-way sync” via cloud to device messaging.  You can now send authenticated messages from your app server to individual devices via Google servers.  (See diagram below for how this works).

In the example included on the Official 2.2 video, a developer sent directions from Google Maps (on a Chrome browser window) instance, to a device.  Intuitively, the device knows to open the same map view in Google Maps.  It will be interesting to see what uses developers come up with for this service.   I see tighter integration between desktop and mobile applications coming in the future.

Next on the agenda is an extension of App2SD.  Developers can choose where to install their application (SDCard vs. Internal memory).  The user can override this choice, but no longer do developers have to be so conscious of application size and no longer are user limited to what their internal memory can hold.

Finally there are going to be improvements to the Android market.  The most important upgrade to the market will be the ability for users to submit bug reports to developers.  When an Android application hangs or crashes, users can choose to submit a report to the developer.  This report will be available through the developers market console.  This will be an ENORMOUS help to developers, allowing debugging to take place beyond the developer’s own device.

What does Android 2.2 mean for Consumers?

Android 2.2 will bring a much improved  user experience to the average consumer.  A lot of the features contained in this release concentrate on making the platform faster, and giving the user more management choices over his / her devices features.  Lets look at some of those features:

  • Speed: Android 2.2 brings the Dalvik JIT (Just in Time) compiler.  This compiler offers a 2 to 5 time speed improvement over Android 2.1.  That means that that game you’re developing will finally run fast enough in Android!
  • Backup / Restore: Applications can now backup their data to the SD card cloud.  Once you backup data for a given app, you will be able to restore that data on another device, effectively transferring you features and preferences between Android devices.
  • Apps2SD:  Fact: You have more room on your SD card than your phone has internal memory.  Apps2SD takes advantage of this fact and allows you to install applications directly on the SD card.  Later, you can transfer the application between internal memory and the SD card of a given device.
  • Portable Hotspot: Let the tethering begin!  Android devices will now support tethering be default.  It will be interesting to see how carriers respond to this.  No longer will users have to root / mod their device to use it as a wifi-router.
  • Browser Power:  Your browser will be faster, much faster.  Google says improvements in the V8 scripting engine will make the Android browser the fastest mobile browser around.
  • Market: There will be several market improvements in this iteration of Android.  Now you will be able to auto-update all of those application that require updating.  As long as the application doesn’t require new permissions to run, you can choose to automatically batch update those applications with a newer version in the market.

What features are you looking forward to in Android?  Let us know in the comments section below!

Starting Android Development Part 3: Layout Tutorial 2

As promised, here’s part two of my coverage on layouts in Android.  Lets pick up where we left off, namely we just created a main.xml file for layout of our temperature conversion application.

So you know what we’re trying to achieve here, here’s a screenshot of the final product.

temp_screen_final

I know what you’re thinking.  That’s not that cute of a layout.  I’ll leave the job of making really pretty layouts to you after you learn the basics.  For now this layout will do to show you how making layouts in Android works.

This layout consists of a TableLayout (A Linear Layout could have done here as well).  Each table row has other items embedded in it.  One row even has a TableLayout embedded within it (just to show that you can do this).  This is a valid layout, but is generally frowned upon, as embedding table layouts within table layouts can lead to slower UI performance in the long run.

Here’s the code for the layout:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:id="@+id/widget45"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff0000ff"
android:padding="10px"
android:text="Temperature Conversion App"
android:textSize="18px"
android:typeface="sans"
android:textStyle="bold"
>
</TextView>
<TableLayout
android:id="@+id/widget62"
android:layout_width="319px"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TableRow
android:id="@+id/widget63"
android:layout_width="149px"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText
android:id="@+id/User_input_F"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text=" "
>
</EditText>
<TextView
android:id="@+id/widget78"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(ºF)"
>
</TextView>
</TableRow>
<TableRow
android:id="@+id/widget64"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText
android:id="@+id/User_input_C"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text=" "
>
</EditText>
<TextView
android:id="@+id/widget79"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(ºC)"
>
</TextView>
</TableRow>
<TableRow
android:id="@+id/widget65"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText
android:id="@+id/widget83"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text=" "
>
</EditText>
<TextView
android:id="@+id/User_input_K"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(ºK)"
>
</TextView>
</TableRow>
</TableLayout>
<TableRow
android:id="@+id/Conversion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="@+id/conversion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Convert to:"
>
</TextView>
<RadioGroup
android:id="@+id/widget144"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RadioButton
android:id="@+id/F_Select"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Fareinheit"
>
</RadioButton>
<RadioButton
android:id="@+id/C_Select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Celcius"
>
</RadioButton>
<RadioButton
android:id="@+id/K_Select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kelvin"
>
</RadioButton>
</RadioGroup>
</TableRow>
<TableRow
android:id="@+id/widget84"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/Calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate"
>
</Button>
</TableRow>
</TableLayout>

Note how each element has an id attribute (android:id) and the value of that attribute starts with “@+id/name“@+id/” identifies the name by which you can refer to this
layout element later in your java programming.  Other things to note include:

  • android:layout_width and android:layout_height: Use these to determine how much space an element is going to take up.  These can have two values: wrap_content and fill_parent.  Wrap content means the element will only be as large as it needs to be to display its content.  Fill_parent means the element will fill all available space it can, as determined by the parent element it resides in
  • To find the attribute applicable to a given layout, check out that layouts documentation at the developer.android.com/reference website.  E.g. the API site for TableLayout is
    http://developer.android.com/reference/android/widget/TableLayout.html. I usually find the page i need by just searching “android layout” and the name of the element I’m using

In the next post of this series I will discuss some common Android layout elements, what they look like, and some of the attributes associated with that element.  Then it’ll be time to connect our layout (frontend) to the logic that makes it work (the backend).  For now check out the code I provided, try to understand how it works, and practice creating your own Android layouts!