From 23254e8998dfe89cbc687b873d466a77bea36a15 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Fri, 26 Nov 2010 03:53:10 +0000 Subject: [PATCH] BatchButton area toggling should't happen from anything other than the UiThread: Fixes a common error from the market: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. at android.view.ViewRoot.checkThread(ViewRoot.java:2802) at android.view.ViewRoot.invalidateChild(ViewRoot.java:607) at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:633) at android.view.ViewGroup.invalidateChild(ViewGroup.java:2505) at android.view.View.invalidate(View.java:5139) at android.view.View.setFlags(View.java:4502) at android.view.View.setVisibility(View.java:3030) at com.fsck.k9.activity.MessageList.hideBatchButtons(MessageList.java:2883) at com.fsck.k9.activity.MessageList.toggleBatchButtons(MessageList.java:2906) at com.fsck.k9.activity.MessageList.access$500(MessageList.java:77) at com.fsck.k9.activity.MessageList$MessageListAdapter.pruneDirtyMessages(MessageList.java:2302) at com.fsck.k9.activity.MessageList$1.run(MessageList.java:811) --- src/com/fsck/k9/activity/MessageList.java | 85 +++++++++++++---------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index cd56b70b6..5ce7e00c4 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -2983,45 +2983,58 @@ public class MessageList private void toggleBatchButtons() { - if (mSelectedCount < 0) - { - mSelectedCount = 0; - } - int readButtonIconId; - int flagButtonIconId; + runOnUiThread(new Runnable() + { + @Override + public void run() + { + + if (mSelectedCount < 0) + { + mSelectedCount = 0; + } + + int readButtonIconId; + int flagButtonIconId; + + if (mSelectedCount==0) + { + readButtonIconId = R.drawable.ic_button_mark_read; + flagButtonIconId = R.drawable.ic_button_flag; + hideBatchButtons(); + } + else + { + boolean newReadState = computeBatchDirection(false); + if (newReadState) + { + readButtonIconId = R.drawable.ic_button_mark_read; + } + else + { + readButtonIconId = R.drawable.ic_button_mark_unread; + } + boolean newFlagState = computeBatchDirection(true); + if (newFlagState) + { + flagButtonIconId = R.drawable.ic_button_flag; + } + else + { + flagButtonIconId = R.drawable.ic_button_unflag; + } + showBatchButtons(); + } + + mBatchReadButton.setImageResource(readButtonIconId); + mBatchFlagButton.setImageResource(flagButtonIconId); + + + } + }); - if (mSelectedCount==0) - { - readButtonIconId = R.drawable.ic_button_mark_read; - flagButtonIconId = R.drawable.ic_button_flag; - hideBatchButtons(); - } - else - { - boolean newReadState = computeBatchDirection(false); - if (newReadState) - { - readButtonIconId = R.drawable.ic_button_mark_read; - } - else - { - readButtonIconId = R.drawable.ic_button_mark_unread; - } - boolean newFlagState = computeBatchDirection(true); - if (newFlagState) - { - flagButtonIconId = R.drawable.ic_button_flag; - } - else - { - flagButtonIconId = R.drawable.ic_button_unflag; - } - showBatchButtons(); - } - mBatchReadButton.setImageResource(readButtonIconId); - mBatchFlagButton.setImageResource(flagButtonIconId); } class FooterViewHolder