From 51789e7254fde5685c1a833172283d0dd74d7b33 Mon Sep 17 00:00:00 2001 From: linyuh Date: Wed, 16 May 2018 10:09:53 -0700 Subject: Improve ContactPhotoView Bug: 70989658 Test: NewCallLogIntegrationTest + Manual PiperOrigin-RevId: 196845473 Change-Id: Ic0cbcf668ea1921c88fb6b080308884fa1113e61 --- java/com/android/dialer/widget/ContactPhotoView.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'java/com/android/dialer/widget/ContactPhotoView.java') diff --git a/java/com/android/dialer/widget/ContactPhotoView.java b/java/com/android/dialer/widget/ContactPhotoView.java index a84111f95..c0c9be7a4 100644 --- a/java/com/android/dialer/widget/ContactPhotoView.java +++ b/java/com/android/dialer/widget/ContactPhotoView.java @@ -21,6 +21,7 @@ import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.QuickContactBadge; @@ -69,6 +70,21 @@ public final class ContactPhotoView extends FrameLayout { hideBadge(); // Hide badges by default. } + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + + // We require both the height and the width to be WRAP_CONTENT to prevent users of + // this widget from clipping the view (by setting a size that is too small) or altering the + // relative position of the contact photo and its badge (by setting a size that is too large). + ViewGroup.LayoutParams layoutParams = Assert.isNotNull(getLayoutParams()); + Assert.checkState( + layoutParams.height == LayoutParams.WRAP_CONTENT, + "The layout height must be WRAP_CONTENT!"); + Assert.checkState( + layoutParams.width == LayoutParams.WRAP_CONTENT, "The layout width must be WRAP_CONTENT!"); + } + private void inflateLayout() { LayoutInflater inflater = Assert.isNotNull(getContext().getSystemService(LayoutInflater.class)); inflater.inflate(R.layout.contact_photo_view, /* root = */ this); -- cgit v1.2.3