summaryrefslogtreecommitdiff
path: root/src/com/android/dialer/dialpad/SmartDialAdapter.java
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2013-01-28 12:10:30 -0800
committerYorke Lee <yorkelee@google.com>2013-02-12 14:13:31 -0800
commit55b030a8bbb0323a4823fc34f3167a248a0ff899 (patch)
tree73b3766312b2f66a19ff2e5241c3c952da63733c /src/com/android/dialer/dialpad/SmartDialAdapter.java
parentaf11e78aecf0c07ae8960210f6c18377035a2c70 (diff)
Smart Dialling v2 with phone number support
Behavior: Use a prefix tree to cache contacts instead of an array list Perform matches against phone numbers as well DialpadFragment now ignores results from stale tasks where queries no longer match Add ability to not use default phone number for phone number disambiguation dialog Contacts are now ranked by the order which they were sorted by in the ContactsProvider (affinity) Change remapAccentedChars to always return lowercase characters to avoid overhead of uppercase character conversion Resource/Layout changes: Tweak margins so that the section containing smart dial suggestions looks cleaner Use color resource instead of hardcoding color values Add phone number to SmartDial items ContentObserver: Add a contentobserver to be notified on changes in contacts Refactored cache to allow for forced cache refreshes Use a single instance of SmartDialCache Tests: Added SmartDialTrie tests Comments: Comment cleanup Change-Id: Ica2854e2845d4d75048aa1fd982f139496d21bf3
Diffstat (limited to 'src/com/android/dialer/dialpad/SmartDialAdapter.java')
-rw-r--r--src/com/android/dialer/dialpad/SmartDialAdapter.java75
1 files changed, 38 insertions, 37 deletions
diff --git a/src/com/android/dialer/dialpad/SmartDialAdapter.java b/src/com/android/dialer/dialpad/SmartDialAdapter.java
index a48473174..0a246e3e5 100644
--- a/src/com/android/dialer/dialpad/SmartDialAdapter.java
+++ b/src/com/android/dialer/dialpad/SmartDialAdapter.java
@@ -18,15 +18,16 @@ package com.android.dialer.dialpad;
import android.content.Context;
import android.content.res.Resources;
-import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.SpannableString;
+import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
+import android.widget.LinearLayout;
import com.android.dialer.R;
import com.google.common.collect.Lists;
@@ -38,16 +39,12 @@ public class SmartDialAdapter extends BaseAdapter {
private final LayoutInflater mInflater;
private List<SmartDialEntry> mEntries;
- private static Drawable mHighConfidenceHint;
private final int mHighlightedTextColor;
public SmartDialAdapter(Context context) {
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final Resources res = context.getResources();
- mHighConfidenceHint = SmartDialTextView.getHighConfidenceHintDrawable(
- res, res.getDimension(R.dimen.smartdial_confidence_hint_text_size),
- res.getColor(R.color.smartdial_confidence_drawable_color));
mHighlightedTextColor = res.getColor(R.color.smartdial_highlighted_text_color);
clear();
}
@@ -109,55 +106,59 @@ public class SmartDialAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
- final SmartDialTextView view;
+ final LinearLayout view;
if (convertView == null) {
- view = (SmartDialTextView) mInflater.inflate(
+ view = (LinearLayout) mInflater.inflate(
R.layout.dialpad_smartdial_item, parent, false);
} else {
- view = (SmartDialTextView) convertView;
+ view = (LinearLayout) convertView;
}
- // Set the display name with highlight.
+
+ final SmartDialTextView nameView = (SmartDialTextView) view.findViewById(R.id.contact_name);
+
+ final SmartDialTextView numberView = (SmartDialTextView) view.findViewById(
+ R.id.contact_number);
final SmartDialEntry item = mEntries.get(position);
if (item == null) {
// Clear the text in case the view was reused.
- view.setText("");
+ nameView.setText("");
+ numberView.setText("");
// Empty view. We use this to force a single entry to be in the middle
return view;
}
- final SpannableString displayName = new SpannableString(item.displayName);
- for (final SmartDialMatchPosition p : item.matchPositions) {
- final int matchStart = p.start;
- final int matchEnd = p.end;
- if (matchStart < matchEnd) {
- // Create a new ForegroundColorSpan for each section of the name to highlight,
- // otherwise multiple highlights won't work.
- try {
- displayName.setSpan(
- new ForegroundColorSpan(mHighlightedTextColor), matchStart, matchEnd,
- Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- } catch (final IndexOutOfBoundsException e) {
- Log.wtf(LOG_TAG,
- "Invalid match positions provided - [" + matchStart + ","
- + matchEnd + "] for display name: " + item.displayName);
+
+ // Highlight the display name with the provided match positions
+ if (!TextUtils.isEmpty(item.displayName)) {
+ final SpannableString displayName = new SpannableString(item.displayName);
+ for (final SmartDialMatchPosition p : item.matchPositions) {
+ if (p.start < p.end) {
+ if (p.end > displayName.length()) {
+ p.end = displayName.length();
+ }
+ // Create a new ForegroundColorSpan for each section of the name to highlight,
+ // otherwise multiple highlights won't work.
+ displayName.setSpan(new ForegroundColorSpan(mHighlightedTextColor), p.start,
+ p.end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
+ nameView.setText(displayName);
}
- if (position == 1) {
- view.setCompoundDrawablesWithIntrinsicBounds(
- null, null, null, mHighConfidenceHint);
- // Hack to align text in this view with text in other views without the
- // overflow drawable
- view.setCompoundDrawablePadding(-mHighConfidenceHint.getIntrinsicHeight());
- } else {
- view.setCompoundDrawablesWithIntrinsicBounds(
- null, null, null, null);
+ // Highlight the phone number with the provided match positions
+ if (!TextUtils.isEmpty(item.phoneNumber)) {
+ final SmartDialMatchPosition p = item.phoneNumberMatchPosition;
+ final SpannableString phoneNumber = new SpannableString(item.phoneNumber);
+ if (p != null && p.start < p.end) {
+ if (p.end > phoneNumber.length()) {
+ p.end = phoneNumber.length();
+ }
+ phoneNumber.setSpan(new ForegroundColorSpan(mHighlightedTextColor), p.start, p.end,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+ numberView.setText(phoneNumber);
}
-
-
- view.setText(displayName);
view.setTag(item);
return view;