Channels ▼
RSS

Mobile

Building an Automotive Dashboard on Android


Setting up the code for the second screen is relatively straightforward. Note that I opted to capture a map for the whole Midwest rather than maps based on my GPS. I opted for approach. Since I rarely drive more than 100 miles away from my home, submitting map coordinates to get the same data within a 500 mile radius would unnecessarily slow my query since the GPS coordinates would first need to be acquired, then a geospatial comparison of which coordinates matched the appropriate weather map would have to be calculated and submitted. If I were regularly traveling cross-country in my car or wanted to share this app on the Asteroid Market, then the inclusion of this routine would make more sense. So rather than spend the extra processing power (not to mention the time it would take to code and debug the routine), I went for the lazy approach of grabbing the map as noted in the code here:


package com.mikeriley.darksky;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

public class ShowMap extends Activity{

    public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
      setContentView(R.layout.weathermap);
      String url = "http://sirocco.accuweather.com/nx_mosaic_400x300c/RE/INMREIL_.gif";           
      Drawable image = ImageOperations(this, url);
      ImageView imgView = (ImageView)findViewById(R.id.weathermap);
      imgView.setImageDrawable(image);
    }	

    public Object fetch(String address) throws MalformedURLException,
    IOException {
      URL url = new URL(address);
      Object content = url.getContent();
      return content;
    }  

    private Drawable ImageOperations(Context ctx, String url) {
      try {
        InputStream imgStream = (InputStream) this.fetch(url);
        Drawable imgDraw = Drawable.createFromStream(imgStream, "src");
        return imgDraw;
      } catch (MalformedURLException e) {
        return null;
      } catch (IOException e) {
        return null;
      }
    }  	

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activity_main, menu);
      return true;
    }
    
    public boolean onOptionsItemSelected (MenuItem item) {
      switch (item.getItemId()) {        
      case R.id.menu_quit:
    	finish();
      }
      return false;
    }	
}

I quickly tested the application in the Android emulator. By the way, one of the changes that was made in the recent Android ADK is that Google no longer supports skinning Android emulators. According to Xavier Ducrohet, Android SDK Tech Lead at Google, he said in this post that "We are kind of going away from custom skins. Generally they aren't that useful." While it makes sense why Google removed this eye candy, its generic skin fails to put you in a mindset of developing for a specific targeted device like the Asteroid Smart. That said, it works just as well even without the graphic skin that Parrot created for the AVD before Google put the kibosh on custom virtual device skins.

Up and Running

Deploying the compiled APK to the Asteroid Smart was a simple affair. I copied the APK to an SD card, placed the card in Asteroid Smart's SD card slot, pulled up the Install Applications from SD card screen and installed the program without incident. Because my program polls the GPS and requires network access, these permissions came up on screen during the installation process, asking me to accept and continue.

With the application installed, I found its icon (actually two icons, one for the main program and one for the Weather Screen intent) in the Applications folder. With a network and GPS connection verified, loading up the application only took a second for it to capture the GPS readings and submit them to the Dark Sky web service.

My Dark Sky-powered Application running on the Asteroid Smart
Figure 3: My Dark Sky-powered Application running on the Asteroid Smart.

I then selected the Weather Map option from the program's menu and it up popped the doppler radar map for the area. Nice. I exited the application and launched just the Weather Map app (thanks to the fact that I registered this screen earlier as an Intent) and the data displayed as expected.

The Weather Map screen displayed on the Asteroid Smart
Figure 4: The Weather Map screen displayed on the Asteroid Smart.

Lessons Learned

The most important lesson I learned from my experience portent applications to the Asteroid is to do away with menus. Even though Asteroid supports them, the touch targets for the menu icon and the menu items themselves are too small to accurately select while driving. A redesign of the application is in the works that will feature a large weather map icon in the upper right corner.

Along with replacing menu choices with on-screen icons is the need to feature the most important information on the screen at once instead of forcing drivers to scroll through a list view or read several lines of data. So rather than listing out the temperature, current and forecasted weather conditions, my redesign will highlight the current temperature in a dedicated area with a large font, and the next hour forecast in a smaller but still easily readable font size. The screen will also feature an icon next to the weather map icon for more forecast details. Selecting the button will display another screen as notably designed to allow for maximum information transfer to the driver shooting a quick glance at the screen.

I intend to continue to refine the application to make it as driver friendly and non-obtrusive as possible while still conveying the pertinent details in the split-second it takes to glance at the display. And who knows, if it gets really well polished, I may even submit it for considering via Parrot's Asteroid app store validation process.

Conclusion

While the Android Smart market is rather small at the moment, the potential for Parrot's first-mover advantage in this dedicated Android-based in-car computing market is huge. The Asteroid Smart is a major step forward compared to Parrot's initial Asteroid entry, and it final brings into focus a dream that Parrot and car computing enthusiasts like myself have been wishing to come true for decades.

If you are an Android developer who spends a good deal of time in your car commuting and you want to get in on a rapidly expanding market for your Android coding skills, I highly recommend the the Asteroid Smart as a great place to start.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video