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

The following examples show how to use android.database.Cursor#getLong() . 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: LogRunnerReceiver.java    From callmeter with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Save sent WebSMS to db.
 *
 * @param context   {@link Context}
 * @param uri       {@link Uri} to sent message
 * @param mid       message id
 * @param connector connector name
 */
private static void saveWebSMS(final Context context, final String uri, final long mid,
        final String connector) {
    final ContentResolver cr = context.getContentResolver();
    final Cursor c = cr.query(Uri.parse(uri), new String[]{"date"}, null, null, null);
    long date = -1;
    if (c != null && c.moveToFirst()) {
        date = c.getLong(0);
    }
    if (c != null && !c.isClosed()) {
        c.close();
    }
    final ContentValues cv = new ContentValues();
    cv.put(DataProvider.WebSMS.ID, mid);
    cv.put(DataProvider.WebSMS.CONNECTOR, connector);
    cv.put(DataProvider.WebSMS.DATE, date);
    cr.insert(DataProvider.WebSMS.CONTENT_URI, cv);
}
 
Example 2
Source File: ImageDao.java    From ml-authentication with Apache License 2.0 6 votes vote down vote up
@Override
public Image readEntity(Cursor cursor, int offset) {
    Image entity = new Image( //
        cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
        localeConverter.convertToEntityProperty(cursor.getString(offset + 1)), // locale
        cursor.isNull(offset + 2) ? null : timeLastUpdateConverter.convertToEntityProperty(cursor.getLong(offset + 2)), // timeLastUpdate
        cursor.getInt(offset + 3), // revisionNumber
        contentStatusConverter.convertToEntityProperty(cursor.getString(offset + 4)), // contentStatus
        cursor.getString(offset + 5), // contentType
        cursor.isNull(offset + 6) ? null : literacySkillsConverter.convertToEntityProperty(cursor.getString(offset + 6)), // literacySkills
        cursor.isNull(offset + 7) ? null : numeracySkillsConverter.convertToEntityProperty(cursor.getString(offset + 7)), // numeracySkills
        cursor.getString(offset + 8), // title
        imageFormatConverter.convertToEntityProperty(cursor.getString(offset + 9)), // imageFormat
        cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10) // dominantColor
    );
    return entity;
}
 
Example 3
Source File: StockUpdateGetResolver.java    From Reactive-Android-Programming with MIT License 6 votes vote down vote up
@NonNull
@Override
public StockUpdate mapFromCursor(@NonNull Cursor cursor) {

    final int id = cursor.getInt(cursor.getColumnIndexOrThrow(StockUpdateTable.Columns.ID));
    final long dateLong = cursor.getLong(cursor.getColumnIndexOrThrow(StockUpdateTable.Columns.DATE));
    final long priceLong = cursor.getLong(cursor.getColumnIndexOrThrow(StockUpdateTable.Columns.PRICE));
    final String stockSymbol = cursor.getString(cursor.getColumnIndexOrThrow(StockUpdateTable.Columns.STOCK_SYMBOL));
    final String twitterStatus = cursor.getString(cursor.getColumnIndexOrThrow(StockUpdateTable.Columns.TWITTER_STATUS));


    Date date = getDate(dateLong);
    BigDecimal price = getPrice(priceLong);

    final StockUpdate stockUpdate = new StockUpdate(
            stockSymbol,
            price,
            date,
            twitterStatus
    );

    stockUpdate.setId(id);

    return stockUpdate;
}
 
