Java Code Examples for android.database.Cursor.getLong()

The following are Jave code examples for showing how to use getLong() of the android.database.Cursor class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: CSipSimple   File: ContactsUtils5.java   Source Code and License Vote up 6 votes
@Override
public ContactInfo getContactInfo(Context context, Cursor cursor) {
    ContactInfo ci = new ContactInfo();
    // Get values
    ci.displayName = cursor.getString(cursor.getColumnIndex(Contacts.DISPLAY_NAME));
    ci.contactId = cursor.getLong(cursor.getColumnIndex(Contacts._ID));
    ci.callerInfo.contactContentUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, ci.contactId);
    ci.callerInfo.photoId = cursor.getLong(cursor.getColumnIndex(Contacts.PHOTO_ID));
    int photoUriColIndex = cursor.getColumnIndex(Contacts.PHOTO_ID);
    ci.status = cursor.getString(cursor.getColumnIndex(Contacts.CONTACT_STATUS));
    ci.presence = cursor.getInt(cursor.getColumnIndex(Contacts.CONTACT_PRESENCE));

    if (photoUriColIndex >= 0) {
        String photoUri = cursor.getString(photoUriColIndex);
        if (!TextUtils.isEmpty(photoUri)) {
            ci.callerInfo.photoUri = Uri.parse(photoUri);
        }
    }
    ci.hasPresence = !TextUtils.isEmpty(ci.status);
    return ci;
}
 
Example 2
Project: RetroMusicPlayer   File: PlaylistSongsLoader.java   Source Code and License Vote up 6 votes
@NonNull
private static PlaylistSong getPlaylistSongFromCursorImpl(@NonNull Cursor cursor, int playlistId) {
    final int id = cursor.getInt(0);
    final String title = cursor.getString(1);
    final int trackNumber = cursor.getInt(2);
    final int year = cursor.getInt(3);
    final long duration = cursor.getLong(4);
    final String data = cursor.getString(5);
    final int dateModified = cursor.getInt(6);
    final int albumId = cursor.getInt(7);
    final String albumName = cursor.getString(8);
    final int artistId = cursor.getInt(9);
    final String artistName = cursor.getString(10);
    final int idInPlaylist = cursor.getInt(11);

    return new PlaylistSong(id, title, trackNumber, year, duration, data, dateModified, albumId, albumName, artistId, artistName, playlistId, idInPlaylist);
}
 
Example 3
Project: Cable-Android   File: ThreadDatabase.java   Source Code and License Vote up 6 votes
public long getThreadIdIfExistsFor(Recipients recipients) {
  long[] recipientIds    = getRecipientIds(recipients);
  String recipientsList  = getRecipientsAsString(recipientIds);
  SQLiteDatabase db      = databaseHelper.getReadableDatabase();
  String where           = RECIPIENT_IDS + " = ?";
  String[] recipientsArg = new String[] {recipientsList};
  Cursor cursor          = null;

  try {
    cursor = db.query(TABLE_NAME, new String[]{ID}, where, recipientsArg, null, null, null);

    if (cursor != null && cursor.moveToFirst())
      return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
    else
      return -1L;
  } finally {
    if (cursor != null)
      cursor.close();
  }
}
 
