1 /* 2 * Copyright (C) 2007 Esmertec AG. 3 * Copyright (C) 2007 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.im.engine; 19 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 public class Contact extends ImEntity implements Parcelable{ 24 private Address mAddress; 25 private String mName; 26 private Presence mPresence; 27 Contact(Address address, String name)28 public Contact(Address address, String name) { 29 mAddress = address; 30 mName = name; 31 32 mPresence = new Presence(); 33 } 34 Contact(Parcel source)35 public Contact(Parcel source) { 36 mAddress = AddressParcelHelper.readFromParcel(source); 37 mName = source.readString(); 38 mPresence = new Presence(source); 39 } 40 getAddress()41 public Address getAddress() { 42 return mAddress; 43 } 44 getName()45 public String getName() { 46 return mName; 47 } 48 getPresence()49 public Presence getPresence() { 50 return mPresence; 51 } 52 equals(Object other)53 public boolean equals(Object other) { 54 return other instanceof Contact 55 && mAddress.equals(((Contact)other).mAddress); 56 } 57 hashCode()58 public int hashCode() { 59 return mAddress.hashCode(); 60 } 61 62 /** 63 * Set the presence of the Contact. Note that this method is public 64 * but not provide to the user. 65 * @param presence the new presence 66 */ setPresence(Presence presence)67 public void setPresence(Presence presence) { 68 mPresence = presence; 69 } 70 writeToParcel(Parcel dest, int flags)71 public void writeToParcel(Parcel dest, int flags) { 72 AddressParcelHelper.writeToParcel(dest, mAddress); 73 dest.writeString(mName); 74 mPresence.writeToParcel(dest, 0); 75 } 76 describeContents()77 public int describeContents() { 78 return 0; 79 } 80 81 public final static Parcelable.Creator<Contact> CREATOR = new Parcelable.Creator<Contact>() { 82 public Contact createFromParcel(Parcel source) { 83 return new Contact(source); 84 } 85 86 public Contact[] newArray(int size) { 87 return new Contact[size]; 88 } 89 }; 90 } 91