//    addContacts
  public void addContact(Contact contact) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, contact.getName());
    values.put(KEY_PH_NO, contact.getPhoneNumber());

    db.insert(TABLE_CONTACTS, null, values);
    db.close();
  }
  //    updateContact
  public int updateContact(Contact contact) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_ID, contact.getID());
    values.put(KEY_NAME, contact.getName());
    values.put(KEY_PH_NO, contact.getPhoneNumber());

    return db.update(
        TABLE_CONTACTS, values, KEY_ID + "=?", new String[] {String.valueOf(contact.getID())});
  }
  //    getAllContacts
  public List<Contact> getAllContacts() {

    List<Contact> contactList = new ArrayList<Contact>();
    String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) {
      do {
        Contact contact = new Contact();
        contact.setID(Integer.parseInt(cursor.getString(0)));
        contact.setName(cursor.getString(1));
        contact.setPhoneNumber(cursor.getString(2));
        contactList.add(contact);
      } while (cursor.moveToNext());
    }
    return contactList;
  }
 //    deleteContact
 public void deleteContact(Contact contact) {
   SQLiteDatabase db = this.getWritableDatabase();
   db.delete(TABLE_CONTACTS, KEY_ID + "=?", new String[] {String.valueOf(contact.getID())});
   db.close();
 }