Example 4
Source File: Progress.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
public static Progress parseCursorToBean(Cursor cursor) {
    Progress progress = new Progress();
    progress.tag = cursor.getString(cursor.getColumnIndex(Progress.TAG));
    progress.url = cursor.getString(cursor.getColumnIndex(Progress.URL));
    progress.folder = cursor.getString(cursor.getColumnIndex(Progress.FOLDER));
    progress.filePath = cursor.getString(cursor.getColumnIndex(Progress.FILE_PATH));
    progress.fileName = cursor.getString(cursor.getColumnIndex(Progress.FILE_NAME));
    progress.fraction = cursor.getFloat(cursor.getColumnIndex(Progress.FRACTION));
    progress.totalSize = cursor.getLong(cursor.getColumnIndex(Progress.TOTAL_SIZE));
    progress.currentSize = cursor.getLong(cursor.getColumnIndex(Progress.CURRENT_SIZE));
    progress.status = cursor.getInt(cursor.getColumnIndex(Progress.STATUS));
    progress.priority = cursor.getInt(cursor.getColumnIndex(Progress.PRIORITY));
    progress.date = cursor.getLong(cursor.getColumnIndex(Progress.DATE));
    progress.request = (Request<?, ? extends Request>) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.REQUEST)));
    progress.extra1 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA1)));
    progress.extra2 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA2)));
    progress.extra3 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA3)));
    return progress;
}
 
Example 5
Source File: DeviceDao.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * サービスIDを登録する.
 * 
 * @param db DB操作オブジェクト
 * @param serviceId サービスID
 * @return 登録出来た場合は登録時のIDを返す。重複している場合は登録済みのIDを返す。処理に失敗した場合は-1を返す。
 */
static long insert(final SQLiteDatabase db, final String serviceId) {

    String did = (serviceId != null) ? serviceId : "";
    long result = -1L;
    Cursor cursor = db.query(TABLE_NAME, new String[] {_ID}, SERVICE_ID + "=?", new String[] {did}, null, null,
            null);
    if (cursor.getCount() == 0) {
        ContentValues values = new ContentValues();
        values.put(SERVICE_ID, did);
        values.put(CREATE_DATE, Utils.getCurreTimestamp().getTime());
        values.put(UPDATE_DATE, Utils.getCurreTimestamp().getTime());
        result = db.insert(TABLE_NAME, null, values);
    } else if (cursor.moveToFirst()) {
        if (cursor.getColumnIndex(_ID) != -1) {
            result = cursor.getLong(0);
        }
    }
    cursor.close();
    
    return result;
}
 
Example 6
Source File: LocationService.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
public Track getTrack(long limit) {
    if (mTrackDB == null)
        openDatabase();
    Track track = new Track(getString(R.string.currentTrack), true);
    if (mTrackDB == null)
        return track;
    String limitStr = limit > 0 ? " LIMIT " + limit : "";
    Cursor cursor = mTrackDB.rawQuery("SELECT * FROM track ORDER BY _id DESC" + limitStr, null);
    for (boolean hasItem = cursor.moveToLast(); hasItem; hasItem = cursor.moveToPrevious()) {
        int latitudeE6 = cursor.getInt(cursor.getColumnIndex("latitude"));
        int longitudeE6 = cursor.getInt(cursor.getColumnIndex("longitude"));
        float elevation = cursor.getFloat(cursor.getColumnIndex("elevation"));
        float speed = cursor.getFloat(cursor.getColumnIndex("speed"));
        float bearing = cursor.getFloat(cursor.getColumnIndex("track"));
        float accuracy = cursor.getFloat(cursor.getColumnIndex("accuracy"));
        int code = cursor.getInt(cursor.getColumnIndex("code"));
        long time = cursor.getLong(cursor.getColumnIndex("datetime"));
        track.addPoint(code == 0, latitudeE6, longitudeE6, elevation, speed, bearing, accuracy, time);
    }
    cursor.close();
    return track;
}
 
