Merge change Ifc1b1ccb into eclair-mr2

* changes:
  Fix eclipse build
diff --git a/samples/ApiDemos/AndroidManifest.xml b/samples/ApiDemos/AndroidManifest.xml
index 01361dd..aba330a 100644
--- a/samples/ApiDemos/AndroidManifest.xml
+++ b/samples/ApiDemos/AndroidManifest.xml
@@ -82,6 +82,14 @@
             </intent-filter>
         </activity>
 
+       <activity android:name=".app.QuickContactsDemo"
+                android:label="@string/quick_contacts_demo">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.SAMPLE_CODE" />
+            </intent-filter>
+        </activity>
+
         <activity android:name=".app.WallpaperActivity"
                 android:label="@string/activity_wallpaper"
                 android:theme="@style/Theme.Wallpaper">
diff --git a/samples/ApiDemos/res/drawable-hdpi/ic_contact_picture.png b/samples/ApiDemos/res/drawable-hdpi/ic_contact_picture.png
new file mode 100755
index 0000000..7c34f5c
--- /dev/null
+++ b/samples/ApiDemos/res/drawable-hdpi/ic_contact_picture.png
Binary files differ
diff --git a/samples/ApiDemos/res/drawable-mdpi/ic_contact_picture.png b/samples/ApiDemos/res/drawable-mdpi/ic_contact_picture.png
new file mode 100644
index 0000000..3a338e8
--- /dev/null
+++ b/samples/ApiDemos/res/drawable-mdpi/ic_contact_picture.png
Binary files differ
diff --git a/samples/ApiDemos/res/layout/quick_contacts.xml b/samples/ApiDemos/res/layout/quick_contacts.xml
new file mode 100644
index 0000000..ffb19ed
--- /dev/null
+++ b/samples/ApiDemos/res/layout/quick_contacts.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<RelativeLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:paddingLeft="0dip"
+    android:paddingRight="9dip"
+    android:layout_height= "wrap_content"
+    android:minHeight="48dip">
+
+    <QuickContactBadge
+        android:id="@+id/badge"
+        android:layout_marginLeft="2dip"
+        android:layout_marginRight="14dip"
+        android:layout_marginTop="4dip"
+        android:layout_marginBottom="3dip"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentTop="true"
+        android:layout_height= "wrap_content"
+        android:layout_width= "wrap_content"
+        android:src="@drawable/ic_contact_picture"
+        style="?android:attr/quickContactBadgeStyleWindowSmall" />
+
+    <TextView
+        android:id="@+id/name"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:paddingLeft="2dip"
+        android:layout_centerVertical="true"
+        android:layout_toRightOf="@id/badge"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content" />
+
+</RelativeLayout>
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index f4e895e..6f91b34 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -32,12 +32,13 @@
     <string name="dialog_activity_text">Example of how you can use the
             Theme.Dialog theme to make an activity that looks like a
             dialog.</string>
-
     <string name="activity_custom_dialog">App/Activity/Custom Dialog</string>
     <string name="custom_dialog_activity_text">Example of how you can use a
             custom Theme.Dialog theme to make an activity that looks like a
             customized dialog, here with an ugly frame.</string>
 
