Example usage for android.database Cursor getLong

List of usage examples for android.database Cursor getLong

Introduction

In this page you can find the example usage for android.database Cursor getLong.

Prototype

long getLong(int columnIndex);

Source Link

Document

Returns the value of the requested column as a long.

Usage

From source file:org.ohmage.sync.ResponseSyncAdapter.java

private Observable<Response> uploadOhmagePoint(Cursor cursor, ResponseFiles files)
        throws AuthenticationException {
    // Make the call to upload responses
    return ohmageService.uploadResponse(cursor.getString(1), cursor.getLong(2),
            new ResponseTypedOutput(cursor.getString(3), cursor.getString(4), files)).cache();

}

From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java

/**
 * ?getItem/*  w w w.  j  a va 2 s .c o m*/
 *
 * @param cursor
 * @return
 */
public static ECMessage packageMessage(Cursor cursor) {
    long id = cursor.getLong(cursor.getColumnIndex(IMessageColumn.ID));
    String sender = cursor.getString(cursor.getColumnIndexOrThrow(IMessageColumn.sender));
    String msgId = cursor.getString(cursor.getColumnIndexOrThrow(IMessageColumn.MESSAGE_ID));
    // long ownThreadId =
    // cursor.getLong(cursor.getColumnIndexOrThrow(IMessageColumn.OWN_THREAD_ID));
    long createDate = cursor.getLong(cursor.getColumnIndexOrThrow(IMessageColumn.CREATE_DATE));
    int version = cursor.getInt(cursor.getColumnIndexOrThrow(IMessageColumn.VERSION));
    String userData = cursor.getString(cursor.getColumnIndexOrThrow(IMessageColumn.USER_DATA));
    int read = cursor.getInt(cursor.getColumnIndexOrThrow(IMessageColumn.READ_STATUS));
    int boxType = cursor.getInt(cursor.getColumnIndexOrThrow(IMessageColumn.BOX_TYPE));
    int msgType = cursor.getInt(cursor.getColumnIndexOrThrow(IMessageColumn.MESSAGE_TYPE));
    int sendStatus = cursor.getInt(cursor.getColumnIndexOrThrow(IMessageColumn.SEND_STATUS));

    ECMessage ecMessage = ECMessage.createECMessage(ECMessage.Type.NONE);
    if (msgType == ECMessage.Type.TXT.ordinal() || msgType == Type.NONE.ordinal()) {
        String content = cursor.getString(cursor.getColumnIndexOrThrow(IMessageColumn.BODY));
        ecMessage.setType(ECMessage.Type.TXT);
        ECTextMessageBody textBody = new ECTextMessageBody(content);
        ecMessage.setBody(textBody);
    } else if (msgType == Type.CALL.ordinal()) {
        String content = cursor.getString(cursor.getColumnIndexOrThrow(IMessageColumn.BODY));
        ECCallMessageBody body = new ECCallMessageBody(content);
        ecMessage.setType(Type.CALL);
        ecMessage.setBody(body);
    } else if (msgType == ECMessage.Type.LOCATION.ordinal()) {
        String content = cursor.getString(cursor.getColumnIndexOrThrow(IMessageColumn.BODY));
        ecMessage.setType(ECMessage.Type.LOCATION);

        String lon;
        String lat;
        try {
            JSONObject jsonObject = new JSONObject(content);
            lon = jsonObject.getString("lon");
            lat = jsonObject.getString("lat");
            ECLocationMessageBody textBody = new ECLocationMessageBody(Double.parseDouble(lat),
                    Double.parseDouble(lon));
            textBody.setTitle(jsonObject.getString("title"));
            ecMessage.setBody(textBody);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    else {
        String fileUrl = cursor.getString(cursor.getColumnIndexOrThrow(IMessageColumn.FILE_URL));
        String fileLocalPath = cursor.getString(cursor.getColumnIndexOrThrow(IMessageColumn.FILE_PATH));

        if (msgType == ECMessage.Type.VOICE.ordinal()) {
            ecMessage.setType(ECMessage.Type.VOICE);
            int duration = cursor.getInt(cursor.getColumnIndexOrThrow(IMessageColumn.DURATION));
            ECVoiceMessageBody voiceBody = new ECVoiceMessageBody(new File(fileLocalPath), 0);
            voiceBody.setRemoteUrl(fileUrl);
            ecMessage.setBody(voiceBody);
            voiceBody.setDuration(duration);
        } else if (msgType == ECMessage.Type.IMAGE.ordinal() || msgType == ECMessage.Type.VIDEO.ordinal()
                || msgType == ECMessage.Type.FILE.ordinal()) {
            ECFileMessageBody fileBody = new ECFileMessageBody();
            if (msgType == ECMessage.Type.FILE.ordinal()) {
                ecMessage.setType(ECMessage.Type.FILE);
            } else if (msgType == ECMessage.Type.IMAGE.ordinal()) {
                fileBody = new ECImageMessageBody();
                ecMessage.setType(ECMessage.Type.IMAGE);
            } else {
                fileBody = new ECVideoMessageBody();
                ecMessage.setType(ECMessage.Type.VIDEO);
            }
            fileBody.setLocalUrl(fileLocalPath);
            fileBody.setRemoteUrl(fileUrl);
            fileBody.setFileName(DemoUtils.getFileNameFormUserdata(userData));
            ecMessage.setBody(fileBody);
        } else if (msgType == Type.RICH_TEXT.ordinal()) {
            {
                ECPreviewMessageBody body = new ECPreviewMessageBody();
                ecMessage.setType(Type.RICH_TEXT);
                String content = cursor.getString(cursor.getColumnIndexOrThrow(IMessageColumn.BODY));
                body.setTitle(content);
                body.setLocalUrl(cursor.getString(cursor.getColumnIndexOrThrow(IMessageColumn.FILE_PATH)));
                body.setUrl(cursor.getString(cursor.getColumnIndexOrThrow(IMessageColumn.FILE_URL)));
                ecMessage.setBody(body);
            }
            //            return null;
        }
    }
    ecMessage.setId(id);
    ecMessage.setFrom(sender);
    ecMessage.setMsgId(msgId);
    ecMessage.setMsgTime(createDate);
    ecMessage.setUserData(userData);
    if (sendStatus == ECMessage.MessageStatus.SENDING.ordinal()) {
        ecMessage.setMsgStatus(ECMessage.MessageStatus.SENDING);
    } else if (sendStatus == ECMessage.MessageStatus.RECEIVE.ordinal() || sendStatus == 4) {
        // sendStatus == 4 ?
        ecMessage.setMsgStatus(ECMessage.MessageStatus.RECEIVE);
    } else if (sendStatus == ECMessage.MessageStatus.SUCCESS.ordinal()) {
        ecMessage.setMsgStatus(ECMessage.MessageStatus.SUCCESS);
    } else if (sendStatus == ECMessage.MessageStatus.FAILED.ordinal()) {
        ecMessage.setMsgStatus(ECMessage.MessageStatus.FAILED);
    }
    ecMessage.setDirection(getMessageDirect(boxType));

    return ecMessage;
}

From source file:de.escoand.readdaily.DownloadHandler.java

@Override
public void onReceive(final Context context, final Intent intent) {
    final DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    final Database db = Database.getInstance(context);
    final Cursor downloads = db.getDownloads();

    LogHandler.log(Log.WARN, "receive starting");

    while (downloads.moveToNext()) {
        final long id = downloads.getLong(downloads.getColumnIndex(Database.COLUMN_ID));
        final String name = downloads.getString(downloads.getColumnIndex(Database.COLUMN_SUBSCRIPTION));
        final String mime = downloads.getString(downloads.getColumnIndex(Database.COLUMN_TYPE));
        final Cursor download = manager.query(new DownloadManager.Query().setFilterById(id));

        // download exists
        if (!download.moveToFirst())
            continue;

        // download finished
        if (download.getInt(
                download.getColumnIndex(DownloadManager.COLUMN_STATUS)) != DownloadManager.STATUS_SUCCESSFUL)
            continue;

        // import file in background
        new Thread(new Runnable() {
            @Override/*www .j av  a  2 s. com*/
            public void run() {
                try {
                    LogHandler.log(Log.WARN, "import starting of " + name);

                    final FileInputStream stream = new ParcelFileDescriptor.AutoCloseInputStream(
                            manager.openDownloadedFile(id));
                    final String mimeServer = manager.getMimeTypeForDownloadedFile(id);

                    LogHandler.log(Log.INFO, "id: " + String.valueOf(id));
                    LogHandler.log(Log.INFO, "manager: " + manager.toString());
                    LogHandler.log(Log.INFO, "stream: " + stream.toString());
                    LogHandler.log(Log.INFO, "mime: " + mime);
                    LogHandler.log(Log.INFO, "mimeServer: " + mimeServer);

                    switch (mime != null ? mime : (mimeServer != null ? mimeServer : "")) {

                    // register feedback
                    case "application/json":
                        final byte[] buf = new byte[256];
                        final int len = stream.read(buf);
                        LogHandler.log(Log.WARN, "register feedback: " + new String(buf, 0, len));
                        break;

                    // csv data
                    case "text/plain":
                        db.importCSV(name, stream);
                        break;

                    // xml data
                    case "application/xml":
                    case "text/xml":
                        db.importXML(name, stream);
                        break;

                    // zipped data
                    case "application/zip":
                        db.importZIP(name, stream);
                        break;

                    // do nothing
                    default:
                        LogHandler.log(new IntentFilter.MalformedMimeTypeException());
                        break;
                    }

                    stream.close();
                    LogHandler.log(Log.WARN, "import finished (" + name + ")");
                }

                // file error
                catch (FileNotFoundException e) {
                    LogHandler.logAndShow(e, context, R.string.message_download_open);
                }

                // stream error
                catch (IOException e) {
                    LogHandler.logAndShow(e, context, R.string.message_download_read);
                }

                // xml error
                catch (XmlPullParserException e) {
                    LogHandler.logAndShow(e, context, R.string.message_download_xml);
                }

                // clean
                finally {
                    manager.remove(id);
                    db.removeDownload(id);
                    LogHandler.log(Log.WARN, "clean finished");
                }
            }
        }).start();
    }

    downloads.close();
    LogHandler.log(Log.WARN, "receiving done");
}

From source file:com.wildplot.android.ankistats.CollectionData.java

private void loadCol() {
    Cursor cursor = null;
    try {//w  w w.  j a  v  a  2  s.c o  m
        // Read in deck table columns
        cursor = mAnkiDb.getDatabase()
                .rawQuery("SELECT crt, mod, scm, dty, usn, ls, " + "conf, decks, dconf FROM col", null);
        if (!cursor.moveToFirst()) {
            return;
        }
        mCrt = cursor.getLong(0);
        mMod = cursor.getLong(1);
        mScm = cursor.getLong(2);
        mDty = cursor.getInt(3) == 1; // No longer used
        mUsn = cursor.getInt(4);
        mLs = cursor.getLong(5);
        try {
            mConf = new JSONObject(cursor.getString(6));
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }

        loadDecks(cursor.getString(7), cursor.getString(8));
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:cn.code.notes.gtask.data.TaskList.java

public int getSyncAction(Cursor c) {
    try {//from w w w  .  j a v a  2  s .  c  om
        if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
            // there is no local update
            if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
                // no update both side
                return SYNC_ACTION_NONE;
            } else {
                // apply remote to local
                return SYNC_ACTION_UPDATE_LOCAL;
            }
        } else {
            // validate gtask id
            if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
                Log.e(TAG, "gtask id doesn't match");
                return SYNC_ACTION_ERROR;
            }
            if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
                // local modification only
                return SYNC_ACTION_UPDATE_REMOTE;
            } else {
                // for folder conflicts, just apply local modification
                return SYNC_ACTION_UPDATE_REMOTE;
            }
        }
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
    }

    return SYNC_ACTION_ERROR;
}