Example 7
Source File: FeedCursorAdapter.java    From v2ex with Apache License 2.0 6 votes vote down vote up
private static Parcelable cursor2Parcelable(Cursor cursor) {
    int feedId = cursor.getInt(FeedsQuery.FEED_ID);
    String feedTitle = cursor.getString(FeedsQuery.FEED_TITLE);
    String feedContent = cursor.getString(FeedsQuery.FEED_CONTENT);
    String feedContentRendered = cursor.getString(FeedsQuery.FEED_CONTENT_RENDERED);
    String feedMember = cursor.getString(FeedsQuery.FEED_MEMBER);
    String feedNode = cursor.getString(FeedsQuery.FEED_NODE);
    int feedReplies = cursor.getInt(FeedsQuery.FEED_REPLIES);
    long lastModified = cursor.getLong(FeedsQuery.FEED_LAST_MODIFIED);

    Feed feed = new Feed();
    feed.id = feedId;
    feed.title = feedTitle;
    feed.content = feedContent;
    feed.content_rendered = feedContentRendered;
    feed.member = ModelUtils.getAuthor(feedMember);
    feed.node = ModelUtils.getNode(feedNode);
    feed.replies = feedReplies;
    feed.last_modified = lastModified;

    return feed;
}
 
Example 8
Source File: RecordCaseInfoDao.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
@Override
public RecordCaseInfo readEntity(Cursor cursor, int offset) {
    RecordCaseInfo entity = new RecordCaseInfo( //
        cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
        cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // caseName
        cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // caseDesc
        cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // targetAppPackage
        cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // targetAppLabel
        cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // recordMode
        cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // advanceSettings
        cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // operationLog
        cursor.getInt(offset + 8), // priority
        cursor.getLong(offset + 9), // gmtCreate
        cursor.getLong(offset + 10) // gmtModify
    );
    return entity;
}
 
Example 9
Source File: HistoryManager.java    From weex with Apache License 2.0 6 votes vote down vote up
public HistoryItem buildHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  Cursor cursor = null;
  try {
    db = helper.getReadableDatabase();
    cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
    cursor.move(number + 1);
    String text = cursor.getString(0);
    String display = cursor.getString(1);
    String format = cursor.getString(2);
    long timestamp = cursor.getLong(3);
    String details = cursor.getString(4);
    Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
    return new HistoryItem(result, display, details);
  } finally {
    close(cursor, db);
  }
}
 
Example 10
Source File: WallpapersDao.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
/**
 * @inheritdoc
 */
@Override
public Wallpapers readEntity(Cursor cursor, int offset) {
    Wallpapers entity = new Wallpapers( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getBlob(offset + 1) // data
    );
    return entity;
}
 
Example 11
Source File: AlgCursorAdapter.java    From TwistyTimer with GNU General Public License v3.0 5 votes vote down vote up
public void handleTime(final AlgHolder holder, final Cursor cursor) {
    final long mId = cursor.getLong(0); // id
    final String pName = cursor.getString(2);
    final String pSubset = cursor.getString(1);
    final String pState = AlgUtils.getCaseState(mContext, pSubset, pName);
    final int pProgress = cursor.getInt(5);

    holder.root.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (! isLocked()) {
                setIsLocked(true);
                AlgDialog algDialog = AlgDialog.newInstance(mId);
                algDialog.show(mFragmentManager, "alg_dialog");
                algDialog.setDialogListener(AlgCursorAdapter.this);
            }

        }
    });

    holder.name.setText(pName);
    holder.progressBar.setProgress(pProgress);
    holder.cube.setCubeState(pState);

    // If the subset is PLL, it'll need to show the pll arrows.
    if (cursor.getString(1).equals("PLL")) {
        holder.pllArrows.setImageDrawable(AlgUtils.getPllArrow(mContext, pName));
        holder.pllArrows.setVisibility(View.VISIBLE);
    }

}
 
Example 12
Source File: AttributeDao.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * アトリビュートを登録する.
 * 
 * @param db データベース操作オブジェクト
 * @param attribute アトリビュート名
 * @param interfaceId インターフェースID
 * @return 登録出来た場合は登録時のIDを返す。重複している場合は登録済みのIDを返す。処理に失敗した場合は-1を返す。
 */
