From 0874af841f7e23357ceb2bb8825180b111d613b4 Mon Sep 17 00:00:00 2001 From: twyen Date: Wed, 24 Jan 2018 16:48:49 -0800 Subject: 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 --- .../contactphoto/ContactPhotoManagerImpl.java | 36 +++++++---- .../contactphoto/NumberAttributeConverter.java | 66 +++++++++++++++++++++ .../res/drawable-xxxhdpi/ic_block_black_48dp.png | Bin 0 -> 2532 bytes .../res/drawable/ic_block_grey_48dp.xml | 17 ++++++ 4 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 java/com/android/dialer/contactphoto/NumberAttributeConverter.java create mode 100644 java/com/android/dialer/contactphoto/res/drawable-xxxhdpi/ic_block_black_48dp.png create mode 100644 java/com/android/dialer/contactphoto/res/drawable/ic_block_grey_48dp.xml (limited to 'java/com/android/dialer/contactphoto') 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}. + * + *

This class is temporary. The new photo manager should take NumberAttributes directly. + */ +public final class NumberAttributeConverter { + + /** + * Computes the photo URI from NumberAttributes. + * + *

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 Binary files /dev/null and b/java/com/android/dialer/contactphoto/res/drawable-xxxhdpi/ic_block_black_48dp.png 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 @@ + + \ No newline at end of file -- cgit v1.2.3