From source file:net.bible.service.db.bookmark.BookmarkDBAdapter.java

/** return Dto from current cursor position or null
 * @param c/*from   w  ww . j  a va2s.c  o m*/
 * @return
 * @throws NoSuchKeyException
 */
private BookmarkDto getBookmarkDto(Cursor c) {
    BookmarkDto dto = new BookmarkDto();
    try {
        //Id
        Long id = c.getLong(BookmarkQuery.ID);
        dto.setId(id);

        //Verse
        String key = c.getString(BookmarkQuery.KEY);
        Versification v11n = null;
        if (!c.isNull(BookmarkQuery.VERSIFICATION)) {
            String v11nString = c.getString(BookmarkQuery.VERSIFICATION);
            if (!StringUtils.isEmpty(v11nString)) {
                v11n = Versifications.instance().getVersification(v11nString);
            }
        }
        if (v11n == null) {
            // use default v11n
            v11n = Versifications.instance().getVersification(Versifications.DEFAULT_V11N);
        }
        dto.setVerse(VerseFactory.fromString(v11n, key));

        //Created date
        long created = c.getLong(BookmarkQuery.CREATED_ON);
        dto.setCreatedOn(new Date(created));

    } catch (NoSuchKeyException nke) {
        Log.e(TAG, "Key error", nke);
    }

    return dto;
}

