diff options
author | Adnan <adnan@cyngn.com> | 2014-11-12 12:30:31 -0800 |
---|---|---|
committer | Matt Garnes <matt@cyngn.com> | 2014-11-12 12:30:31 -0800 |
commit | be9c40e84d5a0fb2ea7353eb2d184680629fa762 (patch) | |
tree | 929a06e8f886165804443cc5160bd29b861dfce0 | |
parent | f138ea681278980a1d37b67e99940eae6cad3cb3 (diff) | |
download | android_packages_apps_ContactsCommon-be9c40e84d5a0fb2ea7353eb2d184680629fa762.tar.gz android_packages_apps_ContactsCommon-be9c40e84d5a0fb2ea7353eb2d184680629fa762.tar.bz2 android_packages_apps_ContactsCommon-be9c40e84d5a0fb2ea7353eb2d184680629fa762.zip |
ContactsCommon: Add direct call from contact list feature. (1/2)
- Requires cmcc overlay flag to be set in Contacts.
Change-Id: I6f957029a26f3e01825cb57b7b0620f618d1eb69
-rw-r--r-- | res/drawable-hdpi/ic_action_call.png | bin | 0 -> 1094 bytes | |||
-rw-r--r-- | res/drawable-mdpi/ic_action_call.png | bin | 0 -> 741 bytes | |||
-rw-r--r-- | res/drawable-xhdpi/ic_action_call.png | bin | 0 -> 1489 bytes | |||
-rw-r--r-- | res/drawable-xxhdpi/ic_action_call.png | bin | 0 -> 2245 bytes | |||
-rw-r--r-- | res/drawable/call_background_activated.xml | 10 | ||||
-rw-r--r-- | res/drawable/call_background_holo.xml | 10 | ||||
-rw-r--r-- | res/drawable/ic_action_call_background.xml | 27 | ||||
-rw-r--r-- | res/values/attrs.xml | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | src/com/android/contacts/common/list/ContactEntryListAdapter.java | 9 | ||||
-rwxr-xr-x | src/com/android/contacts/common/list/ContactEntryListFragment.java | 9 | ||||
-rwxr-xr-x[-rw-r--r--] | src/com/android/contacts/common/list/ContactListAdapter.java | 44 | ||||
-rwxr-xr-x[-rw-r--r--] | src/com/android/contacts/common/list/ContactListItemView.java | 164 | ||||
-rwxr-xr-x | src/com/android/contacts/common/list/DefaultContactListAdapter.java | 3 |
13 files changed, 271 insertions, 8 deletions
diff --git a/res/drawable-hdpi/ic_action_call.png b/res/drawable-hdpi/ic_action_call.png Binary files differnew file mode 100644 index 00000000..7493a607 --- /dev/null +++ b/res/drawable-hdpi/ic_action_call.png diff --git a/res/drawable-mdpi/ic_action_call.png b/res/drawable-mdpi/ic_action_call.png Binary files differnew file mode 100644 index 00000000..a5a7c371 --- /dev/null +++ b/res/drawable-mdpi/ic_action_call.png diff --git a/res/drawable-xhdpi/ic_action_call.png b/res/drawable-xhdpi/ic_action_call.png Binary files differnew file mode 100644 index 00000000..e16ef951 --- /dev/null +++ b/res/drawable-xhdpi/ic_action_call.png diff --git a/res/drawable-xxhdpi/ic_action_call.png b/res/drawable-xxhdpi/ic_action_call.png Binary files differnew file mode 100644 index 00000000..c4cfdac8 --- /dev/null +++ b/res/drawable-xxhdpi/ic_action_call.png diff --git a/res/drawable/call_background_activated.xml b/res/drawable/call_background_activated.xml new file mode 100644 index 00000000..9fe8d3f6 --- /dev/null +++ b/res/drawable/call_background_activated.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle"> + <gradient android:startColor="#33b5e5" android:endColor="#33b5e5" + android:angle="270" /> + <corners android:radius="2dp" /> + <stroke android:color="#33b5e5" android:width="1dp" /> + <padding android:top="5dp" android:bottom="5dp" android:left="5dp" + android:right="5dp" /> +</shape>
\ No newline at end of file diff --git a/res/drawable/call_background_holo.xml b/res/drawable/call_background_holo.xml new file mode 100644 index 00000000..b947b20a --- /dev/null +++ b/res/drawable/call_background_holo.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle"> + <gradient android:startColor="#00000000" + android:endColor="#00000000" + android:angle="270" /> + <corners android:radius="2dp" /> + <padding android:top="5dp" android:bottom="5dp" android:left="5dp" + android:right="5dp" /> +</shape>
\ No newline at end of file diff --git a/res/drawable/ic_action_call_background.xml b/res/drawable/ic_action_call_background.xml new file mode 100644 index 00000000..71ac2a9b --- /dev/null +++ b/res/drawable/ic_action_call_background.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2008 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. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_focused="true" + android:state_pressed="true" + android:drawable="@drawable/call_background_activated" /> + <item android:state_focused="false" + android:state_pressed="true" + android:drawable="@drawable/call_background_activated"/> + <item android:state_focused="false" + android:state_pressed="false" + android:drawable="@drawable/call_background_holo"/> +</selector>
\ No newline at end of file diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 64397caf..b098c0b5 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -62,6 +62,9 @@ <attr name="list_item_text_offset_top" format="dimension"/> <attr name="list_item_data_width_weight" format="integer"/> <attr name="list_item_label_width_weight" format="integer"/> + <attr name="list_item_quick_call_view_source" format="reference" /> + <attr name="list_item_quick_call_view_background" format="reference" /> + <attr name="list_item_quick_call_size" format="dimension" /> </declare-styleable> <declare-styleable name="ContactBrowser"> diff --git a/src/com/android/contacts/common/list/ContactEntryListAdapter.java b/src/com/android/contacts/common/list/ContactEntryListAdapter.java index 2fc57352..2f3e25e8 100644..100755 --- a/src/com/android/contacts/common/list/ContactEntryListAdapter.java +++ b/src/com/android/contacts/common/list/ContactEntryListAdapter.java @@ -63,6 +63,7 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter { private boolean mCircularPhotos = true; private boolean mQuickContactEnabled; private boolean mAdjustSelectionBoundsEnabled; + private boolean mQuickCallButtonEnabled; /** * indicates if contact queries include profile @@ -347,6 +348,10 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter { return mQuickContactEnabled; } + public boolean isQuickCallButtonEnabled() { + return mQuickCallButtonEnabled; + } + public void setQuickContactEnabled(boolean quickContactEnabled) { mQuickContactEnabled = quickContactEnabled; } @@ -359,6 +364,10 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter { mAdjustSelectionBoundsEnabled = enabled; } + public void setQuickCallButtonEnabled(boolean quickCallButtonEnabled) { + mQuickCallButtonEnabled = quickCallButtonEnabled; + } + public boolean shouldIncludeProfile() { return mIncludeProfile; } diff --git a/src/com/android/contacts/common/list/ContactEntryListFragment.java b/src/com/android/contacts/common/list/ContactEntryListFragment.java index 4e2cc4e7..4af18305 100755 --- a/src/com/android/contacts/common/list/ContactEntryListFragment.java +++ b/src/com/android/contacts/common/list/ContactEntryListFragment.java @@ -76,6 +76,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter private static final String KEY_QUICK_CONTACT_ENABLED = "quickContactEnabled"; private static final String KEY_ADJUST_SELECTION_BOUNDS_ENABLED = "adjustSelectionBoundsEnabled"; + private static final String KEY_QUICK_CALL_BUTTON_ENABLED = "quickCallButtonEnabled"; private static final String KEY_INCLUDE_PROFILE = "includeProfile"; private static final String KEY_SEARCH_MODE = "searchMode"; private static final String KEY_VISIBLE_SCROLLBAR_ENABLED = "visibleScrollbarEnabled"; @@ -101,6 +102,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter private boolean mPhotoLoaderEnabled; private boolean mQuickContactEnabled = true; private boolean mAdjustSelectionBoundsEnabled = true; + private boolean mQuickCallButtonEnabled = false; private boolean mIncludeProfile; private boolean mSearchMode; private boolean mVisibleScrollbarEnabled; @@ -242,6 +244,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter outState.putBoolean(KEY_PHOTO_LOADER_ENABLED, mPhotoLoaderEnabled); outState.putBoolean(KEY_QUICK_CONTACT_ENABLED, mQuickContactEnabled); outState.putBoolean(KEY_ADJUST_SELECTION_BOUNDS_ENABLED, mAdjustSelectionBoundsEnabled); + outState.putBoolean(KEY_QUICK_CALL_BUTTON_ENABLED, mQuickCallButtonEnabled); outState.putBoolean(KEY_INCLUDE_PROFILE, mIncludeProfile); outState.putBoolean(KEY_SEARCH_MODE, mSearchMode); outState.putBoolean(KEY_VISIBLE_SCROLLBAR_ENABLED, mVisibleScrollbarEnabled); @@ -283,6 +286,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter mPhotoLoaderEnabled = savedState.getBoolean(KEY_PHOTO_LOADER_ENABLED); mQuickContactEnabled = savedState.getBoolean(KEY_QUICK_CONTACT_ENABLED); mAdjustSelectionBoundsEnabled = savedState.getBoolean(KEY_ADJUST_SELECTION_BOUNDS_ENABLED); + mQuickCallButtonEnabled = savedState.getBoolean(KEY_QUICK_CALL_BUTTON_ENABLED); mIncludeProfile = savedState.getBoolean(KEY_INCLUDE_PROFILE); mSearchMode = savedState.getBoolean(KEY_SEARCH_MODE); mVisibleScrollbarEnabled = savedState.getBoolean(KEY_VISIBLE_SCROLLBAR_ENABLED); @@ -589,6 +593,10 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter mAdjustSelectionBoundsEnabled = flag; } + public void setQuickCallButtonEnabled(boolean flag) { + this.mQuickCallButtonEnabled = flag; + } + public void setIncludeProfile(boolean flag) { mIncludeProfile = flag; if(mAdapter != null) { @@ -811,6 +819,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter mAdapter.setQuickContactEnabled(mQuickContactEnabled); mAdapter.setAdjustSelectionBoundsEnabled(mAdjustSelectionBoundsEnabled); + mAdapter.setQuickCallButtonEnabled(mQuickCallButtonEnabled); mAdapter.setIncludeProfile(mIncludeProfile); mAdapter.setQueryString(mQueryString); mAdapter.setDirectorySearchMode(mDirectorySearchMode); diff --git a/src/com/android/contacts/common/list/ContactListAdapter.java b/src/com/android/contacts/common/list/ContactListAdapter.java index c1c0f02e..a3eb8cbe 100644..100755 --- a/src/com/android/contacts/common/list/ContactListAdapter.java +++ b/src/com/android/contacts/common/list/ContactListAdapter.java @@ -17,6 +17,7 @@ package com.android.contacts.common.list; import android.accounts.Account; import android.content.Context; +import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract; @@ -29,10 +30,12 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ListView; +import android.widget.Toast; import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; import com.android.contacts.common.R; import com.android.contacts.common.preference.ContactsPreferences; +import com.android.contacts.common.model.Contact; /** * A cursor adapter for the {@link ContactsContract.Contacts#CONTENT_TYPE} content type. @@ -53,6 +56,7 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { Contacts.IS_USER_PROFILE, // 7 RawContacts.ACCOUNT_TYPE, // 8 RawContacts.ACCOUNT_NAME, // 9 + Contacts.HAS_PHONE_NUMBER, // 10 }; private static final String[] CONTACT_PROJECTION_ALTERNATIVE = new String[] { @@ -66,6 +70,7 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { Contacts.IS_USER_PROFILE, // 7 RawContacts.ACCOUNT_TYPE, // 8 RawContacts.ACCOUNT_NAME, // 9 + Contacts.HAS_PHONE_NUMBER, // 10 }; private static final String[] FILTER_PROJECTION_PRIMARY = new String[] { @@ -79,7 +84,8 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { Contacts.IS_USER_PROFILE, // 7 RawContacts.ACCOUNT_TYPE, // 8 RawContacts.ACCOUNT_NAME, // 9 - SearchSnippets.SNIPPET, // 10 + Contacts.HAS_PHONE_NUMBER, // 10 + SearchSnippets.SNIPPET, // 11 }; private static final String[] FILTER_PROJECTION_ALTERNATIVE = new String[] { @@ -93,7 +99,8 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { Contacts.IS_USER_PROFILE, // 7 RawContacts.ACCOUNT_TYPE, // 8 RawContacts.ACCOUNT_NAME, // 9 - SearchSnippets.SNIPPET, // 10 + Contacts.HAS_PHONE_NUMBER, // 10 + SearchSnippets.SNIPPET, // 11 }; public static final int CONTACT_ID = 0; @@ -106,7 +113,8 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { public static final int CONTACT_IS_USER_PROFILE = 7; public static final int CONTACT_ACCOUNT_TYPE = 8; public static final int CONTACT_ACCOUNT_NAME = 9; - public static final int CONTACT_SNIPPET = 10; + public static final int CONTACT_HAS_NUMBER = 10; + public static final int CONTACT_SNIPPET = 11; } private CharSequence mUnknownNameText; @@ -212,6 +220,7 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { view.setUnknownNameText(mUnknownNameText); view.setQuickContactEnabled(isQuickContactEnabled()); view.setAdjustSelectionBoundsEnabled(isAdjustSelectionBoundsEnabled()); + view.setQuickCallButtonEnabled(isQuickCallButtonEnabled()); view.setActivatedStateSupported(isSelectionVisible()); if (mPhotoPosition != null) { view.setPhotoPosition(mPhotoPosition); @@ -219,6 +228,29 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { return view; } + private View.OnClickListener mClickListener = new View.OnClickListener() { + @Override + public void onClick(View view) { + String lookup = ((ContactListItemView) view.getParent()).getQuickCallLookup(); + Cursor cursor = mContext.getContentResolver().query( + ContactsContract.CommonDataKinds.Phone.CONTENT_URI, + new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER, + ContactsContract.CommonDataKinds.Phone.LOOKUP_KEY}, + ContactsContract.CommonDataKinds.Phone.LOOKUP_KEY + "=?", + new String[] { lookup }, null); + + if (cursor != null) { + if (cursor.moveToNext()) { + String phoneNumber = cursor.getString(0); + Uri uri = Uri.parse("tel: " + phoneNumber); + Intent intent = new Intent(Intent.ACTION_CALL, uri); + mContext.startActivity(intent); + } + cursor.close(); + } + } + }; + protected void bindSectionHeaderAndDivider(ContactListItemView view, int position, Cursor cursor) { view.setIsSectionHeaderEnabled(isSectionHeaderDisplayEnabled()); @@ -274,6 +306,12 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { bindViewId(view, cursor, ContactQuery.CONTACT_ID); } + protected void bindQuickCallView(final ContactListItemView view, Cursor cursor) { + view.showQuickCallView(cursor, ContactQuery.CONTACT_HAS_NUMBER, + ContactQuery.CONTACT_LOOKUP_KEY); + view.setOnQuickCallClickListener(mClickListener); + } + protected void bindPresenceAndStatusMessage(final ContactListItemView view, Cursor cursor) { view.showPresenceAndStatusMessage(cursor, ContactQuery.CONTACT_PRESENCE_STATUS, ContactQuery.CONTACT_CONTACT_STATUS); diff --git a/src/com/android/contacts/common/list/ContactListItemView.java b/src/com/android/contacts/common/list/ContactListItemView.java index fb007c4c..0f523d66 100644..100755 --- a/src/com/android/contacts/common/list/ContactListItemView.java +++ b/src/com/android/contacts/common/list/ContactListItemView.java @@ -26,6 +26,7 @@ import android.graphics.Color; import android.graphics.Rect; import android.graphics.Typeface; import android.graphics.drawable.Drawable; +import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract; import android.provider.ContactsContract.Contacts; @@ -76,7 +77,7 @@ import java.util.regex.Pattern; */ public class ContactListItemView extends ViewGroup - implements SelectionBoundsAdjuster { + implements SelectionBoundsAdjuster, View.OnClickListener { // Style values for layout and appearance // The initialized values are defaults if none is provided through xml. @@ -150,7 +151,9 @@ public class ContactListItemView extends ViewGroup // The views inside the contact view private boolean mQuickContactEnabled = true; + private boolean mQuickCallButtonEnabled = false; private QuickContactBadge mQuickContact; + private ImageView mQuickCallView; private ImageView mPhotoView; private TextView mNameTextView; private TextView mPhoneticNameTextView; @@ -159,12 +162,15 @@ public class ContactListItemView extends ViewGroup private TextView mSnippetView; private TextView mStatusView; private ImageView mPresenceIcon; + private String mQuickCallKey; private ColorStateList mSecondaryTextColor; - + private int mQuickCallViewImageId = 0; + private int mQuickCallViewBgId = 0; private int mDefaultPhotoViewSize = 0; + private int mDefaultQuickCallViewSize = 0; /** * Can be effective even when {@link #mPhotoView} is null, as we want to have horizontal padding * to align other data in this View. @@ -176,6 +182,15 @@ public class ContactListItemView extends ViewGroup private int mPhotoViewHeight; /** + * Only effective when {@link #mQuickCallView} is null + */ + private int mQuickCallViewWidth; + /** + * Only effective when {@link #mQuickCallView} is null + */ + private int mQuickCallViewHeight; + + /** * Only effective when {@link #mPhotoView} is null. * When true all the Views on the right side of the photo should have horizontal padding on * those left assuming there is a photo. @@ -218,6 +233,8 @@ public class ContactListItemView extends ViewGroup private Rect mBoundsWithoutHeader = new Rect(); + private OnClickListener mListener; + /** A helper used to highlight a prefix in a text field. */ private final TextHighlighter mTextHighlighter; private CharSequence mUnknownNameText; @@ -253,6 +270,9 @@ public class ContactListItemView extends ViewGroup R.styleable.ContactListItemView_list_item_presence_icon_size, mPresenceIconSize); mDefaultPhotoViewSize = a.getDimensionPixelOffset( R.styleable.ContactListItemView_list_item_photo_size, mDefaultPhotoViewSize); + mDefaultQuickCallViewSize = a.getDimensionPixelOffset( + R.styleable.ContactListItemView_list_item_quick_call_size, + mDefaultQuickCallViewSize); mTextIndent = a.getDimensionPixelOffset( R.styleable.ContactListItemView_list_item_text_indent, mTextIndent); mTextOffsetTop = a.getDimensionPixelOffset( @@ -267,6 +287,12 @@ public class ContactListItemView extends ViewGroup mNameTextViewTextSize = (int) a.getDimension( R.styleable.ContactListItemView_list_item_name_text_size, (int) getResources().getDimension(R.dimen.contact_browser_list_item_text_size)); + mQuickCallViewImageId = a.getResourceId( + R.styleable.ContactListItemView_list_item_quick_call_view_source, + R.drawable.ic_action_call); + mQuickCallViewBgId = a.getResourceId( + R.styleable.ContactListItemView_list_item_quick_call_view_background, + R.drawable.ic_action_call_background); setPaddingRelative( a.getDimensionPixelOffset( @@ -307,6 +333,22 @@ public class ContactListItemView extends ViewGroup mQuickContactEnabled = flag; } + public void setQuickCallButtonEnabled(boolean flag) { + mQuickCallButtonEnabled = flag; + } + + public void setQuickCallLookup(String lookupKey) { + mQuickCallKey = lookupKey; + } + + public void setQuickCallButtonImageResource(int resourceId) { + mQuickCallViewImageId = resourceId; + } + + public void setQuickCallButtonBackgroundResource(int resourceId) { + mQuickCallViewBgId = resourceId; + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // We will match parent's width and wrap content vertically, but make sure @@ -323,15 +365,16 @@ public class ContactListItemView extends ViewGroup mStatusTextViewHeight = 0; ensurePhotoViewSize(); + ensureQuickCallViewSize(); // Width each TextView is able to use. int effectiveWidth; // All the other Views will honor the photo, so available width for them may be shrunk. if (mPhotoViewWidth > 0 || mKeepHorizontalPaddingForPhotoView) { effectiveWidth = specWidth - getPaddingLeft() - getPaddingRight() - - (mPhotoViewWidth + mGapBetweenImageAndText); + - (mPhotoViewWidth + mGapBetweenImageAndText + mQuickCallViewWidth); } else { - effectiveWidth = specWidth - getPaddingLeft() - getPaddingRight(); + effectiveWidth = specWidth - getPaddingLeft() - getPaddingRight() - mQuickCallViewWidth; } if (mIsSectionHeaderEnabled) { @@ -449,6 +492,12 @@ public class ContactListItemView extends ViewGroup MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); } + if (isVisible(mQuickCallView)) { + mQuickCallView.measure( + MeasureSpec.makeMeasureSpec(mQuickCallViewWidth, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(mQuickCallViewHeight, MeasureSpec.EXACTLY)); + } + setMeasuredDimension(specWidth, height); } @@ -550,6 +599,9 @@ public class ContactListItemView extends ViewGroup textTopBound += mNameTextViewHeight; } + // Center the photo vertically + final int quickCallTop = topBound + (bottomBound - topBound - mQuickCallViewHeight) / 2; + // Presence and status if (isLayoutRtl) { int statusRightBound = rightBound; @@ -569,6 +621,13 @@ public class ContactListItemView extends ViewGroup statusRightBound, textTopBound + mStatusTextViewHeight); } + + if (isVisible(mQuickCallView)) { + mQuickCallView.layout(-width + (mQuickCallViewWidth + mPhotoViewWidth), + quickCallTop, + rightBound, + quickCallTop + mQuickCallViewHeight); + } } else { int statusLeftBound = leftBound; if (isVisible(mPresenceIcon)) { @@ -587,6 +646,13 @@ public class ContactListItemView extends ViewGroup rightBound, textTopBound + mStatusTextViewHeight); } + + if (isVisible(mQuickCallView)) { + mQuickCallView.layout(rightBound - mQuickCallView.getMeasuredWidth(), + quickCallTop, + rightBound, + quickCallTop + mQuickCallViewHeight); + } } if (isVisible(mStatusView) || isVisible(mPresenceIcon)) { @@ -674,10 +740,33 @@ public class ContactListItemView extends ViewGroup } } + /** + * Extracts width and height from the style + */ + private void ensureQuickCallViewSize() { + mQuickCallViewWidth = mQuickCallViewHeight = getDefaultQuickCallViewSize(); + if (!mQuickCallButtonEnabled || mQuickCallView == null) { + mQuickCallViewWidth = 0; + mQuickCallViewHeight = 0; + } + } + + protected void setDefaultPhotoViewSize(int pixels) { + mDefaultPhotoViewSize = pixels; + } + protected int getDefaultPhotoViewSize() { return mDefaultPhotoViewSize; } + protected void setDefaultQuickCallViewSize(int pixels) { + mDefaultQuickCallViewSize = pixels; + } + + protected int getDefaultQuickCallViewSize() { + return mDefaultQuickCallViewSize; + } + /** * Gets a LayoutParam that corresponds to the default photo size. * @@ -745,6 +834,14 @@ public class ContactListItemView extends ViewGroup } /** + * Get the quick call lookup to use with Intent.ACTION_CALL + * @return + */ + public String getQuickCallLookup() { + return mQuickCallKey; + } + + /** * Returns the quick contact badge, creating it if necessary. */ public QuickContactBadge getQuickContact() { @@ -782,6 +879,31 @@ public class ContactListItemView extends ViewGroup } /** + * Returns the quick call view, creating it if necessary. + */ + public ImageView getQuickCallView() { + if (mQuickCallView == null) { + mQuickCallView = new ImageView(mContext); + mQuickCallView.setLayoutParams(getDefaultPhotoLayoutParams()); + mQuickCallView.setImageResource(mQuickCallViewImageId); + mQuickCallView.setBackgroundResource(mQuickCallViewBgId); + mQuickCallView.setClickable(true); + addView(mQuickCallView); + } + return mQuickCallView; + } + + /** + * Removes the quick call view. + */ + public void removeQuickCallView() { + if (mQuickCallView != null) { + removeView(mQuickCallView); + mQuickCallView = null; + } + } + + /** * Removes the photo view. */ public void removePhotoView() { @@ -1124,6 +1246,18 @@ public class ContactListItemView extends ViewGroup } } + public void showQuickCallView(Cursor cursor, int numberColumIndex, int lookUpKey) { + int hasNumber = cursor.getInt(numberColumIndex); + if (!(hasNumber == 0)) { + getQuickCallView().setVisibility(View.VISIBLE); + setQuickCallLookup(cursor.getString(lookUpKey)); + } else { + if (mQuickCallView != null) { + mQuickCallView.setVisibility(View.GONE); + } + } + } + public void setDisplayName(CharSequence name, boolean highlight) { if (!TextUtils.isEmpty(name) && highlight) { clearHighlightSequences(); @@ -1444,7 +1578,27 @@ public class ContactListItemView extends ViewGroup if (mBoundsWithoutHeader.contains((int) x, (int) y) || !pointIsInView(x, y)) { return super.onTouchEvent(event); } else { - return true; + return false; + } + } + + @Override + public void onClick(View view) { + if (mListener != null && mQuickCallButtonEnabled) { + if (view == mQuickCallView) { + mListener.onClick(view); + } + } + } + + /** + * Set the a click listener for the quick call view + * @param listener + */ + public void setOnQuickCallClickListener(OnClickListener listener) { + this.mListener = listener; + if (mListener != null && mQuickCallView != null) { + mQuickCallView.setOnClickListener(mListener); } } diff --git a/src/com/android/contacts/common/list/DefaultContactListAdapter.java b/src/com/android/contacts/common/list/DefaultContactListAdapter.java index ea177eaf..c44e1e28 100755 --- a/src/com/android/contacts/common/list/DefaultContactListAdapter.java +++ b/src/com/android/contacts/common/list/DefaultContactListAdapter.java @@ -257,6 +257,9 @@ public class DefaultContactListAdapter extends ContactListAdapter { } bindNameAndViewId(view, cursor); + if (isQuickCallButtonEnabled()) { + bindQuickCallView(view, cursor); + } bindPresenceAndStatusMessage(view, cursor); if (isSearchMode()) { |