Home | History | Annotate | Download | only in browse
      1 package com.android.mail.browse;
      2 
      3 import android.content.Context;
      4 import android.util.AttributeSet;
      5 import android.view.View;
      6 import android.view.View.OnClickListener;
      7 import android.widget.ImageView;
      8 import android.widget.RelativeLayout;
      9 import android.widget.TextView;
     10 
     11 import com.android.mail.R;
     12 import com.android.mail.providers.Address;
     13 import com.android.mail.providers.Message;
     14 import com.android.mail.providers.UIProvider;
     15 import com.android.mail.utils.Utils;
     16 
     17 public class SpamWarningView extends RelativeLayout implements OnClickListener {
     18     private ImageView mSpamWarningIcon;
     19     private TextView mSpamWarningText;
     20     private TextView mSpamWarningLink;
     21     private final int mHighWarningColor;
     22     private final int mLowWarningColor;
     23 
     24     public SpamWarningView(Context context) {
     25         this(context, null);
     26     }
     27 
     28     public SpamWarningView(Context context, AttributeSet attrs) {
     29         super(context, attrs);
     30 
     31         mHighWarningColor = getResources().getColor(R.color.high_spam_color);
     32         mLowWarningColor = getResources().getColor(R.color.conv_header_text_light);
     33     }
     34 
     35     @Override
     36     public void onFinishInflate() {
     37         setOnClickListener(this);
     38 
     39         mSpamWarningIcon = (ImageView) findViewById(R.id.spam_warning_icon);
     40         mSpamWarningText = (TextView) findViewById(R.id.spam_warning_text);
     41         mSpamWarningLink = (TextView) findViewById(R.id.spam_warning_link);
     42         mSpamWarningLink.setOnClickListener(this);
     43     }
     44 
     45     @Override
     46     public void onClick(View v) {
     47         final int id = v.getId();
     48 
     49         if (id == R.id.spam_warning) {
     50             // Do nothing (TODO?)
     51         } else if (id == R.id.spam_warning_link) {
     52             // TODO - once we have final design,
     53             // make clicking this text do what needs to be done
     54         }
     55 
     56     }
     57 
     58     public void showSpamWarning(Message message, Address sender) {
     59         setVisibility(VISIBLE);
     60 
     61         // Sets the text and adds any necessary formatting
     62         // to enable the proper display.
     63         final String senderAddress = sender.getAddress();
     64         final String senderDomain = senderAddress.substring(senderAddress.indexOf('@')+1);
     65         mSpamWarningText.setText(Utils.convertHtmlToPlainText(String.format(
     66                 message.spamWarningString, senderAddress, senderDomain)));
     67 
     68         if (message.spamWarningLevel == UIProvider.SpamWarningLevel.HIGH_WARNING) {
     69             mSpamWarningText.setTextColor(mHighWarningColor);
     70             mSpamWarningIcon.setImageResource(R.drawable.ic_alert_red);
     71         } else {
     72             mSpamWarningText.setTextColor(mLowWarningColor);
     73             mSpamWarningIcon.setImageResource(R.drawable.ic_alert_grey);
     74         }
     75 
     76         // Sets the link to the appropriate text
     77         // and sets visibility, if necessary.
     78         final int linkType = message.spamLinkType;
     79         switch (linkType) {
     80             case UIProvider.SpamWarningLinkType.NO_LINK:
     81                 mSpamWarningLink.setVisibility(GONE);
     82                 break;
     83             case UIProvider.SpamWarningLinkType.IGNORE_WARNING:
     84                 mSpamWarningLink.setVisibility(VISIBLE);
     85                 mSpamWarningLink.setText(R.string.ignore_spam_warning);
     86                 break;
     87             case UIProvider.SpamWarningLinkType.REPORT_PHISHING:
     88                 mSpamWarningLink.setVisibility(VISIBLE);
     89                 mSpamWarningLink.setText(R.string.report_phishing);
     90                 break;
     91         }
     92     }
     93 }
     94