public ArrayList<User> getAllContacts() {
   SQLiteDatabase db = mDbHelper.getReadableDatabase();
   ArrayList<User> contactList = new ArrayList<User>();
   String selectQuery = "SELECT " + ThreadHelper.DB_NAME + " FROM " + ThreadHelper.DB_TABLE;
   try {
     Cursor cursor = db.rawQuery(selectQuery, null);
     if (cursor.moveToPosition(1)) { // set 1 cause 0 is myself
       do {
         contactList.add(new User(cursor.getString(0)));
       } while (cursor.moveToNext());
     }
   } catch (NullPointerException e) {
     // No entry found
   }
   return contactList;
 }
 public String getContactName(int id) {
   SQLiteDatabase db = mDbHelper.getReadableDatabase();
   Cursor cursor =
       db.query(
           ThreadHelper.DB_TABLE,
           new String[] {ThreadHelper.DB_NAME},
           ThreadHelper.DB_ID + "=?",
           new String[] {String.valueOf(id)},
           null,
           null,
           null,
           null);
   if (cursor != null) cursor.moveToFirst();
   try {
     return cursor.getString(0);
   } catch (CursorIndexOutOfBoundsException e) {
     Log.e(TAG, e.getMessage());
   }
   return null;
 }
 public String getContactPassword() {
   SQLiteDatabase db = mDbHelper.getReadableDatabase();
   Cursor cursor =
       db.query(
           ThreadHelper.DB_TABLE,
           new String[] {ThreadHelper.DB_PASSWORD},
           ThreadHelper.DB_ID + "=?",
           new String[] {"0"},
           null,
           null,
           null,
           null);
   if (cursor != null) cursor.moveToFirst();
   try {
     return cursor.getString(0);
   } catch (CursorIndexOutOfBoundsException e) {
     Log.e(TAG, e.getMessage());
   }
   return null;
 }
 public String getPrivateKey(int id) {
   String result = null;
   SQLiteDatabase db = mDbHelper.getReadableDatabase();
   Cursor cursor =
       db.query(
           ThreadHelper.DB_TABLE,
           new String[] {ThreadHelper.DB_PRIVATE},
           ThreadHelper.DB_ID + "=?",
           new String[] {String.valueOf(id)},
           null,
           null,
           null,
           null);
   try {
     if (cursor != null) cursor.moveToFirst();
     result = cursor.getString(0);
   } catch (CursorIndexOutOfBoundsException e) {
     Log.e(TAG, e.getMessage());
   }
   return result;
 }
 public String getPublicKey(String name) {
   String result = null;
   SQLiteDatabase db = mDbHelper.getReadableDatabase();
   Cursor cursor =
       db.query(
           ThreadHelper.DB_TABLE,
           new String[] {ThreadHelper.DB_PUBLIC},
           ThreadHelper.DB_NAME + "=?",
           new String[] {name},
           null,
           null,
           null,
           null);
   try {
     if (cursor != null) cursor.moveToFirst();
     result = cursor.getString(0);
   } catch (CursorIndexOutOfBoundsException e) {
     Log.e(TAG, e.getMessage());
   }
   return result;
 }
 public boolean isset(String name) {
   SQLiteDatabase db = mDbHelper.getReadableDatabase();
   try {
     Cursor cursor =
         db.query(
             ThreadHelper.DB_TABLE,
             new String[] {ThreadHelper.DB_NAME},
             ThreadHelper.DB_NAME + "=?",
             new String[] {name},
             null,
             null,
             null,
             null);
     if (cursor != null) cursor.moveToFirst();
     cursor.getString(0);
     return true;
   } catch (CursorIndexOutOfBoundsException e) {
     Log.e(TAG, e.getMessage());
   }
   return false;
 }