summaryrefslogtreecommitdiffstats
path: root/chips
diff options
context:
space:
mode:
authorScott Kennedy <skennedy@google.com>2013-04-05 17:17:24 -0700
committerScott Kennedy <skennedy@google.com>2013-04-05 17:17:24 -0700
commitda491f048fb33b572713b4287436c1cac6898670 (patch)
treedbaff6cacdc3f7f0794d30e06d9064e22930dfe9 /chips
parentf5ecf6ad067fb1036199ad5125949aae7ffd9689 (diff)
downloadandroid_frameworks_ex-da491f048fb33b572713b4287436c1cac6898670.tar.gz
android_frameworks_ex-da491f048fb33b572713b4287436c1cac6898670.tar.bz2
android_frameworks_ex-da491f048fb33b572713b4287436c1cac6898670.zip
Prevent a potential ANR
Move this code into an AsyncTask, since createAlternatesAdapter() can take a while to return. Bug: 8519276 Change-Id: I7b3f30ab13ed894e80ac26c365dcb3cbe178dd37
Diffstat (limited to 'chips')
-rw-r--r--chips/src/com/android/ex/chips/RecipientEditTextView.java69
1 files changed, 39 insertions, 30 deletions
diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java
index d7cd7fa..41bab18 100644
--- a/chips/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java
@@ -1412,36 +1412,45 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
}
}
- private void showAlternates(DrawableRecipientChip currentChip, ListPopupWindow alternatesPopup,
- int width) {
- int line = getLayout().getLineForOffset(getChipStart(currentChip));
- int bottom;
- if (line == getLineCount() -1) {
- bottom = 0;
- } else {
- bottom = -(int) ((mChipHeight + (2 * mLineSpacingExtra)) * (Math.abs(getLineCount() - 1
- - line)));
- }
- // Align the alternates popup with the left side of the View,
- // regardless of the position of the chip tapped.
- alternatesPopup.setWidth(width);
- alternatesPopup.setAnchorView(this);
- alternatesPopup.setVerticalOffset(bottom);
- alternatesPopup.setAdapter(createAlternatesAdapter(currentChip));
- alternatesPopup.setOnItemClickListener(mAlternatesListener);
- // Clear the checked item.
- mCheckedItem = -1;
- alternatesPopup.show();
- ListView listView = alternatesPopup.getListView();
- listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
- // Checked item would be -1 if the adapter has not
- // loaded the view that should be checked yet. The
- // variable will be set correctly when onCheckedItemChanged
- // is called in a separate thread.
- if (mCheckedItem != -1) {
- listView.setItemChecked(mCheckedItem, true);
- mCheckedItem = -1;
- }
+ private void showAlternates(final DrawableRecipientChip currentChip,
+ final ListPopupWindow alternatesPopup, final int width) {
+ new AsyncTask<Void, Void, ListAdapter>() {
+ @Override
+ protected ListAdapter doInBackground(final Void... params) {
+ return createAlternatesAdapter(currentChip);
+ }
+
+ protected void onPostExecute(final ListAdapter result) {
+ int line = getLayout().getLineForOffset(getChipStart(currentChip));
+ int bottom;
+ if (line == getLineCount() -1) {
+ bottom = 0;
+ } else {
+ bottom = -(int) ((mChipHeight + (2 * mLineSpacingExtra)) * (Math
+ .abs(getLineCount() - 1 - line)));
+ }
+ // Align the alternates popup with the left side of the View,
+ // regardless of the position of the chip tapped.
+ alternatesPopup.setWidth(width);
+ alternatesPopup.setAnchorView(RecipientEditTextView.this);
+ alternatesPopup.setVerticalOffset(bottom);
+ alternatesPopup.setAdapter(result);
+ alternatesPopup.setOnItemClickListener(mAlternatesListener);
+ // Clear the checked item.
+ mCheckedItem = -1;
+ alternatesPopup.show();
+ ListView listView = alternatesPopup.getListView();
+ listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
+ // Checked item would be -1 if the adapter has not
+ // loaded the view that should be checked yet. The
+ // variable will be set correctly when onCheckedItemChanged
+ // is called in a separate thread.
+ if (mCheckedItem != -1) {
+ listView.setItemChecked(mCheckedItem, true);
+ mCheckedItem = -1;
+ }
+ }
+ }.execute((Void[]) null);
}
private ListAdapter createAlternatesAdapter(DrawableRecipientChip chip) {