static long insert(final SQLiteDatabase db, final String attribute, final long interfaceId) {

    String attr = attribute;
    if (attr == null) {
        attr = "";
    }
    
    long result = -1L;
    Cursor cursor = db.query(TABLE_NAME, new String[] {_ID}, NAME + "=? AND " + I_ID + "=?", 
            new String[] {attr, "" + interfaceId}, null, null, null);
    if (cursor.getCount() == 0) {
        ContentValues values = new ContentValues();
        values.put(NAME, attr);
        values.put(I_ID, interfaceId);
        values.put(CREATE_DATE, Utils.getCurreTimestamp().getTime());
        values.put(UPDATE_DATE, Utils.getCurreTimestamp().getTime());
        result = db.insert(TABLE_NAME, null, values);
    } else if (cursor.moveToFirst()) {
        if (cursor.getColumnIndex(_ID) != -1) {
            result = cursor.getLong(0);
        }
    }
    cursor.close();

    return result;
}
 
Example 13
Source File: SubscriberDb.java    From tindroid with Apache License 2.0 5 votes vote down vote up
private static Subscription readOne(Cursor c) {
    // StoredSub part
    StoredSubscription ss = new StoredSubscription();
    ss.id = c.getLong(COLUMN_IDX_ID);
    ss.topicId = c.getLong(COLUMN_IDX_TOPIC_ID);
    ss.userId = c.getLong(COLUMN_IDX_USER_ID);
    ss.status = BaseDb.Status.fromInt(c.getInt(COLUMN_IDX_STATUS));

    // Subscription part
    Subscription s = new Subscription();
    // From subs table
    s.acs = BaseDb.deserializeMode(c.getString(COLUMN_IDX_MODE));
    s.updated = new Date(c.getLong(COLUMN_IDX_UPDATED));
    s.read = c.getInt(COLUMN_IDX_READ);
    s.recv = c.getInt(COLUMN_IDX_RECV);
    s.clear = c.getInt(COLUMN_IDX_CLEAR);
    s.seen = new LastSeen(
            new Date(c.getLong(COLUMN_IDX_LAST_SEEN)),
            c.getString(COLUMN_IDX_USER_AGENT)
    );

    // From user table
    s.user = c.getString(JOIN_USER_COLUMN_IDX_UID);
    s.pub = BaseDb.deserialize(c.getString(JOIN_USER_COLUMN_IDX_PUBLIC));

    // From topic table
    s.topic = c.getString(JOIN_TOPIC_COLUMN_IDX_TOPIC);
    s.seq = c.getInt(JOIN_TOPIC_COLUMN_IDX_SEQ);

    s.setLocal(ss);

    return s;
}
 
Example 14
Source File: FolderFragment.java    From Rey-MusicPlayer with Apache License 2.0 5 votes vote down vote up
private Song getSongs(String[] whereArgs) {
    Song song = null;
    String[] columns = {
            BaseColumns._ID,
            MediaStore.Audio.Media.TITLE,
            MediaStore.Audio.Media.ALBUM,
            MediaStore.Audio.Media.ALBUM_ID,
            MediaStore.Audio.Media.ARTIST,
            MediaStore.Audio.Media.ARTIST_ID,
            MediaStore.Audio.Media.DATA,
            MediaStore.Audio.Media.TRACK,
            MediaStore.Audio.Media.DURATION
    };
    Cursor cursor = getActivity().getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            columns,
            MediaStore.Audio.Media.DATA + " LIKE ?", whereArgs, MediaStore.Audio.Media.TITLE);
    if (cursor != null && cursor.moveToFirst()) {
        do {
            song = new Song(
                    cursor.getLong(0),
                    cursor.getString(1),
                    cursor.getString(2),
                    cursor.getLong(3),
                    cursor.getString(4),
                    cursor.getLong(5),
                    cursor.getString(6),
                    cursor.getInt(7),
                    cursor.getLong(8));
        } while (cursor.moveToNext());
    }
    return song;
}
 
