diff options
author | Scott Kennedy <skennedy@google.com> | 2013-04-05 17:35:49 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-04-05 17:35:49 -0700 |
commit | c3a17c96b86bff4e387c361127e04d60173a9ca6 (patch) | |
tree | ae37c7f68d9e652ad6fdd5d8d5da87c478495db0 | |
parent | 4fc5c95c966615b971a8d67dc63b384ae691fb11 (diff) | |
parent | da491f048fb33b572713b4287436c1cac6898670 (diff) | |
download | android_frameworks_ex-c3a17c96b86bff4e387c361127e04d60173a9ca6.tar.gz android_frameworks_ex-c3a17c96b86bff4e387c361127e04d60173a9ca6.tar.bz2 android_frameworks_ex-c3a17c96b86bff4e387c361127e04d60173a9ca6.zip |
am da491f04: Prevent a potential ANR
* commit 'da491f048fb33b572713b4287436c1cac6898670':
Prevent a potential ANR
-rw-r--r-- | chips/src/com/android/ex/chips/RecipientEditTextView.java | 69 |
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 879789c..60bb138 100644 --- a/chips/src/com/android/ex/chips/RecipientEditTextView.java +++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java @@ -1450,36 +1450,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) { |