Show blocked contact instead of profile photo.

Does not yet update on change; figuring to do that in a followup
CL because there are a number of other scenarios where that
needs to be fixed too.

Bug: 23943480
Change-Id: I73615c405d547e74667f6c635b5623708c723347
diff --git a/res/drawable-hdpi/ic_block_18dp.png b/res/drawable-hdpi/ic_block_18dp.png
new file mode 100644
index 0000000..acab511
--- /dev/null
+++ b/res/drawable-hdpi/ic_block_18dp.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_block_18dp.png b/res/drawable-mdpi/ic_block_18dp.png
new file mode 100644
index 0000000..45b83fa
--- /dev/null
+++ b/res/drawable-mdpi/ic_block_18dp.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_block_24dp.png b/res/drawable-mdpi/ic_block_24dp.png
deleted file mode 100644
index ec1b33f..0000000
--- a/res/drawable-mdpi/ic_block_24dp.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/ic_block_24dp.png b/res/drawable-xhdpi/ic_block_18dp.png
similarity index 100%
rename from res/drawable-hdpi/ic_block_24dp.png
rename to res/drawable-xhdpi/ic_block_18dp.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_block_24dp.png b/res/drawable-xhdpi/ic_block_24dp.png
deleted file mode 100644
index 7aba97b..0000000
--- a/res/drawable-xhdpi/ic_block_24dp.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_block_18dp.png b/res/drawable-xxhdpi/ic_block_18dp.png
new file mode 100644
index 0000000..1eee124
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_block_18dp.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_block_24dp.png b/res/drawable-xxxhdpi/ic_block_18dp.png
similarity index 100%
rename from res/drawable-xxhdpi/ic_block_24dp.png
rename to res/drawable-xxxhdpi/ic_block_18dp.png
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_block_24dp.png b/res/drawable-xxxhdpi/ic_block_24dp.png
deleted file mode 100644
index 0378d1b..0000000
--- a/res/drawable-xxxhdpi/ic_block_24dp.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable/blocked_contact.xml b/res/drawable/blocked_contact.xml
new file mode 100644
index 0000000..38c0fc9
--- /dev/null
+++ b/res/drawable/blocked_contact.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+  ~ Copyright (C) 2015 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License
+  -->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <item>
+        <shape android:shape="oval">
+            <solid android:color="@color/blocked_contact_background" />
+            <size android:width="24dp" android:height="24dp" />
+        </shape>
+    </item>
+    <item android:drawable="@drawable/ic_block_18dp" android:gravity="center" />
+</layer-list>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 55970d9..a7044c7 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -111,6 +111,7 @@
     <color name="divider_line_color">#c7c7c7</color>
 
     <!--  Colors for blocked numbers list -->
+    <color name="blocked_contact_background">#afafaf</color>
     <color name="blocked_number_primary_text_color">@color/dialtacts_primary_text_color</color>
     <color name="blocked_number_secondary_text_color">@color/dialtacts_secondary_text_color</color>
     <color name="delete_icon_tint">#6D6D6D</color>
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index 316864f..703b18f 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -44,13 +44,16 @@
 import com.android.dialer.R;
 import com.android.dialer.contactinfo.ContactInfoCache;
 import com.android.dialer.contactinfo.ContactInfoCache.OnContactInfoChangedListener;
+import com.android.dialer.contactinfo.NumberWithCountryIso;
 import com.android.dialer.database.FilteredNumberAsyncQueryHandler;
+import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener;
 import com.android.dialer.util.PhoneNumberUtil;
 import com.android.dialer.voicemail.VoicemailPlaybackPresenter;
 
 import com.google.common.annotations.VisibleForTesting;
 
 import java.util.HashMap;
