List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:Main.java
public static void keep_setLong(Field field, Object obj, Cursor cursor, int i) { try {//from w w w . j a v a2 s. c o m if (field.getType().equals(Long.TYPE)) field.setLong(obj, cursor.getLong(i)); else field.set(obj, Long.valueOf(cursor.getLong(i))); } catch (Exception exception) { exception.printStackTrace(); } }
From source file:Main.java
private static long getLong(final Cursor cursor, final String field, final long defValue) { if (cursor.getColumnIndex(field) >= 0) { return cursor.getLong(cursor.getColumnIndex(field)); } else {//from w w w . j a v a 2 s. c o m return defValue; } }
From source file:Main.java
public static Long gLong(Cursor cursor, String columeName) { Long val = null; if (cursor.getColumnIndex(columeName) != -1) { val = cursor.getLong(cursor.getColumnIndex(columeName)); }/* w w w . j av a 2 s . com*/ return val; }
From source file:Main.java
private static Long readLong(Cursor cursor, int index, Long defaultValue) { Long result = defaultValue;//from ww w. j av a 2s . c o m if (!cursor.isNull(index)) { result = cursor.getLong(index); } return result; }
From source file:br.com.bea.androidtools.api.model.EntityUtils.java
public static final Object convert(final Field field, final Cursor cursor) throws Exception { if (field.getType().equals(Long.class)) return cursor.getLong(cursor.getColumnIndex(field.getAnnotation(Column.class).name())); if (field.getType().equals(Integer.class)) return cursor.getInt(cursor.getColumnIndex(field.getAnnotation(Column.class).name())); if (field.getType().equals(Date.class)) return DATE_FORMAT .parse(cursor.getString(cursor.getColumnIndex(field.getAnnotation(Column.class).name()))); return cursor.getString(cursor.getColumnIndex(field.getAnnotation(Column.class).name())); }
From source file:Main.java
public static long[] readIds(Cursor cursor) { long[] arr = new long[cursor.getCount()]; int count = 0; try {/*from w ww . j a v a2 s . c o m*/ while (cursor.moveToNext()) { arr[count++] = cursor.getLong(0); } } finally { cursor.close(); } return arr; }
From source file:Main.java
/** * method used to lookup the id of a contact photo id * * @param context//from w w w .j a va 2s . c o m * a context object used to get a content resolver * @param phoneNumber * the phone number of the contact * * @return the id of the contact */ public static long lookupPhotoId(Context context, String phoneNumber) { long mPhotoId = -1; Uri mLookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); String[] mProjection = new String[2]; mProjection[0] = PhoneLookup._ID; mProjection[1] = PhoneLookup.PHOTO_ID; Cursor mCursor = context.getContentResolver().query(mLookupUri, mProjection, null, null, null); if (mCursor.getCount() > 0) { mCursor.moveToFirst(); mPhotoId = mCursor.getLong(mCursor.getColumnIndex(PhoneLookup._ID)); mCursor.close(); } return mPhotoId; }
From source file:de.stadtrallye.rallyesoft.util.converters.CursorConverters.java
public static ChatEntry getChatEntry(Cursor cursor, ChatCursorIds c) { return new ChatEntry(cursor.getInt(c.id), cursor.getString(c.message), cursor.getLong(c.timestamp), cursor.getInt(c.groupID), cursor.getString(c.groupName), cursor.getInt(c.userID), cursor.getString(c.userName), cursor.getString(c.pictureHash)); }
From source file:Main.java
public static void addToCalendar(Activity context, Long beginTime, String title) { ContentResolver cr = context.getContentResolver(); Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon(); Long time = new Date(beginTime).getTime(); ContentUris.appendId(builder, time - 10 * 60 * 1000); ContentUris.appendId(builder, time + 10 * 60 * 1000); String[] projection = new String[] { "title", "begin" }; Cursor cursor = cr.query(builder.build(), projection, null, null, null); boolean exists = false; if (cursor != null) { while (cursor.moveToNext()) { if ((time == cursor.getLong(1)) && title.equals(cursor.getString(0))) { exists = true;// w w w .ja v a2 s . c o m } } } if (!exists) { Intent intent = new Intent(Intent.ACTION_EDIT); intent.setType("vnd.android.cursor.item/event"); intent.putExtra("beginTime", time); intent.putExtra("allDay", false); intent.putExtra("endTime", time + 60 * 60 * 1000); intent.putExtra("title", title); context.startActivity(intent); } else { Toast.makeText(context, "Event already exist!", Toast.LENGTH_LONG).show(); } }
From source file:net.sf.sprockets.database.Cursors.java
/** * Get the long value in the first row and column. * * @param close true to close the cursor or false to leave it open * @return {@link Long#MIN_VALUE} if the cursor is empty *//* w w w . j a v a2s . co m*/ public static long firstLong(Cursor cursor, boolean close) { long l = cursor.moveToFirst() ? cursor.getLong(0) : Long.MIN_VALUE; close(cursor, close); return l; }