summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormindyp <mindyp@google.com>2012-12-14 16:41:57 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2012-12-14 16:41:57 -0800
commitf54b35052841b2618a91bff687700203203ef784 (patch)
tree0194fe63b44a9213b75320e0ee54389daaccc086
parent4bd6592a9709c6dab7ba46d1b548d83525e3485d (diff)
parent3665fb7aaf0948f694e2d28ab76e1f5e4befb45d (diff)
downloadandroid_frameworks_ex-f54b35052841b2618a91bff687700203203ef784.tar.gz
android_frameworks_ex-f54b35052841b2618a91bff687700203203ef784.tar.bz2
android_frameworks_ex-f54b35052841b2618a91bff687700203203ef784.zip
am 3665fb7a: Scroll when result of a contacts lookup appear
* commit '3665fb7aaf0948f694e2d28ab76e1f5e4befb45d': Scroll when result of a contacts lookup appear
-rw-r--r--chips/src/com/android/ex/chips/BaseRecipientAdapter.java15
-rw-r--r--chips/src/com/android/ex/chips/RecipientEditTextView.java78
2 files changed, 80 insertions, 13 deletions
diff --git a/chips/src/com/android/ex/chips/BaseRecipientAdapter.java b/chips/src/com/android/ex/chips/BaseRecipientAdapter.java
index c0cfa19..c981728 100644
--- a/chips/src/com/android/ex/chips/BaseRecipientAdapter.java
+++ b/chips/src/com/android/ex/chips/BaseRecipientAdapter.java
@@ -499,6 +499,8 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
private final DelayedMessageHandler mDelayedMessageHandler = new DelayedMessageHandler();
+ private EntriesUpdatedObserver mEntriesUpdatedObserver;
+
/**
* Constructor for email queries.
*/
@@ -706,9 +708,14 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
return entries;
}
+ public void registerUpdateObserver(EntriesUpdatedObserver observer) {
+ mEntriesUpdatedObserver = observer;
+ }
+
/** Resets {@link #mEntries} and notify the event to its parent ListView. */
private void updateEntries(List<RecipientEntry> newEntries) {
mEntries = newEntries;
+ mEntriesUpdatedObserver.onChanged(newEntries);
notifyDataSetChanged();
}
@@ -967,4 +974,12 @@ public abstract class BaseRecipientAdapter extends BaseAdapter implements Filter
protected int getPhotoId() {
return android.R.id.icon;
}
+
+ /**
+ * Interface called before the BaseRecipientAdapter updates recipient
+ * results in the popup window.
+ */
+ protected interface EntriesUpdatedObserver {
+ public void onChanged(List<RecipientEntry> entries);
+ }
}
diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java
index 564bfe1..525f75d 100644
--- a/chips/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java
@@ -54,6 +54,7 @@ import android.text.util.Rfc822Token;
import android.text.util.Rfc822Tokenizer;
import android.util.AttributeSet;
import android.util.Log;
+import android.util.TypedValue;
import android.util.Patterns;
import android.view.ActionMode;
import android.view.ActionMode.Callback;
@@ -72,6 +73,7 @@ import android.view.inputmethod.InputConnection;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
+import android.widget.Filterable;
import android.widget.ListAdapter;
import android.widget.ListPopupWindow;
import android.widget.ListView;
@@ -86,6 +88,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -236,6 +239,10 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
private int mMaxLines;
+ private static int sExcessTopPadding = -1;
+
+ private int mActionBarHeight;
+
public RecipientEditTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setChipDimensions(context, attrs);
@@ -399,6 +406,44 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
}
}
+ private int getExcessTopPadding() {
+ if (sExcessTopPadding == -1) {
+ sExcessTopPadding = (int) mChipHeight;
+ }
+ return sExcessTopPadding;
+ }
+
+ public <T extends ListAdapter & Filterable> void setAdapter(T adapter) {
+ super.setAdapter(adapter);
+ ((BaseRecipientAdapter) adapter)
+ .registerUpdateObserver(new BaseRecipientAdapter.EntriesUpdatedObserver() {
+ @Override
+ public void onChanged(List<RecipientEntry> entries) {
+ // Scroll the chips field to the top of the screen so
+ // that the user can see as many results as possible.
+ if (entries != null && entries.size() > 0) {
+ scrollBottomIntoView();
+ }
+ }
+ });
+ }
+
+ private void scrollBottomIntoView() {
+ if (mScrollView != null && mShouldShrink) {
+ int[] location = new int[2];
+ getLocationOnScreen(location);
+ int height = getHeight();
+ int currentPos = location[1] + height;
+ // Desired position shows at least 1 line of chips below the action
+ // bar. We add excess padding to make sure this is always below other
+ // content.
+ int desiredPos = (int) mChipHeight + mActionBarHeight + getExcessTopPadding();
+ if (currentPos > desiredPos) {
+ mScrollView.scrollBy(0, currentPos - desiredPos);
+ }
+ }
+ }
+
@Override
public void performValidation() {
// Do nothing. Chips handles its own validation.
@@ -711,6 +756,11 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
mInvalidChipBackground = r.getDrawable(R.drawable.chip_background_invalid);
}
mLineSpacingExtra = context.getResources().getDimension(R.dimen.line_spacing_extra);
+ TypedValue tv = new TypedValue();
+ if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
+ mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources()
+ .getDisplayMetrics());
+ }
a.recycle();
}
@@ -1302,7 +1352,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
*/
@Override
protected void performFiltering(CharSequence text, int keyCode) {
- if (enoughToFilter() && !isCompletedToken(text)) {
+ boolean isCompletedToken = isCompletedToken(text);
+ if (enoughToFilter() && !isCompletedToken) {
int end = getSelectionEnd();
int start = mTokenizer.findTokenStart(text, end);
// If this is a RecipientChip, don't filter
@@ -1312,6 +1363,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
if (chips != null && chips.length > 0) {
return;
}
+ } else if (isCompletedToken) {
+ return;
}
super.performFiltering(text, keyCode);
}
@@ -1392,7 +1445,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
private void scrollLineIntoView(int line) {
if (mScrollView != null) {
- mScrollView.scrollBy(0, calculateOffsetFromBottom(line));
+ mScrollView.smoothScrollBy(0, calculateOffsetFromBottom(line));
}
}
@@ -1888,10 +1941,17 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
if (shouldShowEditableText(currentChip)) {
CharSequence text = currentChip.getValue();
Editable editable = getText();
- getSpannable().removeSpan(currentChip);
+ Spannable spannable = getSpannable();
+ int spanStart = spannable.getSpanStart(currentChip);
+ int spanEnd = spannable.getSpanEnd(currentChip);
+ spannable.removeSpan(currentChip);
+ editable.delete(spanStart, spanEnd);
setCursorVisible(true);
setSelection(editable.length());
- return new RecipientChip(null, RecipientEntry.constructFakeEntry((String) text), -1);
+ editable.append(text);
+ return constructChipSpan(
+ RecipientEntry.constructFakeEntry((String) text),
+ getSelectionStart(), true, false);
} else if (currentChip.getContactId() == RecipientEntry.GENERATED_CONTACT) {
int start = getChipStart(currentChip);
int end = getChipEnd(currentChip);
@@ -2183,7 +2243,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
public void onTextChanged(CharSequence s, int start, int before, int count) {
// This is a delete; check to see if the insertion point is on a space
// following a chip.
- if (before > count) {
+ if (before - count == 1) {
// If the item deleted is a space, and the thing before the
// space is a chip, delete the entire span.
int selStart = getSelectionStart();
@@ -2202,8 +2262,6 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
editable.delete(tokenStart, tokenEnd);
getSpannable().removeSpan(repl[0]);
}
- } else if (count > before) {
- scrollBottomIntoView();
}
}
@@ -2213,12 +2271,6 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
}
}
- private void scrollBottomIntoView() {
- if (mScrollView != null) {
- mScrollView.scrollBy(0, (int) (getLineCount() * mChipHeight));
- }
- }
-
/**
* Handles pasting a {@link ClipData} to this {@link RecipientEditTextView}.
*/