Example 4
Project: Quran   File: BookmarksDBAdapter.java   Source Code and License Vote up 6 votes
public long getBookmarkId(Integer sura, Integer ayah, int page) {
  Cursor cursor = null;
  try {
    cursor = mDb.query(BookmarksTable.TABLE_NAME,
        null, BookmarksTable.PAGE + "=" + page + " AND " +
            BookmarksTable.SURA + (sura == null ? " IS NULL" : "=" + sura) +
            " AND " + BookmarksTable.AYAH +
            (ayah == null ? " IS NULL" : "=" + ayah), null, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {
      return cursor.getLong(0);
    }
  } catch (Exception e) {
    // swallow the error for now
  } finally {
    DatabaseUtils.closeCursor(cursor);
  }
  return -1;
}
 
Example 5
Project: PeSanKita-android   File: SmsMigrator.java   Source Code and License Vote up 5 votes
private static boolean isAppropriateTypeForMigration(Cursor cursor, int columnIndex) {
  long systemType = cursor.getLong(columnIndex);
  long ourType    = SmsDatabase.Types.translateFromSystemBaseType(systemType);

  return ourType == MmsSmsColumns.Types.BASE_INBOX_TYPE ||
         ourType == MmsSmsColumns.Types.BASE_SENT_TYPE ||
         ourType == MmsSmsColumns.Types.BASE_SENT_FAILED_TYPE;
}
 
Example 6
Project: Cable-Android   File: ThreadDatabase.java   Source Code and License Vote up 5 votes
public long getLastSeen(long threadId) {
  SQLiteDatabase db     = databaseHelper.getReadableDatabase();
  Cursor         cursor = db.query(TABLE_NAME, new String[]{LAST_SEEN}, ID_WHERE, new String[]{String.valueOf(threadId)}, null, null, null);

  try {
    if (cursor != null && cursor.moveToFirst()) {
      return cursor.getLong(0);
    }

    return -1;
  } finally {
    if (cursor != null) cursor.close();
  }

}
 
Example 7
Project: uchimznaem-helper   File: RoomsListFragment.java   Source Code and License Vote up 5 votes
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    activity = (MainActivity) getActivity();

    //rooms(id, name, type)
    //room_types(id, type_name)
    Cursor c = activity.mDb.rawQuery("SELECT r.id, r.name, rt.type_name FROM rooms r INNER JOIN room_types rt ON r.type=rt.id", new String[]{});
    c.moveToFirst();
    int idIdx = c.getColumnIndex("id");
    int nameIdx = c.getColumnIndex("name");
    int typeIdx = c.getColumnIndex("type_name");
    rooms = new ArrayList<>();
    roomTypes = new ArrayList<>();
    roomNames = new ArrayList<>();

    while (c.moveToNext()) {
        long id = c.getLong(idIdx);
        String name = c.getString(nameIdx);
        roomNames.add(name);
        String type = c.getString(typeIdx);
        roomTypes.add(type);
        rooms.add(name + " (" + type + ")");
    }

    ListAdapter adapter = new ArrayAdapter<>(getActivity(),
            R.layout.rooms_layout_item_1, rooms.toArray());
    setListAdapter(adapter);
}
 
Example 8
Project: NoticeDog   File: DBMigrator.java   Source Code and License Vote up 5 votes
private static void insertMessageFromEntry(InboxManager inboxManager, Cursor entryCursor) {
    int id = entryCursor.getInt(entryCursor.getColumnIndex("_id"));
    int threadId = entryCursor.getInt(entryCursor.getColumnIndex(DBMigratorSQLiteHelper.INBOX_ENTRIES_COLUMN_THREAD_ID));
    String appId = entryCursor.getString(entryCursor.getColumnIndex("_app_id"));
    String senderId = entryCursor.getString(entryCursor.getColumnIndex("_sender_id"));
    String from = entryCursor.getString(entryCursor.getColumnIndex("_from"));
    String message = entryCursor.getString(entryCursor.getColumnIndex(DBMigratorSQLiteHelper.INBOX_ENTRIES_COLUMN_MESSAGE));
    long timestamp = entryCursor.getLong(entryCursor.getColumnIndex("_timestamp"));
    int state = entryCursor.getInt(entryCursor.getColumnIndex("_state"));
    String extra = entryCursor.getString(entryCursor.getColumnIndex("_extra"));
    RawMessage rawMessage = new RawMessage(appId, senderId, from, message, timestamp, null, null, null);
    rawMessage.setState(1);
    inboxManager.injectMessage(rawMessage);
}
 
Example 9
Project: simple-share-android   File: MediaDocumentsProvider.java   Source Code and License Vote up 5 votes
private void includeAlbum(MatrixCursor result, Cursor cursor) {
    final long id = cursor.getLong(AlbumQuery._ID);
    final String docId = getDocIdForIdent(TYPE_ALBUM, id);

    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, docId);
    row.add(Document.COLUMN_DISPLAY_NAME,
            cleanUpMediaDisplayName(cursor.getString(AlbumQuery.ALBUM)));
    row.add(Document.COLUMN_MIME_TYPE, Document.MIME_TYPE_DIR);
    row.add(Document.COLUMN_FLAGS, Document.FLAG_DIR_PREFERS_GRID
            | Document.FLAG_SUPPORTS_THUMBNAIL | Document.FLAG_DIR_PREFERS_LAST_MODIFIED | Document.FLAG_SUPPORTS_DELETE);
}
 
