1 /* 2 * Copyright (C) 2014 Google Inc. 3 * Licensed to The Android Open Source Project. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.mail.browse; 19 20 import android.content.Context; 21 import android.graphics.drawable.Drawable; 22 import android.net.Uri; 23 import android.util.AttributeSet; 24 import android.view.View; 25 import android.widget.ImageView; 26 import android.widget.QuickContactBadge; 27 28 import com.android.mail.R; 29 import com.android.mail.analytics.Analytics; 30 31 public class MessageHeaderContactBadge extends ImageView implements View.OnClickListener { 32 33 private QuickContactBadge mQuickContactBadge; 34 35 private Drawable mDefaultAvatar; 36 MessageHeaderContactBadge(Context context)37 public MessageHeaderContactBadge(Context context) { 38 this(context, null); 39 } 40 MessageHeaderContactBadge(Context context, AttributeSet attrs)41 public MessageHeaderContactBadge(Context context, AttributeSet attrs) { 42 this(context, attrs, 0); 43 } 44 MessageHeaderContactBadge(Context context, AttributeSet attrs, int defStyle)45 public MessageHeaderContactBadge(Context context, AttributeSet attrs, int defStyle) { 46 super(context, attrs, defStyle); 47 48 setOnClickListener(this); 49 } 50 51 @Override onClick(View v)52 public void onClick(View v) { 53 Analytics.getInstance().sendEvent("quick_contact", "clicked", null, 0); 54 if (mQuickContactBadge != null) { 55 mQuickContactBadge.onClick(v); 56 } 57 } 58 setImageToDefault()59 public void setImageToDefault() { 60 if (mDefaultAvatar == null) { 61 mDefaultAvatar = getResources().getDrawable(R.drawable.ic_contact_picture); 62 } 63 setImageDrawable(mDefaultAvatar); 64 } 65 assignContactUri(Uri contactUri)66 public void assignContactUri(Uri contactUri) { 67 if (mQuickContactBadge != null) { 68 mQuickContactBadge.assignContactUri(contactUri); 69 } 70 } 71 assignContactFromEmail(String emailAddress, boolean lazyLookup)72 public void assignContactFromEmail(String emailAddress, boolean lazyLookup) { 73 if (mQuickContactBadge != null) { 74 mQuickContactBadge.assignContactFromEmail(emailAddress, lazyLookup); 75 } 76 } 77 setQuickContactBadge(QuickContactBadge quickContactBadge)78 public void setQuickContactBadge(QuickContactBadge quickContactBadge) { 79 mQuickContactBadge = quickContactBadge; 80 } 81 } 82