+    <string name="quick_contacts_demo">App/Activity/QuickContactsDemo</string>
+
     <string name="activity_wallpaper">App/Activity/Wallpaper</string>
     <string name="activity_setwallpaper">App/Activity/SetWallpaper</string>
     <string name="set_wallpaper">Set Wallpaper</string>
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/QuickContactsDemo.java b/samples/ApiDemos/src/com/example/android/apis/app/QuickContactsDemo.java
new file mode 100644
index 0000000..1ee5742
--- /dev/null
+++ b/samples/ApiDemos/src/com/example/android/apis/app/QuickContactsDemo.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.apis.app;
+
+import com.example.android.apis.R;
+
+import android.app.ListActivity;
+import android.content.Context;
+import android.database.CharArrayBuffer;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.provider.ContactsContract.Contacts;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.QuickContactBadge;
+import android.widget.ResourceCursorAdapter;
+import android.widget.TextView;
+
+public class QuickContactsDemo extends ListActivity {
+    static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] {
+            Contacts._ID, // 0
+            Contacts.DISPLAY_NAME, // 1
+            Contacts.STARRED, // 2
+            Contacts.TIMES_CONTACTED, // 3
+            Contacts.CONTACT_PRESENCE, // 4
+            Contacts.PHOTO_ID, // 5
+            Contacts.LOOKUP_KEY, // 6
+            Contacts.HAS_PHONE_NUMBER, // 7
+    };
+
+    static final int SUMMARY_ID_COLUMN_INDEX = 0;
+    static final int SUMMARY_NAME_COLUMN_INDEX = 1;
+    static final int SUMMARY_STARRED_COLUMN_INDEX = 2;
+    static final int SUMMARY_TIMES_CONTACTED_COLUMN_INDEX = 3;
+    static final int SUMMARY_PRESENCE_STATUS_COLUMN_INDEX = 4;
+    static final int SUMMARY_PHOTO_ID_COLUMN_INDEX = 5;
+    static final int SUMMARY_LOOKUP_KEY = 6;
+    static final int SUMMARY_HAS_PHONE_COLUMN_INDEX = 7;
+
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND ("
+                + Contacts.HAS_PHONE_NUMBER + "=1) AND ("
+                + Contacts.DISPLAY_NAME + " != '' ))";
+        Cursor c =
+                getContentResolver().query(Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, select,
+                null, Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
+        startManagingCursor(c);
+        ContactListItemAdapter adapter = new ContactListItemAdapter(this, R.layout.quick_contacts, c);
+        setListAdapter(adapter);
+
+    }
+
+    private final class ContactListItemAdapter extends ResourceCursorAdapter {
+        public ContactListItemAdapter(Context context, int layout, Cursor c) {
+            super(context, layout, c);
+        }
+
+        @Override
+        public void bindView(View view, Context context, Cursor cursor) {
+            final ContactListItemCache cache = (ContactListItemCache) view.getTag();
+            TextView nameView = cache.nameView;
+            QuickContactBadge photoView = cache.photoView;
+            // Set the name
+            cursor.copyStringToBuffer(SUMMARY_NAME_COLUMN_INDEX, cache.nameBuffer);
+            int size = cache.nameBuffer.sizeCopied;
+            cache.nameView.setText(cache.nameBuffer.data, 0, size);
+            final long contactId = cursor.getLong(SUMMARY_ID_COLUMN_INDEX);
+            final String lookupKey = cursor.getString(SUMMARY_LOOKUP_KEY);
+            cache.photoView.assignContactUri(Contacts.getLookupUri(contactId, lookupKey));
+        }
+
+        @Override
+        public View newView(Context context, Cursor cursor, ViewGroup parent) {
+            View view = super.newView(context, cursor, parent);
+            ContactListItemCache cache = new ContactListItemCache();
+            cache.nameView = (TextView) view.findViewById(R.id.name);
+            cache.photoView = (QuickContactBadge) view.findViewById(R.id.badge);
+            view.setTag(cache);
+
+            return view;
+        }
+    }
+
+    final static class ContactListItemCache {
+        public TextView nameView;
+        public QuickContactBadge photoView;
+        public CharArrayBuffer nameBuffer = new CharArrayBuffer(128);
+    }
+}
diff --git a/simulator/wrapsim/Android.mk b/simulator/wrapsim/Android.mk
index f9a2414..7c2cbf2 100644
--- a/simulator/wrapsim/Android.mk
+++ b/simulator/wrapsim/Android.mk
@@ -25,8 +25,6 @@
 	SysPower.c \
 	Util.c
 
-LOCAL_C_INCLUDES += prebuilt/common/esd
-
 LOCAL_MODULE := libwrapsim
 
 # Relying on other Android libraries is probably a bad idea, since any
@@ -36,7 +34,7 @@
 ifeq ($(BUILD_SIM_WITHOUT_AUDIO),true)
 LOCAL_CFLAGS += -DBUILD_SIM_WITHOUT_AUDIO=1
 else
-LOCAL_LDLIBS += -lesd
+LOCAL_LDLIBS += -lasound
 endif
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/simulator/wrapsim/DevAudio.c b/simulator/wrapsim/DevAudio.c
index af7a950..a8f5c16 100644
--- a/simulator/wrapsim/DevAudio.c
+++ b/simulator/wrapsim/DevAudio.c
@@ -8,7 +8,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <esd.h>
+#include <alsa/asoundlib.h>
 
 #include <fcntl.h>
 #include <sys/ioctl.h>
