diff options
author | Stephen Bird <sbird@cyngn.com> | 2016-01-25 11:46:02 -0800 |
---|---|---|
committer | Richard MacGregor <rmacgregor@cyngn.com> | 2016-03-25 11:42:18 -0700 |
commit | d72d6860769f9580f9075317f5edcfe87c04ba2b (patch) | |
tree | 989f8631ccb8c2d779ce59721ad86f1105d37d68 /src | |
parent | f9b4a8194192e3a3ffdf2b56e842835ce4dfafea (diff) | |
download | packages_apps_ContactsCommon-d72d6860769f9580f9075317f5edcfe87c04ba2b.tar.gz packages_apps_ContactsCommon-d72d6860769f9580f9075317f5edcfe87c04ba2b.tar.bz2 packages_apps_ContactsCommon-d72d6860769f9580f9075317f5edcfe87c04ba2b.zip |
T9 search
Add views and methods for displaying incall usernames.
Change-Id: I8a1add14734a84a455937b984224422f3b2d75d5
Diffstat (limited to 'src')
3 files changed, 138 insertions, 4 deletions
diff --git a/src/com/android/contacts/common/list/ContactListItemView.java b/src/com/android/contacts/common/list/ContactListItemView.java index fa5acaeb..7db7a0a9 100644 --- a/src/com/android/contacts/common/list/ContactListItemView.java +++ b/src/com/android/contacts/common/list/ContactListItemView.java @@ -35,11 +35,13 @@ import android.text.SpannableString; import android.text.TextUtils; import android.text.TextUtils.TruncateAt; import android.util.AttributeSet; +import android.util.Log; import android.util.TypedValue; import android.view.Gravity; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewParent; import android.widget.AbsListView.SelectionBoundsAdjuster; import android.widget.CheckBox; import android.widget.ImageView; @@ -161,6 +163,7 @@ public class ContactListItemView extends ViewGroup private TextView mPhoneticNameTextView; private TextView mLabelView; private TextView mDataView; + private TextView mCallProviderView; private TextView mSnippetView; private TextView mStatusView; private ImageView mPresenceIcon; @@ -203,6 +206,8 @@ public class ContactListItemView extends ViewGroup private int mPhoneticNameTextViewHeight; private int mLabelViewHeight; private int mDataViewHeight; + private int mCallProviderViewHeight; + private int mCallProviderBottomPadding; private int mSnippetTextViewHeight; private int mStatusTextViewHeight; private int mCheckBoxHeight; @@ -335,6 +340,8 @@ public class ContactListItemView extends ViewGroup mStatusTextViewHeight = 0; mCheckBoxWidth = 0; mCheckBoxHeight = 0; + mCallProviderViewHeight = 0; + mCallProviderBottomPadding = 0; ensurePhotoViewSize(); @@ -413,6 +420,17 @@ public class ContactListItemView extends ViewGroup mDataViewHeight = mDataView.getMeasuredHeight(); } + if (isVisible(mCallProviderView)) { + mCallProviderView.measure(MeasureSpec.makeMeasureSpec(dataWidth, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + + // Multiply our height by two + gap + // Why? cause padding below and above the text + text height + mCallProviderViewHeight = mCallProviderView.getMeasuredHeight(); + mCallProviderBottomPadding = getContext().getResources() + .getDimensionPixelSize(R.dimen.call_provider_bottom_padding); + } + if (isVisible(mLabelView)) { // For performance reason we don't want AT_MOST usually, but when the picture is // on right, we need to use it anyway because mDataView is next to mLabelView. @@ -456,8 +474,7 @@ public class ContactListItemView extends ViewGroup // Calculate height including padding. int height = (mNameTextViewHeight + mPhoneticNameTextViewHeight + - mLabelAndDataViewMaxHeight + - mSnippetTextViewHeight + mStatusTextViewHeight); + mLabelAndDataViewMaxHeight + mSnippetTextViewHeight + mStatusTextViewHeight); // Make sure the height is at least as high as the photo height = Math.max(height, mPhotoViewHeight + getPaddingBottom() + getPaddingTop()); @@ -465,6 +482,11 @@ public class ContactListItemView extends ViewGroup // Make sure height is at least the preferred height height = Math.max(height, preferredHeight); + if (isVisible(mCallProviderView)) { + // add callproviderviewheight; + height += mCallProviderViewHeight + mCallProviderBottomPadding; + } + // Measure the header if it is visible. if (mHeaderTextView != null && mHeaderTextView.getVisibility() == VISIBLE) { mHeaderTextView.measure( @@ -542,7 +564,8 @@ public class ContactListItemView extends ViewGroup // Photo is the left most view. All the other Views should on the right of the photo. if (photoView != null) { // Center the photo vertically - final int photoTop = topBound + (bottomBound - topBound - mPhotoViewHeight) / 2; + int photoTop = (topBound + (bottomBound - topBound - mPhotoViewHeight - + mCallProviderViewHeight - mCallProviderBottomPadding) / 2); photoView.layout( leftBound, photoTop, @@ -575,7 +598,8 @@ public class ContactListItemView extends ViewGroup // Center text vertically, then apply the top offset. final int totalTextHeight = mNameTextViewHeight + mPhoneticNameTextViewHeight + - mLabelAndDataViewMaxHeight + mSnippetTextViewHeight + mStatusTextViewHeight; + mLabelAndDataViewMaxHeight + mSnippetTextViewHeight + mStatusTextViewHeight + + mCallProviderViewHeight + mCallProviderBottomPadding; int textTopBound = (bottomBound + topBound - totalTextHeight) / 2 + mTextOffsetTop; // Layout all text view and presence icon @@ -676,10 +700,18 @@ public class ContactListItemView extends ViewGroup rightBound, textTopBound + mLabelAndDataViewMaxHeight); } + if (isVisible(mLabelView) || isVisible(mDataView)) { textTopBound += mLabelAndDataViewMaxHeight; } + if (isVisible(mCallProviderView)) { + mCallProviderView.layout(dataLeftBound, + textTopBound + mCallProviderBottomPadding, + rightBound, + textTopBound + mCallProviderViewHeight + mCallProviderBottomPadding); + } + if (isVisible(mSnippetView)) { mSnippetView.layout(leftBound, textTopBound, @@ -1046,6 +1078,41 @@ public class ContactListItemView extends ViewGroup } } + /** + * Sets phone number for a list item. This takes care of number highlighting if the highlight + * mask exists. + */ + public void setExtraNumber(String text) { + if (TextUtils.isEmpty(text)) { + if (mCallProviderView != null) { + mCallProviderView.setVisibility(View.GONE); + } + } else { + getCallProviderView(); + + // TODO: Format number using PhoneNumberUtils.formatNumber before assigning it to + // mDataView. Make sure that determination of the highlight sequences are done only + // after number formatting. + + // Sets phone number texts for display after highlighting it, if applicable. + // CharSequence textToSet = text; + final SpannableString textToSet = new SpannableString(text); + + if (mNumberHighlightSequence.size() != 0) { + final HighlightSequence highlightSequence = mNumberHighlightSequence.get(0); + mTextHighlighter.applyMaskingHighlight(textToSet, highlightSequence.start, + highlightSequence.end); + } + + setMarqueeText(mCallProviderView, textToSet); + mCallProviderView.setVisibility(VISIBLE); + + // We have a phone number as "mDataView" so make it always LTR and VIEW_START + mCallProviderView.setTextDirection(View.TEXT_DIRECTION_LTR); + mCallProviderView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START); + } + } + private void setMarqueeText(TextView textView, char[] text, int size) { if (getTextEllipsis() == TruncateAt.MARQUEE) { setMarqueeText(textView, new String(text, 0, size)); @@ -1099,6 +1166,24 @@ public class ContactListItemView extends ViewGroup } /** + * Returns the text view for the data text, creating it if necessary. + */ + public TextView getCallProviderView() { + if (mCallProviderView == null) { + mCallProviderView = new TextView(getContext()); + mCallProviderView.setSingleLine(true); + mCallProviderView.setEllipsize(getTextEllipsis()); + mCallProviderView.setTextAppearance(getContext(), R.style.TextAppearanceSmall); + mCallProviderView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START); + mCallProviderView.setActivated(isActivated()); + mCallProviderView.setId(R.id.cliv_data_view); + mCallProviderView.setElegantTextHeight(false); + addView(mCallProviderView); + } + return mCallProviderView; + } + + /** * Adds or updates a text view for the search snippet. */ public void setSnippet(String text) { diff --git a/src/com/android/contacts/common/list/PhoneNumberListAdapter.java b/src/com/android/contacts/common/list/PhoneNumberListAdapter.java index 01d33b8b..d3c423b3 100644 --- a/src/com/android/contacts/common/list/PhoneNumberListAdapter.java +++ b/src/com/android/contacts/common/list/PhoneNumberListAdapter.java @@ -20,8 +20,10 @@ import android.content.ContentUris; import android.content.Context; import android.content.CursorLoader; import android.database.Cursor; +import android.database.DatabaseUtils; import android.net.Uri; import android.net.Uri.Builder; +import android.os.Bundle; import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.Callable; import android.provider.ContactsContract.CommonDataKinds.Phone; @@ -37,6 +39,7 @@ import android.util.Log; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import com.android.contacts.common.GeoUtil; import com.android.contacts.common.R; import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest; @@ -313,6 +316,11 @@ public class PhoneNumberListAdapter extends ContactEntryListAdapter { return item != null ? item.getString(PhoneQuery.PHONE_MIME_TYPE) : null; } + public String getUsername(int position) { + final Cursor item = (Cursor)getItem(position); + return item != null ? item.getString(item.getColumnIndex("callable_extra_number")) : null; + } + /** * Builds a {@link Data#CONTENT_URI} for the given cursor position. * @@ -437,6 +445,32 @@ public class PhoneNumberListAdapter extends ContactEntryListAdapter { final DirectoryPartition directory = (DirectoryPartition) getPartition(partition); bindPhoneNumber(view, cursor, directory.isDisplayNumber()); + bindExtraCallAction(view, cursor, position); + } + + public View.OnClickListener bindExtraCallActionOnClick(TextView v, String text, int position) { + return new View.OnClickListener() { + @Override + public void onClick(View view) { + // Implement in other adapters; + } + }; + } + + private void bindExtraCallAction(ContactListItemView view, Cursor cursor, int position) { + try { + int columnIndex = cursor.getColumnIndexOrThrow("callable_extra_number"); + final String extra = cursor.getString(columnIndex); + + if (!TextUtils.isEmpty(extra)) { + TextView callProviderView = view.getCallProviderView(); + view.setExtraNumber(extra); + callProviderView.setOnClickListener( + bindExtraCallActionOnClick(callProviderView, extra, position)); + } + } catch (IllegalArgumentException e) { + Log.i(TAG, "Column does not exist", e); + } } protected void bindPhoneNumber(ContactListItemView view, Cursor cursor, boolean displayNumber) { diff --git a/src/com/android/contacts/common/list/PhoneNumberPickerFragment.java b/src/com/android/contacts/common/list/PhoneNumberPickerFragment.java index 97d1f2a6..f16167f5 100644 --- a/src/com/android/contacts/common/list/PhoneNumberPickerFragment.java +++ b/src/com/android/contacts/common/list/PhoneNumberPickerFragment.java @@ -33,6 +33,10 @@ import com.android.contacts.common.list.ShortcutIntentBuilder.OnShortcutIntentCr import com.android.contacts.common.util.AccountFilterUtil; import com.android.contacts.commonbind.analytics.AnalyticsUtil; +import com.android.phone.common.incall.CallMethodInfo; + +import com.cyanogen.ambient.incall.extension.OriginCodes; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -210,6 +214,12 @@ public class PhoneNumberPickerFragment extends ContactEntryListFragment<ContactE } } + protected void onProviderClick(int position, long id, CallMethodInfo cmi) { + final String number = getPhoneNumber(position); + final String username = getUserName(position); + cmi.placeCall(OriginCodes.DIALPAD_T9_SEARCH, username, getContext()); + } + protected void cacheContactInfo(int position) { // Not implemented. Hook for child classes } @@ -229,6 +239,11 @@ public class PhoneNumberPickerFragment extends ContactEntryListFragment<ContactE return adapter.getDataUri(position); } + protected String getUserName(int position) { + final PhoneNumberListAdapter adapter = (PhoneNumberListAdapter) getAdapter(); + return adapter.getUsername(position); + } + protected String getLookupKey(int position) { final PhoneNumberListAdapter adapter = (PhoneNumberListAdapter) getAdapter(); return adapter.getLookupKey(position); |