diff options
author | Adnan <adnan@cyngn.com> | 2014-10-15 14:23:55 -0700 |
---|---|---|
committer | Adnan <adnan@cyngn.com> | 2014-10-20 10:38:03 -0700 |
commit | 18c3f81ef95fcdfc0005c1e03bc5c7f686735357 (patch) | |
tree | 1f2e3baadcd0fc7cf899caa9ab01a31f70314bd2 | |
parent | b39a4ac25117fb0c254051985546293be2bf34fc (diff) | |
download | packages_apps_ContactsCommon-18c3f81ef95fcdfc0005c1e03bc5c7f686735357.tar.gz packages_apps_ContactsCommon-18c3f81ef95fcdfc0005c1e03bc5c7f686735357.tar.bz2 packages_apps_ContactsCommon-18c3f81ef95fcdfc0005c1e03bc5c7f686735357.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 | ||||
-rw-r--r-- | src/com/android/contacts/common/list/ContactEntryListAdapter.java | 9 | ||||
-rw-r--r-- | src/com/android/contacts/common/list/ContactEntryListFragment.java | 9 | ||||
-rw-r--r-- | src/com/android/contacts/common/list/ContactListAdapter.java | 48 | ||||
-rw-r--r-- | src/com/android/contacts/common/list/ContactListItemView.java | 160 | ||||
-rw-r--r-- | src/com/android/contacts/common/list/DefaultContactListAdapter.java | 4 |
13 files changed, 272 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 9e8c08d8..9cd22b0d 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -44,6 +44,9 @@ <attr name="list_item_contacts_count_text_size" 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 202f1219..1bc10f36 100644 --- a/src/com/android/contacts/common/list/ContactEntryListAdapter.java +++ b/src/com/android/contacts/common/list/ContactEntryListAdapter.java @@ -60,6 +60,7 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter { private boolean mDisplayPhotos; private boolean mQuickContactEnabled; + private boolean mQuickCallButtonEnabled; /** * indicates if contact queries include profile @@ -325,10 +326,18 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter { return mQuickContactEnabled; } + public boolean isQuickCallButtonEnabled() { + return mQuickCallButtonEnabled; + } + public void setQuickContactEnabled(boolean quickContactEnabled) { mQuickContactEnabled = quickContactEnabled; } + 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 cad4ae69..0d488187 100644 --- a/src/com/android/contacts/common/list/ContactEntryListFragment.java +++ b/src/com/android/contacts/common/list/ContactEntryListFragment.java @@ -71,6 +71,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter private static final String KEY_SECTION_HEADER_DISPLAY_ENABLED = "sectionHeaderDisplayEnabled"; private static final String KEY_PHOTO_LOADER_ENABLED = "photoLoaderEnabled"; private static final String KEY_QUICK_CONTACT_ENABLED = "quickContactEnabled"; + 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"; @@ -95,6 +96,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter private boolean mSectionHeaderDisplayEnabled; private boolean mPhotoLoaderEnabled; private boolean mQuickContactEnabled = true; + private boolean mQuickCallButtonEnabled = false; private boolean mIncludeProfile; private boolean mSearchMode; private boolean mVisibleScrollbarEnabled; @@ -234,6 +236,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter outState.putBoolean(KEY_SECTION_HEADER_DISPLAY_ENABLED, mSectionHeaderDisplayEnabled); outState.putBoolean(KEY_PHOTO_LOADER_ENABLED, mPhotoLoaderEnabled); outState.putBoolean(KEY_QUICK_CONTACT_ENABLED, mQuickContactEnabled); + 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); @@ -271,6 +274,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter mSectionHeaderDisplayEnabled = savedState.getBoolean(KEY_SECTION_HEADER_DISPLAY_ENABLED); mPhotoLoaderEnabled = savedState.getBoolean(KEY_PHOTO_LOADER_ENABLED); mQuickContactEnabled = savedState.getBoolean(KEY_QUICK_CONTACT_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); @@ -585,6 +589,10 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter this.mQuickContactEnabled = flag; } + public void setQuickCallButtonEnabled(boolean flag) { + this.mQuickCallButtonEnabled = flag; + } + public void setIncludeProfile(boolean flag) { mIncludeProfile = flag; if(mAdapter != null) { @@ -783,6 +791,7 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter } mAdapter.setQuickContactEnabled(mQuickContactEnabled); + 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 07504594..a4e6d944 100644 --- a/src/com/android/contacts/common/list/ContactListAdapter.java +++ b/src/com/android/contacts/common/list/ContactListAdapter.java @@ -16,6 +16,7 @@ package com.android.contacts.common.list; import android.content.Context; +import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract; @@ -28,9 +29,11 @@ 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.model.Contact; /** * A cursor adapter for the {@link ContactsContract.Contacts#CONTENT_TYPE} content type. @@ -49,6 +52,7 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { Contacts.PHOTO_THUMBNAIL_URI, // 5 Contacts.LOOKUP_KEY, // 6 Contacts.IS_USER_PROFILE, // 7 + Contacts.HAS_PHONE_NUMBER // 8 }; private static final String[] CONTACT_PROJECTION_ALTERNATIVE = new String[] { @@ -60,6 +64,7 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { Contacts.PHOTO_THUMBNAIL_URI, // 5 Contacts.LOOKUP_KEY, // 6 Contacts.IS_USER_PROFILE, // 7 + Contacts.HAS_PHONE_NUMBER, // 8 }; private static final String[] FILTER_PROJECTION_PRIMARY = new String[] { @@ -71,7 +76,8 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { Contacts.PHOTO_THUMBNAIL_URI, // 5 Contacts.LOOKUP_KEY, // 6 Contacts.IS_USER_PROFILE, // 7 - SearchSnippetColumns.SNIPPET, // 8 + Contacts.HAS_PHONE_NUMBER, // 8 + SearchSnippetColumns.SNIPPET, // 9 }; private static final String[] FILTER_PROJECTION_ALTERNATIVE = new String[] { @@ -83,7 +89,8 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { Contacts.PHOTO_THUMBNAIL_URI, // 5 Contacts.LOOKUP_KEY, // 6 Contacts.IS_USER_PROFILE, // 7 - SearchSnippetColumns.SNIPPET, // 8 + Contacts.HAS_PHONE_NUMBER, // 8 + SearchSnippetColumns.SNIPPET, // 9 }; public static final int CONTACT_ID = 0; @@ -94,6 +101,7 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { public static final int CONTACT_PHOTO_URI = 5; public static final int CONTACT_LOOKUP_KEY = 6; public static final int CONTACT_IS_USER_PROFILE = 7; + public static final int CONTACT_HAS_NUMBER = 8; public static final int CONTACT_SNIPPET = 8; } @@ -198,7 +206,12 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { ViewGroup parent) { ContactListItemView view = new ContactListItemView(context, null); view.setUnknownNameText(mUnknownNameText); - view.setQuickContactEnabled(isQuickContactEnabled()); + if (isQuickContactEnabled()) { + view.setQuickContactEnabled(isQuickContactEnabled()); + view.setQuickCallButtonImageResource(R.drawable.ic_action_call); + view.setQuickCallButtonBackgroundResource( + R.drawable.ic_action_call_background); + } view.setActivatedStateSupported(isSelectionVisible()); if (mPhotoPosition != null) { view.setPhotoPosition(mPhotoPosition); @@ -206,6 +219,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) { if (isSectionHeaderDisplayEnabled()) { @@ -259,6 +295,12 @@ public abstract class ContactListAdapter extends ContactEntryListAdapter { // Note: we don't show phonetic any more (See issue 5265330) } + 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 fcfc216a..cda2156e 100644 --- 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; @@ -75,7 +76,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. @@ -160,7 +161,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; @@ -170,12 +173,15 @@ public class ContactListItemView extends ViewGroup private TextView mStatusView; private TextView mCountView; 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. @@ -187,6 +193,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. @@ -227,6 +242,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; @@ -265,6 +282,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); mHeaderTextIndent = a.getDimensionPixelOffset( R.styleable.ContactListItemView_list_item_header_text_indent, mHeaderTextIndent); mHeaderTextColor = a.getColor( @@ -292,6 +312,12 @@ public class ContactListItemView extends ViewGroup mLabelViewWidthWeight = a.getInteger( R.styleable.ContactListItemView_list_item_label_width_weight, mLabelViewWidthWeight); + mQuickCallViewImageId = a.getResourceId( + R.styleable.ContactListItemView_list_item_quick_call_view_source, + mQuickCallViewImageId); + mQuickCallViewImageId = a.getResourceId( + R.styleable.ContactListItemView_list_item_quick_call_view_background, + mQuickCallViewBgId); setPaddingRelative( a.getDimensionPixelOffset( @@ -330,6 +356,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 @@ -351,15 +393,16 @@ public class ContactListItemView extends ViewGroup mStatusTextViewHeight = 0; ensurePhotoViewSize(); + ensureQuickCallViewSize(); // Width each TextView is able to use. final 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; } // Go over all visible text views and measure actual width of each of them. @@ -488,6 +531,12 @@ public class ContactListItemView extends ViewGroup height += (mHeaderBackgroundHeight + mHeaderUnderlineHeight); } + if (isVisible(mQuickCallView)) { + mQuickCallView.measure( + MeasureSpec.makeMeasureSpec(mQuickCallViewWidth, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(mQuickCallViewHeight, MeasureSpec.EXACTLY)); + } + setMeasuredDimension(specWidth, height); } @@ -590,6 +639,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; @@ -609,6 +661,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)) { @@ -627,6 +686,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)) { @@ -712,6 +778,17 @@ 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; } @@ -720,6 +797,14 @@ public class ContactListItemView extends ViewGroup return mDefaultPhotoViewSize; } + protected void setDefaultQuickCallViewSize(int pixels) { + mDefaultQuickCallViewSize = pixels; + } + + protected int getDefaultQuickCallViewSize() { + return mDefaultQuickCallViewSize; + } + /** * Gets a LayoutParam that corresponds to the default photo size. * @@ -809,6 +894,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() { @@ -845,6 +938,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() { @@ -1212,6 +1330,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(); @@ -1542,7 +1672,27 @@ public class ContactListItemView extends ViewGroup if (mBoundsWithoutHeader.contains((int) x, (int) y) || !pointInView(x, y, 0)) { 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 1873896b..666e0be6 100644 --- a/src/com/android/contacts/common/list/DefaultContactListAdapter.java +++ b/src/com/android/contacts/common/list/DefaultContactListAdapter.java @@ -266,6 +266,10 @@ public class DefaultContactListAdapter extends ContactListAdapter { } } + if (isQuickCallButtonEnabled()) { + bindQuickCallView(view, cursor); + } + bindName(view, cursor); bindPresenceAndStatusMessage(view, cursor); |