1 18 19 package sync4j.syncclient.blackberry.listener; 20 21 import javax.microedition.pim.Contact; 22 import javax.microedition.pim.Event; 23 import javax.microedition.pim.PIMItem; 24 import net.rim.blackberry.api.pdap.PIMListListener; 25 26 import sync4j.syncclient.sps.ContactDataStore; 27 28 37 public class Sync4jContactListener implements PIMListListener{ 38 39 private ContactDataStore contactDataStore ; 41 42 49 public Sync4jContactListener() { 50 this.contactDataStore = new ContactDataStore(); 51 } 52 53 58 public void itemAdded(PIMItem item) { 59 storeRecord(item, ContactDataStore.RECORD_STATE_NEW); 60 } 61 62 68 public void itemUpdated(PIMItem oldItem, PIMItem newItem) { 69 storeRecord(newItem, ContactDataStore.RECORD_STATE_UPDATED); 70 } 71 72 77 public void itemRemoved(PIMItem item) { 78 storeRecord(item, ContactDataStore.RECORD_STATE_DELETED); 79 } 80 81 89 private void storeRecord(PIMItem item, char state) { 90 Contact contact = (Contact) item; 91 String uid = contact.getString(Contact.UID, 0); 92 93 try{ 94 95 contactDataStore.addRecord(uid,state, contact); 96 97 } catch(Exception e){ 98 e.printStackTrace(); 99 } 100 101 } 102 } 103 | Popular Tags |