From 9e8b6733962641d137c4d084b843c069b6545953 Mon Sep 17 00:00:00 2001 From: linyuh Date: Tue, 6 Mar 2018 12:13:27 -0800 Subject: Covnert @AutoValue PhotoInfo into a proto. Bug: 74202944 Test: Existing tests PiperOrigin-RevId: 188060790 Change-Id: I4d79a353abf767935383d4149f261f5e96fd7acb --- .../dialer/glidephotomanager/PhotoInfo.java | 100 --------------------- .../impl/GlidePhotoManagerImpl.java | 30 ++++--- .../dialer/glidephotomanager/photo_info.proto | 44 +++++++++ 3 files changed, 60 insertions(+), 114 deletions(-) delete mode 100644 java/com/android/dialer/glidephotomanager/PhotoInfo.java create mode 100644 java/com/android/dialer/glidephotomanager/photo_info.proto (limited to 'java/com/android/dialer/glidephotomanager') diff --git a/java/com/android/dialer/glidephotomanager/PhotoInfo.java b/java/com/android/dialer/glidephotomanager/PhotoInfo.java deleted file mode 100644 index 016221f40..000000000 --- a/java/com/android/dialer/glidephotomanager/PhotoInfo.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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.glidephotomanager; - -import android.support.annotation.Nullable; -import com.google.auto.value.AutoValue; - -/** The number information used to create the photo.. */ -@AutoValue -public abstract class PhotoInfo { - - /** The display name of the number */ - @Nullable - public abstract String name(); - - /** The number displayed to the user. */ - @Nullable - public abstract String formattedNumber(); - - /** The URI to the photo */ - @Nullable - public abstract String photoUri(); - - /** Value of {@link android.provider.ContactsContract.CommonDataKinds.Photo#_ID} */ - public abstract long photoId(); - - /** The contacts provider lookup URI for the contact associated with the number */ - @Nullable - public abstract String lookupUri(); - - /** Should a business icon be displayed */ - public abstract boolean isBusiness(); - - /** Should a voicemail icon be displayed */ - public abstract boolean isVoicemail(); - - /** Should a blocked icon be displayed */ - public abstract boolean isBlocked(); - - /** Should a spam icon be displayed */ - public abstract boolean isSpam(); - - /** - * Should the photo be badged as video call. - * - *

Defaults to false. - */ - public abstract boolean isVideo(); - - /** Builder for {@link PhotoInfo} */ - @AutoValue.Builder - public abstract static class Builder { - - public abstract Builder setName(@Nullable String name); - - public abstract Builder setFormattedNumber(@Nullable String formattedNumber); - - public abstract Builder setPhotoUri(@Nullable String uri); - - public abstract Builder setPhotoId(long id); - - public abstract Builder setLookupUri(@Nullable String uri); - - public abstract Builder setIsBusiness(boolean isBusiness); - - public abstract Builder setIsVoicemail(boolean isVoicemail); - - public abstract Builder setIsBlocked(boolean isBlocked); - - public abstract Builder setIsSpam(boolean isSpam); - - public abstract Builder setIsVideo(boolean isVideo); - - public abstract PhotoInfo build(); - } - - public static PhotoInfo.Builder builder() { - return new AutoValue_PhotoInfo.Builder() - .setPhotoId(0) - .setIsBusiness(false) - .setIsVoicemail(false) - .setIsBlocked(false) - .setIsSpam(false) - .setIsVideo(false); - } -} diff --git a/java/com/android/dialer/glidephotomanager/impl/GlidePhotoManagerImpl.java b/java/com/android/dialer/glidephotomanager/impl/GlidePhotoManagerImpl.java index e14e604a1..45af4e3e2 100644 --- a/java/com/android/dialer/glidephotomanager/impl/GlidePhotoManagerImpl.java +++ b/java/com/android/dialer/glidephotomanager/impl/GlidePhotoManagerImpl.java @@ -49,7 +49,7 @@ public class GlidePhotoManagerImpl implements GlidePhotoManager { @Override public void loadQuickContactBadge(QuickContactBadge badge, PhotoInfo photoInfo) { Assert.isMainThread(); - badge.assignContactUri(parseUri(photoInfo.lookupUri())); + badge.assignContactUri(parseUri(photoInfo.getLookupUri())); badge.setOverlay(null); GlideRequest request = buildRequest(GlideApp.with(badge), photoInfo); request.into(badge); @@ -62,20 +62,20 @@ public class GlidePhotoManagerImpl implements GlidePhotoManager { GlideRequest request; boolean circleCrop = true; // Photos are cropped to a circle by default. - if (photoInfo.isBlocked()) { + if (photoInfo.getIsBlocked()) { // Whether the number is blocked takes precedence over the spam status. request = requestManager.load(R.drawable.ic_block_grey_48dp); - } else if (photoInfo.isSpam()) { + } else if (photoInfo.getIsSpam()) { request = requestManager.load(R.drawable.quantum_ic_report_vd_red_24); circleCrop = false; // The spam icon is an octagon so we don't crop it. - } else if (!TextUtils.isEmpty(photoInfo.photoUri())) { - request = requestManager.load(parseUri(photoInfo.photoUri())); + } else if (!TextUtils.isEmpty(photoInfo.getPhotoUri())) { + request = requestManager.load(parseUri(photoInfo.getPhotoUri())); - } else if (photoInfo.photoId() != 0) { + } else if (photoInfo.getPhotoId() != 0) { request = - requestManager.load(ContentUris.withAppendedId(Data.CONTENT_URI, photoInfo.photoId())); + requestManager.load(ContentUris.withAppendedId(Data.CONTENT_URI, photoInfo.getPhotoId())); } else { // load null to indicate fallback should be used. @@ -102,23 +102,25 @@ public class GlidePhotoManagerImpl implements GlidePhotoManager { LetterTileDrawable letterTileDrawable = new LetterTileDrawable(appContext.getResources()); String displayName; String identifier; - if (TextUtils.isEmpty(photoInfo.lookupUri())) { + if (TextUtils.isEmpty(photoInfo.getLookupUri())) { // Use generic avatar instead of letter for non-contacts. displayName = null; identifier = - TextUtils.isEmpty(photoInfo.name()) ? photoInfo.formattedNumber() : photoInfo.name(); + TextUtils.isEmpty(photoInfo.getName()) + ? photoInfo.getFormattedNumber() + : photoInfo.getName(); } else { - displayName = photoInfo.name(); - identifier = photoInfo.lookupUri(); + displayName = photoInfo.getName(); + identifier = photoInfo.getLookupUri(); } letterTileDrawable.setCanonicalDialerLetterTileDetails( displayName, identifier, LetterTileDrawable.SHAPE_CIRCLE, LetterTileDrawable.getContactTypeFromPrimitives( - photoInfo.isVoicemail(), - photoInfo.isSpam(), - photoInfo.isBusiness(), + photoInfo.getIsVoicemail(), + photoInfo.getIsSpam(), + photoInfo.getIsBusiness(), TelecomManager.PRESENTATION_ALLOWED, // TODO(twyen):implement false)); // TODO(twyen):implement return letterTileDrawable; diff --git a/java/com/android/dialer/glidephotomanager/photo_info.proto b/java/com/android/dialer/glidephotomanager/photo_info.proto new file mode 100644 index 000000000..447cfe83f --- /dev/null +++ b/java/com/android/dialer/glidephotomanager/photo_info.proto @@ -0,0 +1,44 @@ +syntax = "proto2"; + +option java_package = "com.android.dialer.glidephotomanager"; +option java_multiple_files = true; +option optimize_for = LITE_RUNTIME; + + +package com.android.dialer.glidephotomanager; + +// Contains information associated with a number, which is used to create the +// photo. +// Next ID: 11 +message PhotoInfo { + // The display name of the number. + optional string name = 1; + + // The number presented to the user. + optional string formatted_number = 2; + + // The URI of the photo. + optional string photo_uri = 3; + + // Value of android.provider.ContactsContract.CommonDataKinds.Photo#_ID + optional int64 photo_id = 4; + + // The Contacts Provider lookup URI for the contact associated with the + // number. + optional string lookup_uri = 5; + + // Whether a business icon should be displayed. + optional bool is_business = 6; + + // Whether a voicemail icon should be displayed. + optional bool is_voicemail = 7; + + // Whether a "blocked" icon should be displayed. + optional bool is_blocked = 8; + + // Whether a "spam" icon should be displayed. + optional bool is_spam = 9; + + // Whether the photo should be badged as video call. + optional bool is_video = 10; +} -- cgit v1.2.3