1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.dialer.calllog; 18 19import android.net.Uri; 20import android.text.TextUtils; 21 22import com.android.contacts.common.util.UriUtils; 23import com.google.common.base.Objects; 24 25/** 26 * Information for a contact as needed by the Call Log. 27 */ 28public class ContactInfo { 29 public Uri lookupUri; 30 public String name; 31 public int type; 32 public String label; 33 public String number; 34 public String formattedNumber; 35 public String normalizedNumber; 36 /** The photo for the contact, if available. */ 37 public long photoId; 38 /** The high-res photo for the contact, if available. */ 39 public Uri photoUri; 40 41 public static ContactInfo EMPTY = new ContactInfo(); 42 43 public static String GEOCODE_AS_LABEL = ""; 44 45 public int sourceType = 0; 46 47 @Override 48 public int hashCode() { 49 // Uses only name and contactUri to determine hashcode. 50 // This should be sufficient to have a reasonable distribution of hash codes. 51 // Moreover, there should be no two people with the same lookupUri. 52 final int prime = 31; 53 int result = 1; 54 result = prime * result + ((lookupUri == null) ? 0 : lookupUri.hashCode()); 55 result = prime * result + ((name == null) ? 0 : name.hashCode()); 56 return result; 57 } 58 59 @Override 60 public boolean equals(Object obj) { 61 if (this == obj) return true; 62 if (obj == null) return false; 63 if (getClass() != obj.getClass()) return false; 64 ContactInfo other = (ContactInfo) obj; 65 if (!UriUtils.areEqual(lookupUri, other.lookupUri)) return false; 66 if (!TextUtils.equals(name, other.name)) return false; 67 if (type != other.type) return false; 68 if (!TextUtils.equals(label, other.label)) return false; 69 if (!TextUtils.equals(number, other.number)) return false; 70 if (!TextUtils.equals(formattedNumber, other.formattedNumber)) return false; 71 if (!TextUtils.equals(normalizedNumber, other.normalizedNumber)) return false; 72 if (photoId != other.photoId) return false; 73 if (!UriUtils.areEqual(photoUri, other.photoUri)) return false; 74 return true; 75 } 76 77 @Override 78 public String toString() { 79 return Objects.toStringHelper(this).add("lookupUri", lookupUri).add("name", name).add( 80 "type", type).add("label", label).add("number", number).add("formattedNumber", 81 formattedNumber).add("normalizedNumber", normalizedNumber).add("photoId", photoId) 82 .add("photoUri", photoUri).toString(); 83 } 84} 85