New social item layout. Using spannable.
diff --git a/res/layout-finger/social_list_item.xml b/res/layout-finger/social_list_item.xml
index 96164cf..3e6644d 100644
--- a/res/layout-finger/social_list_item.xml
+++ b/res/layout-finger/social_list_item.xml
@@ -19,42 +19,57 @@
android:layout_height="wrap_content">
<ImageView
+ android:id="@+id/sourceIcon"
+ android:layout_width="32dip"
+ android:layout_height="32dip"
+ android:layout_alignParentRight="true"
+ android:layout_alignParentTop="true"
+ android:layout_centerVertical="true"
+ android:layout_marginLeft="5dip"
+ android:layout_marginRight="5dip"
+
+ android:gravity="center"
+ android:scaleType="centerInside"
+ />
+
+ <ImageView
android:id="@+id/photo"
android:layout_width="58dip"
- android:layout_height="58dip" />
+ android:layout_height="58dip"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true"
+ android:layout_centerVertical="true"
+ android:layout_marginRight="8dip"
+
+ android:background="@drawable/contact_picture_border_in_list"
+ android:gravity="center"
+ android:scaleType="fitCenter"
+ />
<TextView
- android:id="@+id/displayname"
+ android:id="@+id/content"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
android:layout_toRightOf="@id/photo"
- android:textStyle="bold"
- android:textSize="18sp"
- android:paddingLeft="8dip"
- android:paddingTop="3dip"
- android:textColor="#f000"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" />
+ android:layout_toLeftOf="@id/sourceIcon"
+ android:layout_alignParentTop="true"
+ android:layout_alignWithParentIfMissing="true"
- <TextView
- android:id="@+id/title"
- android:layout_toRightOf="@id/photo"
- android:layout_below="@id/displayname"
- android:textSize="16sp"
android:lineSpacingMultiplier="0.9"
- android:paddingLeft="8dip"
- android:textColor="#f000"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" />
+ />
<TextView
android:id="@+id/published"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
android:layout_toRightOf="@id/photo"
- android:layout_below="@id/title"
- android:textSize="14sp"
- android:paddingLeft="8dip"
- android:paddingTop="2dip"
- android:paddingBottom="5dip"
+ android:layout_below="@id/content"
+ android:layout_marginTop="2dip"
+ android:layout_marginBottom="5dip"
+
+ android:lines="1"
+ android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#8000"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" />
+ />
</RelativeLayout>
diff --git a/src/com/android/contacts/SocialStreamActivity.java b/src/com/android/contacts/SocialStreamActivity.java
index 920999b..486ee22 100644
--- a/src/com/android/contacts/SocialStreamActivity.java
+++ b/src/com/android/contacts/SocialStreamActivity.java
@@ -17,12 +17,12 @@
package com.android.contacts;
import com.android.contacts.EdgeTriggerView.EdgeTriggerListener;
+import com.android.contacts.SocialStreamActivity.MappingCache.Mapping;
import com.android.providers.contacts2.ContactsContract;
import com.android.providers.contacts2.ContactsContract.Aggregates;
import com.android.providers.contacts2.ContactsContract.Contacts;
import com.android.providers.contacts2.ContactsContract.Data;
import com.android.providers.contacts2.ContactsContract.CommonDataKinds.Photo;
-import com.android.providers.contacts2.ContactsContract.CommonDataKinds.StructuredName;
import com.android.providers.contacts2.SocialContract.Activities;
import org.xmlpull.v1.XmlPullParser;
@@ -35,7 +35,6 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.Bitmap;
@@ -43,26 +42,21 @@
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
-import android.graphics.PixelFormat;
import android.graphics.Rect;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.PaintDrawable;
import android.net.Uri;
import android.os.Bundle;
+import android.text.SpannableStringBuilder;
import android.text.format.DateUtils;
+import android.text.style.TextAppearanceSpan;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.BaseAdapter;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
-import android.widget.ListView;
-import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import java.io.IOException;
@@ -116,11 +110,7 @@
mMappingCache = MappingCache.createAndFill(this);
Cursor cursor = managedQuery(Activities.CONTENT_URI, PROJ_ACTIVITIES, null, null);
- mAdapter = new SocialAdapter(this, cursor, mContactsCache);
-
-// mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor,
-// new String[] { Activities.AUTHOR_CONTACT_ID, Activities.TITLE },
-// new int[] { android.R.id.text1, android.R.id.text2 });
+ mAdapter = new SocialAdapter(this, cursor, mContactsCache, mMappingCache);
setListAdapter(mAdapter);
@@ -158,42 +148,67 @@
* {@link Activities#CONTENT_URI}.
*/
private static class SocialAdapter extends CursorAdapter {
- private Context mContext;
- private LayoutInflater mInflater;
- private ContactsCache mContactsCache;
+ private final Context mContext;
+ private final LayoutInflater mInflater;
+ private final ContactsCache mContactsCache;
+ private final MappingCache mMappingCache;
+ private final TextAppearanceSpan mTextAppearanceName;
+ private final TextAppearanceSpan mTextAppearanceStatus;
private static class SocialHolder {
ImageView photo;
- TextView displayname;
- TextView title;
+ ImageView sourceIcon;
+ TextView content;
+ SpannableStringBuilder contentBuilder = new SpannableStringBuilder();
TextView published;
}
- public SocialAdapter(Context context, Cursor c, ContactsCache contactsCache) {
+ public SocialAdapter(Context context, Cursor c, ContactsCache contactsCache,
+ MappingCache mappingCache) {
super(context, c, true);
mContext = context;
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mContactsCache = contactsCache;
- }
+ mMappingCache = mappingCache;
+ mTextAppearanceName =
+ new TextAppearanceSpan(mContext, android.R.style.TextAppearance_Medium);
+ mTextAppearanceStatus =
+ new TextAppearanceSpan(mContext, android.R.style.TextAppearance_Small);
+ }
@Override
public void bindView(View view, Context context, Cursor cursor) {
SocialHolder holder = (SocialHolder)view.getTag();
long contactId = cursor.getLong(COL_AUTHOR_CONTACT_ID);
+ String name = cursor.getString(COL_DISPLAY_NAME);
+ String title = cursor.getString(COL_TITLE);
+ long published = cursor.getLong(COL_PUBLISHED);
// TODO: trigger async query to find actual name and photo instead
// of using this lazy caching mechanism
holder.photo.setImageBitmap(mContactsCache.getPhoto(contactId));
+ holder.contentBuilder.clear();
+ holder.contentBuilder.append(name);
+ holder.contentBuilder.append(": ");
+ holder.contentBuilder.append(title);
+ holder.contentBuilder.setSpan(mTextAppearanceName, 0, name.length() + 2, 0);
+ holder.contentBuilder.setSpan(mTextAppearanceStatus, name.length() + 2,
+ holder.contentBuilder.length(), 0);
+ holder.content.setText(holder.contentBuilder);
- holder.displayname.setText(cursor.getString(COL_DISPLAY_NAME));
- holder.title.setText(cursor.getString(COL_TITLE));
-
- long published = cursor.getLong(COL_PUBLISHED);
- CharSequence relativePublished = DateUtils.getRelativeTimeSpanString(published, System
- .currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS);
+ CharSequence relativePublished = DateUtils.getRelativeTimeSpanString(published,
+ System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS);
holder.published.setText(relativePublished);
+ String packageName = cursor.getString(COL_PACKAGE);
+ String mimeType = cursor.getString(COL_MIMETYPE);
+ Mapping mapping = mMappingCache.getMapping(packageName, mimeType);
+ if (mapping != null && mapping.icon != null) {
+ holder.sourceIcon.setImageBitmap(mapping.icon);
+ } else {
+ holder.sourceIcon.setImageDrawable(null);
+ }
}
@Override
@@ -201,10 +216,10 @@
View view = mInflater.inflate(R.layout.social_list_item, parent, false);
SocialHolder holder = new SocialHolder();
- holder.photo = (ImageView)view.findViewById(R.id.photo);
- holder.displayname = (TextView)view.findViewById(R.id.displayname);
- holder.title = (TextView)view.findViewById(R.id.title);
- holder.published = (TextView)view.findViewById(R.id.published);
+ holder.photo = (ImageView) view.findViewById(R.id.photo);
+ holder.sourceIcon = (ImageView) view.findViewById(R.id.sourceIcon);
+ holder.content = (TextView) view.findViewById(R.id.content);
+ holder.published = (TextView) view.findViewById(R.id.published);
view.setTag(holder);
return view;
@@ -365,8 +380,9 @@
final int depth = parser.getDepth();
while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
&& type != XmlPullParser.END_DOCUMENT) {
- if (type == XmlPullParser.END_TAG)
+ if (type == XmlPullParser.END_TAG) {
continue;
+ }
if (!TAG_MAPPING.equals(parser.getName())) {
throw new InflateException("Expected Mapping tag");
@@ -420,7 +436,7 @@
* The size of the thumbnail is defined by the dimension
* android.R.dimen.launcher_application_icon_size. This method is not
* thread-safe and should be invoked on the UI thread only.
- *
+ *
* @param bitmap The bitmap to get a thumbnail of.
* @param context The application's context.
* @return A thumbnail for the specified bitmap or the bitmap itself if