summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/contactphoto
diff options
context:
space:
mode:
authortwyen <twyen@google.com>2018-01-24 16:48:49 -0800
committerCopybara-Service <copybara-piper@google.com>2018-01-24 19:09:39 -0800
commit0874af841f7e23357ceb2bb8825180b111d613b4 (patch)
tree23982c4a353490aa0a605b0e04b8656def2a3775 /java/com/android/dialer/contactphoto
parent2a422f719b70f6c292b954fb24f324b7f4ac1858 (diff)
Show Icon and label for blocked numbers
CallLogPhoto.getPhotoUri() returns a URI to a drawable so it will be easier to transition into glide. Meanwhile ContactPhotoManager will just show the drawable directly. Bug: 70989547 Test: Unit tests PiperOrigin-RevId: 183163818 Change-Id: I4ee4ff98782e35d2be03dfe14f8bf3dfd6ded074
Diffstat (limited to 'java/com/android/dialer/contactphoto')
-rw-r--r--java/com/android/dialer/contactphoto/ContactPhotoManagerImpl.java36
-rw-r--r--java/com/android/dialer/contactphoto/NumberAttributeConverter.java66
-rw-r--r--java/com/android/dialer/contactphoto/res/drawable-xxxhdpi/ic_block_black_48dp.pngbin0 -> 2532 bytes
-rw-r--r--java/com/android/dialer/contactphoto/res/drawable/ic_block_grey_48dp.xml17
4 files changed, 107 insertions, 12 deletions
diff --git a/java/com/android/dialer/contactphoto/ContactPhotoManagerImpl.java b/java/com/android/dialer/contactphoto/ContactPhotoManagerImpl.java
index edeeb78d6..cf42606a6 100644
--- a/java/com/android/dialer/contactphoto/ContactPhotoManagerImpl.java
+++ b/java/com/android/dialer/contactphoto/ContactPhotoManagerImpl.java
@@ -414,20 +414,32 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback {
// No photo is needed
defaultProvider.applyDefaultImage(view, requestedExtent, darkTheme, defaultImageRequest);
pendingRequests.remove(view);
+ return;
+ }
+ if (isDrawableUri(photoUri)) {
+ view.setImageURI(photoUri);
+ pendingRequests.remove(view);
+ return;
+ }
+ if (DEBUG) {
+ LogUtil.d("ContactPhotoManagerImpl.loadPhoto", "loadPhoto request: " + photoUri);
+ }
+
+ if (isDefaultImageUri(photoUri)) {
+ createAndApplyDefaultImageForUri(
+ view, photoUri, requestedExtent, darkTheme, isCircular, defaultProvider);
} else {
- if (DEBUG) {
- LogUtil.d("ContactPhotoManagerImpl.loadPhoto", "loadPhoto request: " + photoUri);
- }
- if (isDefaultImageUri(photoUri)) {
- createAndApplyDefaultImageForUri(
- view, photoUri, requestedExtent, darkTheme, isCircular, defaultProvider);
- } else {
- loadPhotoByIdOrUri(
- view,
- Request.createFromUri(
- photoUri, requestedExtent, darkTheme, isCircular, defaultProvider));
- }
+ loadPhotoByIdOrUri(
+ view,
+ Request.createFromUri(photoUri, requestedExtent, darkTheme, isCircular, defaultProvider));
+ }
+ }
+
+ private static boolean isDrawableUri(Uri uri) {
+ if (!ContentResolver.SCHEME_ANDROID_RESOURCE.equals(uri.getScheme())) {
+ return false;
}
+ return uri.getPathSegments().get(0).equals("drawable");
}
private void createAndApplyDefaultImageForUri(
diff --git a/java/com/android/dialer/contactphoto/NumberAttributeConverter.java b/java/com/android/dialer/contactphoto/NumberAttributeConverter.java
new file mode 100644
index 000000000..d7bf9bda7
--- /dev/null
+++ b/java/com/android/dialer/contactphoto/NumberAttributeConverter.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+package com.android.dialer.contactphoto;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.res.Resources;
+import android.net.Uri;
+import android.support.annotation.DrawableRes;
+import android.support.annotation.Nullable;
+import android.text.TextUtils;
+import com.android.dialer.NumberAttributes;
+
+/**
+ * Convert photo information in {@link NumberAttributes} to an URI suitable for {@link
+ * ContactPhotoManager}.
+ *
+ * <p>This class is temporary. The new photo manager should take NumberAttributes directly.
+ */
+public final class NumberAttributeConverter {
+
+ /**
+ * Computes the photo URI from NumberAttributes.
+ *
+ * <p>The photo URI is shown in the quick contact badge in the main call log list or in the top
+ * item of the bottom sheet menu.
+ */
+ @Nullable
+ public static Uri getPhotoUri(Context context, NumberAttributes numberAttributes) {
+ if (numberAttributes.getIsBlocked()) {
+ return getResourceUri(context.getResources(), R.drawable.ic_block_grey_48dp);
+ } else {
+ return parseUri(numberAttributes.getPhotoUri());
+ }
+ }
+
+ @Nullable
+ private static Uri parseUri(@Nullable String uri) {
+ return TextUtils.isEmpty(uri) ? null : Uri.parse(uri);
+ }
+
+ private static Uri getResourceUri(Resources resources, @DrawableRes int drawable) {
+ return Uri.parse(
+ ContentResolver.SCHEME_ANDROID_RESOURCE
+ + "://"
+ + resources.getResourcePackageName(drawable)
+ + "/"
+ + resources.getResourceTypeName(drawable)
+ + "/"
+ + resources.getResourceEntryName(drawable));
+ }
+}
diff --git a/java/com/android/dialer/contactphoto/res/drawable-xxxhdpi/ic_block_black_48dp.png b/java/com/android/dialer/contactphoto/res/drawable-xxxhdpi/ic_block_black_48dp.png
new file mode 100644
index 000000000..1168bd8d5
--- /dev/null
+++ b/java/com/android/dialer/contactphoto/res/drawable-xxxhdpi/ic_block_black_48dp.png
Binary files differ
diff --git a/java/com/android/dialer/contactphoto/res/drawable/ic_block_grey_48dp.xml b/java/com/android/dialer/contactphoto/res/drawable/ic_block_grey_48dp.xml
new file mode 100644
index 000000000..42cfa99bd
--- /dev/null
+++ b/java/com/android/dialer/contactphoto/res/drawable/ic_block_grey_48dp.xml
@@ -0,0 +1,17 @@
+<!-- Copyright (C) 2018 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.
+-->
+<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
+ android:src="@drawable/ic_block_black_48dp"
+ android:tint="#757575" /> \ No newline at end of file