Extracts the header code from BaseContactCardActivity
BaseContactCardActivity used to contain code for displaying the
contact card banner. As that is an element needed in other system
apps, it was extracted and made into a reusable widget in
com.android.internal.widget.
diff --git a/res/drawable-finger/contact_picture_bg.9.png b/res/drawable-finger/contact_picture_bg.9.png
deleted file mode 100644
index ae9c709..0000000
--- a/res/drawable-finger/contact_picture_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable/contact_header_bg.9.png b/res/drawable/contact_header_bg.9.png
deleted file mode 100644
index 7f9a5a3..0000000
--- a/res/drawable/contact_header_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/res/layout-finger/contact_card_layout.xml b/res/layout-finger/contact_card_layout.xml
index ee2fcf8..d32ce6f 100644
--- a/res/layout-finger/contact_card_layout.xml
+++ b/res/layout-finger/contact_card_layout.xml
@@ -20,45 +20,10 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent">
- <LinearLayout android:id="@+id/banner"
+ <com.android.internal.widget.ContactHeaderWidget
+ android:id="@+id/contact_header_widget"
android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:background="@drawable/contact_header_bg"
- android:paddingRight="5dip"
- android:gravity="center_vertical">
-
- <ImageView android:id="@+id/photo"
- android:layout_width="64dip"
- android:layout_height="64dip"
- android:layout_marginRight="7dip"
- android:layout_marginLeft="2dip"
- android:scaleType="fitCenter"
- android:background="@drawable/contact_picture_bg"/>
-
- <LinearLayout
- android:layout_width="0dip"
- android:layout_height="fill_parent"
- android:layout_weight="1"
- android:orientation="vertical">
-
- <!-- "Name" field is locale-specific. -->
- <include layout="@layout/view_contact_name"/>
-
- <TextView android:id="@+id/status"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:maxLines="2"/>
-
- </LinearLayout>
-
- <CheckBox android:id="@+id/star"
- style="?android:attr/starStyle"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
-
- </LinearLayout>
+ android:layout_height="wrap_content"/>
<com.android.contacts.ScrollingTabWidget android:id="@+id/tab_widget"
android:layout_width="fill_parent"
diff --git a/res/layout-finger/view_contact_name.xml b/res/layout-finger/view_contact_name.xml
deleted file mode 100644
index aec943e..0000000
--- a/res/layout-finger/view_contact_name.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?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.
--->
-
-<!-- In the default locale, the "Name" field is a single TextView -->
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/name"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceLargeInverse"
- android:textColor="@android:color/secondary_text_light"
- android:maxLines="2"
- android:ellipsize="end"
- />
diff --git a/res/layout-ja-finger/view_contact_name.xml b/res/layout-ja-finger/view_contact_name.xml
deleted file mode 100644
index 03332b1..0000000
--- a/res/layout-ja-finger/view_contact_name.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-<?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.
--->
-
-<!-- In Japanese-language locales, the "Name" field contains two separate
- TextViews: the name itself, and also the phonetic ("furigana") field. -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="0dip"
- android:layout_weight="1"
- android:layout_height="wrap_content">
-
- <TextView android:id="@+id/name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceLargeInverse"
- android:textColor="@android:color/secondary_text_light"
- />
-
- <TextView android:id="@+id/phonetic_name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceSmallInverse"
- android:textColor="@android:color/secondary_text_light"
- />
-
-</LinearLayout>
diff --git a/src/com/android/contacts/BaseContactCardActivity.java b/src/com/android/contacts/BaseContactCardActivity.java
index d6ed5fd..7d9b880 100644
--- a/src/com/android/contacts/BaseContactCardActivity.java
+++ b/src/com/android/contacts/BaseContactCardActivity.java
@@ -18,6 +18,7 @@
import com.android.contacts.ScrollingTabWidget.OnTabSelectionChangedListener;
import com.android.contacts.NotifyingAsyncQueryHandler.QueryCompleteListener;
+import com.android.internal.widget.ContactHeaderWidget;
import android.app.Activity;
import android.content.ContentUris;
@@ -47,22 +48,15 @@
* The base Activity class for viewing and editing a contact.
*/
public abstract class BaseContactCardActivity extends Activity
- implements QueryCompleteListener, OnTabSelectionChangedListener, View.OnClickListener {
+ implements QueryCompleteListener, OnTabSelectionChangedListener {
private static final String TAG = "BaseContactCardActivity";
private SparseArray<Long> mTabRawContactIdMap;
protected Uri mUri;
- protected long mContactId;
protected ScrollingTabWidget mTabWidget;
+ protected ContactHeaderWidget mContactHeaderWidget;
private NotifyingAsyncQueryHandler mHandler;
- private TextView mDisplayNameView;
- private TextView mPhoneticNameView;
- private CheckBox mStarredView;
- private ImageView mPhotoView;
- private TextView mStatusView;
-
- private int mNoPhotoResource;
protected LayoutInflater mInflater;
@@ -76,29 +70,7 @@
protected static final int TAB_ACCOUNT_NAME_COLUMN_INDEX = 1;
protected static final int TAB_ACCOUNT_TYPE_COLUMN_INDEX = 2;
- //Projection used for the summary info in the header.
- protected static final String[] HEADER_PROJECTION = new String[] {
- Contacts.DISPLAY_NAME,
- Contacts.STARRED,
- Contacts.PHOTO_ID,
- };
- protected static final int HEADER_DISPLAY_NAME_COLUMN_INDEX = 0;
- //TODO: We need to figure out how we're going to get the phonetic name.
- //static final int HEADER_PHONETIC_NAME_COLUMN_INDEX
- protected static final int HEADER_STARRED_COLUMN_INDEX = 1;
- protected static final int HEADER_PHOTO_ID_COLUMN_INDEX = 2;
-
- //Projection used for finding the most recent social status.
- protected static final String[] SOCIAL_PROJECTION = new String[] {
- Activities.TITLE,
- Activities.PUBLISHED,
- };
- protected static final int SOCIAL_TITLE_COLUMN_INDEX = 0;
- protected static final int SOCIAL_PUBLISHED_COLUMN_INDEX = 1;
-
- private static final int TOKEN_HEADER = 0;
- private static final int TOKEN_SOCIAL = 1;
- private static final int TOKEN_TABS = 2;
+ private static final int TOKEN_TABS = 0;
@Override
protected void onCreate(Bundle icicle) {
@@ -108,50 +80,21 @@
final Intent intent = getIntent();
mUri = intent.getData();
- mContactId = ContentUris.parseId(mUri);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.contact_card_layout);
+ mContactHeaderWidget = (ContactHeaderWidget) findViewById(R.id.contact_header_widget);
+ mContactHeaderWidget.showStar(true);
+ mContactHeaderWidget.bindFromContactId(ContentUris.parseId(mUri));
mTabWidget = (ScrollingTabWidget) findViewById(R.id.tab_widget);
- mDisplayNameView = (TextView) findViewById(R.id.name);
- mPhoneticNameView = (TextView) findViewById(R.id.phonetic_name);
- mStarredView = (CheckBox) findViewById(R.id.star);
- mStarredView.setOnClickListener(this);
- mPhotoView = (ImageView) findViewById(R.id.photo);
- mStatusView = (TextView) findViewById(R.id.status);
mTabWidget.setTabSelectionListener(this);
mTabRawContactIdMap = new SparseArray<Long>();
- // Set the photo with a random "no contact" image
- long now = SystemClock.elapsedRealtime();
- int num = (int) now & 0xf;
- if (num < 9) {
- // Leaning in from right, common
- mNoPhotoResource = R.drawable.ic_contact_picture;
- } else if (num < 14) {
- // Leaning in from left uncommon
- mNoPhotoResource = R.drawable.ic_contact_picture_2;
- } else {
- // Coming in from the top, rare
- mNoPhotoResource = R.drawable.ic_contact_picture_3;
- }
-
mHandler = new NotifyingAsyncQueryHandler(this, this);
setupTabs();
- setupHeader();
- }
-
- private void setupHeader() {
- Uri headerUri = Uri.withAppendedPath(mUri, "data");
-
- Uri socialUri = ContentUris.withAppendedId(
- SocialContract.Activities.CONTENT_CONTACT_STATUS_URI, mContactId);
-
- mHandler.startQuery(TOKEN_HEADER, null, headerUri, HEADER_PROJECTION, null, null, null);
- mHandler.startQuery(TOKEN_SOCIAL, null, socialUri, SOCIAL_PROJECTION, null, null, null);
}
private void setupTabs() {
@@ -171,20 +114,15 @@
/** {@inheritDoc} */
public void onQueryComplete(int token, Object cookie, Cursor cursor) {
- if (cursor == null) {
- return;
- }
try{
- if (token == TOKEN_HEADER) {
- bindHeader(cursor);
- } else if (token == TOKEN_SOCIAL) {
- bindSocial(cursor);
- } else if (token == TOKEN_TABS) {
+ if (token == TOKEN_TABS) {
clearCurrentTabs();
bindTabs(cursor);
}
} finally {
- cursor.close();
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
@@ -210,69 +148,6 @@
}
- //TODO: This will be part of the ContactHeaderWidget eventually.
- protected void bindHeader(Cursor c) {
- if (c == null) {
- return;
- }
- if (c.moveToFirst()) {
- //Set name
- String displayName = c.getString(HEADER_DISPLAY_NAME_COLUMN_INDEX);
- Log.i(TAG, displayName);
- mDisplayNameView.setText(displayName);
- //TODO: Bring back phonetic name
- /*if (mPhoneticNameView != null) {
- String phoneticName = c.getString(CONTACT_PHONETIC_NAME_COLUMN);
- mPhoneticNameView.setText(phoneticName);
- }*/
-
- //Set starred
- boolean starred = c.getInt(HEADER_STARRED_COLUMN_INDEX) == 1;
- mStarredView.setChecked(starred);
-
- //Set the photo
- long photoId = c.getLong(HEADER_PHOTO_ID_COLUMN_INDEX);
- Bitmap photoBitmap = ContactsUtils.loadContactPhoto(
- this, photoId, null);
- if (photoBitmap == null) {
- photoBitmap = ContactsUtils.loadPlaceholderPhoto(mNoPhotoResource, this, null);
- }
- mPhotoView.setImageBitmap(photoBitmap);
- }
- }
-
- //TODO: This will be part of the ContactHeaderWidget eventually.
- protected void bindSocial(Cursor c) {
- if (c == null) {
- return;
- }
- if (c.moveToFirst()) {
- String status = c.getString(SOCIAL_TITLE_COLUMN_INDEX);
- mStatusView.setText(status);
- }
- }
-
- //TODO: This will be part of the ContactHeaderWidget eventually.
- public void onClick(View view) {
- switch (view.getId()) {
- case R.id.star: {
- Uri uri = Uri.withAppendedPath(mUri, "data");
- Cursor c = getContentResolver().query(uri, HEADER_PROJECTION, null, null, null);
- try {
- c.moveToFirst();
- int oldStarredState = c.getInt(HEADER_STARRED_COLUMN_INDEX);
- ContentValues values = new ContentValues(1);
- values.put(Contacts.STARRED, oldStarredState == 1 ? 0 : 1);
- getContentResolver().update(mUri, values, null, null);
- } finally {
- c.close();
- }
- setupHeader();
- break;
- }
- }
- }
-
/**
* Add a tab to be displayed in the {@link ScrollingTabWidget}.
*