Java Code Examples for android.database.Cursor#isBeforeFirst()

The following examples show how to use android.database.Cursor#isBeforeFirst() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageListItem.java    From zom-android-matrix with Apache License 2.0 6 votes vote down vote up
protected String convertMediaUriToPath(Uri uri) {
    String path = null;

    String [] proj={MediaStore.Images.Media.DATA};
    Cursor cursor = getContext().getContentResolver().query(uri, proj,  null, null, null);
    if (cursor != null && (!cursor.isClosed()))
    {
        if (cursor.isBeforeFirst())
        {
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            path = cursor.getString(column_index);
        }

        cursor.close();
    }

    return path;
}
 
Example 2
Source File: MessageListItem.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
protected String convertMediaUriToPath(Uri uri) {
    String path = null;

    String [] proj={MediaStore.Images.Media.DATA};
    Cursor cursor = getContext().getContentResolver().query(uri, proj,  null, null, null);
    if (cursor != null && (!cursor.isClosed()))
    {
        if (cursor.isBeforeFirst())
        {
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            path = cursor.getString(column_index);
        }

        cursor.close();
    }

    return path;
}
 
Example 3
Source File: HashActivity.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
public String getRealPathFromURI(Uri contentUri) {
 String[] proj = { MediaStore.Images.Media.DATA };
 
 //This method was deprecated in API level 11
 //Cursor cursor = managedQuery(contentUri, proj, null, null, null);
 
 CursorLoader cursorLoader = new CursorLoader(
           this, 
           contentUri, proj, null, null, null);        
 Cursor cursor = cursorLoader.loadInBackground();
 
 int column_index = 
   cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
 
 if (cursor.isBeforeFirst())
 {
  cursor.moveToFirst();
  return cursor.getString(column_index); 
 }
 else
  return null;
}
 
Example 4
Source File: CityManager.java    From sms-ticket with Apache License 2.0 5 votes vote down vote up
public City getCity(Cursor c) {
    if (c.isClosed() || c.isAfterLast() || c.isBeforeFirst()) {
        return null;
    }

    return new City(
        c.getLong(c.getColumnIndex(Cities._ID)),
        c.getString(c.getColumnIndex(Cities.COUNTRY)),
        c.getString(c.getColumnIndex(Cities.CITY)),
        c.getString(c.getColumnIndex(Cities.CITY_PUBTRAN)),
        c.getDouble(c.getColumnIndex(Cities.LAT)),
        c.getDouble(c.getColumnIndex(Cities.LON)),
        c.getInt(c.getColumnIndex(Cities.VALIDITY)),
        c.getString(c.getColumnIndex(Cities.NOTE)),
        c.getString(c.getColumnIndex(Cities.PRICE)),
        c.getString(c.getColumnIndex(Cities.CURRENCY)),
        c.getString(c.getColumnIndex(Cities.PRICE_NOTE)),
        c.getString(c.getColumnIndex(Cities.REQUEST)),
        c.getString(c.getColumnIndex(Cities.NUMBER)),
        new String[]{c.getString(c.getColumnIndex(Cities.ADDITIONAL_NUMBER_1))},
        c.getString(c.getColumnIndex(Cities.IDENTIFICATION)),
        c.getString(c.getColumnIndex(Cities.P_DATE_FROM)),
        c.getString(c.getColumnIndex(Cities.P_DATE_TO)),
        c.getString(c.getColumnIndex(Cities.P_HASH)),
        c.getString(c.getColumnIndex(Cities.DATE_FORMAT)),
        c.getString(c.getColumnIndex(Cities.CONFIRM_REQ)),
        c.getString(c.getColumnIndex(Cities.CONFIRM)));
}
 
Example 5
Source File: DatabaseHelper.java    From spidey with GNU General Public License v3.0 5 votes vote down vote up
/**
 * get single scan
 */