Example 10
Project: Android-Wear-Projects   File: MemoriesDataSource.java   Source Code and License Vote up 5 votes
private Memory cursorToMemory(Cursor cursor){
    Memory memory = new Memory();
    memory.id = cursor.getLong(0);
    memory.city = cursor.getString(1);
    memory.country = cursor.getString(2);
    memory.latitude = cursor.getDouble(3);
    memory.longitude = cursor.getDouble(4);
    memory.notes = cursor.getString(5);
    return memory;
}
 
Example 11
Project: KUtils-master   File: UserDao.java   Source Code and License Vote up 5 votes
@Override
public User readEntity(Cursor cursor, int offset) {
    User entity = new User( //
        cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
        cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
        cursor.getInt(offset + 2) // age
    );
    return entity;
}
 
Example 12
Project: simple-share-android   File: StorageProvider.java   Source Code and License Vote up 5 votes
protected long getAlbumForPathCleared(String path) throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    Cursor cursor = null;
    try {
        cursor = resolver.query(Audio.Media.EXTERNAL_CONTENT_URI,
        		AudioAlbumThumbnailQuery.PROJECTION, Audio.Media.DATA + " LIKE ?",
        		new String[] { path.replaceAll("'", "''") }, Audio.Media.DATE_MODIFIED + " DESC");
        if (cursor.moveToFirst()) {
            return cursor.getLong(AudioAlbumThumbnailQuery.ALBUM_ID);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    throw new FileNotFoundException("No Audio found for album");
}
 
Example 13
Project: chat-sdk-android-push-firebase   File: FollowerLinkDao.java   Source Code and License Vote up 5 votes
/** @inheritdoc */
@Override
public FollowerLink readEntity(Cursor cursor, int offset) {
    FollowerLink entity = new FollowerLink( //
        cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
        cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1), // type
        cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2), // BUserDaoId
        cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3) // linkOwnerBUserDaoId
    );
    return entity;
}
 
Example 14
Project: mobile-store   File: ApkProvider.java   Source Code and License Vote up 5 votes
@Override
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    if (MATCHER.match(uri) != CODE_APK_FROM_REPO) {
        throw new UnsupportedOperationException("Cannot update anything other than a single apk.");
    }

    boolean saveAntiFeatures = false;
    String[] antiFeatures = null;
    if (values.containsKey(Cols.AntiFeatures.ANTI_FEATURES)) {
        saveAntiFeatures = true;
        String antiFeaturesString = values.getAsString(Cols.AntiFeatures.ANTI_FEATURES);
        antiFeatures = Utils.parseCommaSeparatedString(antiFeaturesString);
        values.remove(Cols.AntiFeatures.ANTI_FEATURES);
    }

    validateFields(Cols.ALL, values);
    removeFieldsFromOtherTables(values);

    QuerySelection query = new QuerySelection(where, whereArgs);
    query = query.add(querySingleWithAppId(uri));

    int numRows = db().update(getTableName(), values, query.getSelection(), query.getArgs());

    if (saveAntiFeatures) {
        // Get the database ID of the row we just updated, so that we can join relevant anti features to it.
        Cursor result = db().query(getTableName(), new String[]{Cols.ROW_ID},
                query.getSelection(), query.getArgs(), null, null, null);
        if (result != null) {
            result.moveToFirst();
            long apkId = result.getLong(0);
            ensureAntiFeatures(antiFeatures, apkId);
            result.close();
        }
    }

    if (!isApplyingBatch()) {
        getContext().getContentResolver().notifyChange(uri, null);
    }
    return numRows;
}
 
Example 15
Project: popomusic   File: MusicBeanDao.java   Source Code and License Vote up 4 votes
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
 
Example 16
Project: sctalk   File: MessageDao.java   Source Code and License Vote up 4 votes
/** @inheritdoc */
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
 