From source file:cn.code.notes.gtask.data.SqlNote.java

private void loadFromCursor(Cursor c) {
    mId = c.getLong(ID_COLUMN);
    mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
    mBgColorId = c.getInt(BG_COLOR_ID_COLUMN);
    mCreatedDate = c.getLong(CREATED_DATE_COLUMN);
    mHasAttachment = c.getInt(HAS_ATTACHMENT_COLUMN);
    mModifiedDate = c.getLong(MODIFIED_DATE_COLUMN);
    mParentId = c.getLong(PARENT_ID_COLUMN);
    mSnippet = c.getString(SNIPPET_COLUMN);
    mType = c.getInt(TYPE_COLUMN);// ww w.  jav  a 2 s  . c om
    mWidgetId = c.getInt(WIDGET_ID_COLUMN);
    mWidgetType = c.getInt(WIDGET_TYPE_COLUMN);
    mVersion = c.getLong(VERSION_COLUMN);
}

From source file:com.asd.littleprincesbeauty.data.TaskList.java

@Override
public int getSyncAction(Cursor c) {
    try {/*ww w .j av  a2  s .c om*/
        if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
            // there is no local update
            if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
                // no update both side
                return SYNC_ACTION_NONE;
            } else {
                // apply remote to local
                return SYNC_ACTION_UPDATE_LOCAL;
            }
        } else {
            // validate gtask id
            if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
                Log.e(TAG, "gtask id doesn't match");
                return SYNC_ACTION_ERROR;
            }
            if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
                // local modification only
                return SYNC_ACTION_UPDATE_REMOTE;
            } else {
                // for folder conflicts, just apply local modification
                return SYNC_ACTION_UPDATE_REMOTE;
            }
        }
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
    }

    return SYNC_ACTION_ERROR;
}

