1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-31 07:10:14 -05:00

Avoid creating new objects for handling click events

This commit is contained in:
cketti 2012-02-21 16:21:47 +01:00
parent 9f42ff61d3
commit ec6645bf6a
2 changed files with 69 additions and 48 deletions

View File

@ -10,6 +10,7 @@ import android.util.AttributeSet;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ScrollView; import android.widget.ScrollView;
@ -33,7 +34,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.text.DateFormat; import java.text.DateFormat;
public class MessageHeader extends ScrollView { public class MessageHeader extends ScrollView implements OnClickListener {
private Context mContext; private Context mContext;
private TextView mFromView; private TextView mFromView;
private TextView mDateView; private TextView mDateView;
@ -54,7 +55,6 @@ public class MessageHeader extends ScrollView {
private Account mAccount; private Account mAccount;
private FontSizes mFontSizes = K9.getFontSizes(); private FontSizes mFontSizes = K9.getFontSizes();
private Contacts mContacts; private Contacts mContacts;
private View mAdditionalHeadersArea;
private ImageView mShowAdditionalHeadersIcon; private ImageView mShowAdditionalHeadersIcon;
/** /**
@ -91,7 +91,6 @@ public class MessageHeader extends ScrollView {
mDateView = (TextView) findViewById(R.id.date); mDateView = (TextView) findViewById(R.id.date);
mTimeView = (TextView) findViewById(R.id.time); mTimeView = (TextView) findViewById(R.id.time);
mFlagged = (CheckBox) findViewById(R.id.flagged); mFlagged = (CheckBox) findViewById(R.id.flagged);
mAdditionalHeadersArea = findViewById(R.id.show_additional_headers_area);
mShowAdditionalHeadersIcon = (ImageView) findViewById(R.id.show_additional_headers_icon); mShowAdditionalHeadersIcon = (ImageView) findViewById(R.id.show_additional_headers_icon);
@ -109,26 +108,33 @@ public class MessageHeader extends ScrollView {
((TextView) findViewById(R.id.to_label)).setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewTo()); ((TextView) findViewById(R.id.to_label)).setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewTo());
((TextView) findViewById(R.id.cc_label)).setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewCC()); ((TextView) findViewById(R.id.cc_label)).setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getMessageViewCC());
mAdditionalHeadersArea.setOnClickListener(new OnClickListener() { findViewById(R.id.show_additional_headers_area).setOnClickListener(this);
@Override mFromView.setOnClickListener(this);
public void onClick(View v) { }
onShowAdditionalHeaders();
}
});
mFromView.setOnClickListener(new OnClickListener() { @Override
@Override public void onClick(View view) {
public void onClick(View v) { switch (view.getId()) {
if (mMessage != null) { case R.id.show_additional_headers_area: {
try { onShowAdditionalHeaders();
final Address senderEmail = mMessage.getFrom()[0]; break;
mContacts.createContact(senderEmail);
} catch (Exception e) {
Log.e(K9.LOG_TAG, "Couldn't create contact", e);
}
}
} }
}); case R.id.from: {
onAddSenderToContacts();
break;
}
}
}
private void onAddSenderToContacts() {
if (mMessage != null) {
try {
final Address senderEmail = mMessage.getFrom()[0];
mContacts.createContact(senderEmail);
} catch (Exception e) {
Log.e(K9.LOG_TAG, "Couldn't create contact", e);
}
}
} }
public void setOnFlagListener(OnClickListener listener) { public void setOnFlagListener(OnClickListener listener) {

View File

@ -12,6 +12,7 @@ import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import com.fsck.k9.Account; import com.fsck.k9.Account;
@ -29,7 +30,7 @@ import com.fsck.k9.mail.store.LocalStore;
import java.util.List; import java.util.List;
public class SingleMessageView extends LinearLayout { public class SingleMessageView extends LinearLayout implements OnClickListener {
private boolean mScreenReaderEnabled; private boolean mScreenReaderEnabled;
private MessageCryptoView mCryptoView; private MessageCryptoView mCryptoView;
private MessageWebView mMessageContentView; private MessageWebView mMessageContentView;
@ -65,39 +66,13 @@ public class SingleMessageView extends LinearLayout {
mHiddenAttachments.setVisibility(View.GONE); mHiddenAttachments.setVisibility(View.GONE);
mShowHiddenAttachments = (Button) findViewById(R.id.show_hidden_attachments); mShowHiddenAttachments = (Button) findViewById(R.id.show_hidden_attachments);
mShowHiddenAttachments.setVisibility(View.GONE); mShowHiddenAttachments.setVisibility(View.GONE);
mShowHiddenAttachments.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
mShowHiddenAttachments.setVisibility(View.GONE);
mHiddenAttachments.setVisibility(View.VISIBLE);
}
});
mCryptoView = (MessageCryptoView) findViewById(R.id.layout_decrypt); mCryptoView = (MessageCryptoView) findViewById(R.id.layout_decrypt);
mCryptoView.setActivity(activity); mCryptoView.setActivity(activity);
mCryptoView.setupChildViews(); mCryptoView.setupChildViews();
mShowPicturesAction = findViewById(R.id.show_pictures); mShowPicturesAction = findViewById(R.id.show_pictures);
mShowMessageAction = findViewById(R.id.show_message); mShowMessageAction = findViewById(R.id.show_message);
mShowMessageAction.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showShowMessageAction(false);
showAttachments(false);
showMessageWebView(true);
showShowAttachmentsAction(true);
}
});
mShowAttachmentsAction = findViewById(R.id.show_attachments); mShowAttachmentsAction = findViewById(R.id.show_attachments);
mShowAttachmentsAction.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showMessageWebView(false);
showShowAttachmentsAction(false);
showShowMessageAction(true);
showAttachments(true);
}
});
mShowPictures = false; mShowPictures = false;
@ -126,6 +101,46 @@ public class SingleMessageView extends LinearLayout {
mMessageContentView.wrapSetTitleBar(mTitleBarHeaderContainer); mMessageContentView.wrapSetTitleBar(mTitleBarHeaderContainer);
} }
mShowHiddenAttachments.setOnClickListener(this);
mShowMessageAction.setOnClickListener(this);
mShowAttachmentsAction.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.show_hidden_attachments: {
onShowHiddenAttachments();
break;
}
case R.id.show_message: {
onShowMessage();
break;
}
case R.id.show_attachments: {
onShowAttachments();
break;
}
}
}
private void onShowHiddenAttachments() {
mShowHiddenAttachments.setVisibility(View.GONE);
mHiddenAttachments.setVisibility(View.VISIBLE);
}
private void onShowMessage() {
showShowMessageAction(false);
showAttachments(false);
showMessageWebView(true);
showShowAttachmentsAction(true);
}
private void onShowAttachments() {
showMessageWebView(false);
showShowAttachmentsAction(false);
showShowMessageAction(true);
showAttachments(true);
} }
public SingleMessageView(Context context, AttributeSet attrs) { public SingleMessageView(Context context, AttributeSet attrs) {