Example 17
Project: RLibrary   File: ImageDataSource.java   Source Code and License Vote up 4 votes
public static ArrayList<ImageItem> queryRecentlyPhoto(ContentResolver contentResolver, long recentlyTime /*最近多长时间的照片, 秒*/) {
    final String[] IMAGE_PROJECTION = {
            MediaStore.Images.Media.DISPLAY_NAME,
            MediaStore.Images.Media.DATA,
            MediaStore.Images.Media.SIZE,
            MediaStore.Images.Media.WIDTH,
            MediaStore.Images.Media.HEIGHT,
            MediaStore.Images.Media.MIME_TYPE,
            MediaStore.Images.Media.DATE_ADDED};

    Cursor query = contentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            IMAGE_PROJECTION, IMAGE_PROJECTION[6] + ">" + recentlyTime,
            null, IMAGE_PROJECTION[6] + " DESC" /*按照时间降序*/);
    ArrayList<ImageItem> allImages = new ArrayList<>();
    if (query != null) {
        while (query.moveToNext()) {
            //查询数据
            String imageName = query.getString(query.getColumnIndexOrThrow(IMAGE_PROJECTION[0]));
            String imagePath = query.getString(query.getColumnIndexOrThrow(IMAGE_PROJECTION[1]));
            long imageSize = query.getLong(query.getColumnIndexOrThrow(IMAGE_PROJECTION[2]));
            int imageWidth = query.getInt(query.getColumnIndexOrThrow(IMAGE_PROJECTION[3]));
            int imageHeight = query.getInt(query.getColumnIndexOrThrow(IMAGE_PROJECTION[4]));
            String imageMimeType = query.getString(query.getColumnIndexOrThrow(IMAGE_PROJECTION[5]));
            long imageAddTime = query.getLong(query.getColumnIndexOrThrow(IMAGE_PROJECTION[6]));

            File imageFile = new File(imagePath);
            if (!imageFile.exists() || !imageFile.isFile()) {
                continue;
            }

            //封装实体
            ImageItem imageItem = new ImageItem(IMAGE);
            imageItem.name = imageName;
            imageItem.path = imagePath;
            imageItem.size = imageSize;
            imageItem.width = imageWidth;
            imageItem.height = imageHeight;
            imageItem.mimeType = imageMimeType;
            imageItem.addTime = imageAddTime;
            //imageItem.placeholderDrawable = ContextCompat.getDrawable(activity, R.drawable.image_placeholder_shape);

            allImages.add(imageItem);
        }
        query.close();
    }
    //L.e("call: initOnShowContentLayout -> ${allImages.size}");
    return allImages;
}
 
Example 18
Project: Taxi-Datalogger   File: CloudPublisherService.java   Source Code and License Vote up 4 votes
@WorkerThread
void processCollectedSensorData() throws JSONException {
    if (mPublisher == null || !mPublisher.isReady()) {
        return;
    }

    // Query the data we wish to push to the cloud
    long lastSyndId = DatalogDbHelper.getLastSyncId(this);
    Cursor cursor = mDatabase.query(DatalogDbHelper.TABLE_NAME,
            null,
            DatalogDbHelper.DatalogEntry._ID + " > " + lastSyndId,
            null,
            null,
            null,
            BaseColumns._ID + " ASC");
    Log.i(TAG, "publishing " + cursor.getCount() + " log entries");

    final int columnCount = cursor.getColumnCount();
    for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
        JSONObject entryObject = new JSONObject();
        // Add the device ID to the JSON record.
        //
        // FIXME: There should be a way to get Google Cloud IOT to do this on its
        // end, so I don't need to trust the IDs.
        entryObject.put("deviceId", mDeviceId);
        long id = 0;
        for (int i = 0; i < columnCount; i++) {
            String columnName = cursor.getColumnName(i);
            if (columnName != null) {
                // Note the most recent ID we've transmitted, but don't include
                // the ID column in the JSON message
                if (columnName.equals(BaseColumns._ID)) {
                    id = cursor.getLong(i);
                    continue;
                }
                if (cursor.getType(i) == Cursor.FIELD_TYPE_FLOAT) {
                    entryObject.put(columnName, cursor.getDouble(i));
                } else {
                    entryObject.put(columnName, cursor.getString(i));
                }
            }
        }
        // Push message to the cloud
        mPublisher.publish(entryObject.toString());
        Log.d(TAG, "Sent entry: " + (cursor.getPosition()+1) + "/" +
                cursor.getCount());
        if (id > lastSyndId)
            DatalogDbHelper.setLastSyncId(this, id);
    }
    cursor.close();
}
 
Example 19
Project: AndroidBackendlessChat   File: ContactLinkDao.java   Source Code and License Vote up 4 votes
/** @inheritdoc */
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
 
Example 20
Project: greendao_expand   File: RepositoryNoteDao.java   Source Code and License Vote up 4 votes
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.getLong(offset + 0);
}