Another JS1K Submission

| | Comments (0)
heartbeat.jpgLong time no see ;-) Just wanted to let you know that I submittet a (very) little Javascript animation to the JS1K competition. The motto of the current competition is "Love". So I decided to do an EKG style heartbeat animation (440 Bytes). It runs with IE9, FF10, Chrome 17 and Safari 5. You can find it here: http://js1k.com/2012-love/demo/1173.

Javascript Demo (Game) - less than 1024 chars of code

| | Comments (0)
Have contributed a little minesweeper game, have a look at: http://js1k.com/demo/512

Android How-Tos and Samples updated to new SDK (1.0 R2)

| | Comments (0)
I've updated the code snippets of this blog to the newest SDK of Android (1.0 R2).

TrackBacks for this BLOG deactivated

| | Comments (0)
Due to spamming attempts I decided to deactivate the trackbacks for this log!

Programming Concepts of Android Explained

| | Comments (0)
Today I stumbled accross a little paper which explains some programming concepts of Android. It has been written by D. Guntz and J. Pleumann who were involved in the creation of core libraries of Android. So have a look at their site for details (paper + full source and binary).

Android How-To: See also ...

| | Comments (0)
Here are some resources where you can also find How-Tos as well as other interesting Android related stuff:


Exploring jQuery

| | Comments (0)
jQuery is well known to the "Ajax-Community". To get familiar with this Javascript library and tools, I implemented the little game "Trap" (a minesweeper clone) using jQuery features.

Findings: Maybe I need further experience, but for now jQuery reminds me of ancient times in which some self-styled programming gurus wrote single lines of code in C that nobody else could read....

Anyway: here is the result of my implementation and exploration efforts, feel free to play, copy, re-use and comment.
trap.jpg
[NOTE] Updated on 2009-01-17: Adopted Samples to final release of Android SDK (1.0 R2)

An Android user interface is created by specifying a layout XML usually, but sometimes you need to create your interfaces or parts of it "on-the-fly" in your programm code. This is not very easy sometimes because of the lack of documentation. The following code snippets show you how I could create a Spinner and a ListView widget programmatically:

...
public class Sample extends Activity
  ...
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    ...
    
//Creating a spinner
Spinner spinner = new Spinner(this); ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, new String[] { "Apple", "Peach", "Banana" }); spinner.setAdapter(spinnerArrayAdapter);
//Add spinner to this activity's view (a LinearLayout)
mainLayout.addView(spinner, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); ... } }
...
public class Sample extends Activity
  ...
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    ...
    
//Creating a ListView with Context Menu
ListView listView = new ListView(this); ArrayAdapter listViewArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, new String[] { "Apple", "Peach","Banane" }); listView.setAdapter(listViewArrayAdapter); listView.setFocusableInTouchMode(true); listView.setOnFocusChangeListener( new View.OnFocusChangeListener() { @Override public void onFocusChange(View arg0, boolean arg1) { Log.i("SampleApp", "onFocusChanged() - view=" + arg0); } }); listView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int arg2, long arg3) { int selectedPosition = adapterView.getSelectedItemPosition(); Log.i("SampleApp", "Click on position"+selectedPosition); } }); listView .setOnCreateContextMenuListener( new View.OnCreateContextMenuListener() { public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo; menu.add(0, 0, 0, "Context-Menu-Entry"); } }); ... } }

Android How-To: Invoke a phone call Activity

| | Comments (0)
Here's the code to invoke a phone call for a given number:

try {
   Intent intent = new Intent(Intent.CALL_ACTION);
   intent.setData(Uri.parse("tel:+436641234567"));
   startActivity(intent);
} catch (Exception e) {
   Log.e("SampleApp", "Failed to invoke call", e);
}

Android How-To: Create a new Contact

| | Comments (2)
[NOTE] Updated on 2009-03-11: Adopted sample to release of Android SDK (1.1 R1)

It took me some time to figure out how contacts are created and stored in Android. There were a couple of postings (see Android Google Groups) I had to consult, but finally I did it :-). In case you experience the same difficulties here is the full picture (source code) that worked for me:


ContentValues personValues = new ContentValues();
personValues.put(Contacts.People.NAME, "John F. Doe");
/* STARRED 0 = Contacts, 1 = Favorites */
personValues.put(Contacts.People.STARRED, 1);


// worked in SDK 1.0 R2 but not in SDK 1.1 R1 anymore //Uri newPersonUri = getContentResolver() // .insert(Contacts.People.CONTENT_URI, personValues);
Uri newPersonUri = Contacts.People .createPersonInMyContactsGroup(getContentResolver(), personValues); if (newPersonUri != null) {
// add company (organisation)
ContentValues organisationValues = new ContentValues(); Uri orgUri = Uri.withAppendedPath(newPersonUri, Contacts.Organizations.CONTENT_DIRECTORY); organisationValues.put(Contacts.Organizations.COMPANY, "MyCompany Inc."); organisationValues.put(Contacts.Organizations.TYPE, Contacts.Organizations.TYPE_WORK); Uri orgUpdate = getContentResolver() .insert(orgUri, organisationValues); if (orgUpdate == null) { throw new Exception("Failed to insert organisation"); }
// add mobile phone number
ContentValues mobileValues = new ContentValues(); Uri mobileUri = Uri.withAppendedPath(newPersonUri, Contacts.People.Phones.CONTENT_DIRECTORY); mobileValues.put(Contacts.Phones.NUMBER, "(660) 111-1111"); mobileValues.put(Contacts.Phones.TYPE, Contacts.Phones.TYPE_MOBILE); Uri phoneUpdate = getContentResolver() .insert(mobileUri, mobileValues); if (phoneUpdate == null) { throw new Exception( "Failed to insert mobile phone number"); }
// add fax number
ContentValues faxValues = new ContentValues(); Uri faxUri = Uri.withAppendedPath(newPersonUri, Contacts.People.Phones .CONTENT_DIRECTORY); faxValues.put(Contacts.Phones.NUMBER, "(408) 111-1111-1"); faxValues.put(Contacts.Phones.TYPE, Contacts.Phones.TYPE_FAX_WORK); phoneUpdate = getContentResolver() .insert(faxUri, faxValues); if (phoneUpdate == null) { throw new Exception( "Failed to insert work fax number"); }
// add email
ContentValues emailValues = new ContentValues(); Uri emailUri = Uri .withAppendedPath( newPersonUri, Contacts.People.ContactMethods .CONTENT_DIRECTORY); emailValues.put(Contacts.ContactMethods.KIND, Contacts.KIND_EMAIL); emailValues.put(Contacts.ContactMethods.TYPE, Contacts.ContactMethods.TYPE_HOME); emailValues.put(Contacts.ContactMethods.DATA, "john.f.doe@exit.com"); Uri emailUpdate = getContentResolver() .insert(emailUri, emailValues); if (emailUpdate == null) { throw new Exception("Failed to insert email"); }
// add address
ContentValues addressValues = new ContentValues(); Uri addressUri = Uri .withAppendedPath( newPersonUri, Contacts.People.ContactMethods .CONTENT_DIRECTORY); addressValues.put(Contacts.ContactMethods.KIND, Contacts.KIND_POSTAL); addressValues.put(Contacts.ContactMethods.TYPE, Contacts.ContactMethods.TYPE_HOME); addressValues.put(Contacts.ContactMethods.DATA, "Baker Street 14\n54123 New Hampshire"); Uri addressUpdate = getContentResolver().insert(addressUri, addressValues); if (addressUpdate == null) { throw new Exception("Failed to insert address"); }