summaryrefslogtreecommitdiffstats
path: root/src/com/android/contacts/common/list/ContactListItemView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/contacts/common/list/ContactListItemView.java')
-rwxr-xr-x[-rw-r--r--]src/com/android/contacts/common/list/ContactListItemView.java195
1 files changed, 183 insertions, 12 deletions
diff --git a/src/com/android/contacts/common/list/ContactListItemView.java b/src/com/android/contacts/common/list/ContactListItemView.java
index 4c561dfc..dd869b0c 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;
@@ -52,6 +53,8 @@ import com.android.contacts.common.format.TextHighlighter;
import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.contacts.common.util.SearchUtil;
import com.android.contacts.common.util.ViewUtil;
+import com.android.contacts.common.widget.CheckableImageView;
+import com.android.contacts.common.widget.CheckableQuickContactBadge;
import com.google.common.collect.Lists;
@@ -77,7 +80,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.
@@ -136,7 +139,7 @@ public class ContactListItemView extends ViewGroup
final int layoutDirection = TextUtils.getLayoutDirectionFromLocale(locale);
switch (layoutDirection) {
case View.LAYOUT_DIRECTION_RTL:
- return (opposite ? PhotoPosition.LEFT : PhotoPosition.RIGHT);
+ return (PhotoPosition.RIGHT);
case View.LAYOUT_DIRECTION_LTR:
default:
return (opposite ? PhotoPosition.RIGHT : PhotoPosition.LEFT);
@@ -151,8 +154,10 @@ public class ContactListItemView extends ViewGroup
// The views inside the contact view
private boolean mQuickContactEnabled = true;
- private QuickContactBadge mQuickContact;
- private ImageView mPhotoView;
+ private boolean mQuickCallButtonEnabled = false;
+ private CheckableQuickContactBadge mQuickContact;
+ private ImageView mQuickCallView;
+ private CheckableImageView mPhotoView;
private TextView mNameTextView;
private TextView mPhoneticNameTextView;
private TextView mLabelView;
@@ -160,12 +165,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.
@@ -177,6 +185,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.
@@ -219,6 +236,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;
@@ -226,7 +245,9 @@ public class ContactListItemView extends ViewGroup
public ContactListItemView(Context context) {
super(context);
- mTextHighlighter = new TextHighlighter(Typeface.BOLD);
+ mTextHighlighter = new TextHighlighter(Typeface.BOLD,
+ context.getResources().getColor(R.color.text_highlight_color));
+
mNameHighlightSequence = new ArrayList<HighlightSequence>();
mNumberHighlightSequence = new ArrayList<HighlightSequence>();
}
@@ -254,6 +275,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(
@@ -268,6 +292,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(
@@ -279,7 +309,9 @@ public class ContactListItemView extends ViewGroup
a.getDimensionPixelOffset(
R.styleable.ContactListItemView_list_item_padding_bottom, 0));
- mTextHighlighter = new TextHighlighter(Typeface.BOLD);
+ mTextHighlighter = new TextHighlighter(Typeface.BOLD,
+ context.getResources().getColor(R.color.text_highlight_color));
+
a.recycle();
@@ -308,6 +340,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
@@ -324,15 +372,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) {
@@ -450,6 +499,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);
}
@@ -551,6 +606,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;
@@ -570,6 +628,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)) {
@@ -588,6 +653,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)) {
@@ -675,10 +747,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.
*
@@ -746,6 +841,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() {
@@ -753,7 +856,7 @@ public class ContactListItemView extends ViewGroup
throw new IllegalStateException("QuickContact is disabled for this view");
}
if (mQuickContact == null) {
- mQuickContact = new QuickContactBadge(getContext());
+ mQuickContact = new CheckableQuickContactBadge(getContext());
mQuickContact.setOverlay(null);
mQuickContact.setLayoutParams(getDefaultPhotoLayoutParams());
if (mNameTextView != null) {
@@ -767,12 +870,21 @@ public class ContactListItemView extends ViewGroup
return mQuickContact;
}
+ public void setChecked(boolean checked, boolean animate) {
+ if (mQuickContact != null) {
+ mQuickContact.setChecked(checked, animate);
+ }
+ if (mPhotoView != null) {
+ mPhotoView.setChecked(checked, animate);
+ }
+ }
+
/**
* Returns the photo view, creating it if necessary.
*/
public ImageView getPhotoView() {
if (mPhotoView == null) {
- mPhotoView = new ImageView(getContext());
+ mPhotoView = new CheckableImageView(getContext());
mPhotoView.setLayoutParams(getDefaultPhotoLayoutParams());
// Quick contact style used above will set a background - remove it
mPhotoView.setBackground(null);
@@ -783,6 +895,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() {
@@ -1135,6 +1272,20 @@ public class ContactListItemView extends ViewGroup
}
}
+ public void showQuickCallView(Cursor cursor, int numberColumIndex, int lookUpKey,
+ int profileKey) {
+ int hasNumber = cursor.getInt(numberColumIndex);
+ boolean isProfile = cursor.getInt(profileKey) == 1;
+ if (!(hasNumber == 0) && !isProfile) {
+ 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();
@@ -1463,7 +1614,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);
}
}