Example 15
Source File: FileBackend.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
public static long getFileSize(Context context, Uri uri) {
    try {
        final Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            long size = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
            cursor.close();
            return size;
        } else {
            return -1;
        }
    } catch (Exception e) {
        return -1;
    }
}
 
Example 16
Source File: MusicLibraryHelper.java    From odyssey with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return a list of all tracks of an album.
 *
 * @param context  The application context to access the content resolver.
 * @param albumKey The key to identify the album in the MediaStore
 * @return The list of {@link TrackModel} of all tracks for the given album.
 */
public static List<TrackModel> getTracksForAlbum(final String albumKey, final Context context) {
    final List<TrackModel> albumTracks = new ArrayList<>();

    final String[] whereVal = {albumKey};

    final String where = ProjectionTracks.ALBUM_KEY + "=?";

    final String orderBy = ProjectionTracks.TRACK;

    final Cursor cursor = PermissionHelper.query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, ProjectionTracks.PROJECTION, where, whereVal, orderBy);

    if (cursor != null) {
        // get all tracks on the current album
        if (cursor.moveToFirst()) {
            do {
                final String trackName = cursor.getString(cursor.getColumnIndex(ProjectionTracks.TITLE));
                final long duration = cursor.getLong(cursor.getColumnIndex(ProjectionTracks.DURATION));
                final int number = cursor.getInt(cursor.getColumnIndex(ProjectionTracks.TRACK));
                final String artistName = cursor.getString(cursor.getColumnIndex(ProjectionTracks.ARTIST));
                final String albumName = cursor.getString(cursor.getColumnIndex(ProjectionTracks.ALBUM));
                final String url = cursor.getString(cursor.getColumnIndex(ProjectionTracks.DATA));
                final long id = cursor.getLong(cursor.getColumnIndex(ProjectionTracks.ID));

                // add current track
                albumTracks.add(new TrackModel(trackName, artistName, albumName, albumKey, duration, number, url, id));

            } while (cursor.moveToNext());
        }

        cursor.close();
    }

    return albumTracks;
}
 
Example 17
Source File: DepartmentDao.java    From sctalk with Apache License 2.0 4 votes vote down vote up
/** @inheritdoc */
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
 
Example 18
Source File: FileOfficeScanManager.java    From YCAudioPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * 通过文件类型得到相应文件的集合
 **/
public List<OfficeBean> getFilesByType(Context context , int fileType) {
    List<OfficeBean> files = new ArrayList<>();
    // 扫描files文件库
    Cursor c = null;
    try {
        c = context.getContentResolver()
                .query(MediaStore.Files.getContentUri("external"),
                        new String[]{"_id", "_data", "_size"},
                        null,
                        null,
                        null);

        if (c == null) {
            return files;
        }


        int dataIndex = c.getColumnIndex(MediaStore.Files.FileColumns.DATA);
        int sizeIndex = c.getColumnIndex(MediaStore.Files.FileColumns.SIZE);

        while (c.moveToNext()) {
            String path = c.getString(dataIndex);

            if (getFileType(path) == fileType) {
                if (!new File(path).exists()) {
                    continue;
                }
                long size = c.getLong(sizeIndex);
                OfficeBean fileBean = new OfficeBean(path, getFileIconByPath(path));
                files.add(fileBean);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return files;
}
 
Example 19
Source File: Utils.java    From sqlitemagic with Apache License 2.0 4 votes vote down vote up
@Override
public Byte parseFromCursor(@NonNull Cursor fastCursor) {
  return (byte) fastCursor.getLong(0);
}
 
Example 20
Source File: UserDao.java    From enjoyshop with Apache License 2.0 4 votes vote down vote up
@Override
public Long readKey(Cursor cursor, int offset) {
    return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}