public Scan getScan(long scan_id) {
	SQLiteDatabase db = this.getReadableDatabase();

	String selectQuery = "SELECT  * FROM " + TABLE_SCANS + " WHERE "
			+ COLUMN_ID + " = " + scan_id;
	
	Cursor c = db.rawQuery(selectQuery, null);

	if (c != null && c.isBeforeFirst())
	{
		c.moveToFirst();

		Scan scan = new Scan();
		scan.setId(c.getInt(c.getColumnIndex(COLUMN_ID)));
		scan.setLocation(c.getString(c.getColumnIndex(COLUMN_LOCATION)));
		scan.setLatitude(c.getDouble(c.getColumnIndex(COLUMN_LATITUDE)));
		scan.setLongitude(c.getDouble(c.getColumnIndex(COLUMN_LONGITUDE)));
		scan.setCreatedAt(c.getString(c.getColumnIndex(COLUMN_CREATED_AT)));

		 List<CellInfo> cells = getAllCellsByScanId(scan.getId());
		 scan.setCellInfos(cells);
		
		return scan;
	}
	else
		return null;
}
 
Example 6
Source File: CursorHelper.java    From libcommon with Apache License 2.0 4 votes vote down vote up
/**
 * 指定したCursorの現在のレコードを文字列に変換
 * @param cursor
 */
public static String toString(@Nullable final Cursor cursor) {
	if (cursor == null) {
		return "{null}";
	} else if (cursor.isClosed()) {
		return "{closed}";
	} else if (cursor.isBeforeFirst()) {
		return "{before first}";
	} else if (cursor.isAfterLast()) {
		return "{after last}";
	} else {
		final StringBuilder sb = new StringBuilder();
		final int n = cursor.getColumnCount();
		final String[] columnNames = cursor.getColumnNames();
		sb.append("{");
		for (int i = 0; i < n; i++) {
			switch (cursor.getType(i)) {
			case Cursor.FIELD_TYPE_FLOAT:
				sb.append(columnNames[i]).append("=").append(cursor.getDouble(i));
				break;
			case Cursor.FIELD_TYPE_INTEGER:
				sb.append(columnNames[i]).append("=").append(cursor.getLong(i));
				break;
			case Cursor.FIELD_TYPE_STRING:
				sb.append(columnNames[i]).append("=").append(cursor.getString(i));
				break;
			case Cursor.FIELD_TYPE_BLOB:
				sb.append(columnNames[i]).append("=").append("BLOB");
				break;
			case Cursor.FIELD_TYPE_NULL:
				sb.append(columnNames[i]).append("=").append("NULL");
				break;
			default:
				sb.append(columnNames[i]).append("=").append("UNKNOWN");
				break;
			}
			if (i < n-1) {
				sb.append(",");
			}
		}
		sb.append("}");
		return sb.toString();
	}
}
 
Example 7
Source File: HumanReadables.java    From android-test with Apache License 2.0 4 votes vote down vote up
public static String describe(Cursor c) {
  if (c.isBeforeFirst()) {
    return "Cursor positioned before first element.";
  } else if (c.isAfterLast()) {
    return "Cursor positioned after last element.";
  }
  StringBuilder result = new StringBuilder("Row ").append(c.getPosition()).append(": {");
  String[] columns = c.getColumnNames();
  for (int i = 0; i < columns.length; i++) {
    result.append(columns[i]).append(":");
    int type = Cursor.FIELD_TYPE_STRING;
    if (Build.VERSION.SDK_INT > 10) {
      type = c.getType(i);
    }
    switch (type) {
      case Cursor.FIELD_TYPE_STRING:
        result.append("\"").append(c.getString(i)).append("\"");
        break;
      case Cursor.FIELD_TYPE_INTEGER:
        result.append(c.getLong(i));
        break;
      case Cursor.FIELD_TYPE_FLOAT:
        result.append(c.getDouble(i));
        result.append("f");
        break;
      case Cursor.FIELD_TYPE_NULL:
        result.append("null");
        break;
      case Cursor.FIELD_TYPE_BLOB:
        byte[] val = c.getBlob(i);
        result.append("[");
        for (int j = 0; j < 5 && j < val.length; j++) {
          result.append(val[j]);
          result.append(",");
        }
        if (5 < val.length) {
          result.append("... (").append(val.length - 5).append(" more elements)");
        }
        result.append("]");
        break;
      default:
        result.append("\"").append(c.getString(i)).append("\"");
        break;
    }
    result.append(", ");
  }
  result.append("}");
  return result.toString();
}