• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.dialer.calllog;
18 
19 import android.net.Uri;
20 import android.text.TextUtils;
21 
22 import com.android.contacts.common.ContactsUtils.UserType;
23 import com.android.contacts.common.util.UriUtils;
24 import com.google.common.base.Objects;
25 
26 /**
27  * Information for a contact as needed by the Call Log.
28  */
29 public class ContactInfo {
30     public Uri lookupUri;
31 
32     /**
33      * Contact lookup key.  Note this may be a lookup key for a corp contact, in which case
34      * "lookup by lookup key" doesn't work on the personal profile.
35      */
36     public String lookupKey;
37     public String name;
38     public String nameAlternative;
39     public int type;
40     public String label;
41     public String number;
42     public String formattedNumber;
43     /*
44      * ContactInfo.normalizedNumber is a column value returned by PhoneLookup query. By definition,
45      * it's E164 representation.
46      * http://developer.android.com/reference/android/provider/ContactsContract.PhoneLookupColumns.
47      * html#NORMALIZED_NUMBER.
48      *
49      * The fallback value, when PhoneLookup fails or else, should be either null or
50      * PhoneNumberUtils.formatNumberToE164.
51      */
52     public String normalizedNumber;
53     /** The photo for the contact, if available. */
54     public long photoId;
55     /** The high-res photo for the contact, if available. */
56     public Uri photoUri;
57     public boolean isBadData;
58     public String objectId;
59     public @UserType long userType;
60 
61     public static ContactInfo EMPTY = new ContactInfo();
62 
63     public int sourceType = 0;
64 
65     @Override
hashCode()66     public int hashCode() {
67         // Uses only name and contactUri to determine hashcode.
68         // This should be sufficient to have a reasonable distribution of hash codes.
69         // Moreover, there should be no two people with the same lookupUri.
70         final int prime = 31;
71         int result = 1;
72         result = prime * result + ((lookupUri == null) ? 0 : lookupUri.hashCode());
73         result = prime * result + ((name == null) ? 0 : name.hashCode());
74         return result;
75     }
76 
77     @Override
equals(Object obj)78     public boolean equals(Object obj) {
79         if (this == obj) return true;
80         if (obj == null) return false;
81         if (getClass() != obj.getClass()) return false;
82         ContactInfo other = (ContactInfo) obj;
83         if (!UriUtils.areEqual(lookupUri, other.lookupUri)) return false;
84         if (!TextUtils.equals(name, other.name)) return false;
85         if (!TextUtils.equals(nameAlternative, other.nameAlternative)) return false;
86         if (type != other.type) return false;
87         if (!TextUtils.equals(label, other.label)) return false;
88         if (!TextUtils.equals(number, other.number)) return false;
89         if (!TextUtils.equals(formattedNumber, other.formattedNumber)) return false;
90         if (!TextUtils.equals(normalizedNumber, other.normalizedNumber)) return false;
91         if (photoId != other.photoId) return false;
92         if (!UriUtils.areEqual(photoUri, other.photoUri)) return false;
93         if (!TextUtils.equals(objectId, other.objectId)) return false;
94         if (userType != other.userType) return false;
95         return true;
96     }
97 
98     @Override
toString()99     public String toString() {
100         return Objects.toStringHelper(this).add("lookupUri", lookupUri).add("name", name)
101                 .add("nameAlternative", nameAlternative)
102                 .add("type", type).add("label", label)
103                 .add("number", number).add("formattedNumber",formattedNumber)
104                 .add("normalizedNumber", normalizedNumber).add("photoId", photoId)
105                 .add("photoUri", photoUri).add("objectId", objectId)
106                 .add("userType",userType).toString();
107     }
108 }
109