@@ -19,10 +19,7 @@
  * Input event device state.
  */
 typedef struct AudioState {
-    int fd;
-    int sourceId;
-    int esdVol;
-    int streamType;
+    snd_pcm_t *handle;
 } AudioState;
 
 /*
@@ -33,45 +30,31 @@
 #if BUILD_SIM_WITHOUT_AUDIO
     return 0;
 #else
-    esd_player_info_t *pi; 
-    audioState->fd = -1;
-    audioState->sourceId = -1;
-    audioState->esdVol = -1;
-    audioState->streamType = 0;
+    audioState->handle = NULL;
 
-    int format = ESD_BITS16 | ESD_STEREO | ESD_STREAM | ESD_PLAY;
-    char namestring[] = "Android Audio XXXXXXXX";
-    sprintf(namestring,"Android Audio %08x", (unsigned int)audioState);
-    int esd_fd = esd_play_stream_fallback(format, 44100, NULL, namestring);
-    if (esd_fd > 0) {
-        // find the source_id for this stream
-        int mix = esd_open_sound(NULL);
-        if (mix > 0) {
-            esd_info_t *info = esd_get_all_info(mix);
+    snd_pcm_open(&audioState->handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
 
-            if (info) {
-                for(pi = info->player_list; pi; pi = pi->next) {
-                    if(strcmp(pi->name, namestring) == 0) {
-                        audioState->sourceId = pi->source_id;
-                        break;
-                    }
-                }
-                esd_free_all_info(info);
-            }
-            esd_close(mix);
-        }
-        audioState->fd = esd_fd;
-        return 0;
+    if (audioState->handle) {
+        snd_pcm_hw_params_t *params;
+        snd_pcm_hw_params_malloc(&params);
+        snd_pcm_hw_params_any(audioState->handle, params);
+        snd_pcm_hw_params_set_access(audioState->handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);
+        snd_pcm_hw_params_set_format(audioState->handle, params, SND_PCM_FORMAT_S16_LE);
+        unsigned int rate = 44100;
+        snd_pcm_hw_params_set_rate_near(audioState->handle, params, &rate, NULL);
+        snd_pcm_hw_params_set_channels(audioState->handle, params, 2);
+        snd_pcm_hw_params(audioState->handle, params);
+        snd_pcm_hw_params_free(params);
+    } else {
+        wsLog("Couldn't open audio hardware, faking it\n");
     }
-    printf("Couldn't open audio device. Faking it.\n");
+
     return 0;
 #endif
 }
 
 /*
- * Return the next available input event.
- *
- * We just pass this through to the real "write", since "fd" is real.
+ * Write audio data.
  */
 static ssize_t writeAudio(FakeDev* dev, int fd, const void* buf, size_t count)
 {
@@ -79,8 +62,10 @@
     return 0;
 #else
     AudioState *state = (AudioState*)dev->state;
-    if (state->fd >= 0)
-        return _ws_write(state->fd, buf, count);
+    if (state->handle != NULL) {
+        snd_pcm_writei(state->handle, buf, count / 4);
+        return count;
+    }
 
     // fake timing
     usleep(count * 10000 / (441 * 4));
@@ -105,7 +90,7 @@
     return 0;
 #else
     AudioState *state = (AudioState*)dev->state;
-    close(state->fd);
+    snd_pcm_close(state->handle);
     free(state);
     dev->state = NULL;
     return 0;
diff --git a/simulator/wrapsim/README.txt b/simulator/wrapsim/README.txt
index 358c06c..364d96d 100644
--- a/simulator/wrapsim/README.txt
+++ b/simulator/wrapsim/README.txt
@@ -19,3 +19,6 @@
 For more verbose logging, you can enable the verbose forms of CALLTRACE
 and CALLTRACEV in Intercept.c.
 
+To build, you will need to have the 32-bit libaudio2 development package
+installed. On Ubuntu Hardy, do something like:
+% sudo apt-get install lib32asound2-dev