1e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinpackage com.android.mail.browse; 2e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 3e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinimport android.content.Context; 4e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinimport android.util.AttributeSet; 5e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinimport android.view.View; 6735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sappersteinimport android.view.ViewGroup; 7e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinimport android.widget.LinearLayout; 8e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 9e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinimport com.android.mail.R; 10e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinimport com.android.mail.browse.ConversationViewAdapter.ConversationFooterItem; 11e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinimport com.android.mail.browse.ConversationViewAdapter.MessageHeaderItem; 12e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinimport com.android.mail.compose.ComposeActivity; 13e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinimport com.android.mail.providers.Account; 14e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinimport com.android.mail.providers.Message; 15e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinimport com.android.mail.utils.LogTag; 16e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinimport com.android.mail.utils.LogUtils; 17735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sappersteinimport com.android.mail.utils.Utils; 18e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 19e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein/** 20e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein * A view placed at the bottom of the conversation view that allows the user to 21e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein * reply/reply all/forward to the last message in the conversation. 22e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein */ 23e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sappersteinpublic class ConversationFooterView extends LinearLayout implements View.OnClickListener { 24e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 25735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein public interface ConversationFooterCallbacks { 26735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein /** 27735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein * Called when the height of the {@link ConversationFooterView} changes. 28735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein * 29735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein * @param newHeight the new height in px 30735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein */ 31735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein void onConversationFooterHeightChange(int newHeight); 32735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein } 33e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein private static final String LOG_TAG = LogTag.getLogTag(); 34e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 35e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein private ConversationFooterItem mFooterItem; 36e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein private ConversationAccountController mAccountController; 37735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein private ConversationFooterCallbacks mCallbacks; 38735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein 39735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein private View mFooterButtons; 40e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 41e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein public ConversationFooterView(Context context) { 42e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein super(context); 43e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } 44e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 45e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein public ConversationFooterView(Context context, AttributeSet attrs) { 46e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein super(context, attrs); 47e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } 48e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 49e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein public ConversationFooterView(Context context, AttributeSet attrs, int defStyle) { 50e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein super(context, attrs, defStyle); 51e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } 52e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 53e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein @Override 54e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein protected void onFinishInflate() { 55e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein super.onFinishInflate(); 56e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 57735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein mFooterButtons = findViewById(R.id.footer_buttons); 58735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein 59e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein findViewById(R.id.reply_button).setOnClickListener(this); 60e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein findViewById(R.id.reply_all_button).setOnClickListener(this); 61e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein findViewById(R.id.forward_button).setOnClickListener(this); 62e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } 63e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 64e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein @Override 65e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein public void onClick(View v) { 66e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein if (mFooterItem == null) { 67e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein LogUtils.i(LOG_TAG, "ignoring conversation footer tap on unbound view"); 68e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein return; 69e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } 70e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein final MessageHeaderItem headerItem = mFooterItem.getLastMessageHeaderItem(); 71e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein if (headerItem == null) { 72e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein LogUtils.i(LOG_TAG, "ignoring conversation footer tap on null header item"); 73e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein return; 74e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } 75e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein final Message message = headerItem.getMessage(); 76e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein if (message == null) { 77e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein LogUtils.i(LOG_TAG, "ignoring conversation footer tap on null message"); 78e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein return; 79e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } 80e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein final int id = v.getId(); 81e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein if (id == R.id.reply_button) { 82e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein ComposeActivity.reply(getContext(), getAccount(), message); 83e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } else if (id == R.id.reply_all_button) { 84e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein ComposeActivity.replyAll(getContext(), getAccount(), message); 85e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } else if (id == R.id.forward_button) { 86e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein ComposeActivity.forward(getContext(), getAccount(), message); 87e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } 88e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } 89e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 90e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein public void bind(ConversationFooterItem footerItem) { 91e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein mFooterItem = footerItem; 92735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein 93735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein if (mFooterItem == null) { 94735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein LogUtils.i(LOG_TAG, "ignoring conversation footer tap on unbound view"); 95735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein return; 96735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein } 97735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein final MessageHeaderItem headerItem = mFooterItem.getLastMessageHeaderItem(); 98735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein if (headerItem == null) { 99735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein LogUtils.i(LOG_TAG, "ignoring conversation footer tap on null header item"); 100735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein return; 101735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein } 102735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein final Message message = headerItem.getMessage(); 103735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein if (message == null) { 104735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein LogUtils.i(LOG_TAG, "ignoring conversation footer tap on null message"); 105735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein return; 106735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein } 107735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein 108735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein // hide the footer icons 109735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein mFooterButtons.setVisibility(message.isDraft() ? GONE : VISIBLE); 110735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein } 111735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein 112735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein public void rebind(ConversationFooterItem footerItem) { 113735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein bind(footerItem); 114735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein 115735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein if (mFooterItem != null) { 116735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein final int h = measureHeight(); 117735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein if (mFooterItem.setHeight(h)) { 118735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein mCallbacks.onConversationFooterHeightChange(h); 119735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein } 120735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein } 121735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein } 122735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein 123735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein private int measureHeight() { 124735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein ViewGroup parent = (ViewGroup) getParent(); 125735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein if (parent == null) { 126735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein LogUtils.e(LOG_TAG, "Unable to measure height of conversation header"); 127735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein return getHeight(); 128735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein } 129735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein final int h = Utils.measureViewHeight(this, parent); 130735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein return h; 131e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } 132e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 133e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein public void setAccountController(ConversationAccountController accountController) { 134e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein mAccountController = accountController; 135e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } 136e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein 137735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein public void setConversationFooterCallbacks(ConversationFooterCallbacks callbacks) { 138735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein mCallbacks = callbacks; 139735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein } 140735a22a197215ec4787ad9f3cbaf465cce54f4d0Andrew Sapperstein 141e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein private Account getAccount() { 142e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein return mAccountController != null ? mAccountController.getAccount() : null; 143e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein } 144e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2Andrew Sapperstein} 145