From source file:de.stadtrallye.rallyesoft.model.map.MapManager.java

private void readDatabase(List<Node> nodes, List<Edge> edges) {
    Cursor c = getDb().query(Nodes.TABLE, Nodes.COLS, null, null, null, null, null);

    while (c.moveToNext()) {
        nodes.add(new Node((int) c.getLong(0), c.getString(1), new LatLng(c.getDouble(2), c.getDouble(3)),
                c.getString(4)));// ww w. jav  a 2  s .  co m
    }
    c.close();

    c = getDb().query(Edges.TABLE, Edges.COLS, null, null, null, null, null);

    while (c.moveToNext()) {
        edges.add(new Edge(nodes.get((int) c.getLong(0)), nodes.get((int) c.getLong(1)), c.getString(2)));
    }
    c.close();
}

From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java

/**
 * return Dto from current cursor position or null
 *
 * @param c//from   w  ww. j a v a  2 s .com
 * @return
 * @throws NoSuchKeyException
 */
private BookmarkDto getBookmarkDto(Cursor c) {
    BookmarkDto dto = new BookmarkDto();
    try {
        //Id
        Long id = c.getLong(BookmarkQuery.ID);
        dto.setId(id);

        //Verse
        String key = c.getString(BookmarkQuery.KEY);
        Versification v11n = null;
        if (!c.isNull(BookmarkQuery.VERSIFICATION)) {
            String v11nString = c.getString(BookmarkQuery.VERSIFICATION);
            if (!StringUtils.isEmpty(v11nString)) {
                v11n = Versifications.instance().getVersification(v11nString);
            }
        }
        if (v11n == null) {
            // use default v11n
            v11n = Versifications.instance().getVersification(Versifications.DEFAULT_V11N);
        }
        dto.setVerseRange(VerseRangeFactory.fromString(v11n, key));

        //Created date
        long created = c.getLong(BookmarkQuery.CREATED_ON);
        dto.setCreatedOn(new Date(created));

    } catch (NoSuchKeyException nke) {
        Log.e(TAG, "Key error", nke);
    }

    return dto;
}