Noyzee Box Android App released

I have released onto the market my first free Android App. Noyzee Box is a simple press-a-button-makes-a-noise application.

What was interesting about this app is that instead of hard coding the noise files. I am instead finding all sound resources and then creating a mapping of resource IDs to the resource name, then they are automatically displayed in the Android "ListView".

The benefit of this is that if i require to add more sounds, this is as easy as dropping them into the resources folder then recompiling the project!

The code i used to achieve this is listed below.


private void createIDMap() {
R.raw ids = new R.raw() ;
// Get all the fields declared under R.id
Class c = R.raw.class ;
Field fields[] = c.getDeclaredFields() ;

countries = new String[fields.length];

try {
int i = 0 ;
while( i Field field = fields[i] ;
countries[i] = field.getName();
String idStr = "R.raw." + field.getName() ;
int idVal = field.getInt(ids) ;

m_idMap.put( idStr, new Integer(idVal) ) ;
Log.d(TAG, "Adding "+idStr+" with value "+idVal) ;
i++ ;
}
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}