ContactInfo.java revision 034a2b329e469bf6888fbbcf91992f974015c2a8
194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng/*
294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Copyright (C) 2011 The Android Open Source Project
394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng *
494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Licensed under the Apache License, Version 2.0 (the "License");
594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * you may not use this file except in compliance with the License.
694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * You may obtain a copy of the License at
794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng *
894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng *      http://www.apache.org/licenses/LICENSE-2.0
994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng *
1094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Unless required by applicable law or agreed to in writing, software
1194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * distributed under the License is distributed on an "AS IS" BASIS,
1294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * See the License for the specific language governing permissions and
1494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * limitations under the License.
1594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */
1694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng
1794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengpackage com.android.dialer.calllog;
1894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng
1994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.net.Uri;
2094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.text.TextUtils;
2194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng
2235071c06d1587942f5a66c8f12e6247e8f904d26Chiao Chengimport com.android.contacts.common.util.UriUtils;
2394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng
2494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng/**
2594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Information for a contact as needed by the Call Log.
2694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */
2794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengpublic final class ContactInfo {
2894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public Uri lookupUri;
2994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public String name;
3094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public int type;
3194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public String label;
3294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public String number;
3394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public String formattedNumber;
3494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public String normalizedNumber;
3594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    /** The photo for the contact, if available. */
3694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public long photoId;
3794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    /** The high-res photo for the contact, if available. */
3894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public Uri photoUri;
3994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng
4094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public static ContactInfo EMPTY = new ContactInfo();
4194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng
42034a2b329e469bf6888fbbcf91992f974015c2a8Yorke Lee    public static String GEOCODE_AS_LABEL = "";
43034a2b329e469bf6888fbbcf91992f974015c2a8Yorke Lee
4494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    @Override
4594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public int hashCode() {
4694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        // Uses only name and contactUri to determine hashcode.
4794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        // This should be sufficient to have a reasonable distribution of hash codes.
4894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        // Moreover, there should be no two people with the same lookupUri.
4994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        final int prime = 31;
5094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        int result = 1;
5194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        result = prime * result + ((lookupUri == null) ? 0 : lookupUri.hashCode());
5294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        result = prime * result + ((name == null) ? 0 : name.hashCode());
5394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        return result;
5494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    }
5594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng
5694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    @Override
5794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public boolean equals(Object obj) {
5894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (this == obj) return true;
5994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (obj == null) return false;
6094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (getClass() != obj.getClass()) return false;
6194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        ContactInfo other = (ContactInfo) obj;
6294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!UriUtils.areEqual(lookupUri, other.lookupUri)) return false;
6394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!TextUtils.equals(name, other.name)) return false;
6494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (type != other.type) return false;
6594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!TextUtils.equals(label, other.label)) return false;
6694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!TextUtils.equals(number, other.number)) return false;
6794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!TextUtils.equals(formattedNumber, other.formattedNumber)) return false;
6894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!TextUtils.equals(normalizedNumber, other.normalizedNumber)) return false;
6994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (photoId != other.photoId) return false;
7094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!UriUtils.areEqual(photoUri, other.photoUri)) return false;
7194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        return true;
7294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    }
7394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng}
74