Archiv for December, 2008


published: December 31st, 2008

2009 Android wishlist for my HTC G1

Thought I’d throw down a wish list for things to have Google development, show up in the Android Market or just development myself.

1. Touch-Screen keyboard (come on Cupcake!)

2. Better workflow for Music Player

3. Support for AVI video playback

4. Access for developers to the Widget API

5. Better RSS reader

6. Ability to edit Contact Groups from my G1

7. Port of Spore to Android!!

8. PDF and EBook reader

maybe more to come later…any other ideas?

published: December 30th, 2008

Passing on email from Google about Android Market

For any of you developers out there who aren’t on the mailing list and didn’t get the following email from Google about the Android Market, I thought I’d pass it on.

Hello,

Thank you for your participation in Android Market!

Since we launched a couple months ago, the team has been working on
several significant updates to Android Market. I’d like to let you know
about these upcoming changes and what they will mean to you and other
members of our developer community.

(more…)

published: December 29th, 2008

SimpleAdapter ViewBinders

Used a SimpleAdapter.ViewBinder the other day.  ViewBinders allow another way of attaching data to an Adapter.  I needed to capture an onClick event from a row in a ListActivity and fire a corresponding Intent to open a new Activity; basically mimicking the behavior of the API Demos Google provides in the Android SDK.

(more…)

published: December 19th, 2008

Boilerplate SQL CRUD code

I’m tired of rewriting these, so here’s a simple set of boilerplate methods to CRUD objects for an Android SQLite3 db for your copy and pasting pleasure.

    public long createThing(String name)
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_NAME, name);

        return mDb.insert(THINGS_TABLE, null, initialValues);
    }

    public boolean updateThing(long rowId, String name)
    {
        ContentValues args = new ContentValues();
        args.put(KEY_NAME, name);

        return mDb.update(THINGS_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
    }

    public boolean deleteThing(long rowId)
    {
        return mDb.delete(THINGS_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
    }

    public Cursor fetchThing(long rowId)
    {
    	String query = KEY_ROWID + "=" + rowId;
        Cursor mCursor =
                mDb.query(true, THINGS_TABLE,
                		new String[] {KEY_ROWID, KEY_NAME},
                		query,
                        null, null, null, null, null);

        if (mCursor != null)
        {
            mCursor.moveToFirst();
        }

        return mCursor;
    }

    public Cursor fetchAllThings()
    {
        return mDb.query(THINGS_TABLE,
        		new String[] {KEY_ROWID, KEY_NAME},
        		null, null, null, null, null);
    }

published: December 18th, 2008

Icons and MenuItem for Android

I’ve been working through Ed Burnette’s book, “Hello, Andorid” and it’s given me a number of new tricks already; I’m only about a quarter of the way through.  One of the changes I made for my Android game Jumpy was to move the programmatic building of the menu to a menu.xml file instead, as Mr. Burnette describes in Chapter 3 of his book.

(more…)

published: December 16th, 2008

Please check the DATA_ROAMING setting

With T-Mobiles data roaming issue out there for Android developers to worry about, it seems like programs accessing the web for data should be checking the DATA_ROAMING System Setting before they acquire their data.  The Activity below accesses and displays the result of the Setting.

I’m not a lawyer, but I do feel like I need to state that if your program still incurs roaming charges for the user, please don’t send them to me if you use this code bit.  Please thoroughly  test your code before you deploy!!  Just as a note, I had to install this on my G1 to test it because I couldn’t access the Setting directory from the Android Emulator.
(more…)

published: December 12th, 2008

Listing Androids drawable Resources

Wrote this real quick Android ListActivity to display the Resources from the android.R.drawable.  Not very pretty, but I just wanted something to display the images and show the associated Resource id.  Sorry in advance for any wacky formatting issues due to cutting and pasting from Eclipse into the WordPress editor.

(more…)

published: December 11th, 2008

SQLite SUM and IN commands for Android

public int calculateTotalSalaryForEmployees( long[] departmentIds )
{
    int total = 0;
    // create a list of ids to use in the IN statement
    // Arrays.toString creates String which looks like [1,2,3]
    String deptlist = Arrays.toString( departmentIds );

    // remove the enclosing brackets from id list
    String inClause = deptlist.substring( 1, deptlist.length() - 1 );
    String sql = "select sum(salary) from employees where department_id " +
        "in (" + inClause + ")";

    Cursor c = mDb.rawQuery( sql, null );
    // move to the first row of the cursor
    c.moveToFirst();
    total = c.getInt(0);
    c.close();

    return total;
}

Trying something new out here. As I’m programming I find many little hints and tips that I want to remember or share. Not the longer more in-depth posts I’ve been trying out with the subjects on Android HTTP and Ruby on Rails, but little quick things to put into ones toolbox.

So here’s the first one, a little method to retrieve the sum of all the salaries of employees within a department.  It utilizes the SQL SUM and IN commands.  It was surprisingly difficult to find the exact way to perform these command, but surprisingly obvious and easy once I figured it out.  Just the types of little tools I don’t want to loose.

published: December 8th, 2008

Hide the Title bar in an Android View by using the Window Class

Had to hunt around for this in the Android documentation so I thought I’d mention it in case anyone else could utilize it.  In my new shopping list application I want to display dynamic information in the title bar and didn’t want to display the default title bar.  I knew it could be done from looking at the application view screen on the Android Market. There is a flag in the Window class to hide the title bar, and it’s placed in the onCreate method of an Activity.

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    ...

I was expecting to find a setter method in either the Activity or the View class.  After hiding the title bar, I simply added a TableLayout to the top of my View to display the information.

I’m not exactly sure what the relationship is of the Window to the View or the Activity other then what is already documented in the Window API and Google’s glossary for Android, maybe I’ll get some time in the future to poke around a bit more.

published: December 6th, 2008

Android SDK 1.0 release 2 available

Dan Morrill snuck out a post late yesterday on the Android Developers blog stating that Android SDK 2.0 is now available.  Apparently no new features, but fixes for some bugs.  Dan also stated that a G1 developers device is now available.  So if you aren’t in an area where the HTC G1 has been made available you now have a means to test your applications.