+import java.util.Map;
 
 /**
  * Adapter class to fill in data for the Call Log.
@@ -85,6 +88,7 @@
     private final FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler;
 
     protected ContactInfoCache mContactInfoCache;
+    protected final Map<NumberWithCountryIso, Integer> mBlockedIdCache;
 
     private boolean mIsCallLogActivity;
 
@@ -248,6 +252,7 @@
         CallTypeHelper callTypeHelper = new CallTypeHelper(resources);
 
         mTelecomCallLogCache = new TelecomCallLogCache(mContext);
+        mBlockedIdCache = new HashMap<NumberWithCountryIso, Integer>();
         PhoneCallDetailsHelper phoneCallDetailsHelper =
                 new PhoneCallDetailsHelper(mContext, resources, mTelecomCallLogCache);
         mCallLogListItemHelper =
@@ -296,6 +301,7 @@
 
     public void invalidateCache() {
         mContactInfoCache.invalidate();
+        mBlockedIdCache.clear();
     }
 
     public void startCache() {
@@ -456,7 +462,7 @@
             details.objectId = info.objectId;
         }
 
-        CallLogListItemViewHolder views = (CallLogListItemViewHolder) viewHolder;
+        final CallLogListItemViewHolder views = (CallLogListItemViewHolder) viewHolder;
         views.info = info;
         views.rowId = c.getLong(CallLogQuery.ID);
         // Store values used when the actions ViewStub is inflated on expansion.
@@ -492,8 +498,28 @@
             mCurrentlyExpandedPosition = position;
         }
 
+        // Update the photo, once we know whether the user's number is blocked or not.
+        final NumberWithCountryIso blockedIdKey = new NumberWithCountryIso(number, countryIso);
+        if (mBlockedIdCache.containsKey(blockedIdKey)) {
+            views.blockId = mBlockedIdCache.get(blockedIdKey);
+            views.updatePhoto();
+        } else {
+            views.blockId = null;
+            boolean failed = mFilteredNumberAsyncQueryHandler.startBlockedQuery(
+                        new OnCheckBlockedListener() {
+                    @Override
+                    public void onCheckComplete(Integer id) {
+                        mBlockedIdCache.put(blockedIdKey, id);
+                        views.blockId = id;
+                        views.updatePhoto();
+                    }
+                }, null, number, countryIso);
+            if (failed) {
+                views.updatePhoto();
+            }
+        }
+
         views.showActions(mCurrentlyExpandedPosition == position);
-        views.updatePhoto();
 
         mCallLogListItemHelper.setPhoneCallDetails(views, details);
     }
diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
index 5b47d44..d22947b 100644
--- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
+++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
@@ -528,8 +528,13 @@
     }
 
     public void updatePhoto() {
-        quickContactView.assignContactUri(info.lookupUri);
         quickContactView.setOverlay(null);
+        quickContactView.assignContactUri(info.lookupUri);
+
+        if (blockId != null) {
+            quickContactView.setImageDrawable(mContext.getDrawable(R.drawable.blocked_contact));
+            return;
+        }
 
         final boolean isVoicemail = mTelecomCallLogCache.isVoicemailNumber(accountHandle, number);
         int contactType = ContactPhotoManager.TYPE_DEFAULT;
diff --git a/src/com/android/dialer/calllog/CallTypeIconsView.java b/src/com/android/dialer/calllog/CallTypeIconsView.java
index cfd8f97..d2be380 100644
--- a/src/com/android/dialer/calllog/CallTypeIconsView.java
+++ b/src/com/android/dialer/calllog/CallTypeIconsView.java
@@ -199,7 +199,7 @@
 
             voicemail = r.getDrawable(R.drawable.ic_call_voicemail_holo_dark);
 
-            blocked = getScaledBitmap(context, R.drawable.ic_block_24dp);
+            blocked = getScaledBitmap(context, R.drawable.ic_block_18dp);
             blocked.setColorFilter(r.getColor(R.color.blocked_call), PorterDuff.Mode.MULTIPLY);
 
             videoCall = getScaledBitmap(context, R.drawable.ic_videocam_24dp);