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;
23e6933be00d2ecc266612a374a62e05352937408eChiao Chengimport com.google.common.base.Objects;
2494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng
2594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng/**
2694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Information for a contact as needed by the Call Log.
2794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */
28173ec96476278f0d6aa147d31a60aa3e419e5ca3Jay Shraunerpublic class ContactInfo {
2994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public Uri lookupUri;
307c414093c8c66a69cfea77a0ac10c1354f96cb7cMakoto Onuki
317c414093c8c66a69cfea77a0ac10c1354f96cb7cMakoto Onuki    /**
327c414093c8c66a69cfea77a0ac10c1354f96cb7cMakoto Onuki     * Contact lookup key.  Note this may be a lookup key for a corp contact, in which case
337c414093c8c66a69cfea77a0ac10c1354f96cb7cMakoto Onuki     * "lookup by lookup key" doesn't work on the personal profile.
347c414093c8c66a69cfea77a0ac10c1354f96cb7cMakoto Onuki     */
3556cb0efa5eda1670077e66fc0e8c79478d0c1c67Yorke Lee    public String lookupKey;
3694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public String name;
3794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public int type;
3894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public String label;
3994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public String number;
4094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public String formattedNumber;
4194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public String normalizedNumber;
4294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    /** The photo for the contact, if available. */
4394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public long photoId;
4494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    /** The high-res photo for the contact, if available. */
4594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public Uri photoUri;
46b77bf5df2b866dd40e330b7c2dedee4a1d51fc78Sai Cheemalapati    public boolean isBadData;
4755733814f213809baaa8eaa8984ff026bdb08b4eAnthony Lee    public String objectId;
4894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng
4994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public static ContactInfo EMPTY = new ContactInfo();
5094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng
519fd02a6742c8e9139a03d80bacca360238be11bfChiao Cheng    public int sourceType = 0;
529fd02a6742c8e9139a03d80bacca360238be11bfChiao Cheng
5394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    @Override
5494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public int hashCode() {
5594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        // Uses only name and contactUri to determine hashcode.
5694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        // This should be sufficient to have a reasonable distribution of hash codes.
5794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        // Moreover, there should be no two people with the same lookupUri.
5894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        final int prime = 31;
5994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        int result = 1;
6094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        result = prime * result + ((lookupUri == null) ? 0 : lookupUri.hashCode());
6194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        result = prime * result + ((name == null) ? 0 : name.hashCode());
6294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        return result;
6394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    }
6494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng
6594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    @Override
6694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    public boolean equals(Object obj) {
6794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (this == obj) return true;
6894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (obj == null) return false;
6994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (getClass() != obj.getClass()) return false;
7094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        ContactInfo other = (ContactInfo) obj;
7194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!UriUtils.areEqual(lookupUri, other.lookupUri)) return false;
7294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!TextUtils.equals(name, other.name)) return false;
7394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (type != other.type) return false;
7494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!TextUtils.equals(label, other.label)) return false;
7594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!TextUtils.equals(number, other.number)) return false;
7694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!TextUtils.equals(formattedNumber, other.formattedNumber)) return false;
7794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!TextUtils.equals(normalizedNumber, other.normalizedNumber)) return false;
7894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (photoId != other.photoId) return false;
7994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        if (!UriUtils.areEqual(photoUri, other.photoUri)) return false;
8055733814f213809baaa8eaa8984ff026bdb08b4eAnthony Lee        if (!TextUtils.equals(objectId, other.objectId)) return false;
8194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng        return true;
8294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng    }
83e6933be00d2ecc266612a374a62e05352937408eChiao Cheng
84e6933be00d2ecc266612a374a62e05352937408eChiao Cheng    @Override
85e6933be00d2ecc266612a374a62e05352937408eChiao Cheng    public String toString() {
86e6933be00d2ecc266612a374a62e05352937408eChiao Cheng        return Objects.toStringHelper(this).add("lookupUri", lookupUri).add("name", name).add(
87e6933be00d2ecc266612a374a62e05352937408eChiao Cheng                "type", type).add("label", label).add("number", number).add("formattedNumber",
88e6933be00d2ecc266612a374a62e05352937408eChiao Cheng                formattedNumber).add("normalizedNumber", normalizedNumber).add("photoId", photoId)
8955733814f213809baaa8eaa8984ff026bdb08b4eAnthony Lee                .add("photoUri", photoUri).add("objectId", objectId).toString();
90e6933be00d2ecc266612a374a62e05352937408eChiao Cheng    }
9194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng}
92